aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2021-08-17 18:48:51 +0300
committerSergey Poznyakoff <gray@gnu.org>2021-09-03 13:23:50 +0300
commitc4d69594f6285bc050db43828fac333588401511 (patch)
tree21659aad0b8ff89554a9dad26c6fde158454b787 /src
parent3028d909b5386cf9c1b7a87e8b590d12dc9ec443 (diff)
downloadgdbm-c4d69594f6285bc050db43828fac333588401511.tar.gz
gdbm-c4d69594f6285bc050db43828fac333588401511.tar.bz2
gdbmtool: optionally print real execution time at the end of each command
* src/gdbmshell.c (run_command): Print real execution time, if the "timing" variable is set. * src/var.c: New boolean variable: timing
Diffstat (limited to 'src')
-rw-r--r--src/gdbmshell.c16
-rw-r--r--src/var.c4
2 files changed, 19 insertions, 1 deletions
diff --git a/src/gdbmshell.c b/src/gdbmshell.c
index f1742e7..24dd37c 100644
--- a/src/gdbmshell.c
+++ b/src/gdbmshell.c
@@ -24,6 +24,7 @@
#include <pwd.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
+#include <sys/time.h>
#include <termios.h>
#include <stdarg.h>
#ifdef HAVE_LOCALE_H
@@ -2425,6 +2426,10 @@ run_last_command (void)
return 0;
}
+#define DIFFTIME(now,then)\
+ (((now).tv_sec - (then).tv_sec) \
+ + ((double)((now).tv_usec - (then).tv_usec))/1000000)
+
int
run_command (struct command *cmd, struct gdbmarglist *arglist)
{
@@ -2437,6 +2442,7 @@ run_command (struct command *cmd, struct gdbmarglist *arglist)
struct command_param param = HANDLER_PARAM_INITIALIZER;
struct command_environ cenv = COMMAND_ENVIRON_INITIALIZER;
int rc = 0;
+ struct timeval start, stop;
variable_get ("pager", VART_STRING, (void**) &pager);
@@ -2517,13 +2523,21 @@ run_command (struct command *cmd, struct gdbmarglist *arglist)
}
else
cenv.fp = stdout;
-
+
+ gettimeofday (&start, NULL);
rc = cmd->handler (&param, &cenv);
+ gettimeofday (&stop, NULL);
if (cmd->end)
cmd->end (cenv.data);
else if (cenv.data)
free (cenv.data);
+ if (variable_is_true ("timing"))
+ {
+ double t = DIFFTIME (stop, start);
+ fprintf (cenv.fp, "[t=%0.9f]\n", t);
+ }
+
if (pagfp)
pclose (pagfp);
}
diff --git a/src/var.c b/src/var.c
index f15a291..ab312a3 100644
--- a/src/var.c
+++ b/src/var.c
@@ -186,6 +186,10 @@ static struct variable vartab[] = {
.sethook = errormask_sethook,
.typeconv = errormask_typeconv
},
+ {
+ .name = "timing",
+ .type = VART_BOOL
+ },
{ NULL }
};

Return to:

Send suggestions and report system problems to the System administrator.