diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-03-30 16:05:46 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-03-30 16:05:46 -0400 |
commit | 4c1493a5ec7b48170e5edce24ccebdf925c62a17 (patch) | |
tree | 81dbcf6efb2eef9d77a80b674906c039fad4ff4b /lib | |
parent | 81a87ac139e26b1746c0370a4453bf5938e8eba9 (diff) | |
download | spmc-4c1493a5ec7b48170e5edce24ccebdf925c62a17.tar.gz |
Fix shell command benchmarking
Diffstat (limited to 'lib')
-rw-r--r-- | lib/shell.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/lib/shell.c b/lib/shell.c index 6b28e64..18781c0 100644 --- a/lib/shell.c +++ b/lib/shell.c @@ -32,7 +32,8 @@ void shell(Process **proc_info, u_int64_t option, const char *fmt, ...) { va_list args; va_start(args, fmt); - clockid_t clkid = CLOCK_REALTIME; + clockid_t clockid = CLOCK_REALTIME; + struct timespec start, stop; FILE *proc = NULL; (*proc_info) = (Process *)calloc(1, sizeof(Process)); @@ -57,7 +58,7 @@ void shell(Process **proc_info, u_int64_t option, const char *fmt, ...) { vsnprintf(cmd, PATH_MAX, fmt, args); if (option & SHELL_BENCHMARK) { - if (clock_gettime(clkid, &(*proc_info)->start_time) == -1) { + if (clock_gettime(clockid, &start) < 0) { perror("clock_gettime"); exit(errno); } @@ -70,15 +71,6 @@ void shell(Process **proc_info, u_int64_t option, const char *fmt, ...) { return; } - if (option & SHELL_BENCHMARK) { - if (clock_gettime(clkid, &(*proc_info)->stop_time) == -1) { - perror("clock_gettime"); - exit(errno); - } - (*proc_info)->time_elapsed = ((*proc_info)->stop_time.tv_sec - (*proc_info)->start_time.tv_sec) - + ((*proc_info)->stop_time.tv_nsec - (*proc_info)->start_time.tv_nsec) / 1E9; - } - if (option & SHELL_OUTPUT) { size_t bytes_read = 0; size_t i = 0; @@ -99,6 +91,15 @@ void shell(Process **proc_info, u_int64_t option, const char *fmt, ...) { } } (*proc_info)->returncode = pclose(proc); + + if (option & SHELL_BENCHMARK) { + if (clock_gettime(clockid, &stop) < 0) { + perror("clock_gettime"); + exit(errno); + } + (*proc_info)->time_elapsed = (double)(stop.tv_sec - start.tv_sec) + (double)(stop.tv_nsec - start.tv_nsec) / 1E9;; + } + va_end(args); free(outbuf); free(cmd); |