aboutsummaryrefslogtreecommitdiff
path: root/src/fetchkeys.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fetchkeys.c')
-rw-r--r--src/fetchkeys.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/fetchkeys.c b/src/fetchkeys.c
index a655a0d..694f4d9 100644
--- a/src/fetchkeys.c
+++ b/src/fetchkeys.c
@@ -9,6 +9,7 @@
#include <assert.h>
#include <sys/time.h>
#include <sys/stat.h>
+#include <sys/resource.h>
#include "gdbmdefs.h"
static unsigned long
@@ -173,6 +174,16 @@ readkeys (char const *name)
}
}
+static struct timeval
+get_cpu_time (void)
+{
+ struct rusage usage;
+ struct timeval res;
+ assert (getrusage (RUSAGE_SELF, &usage) == 0);
+ timeradd (&usage.ru_utime, &usage.ru_stime, &res);
+ return res;
+}
+
int
main (int argc, char **argv)
{
@@ -245,10 +256,10 @@ main (int argc, char **argv)
signal (SIGUSR1, sighan);
#endif
- gettimeofday (&t_start, NULL);
+ t_start = get_cpu_time ();
dbf = gdbm_open (dbname, 0, GDBM_READER | flags, 00664, NULL);
assert (dbf != NULL);
- gettimeofday (&t_open, NULL);
+ t_open = get_cpu_time ();
if (maxsize)
{
@@ -269,7 +280,7 @@ main (int argc, char **argv)
if (verbose)
{
unsigned long long k = (unsigned long long) i * 100 / nkeys;
- gettimeofday (&t_now, NULL);
+ t_now = get_cpu_time ();
timersub (&t_now, &t_start, &td);
printf ("%8u %6zu / %6zu % 2d%%\r", td.tv_sec, i, nkeys, k);
fflush (stdout);
@@ -323,12 +334,11 @@ main (int argc, char **argv)
}
}
}
- gdbm_close (dbf);
if (verbose)
putchar ('\n');
if (time_verbose)
{
- gettimeofday (&t_now, NULL);
+ t_now = get_cpu_time ();
timersub (&t_now, &t_start, &td);
printf ("%lu.%06lu\n", td.tv_sec, td.tv_usec);
timersub (&t_open, &t_start, &td);
@@ -336,6 +346,7 @@ main (int argc, char **argv)
timersub (&t_now, &t_open, &td);
printf ("%lu.%06lu\n", td.tv_sec, td.tv_usec);
}
+ gdbm_close (dbf);
return status;
}

Return to:

Send suggestions and report system problems to the System administrator.