diff options
author | Joseph Hunkeler <jhunkeler@users.noreply.github.com> | 2020-03-30 16:22:24 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-30 16:22:24 -0400 |
commit | 70b7285967f9d5e6f8a8c4624b69ebf1adedca76 (patch) | |
tree | a31c8cb8c169c9f70c5c93759d578b15a7ebc489 /lib/shell.c | |
parent | 81a87ac139e26b1746c0370a4453bf5938e8eba9 (diff) | |
parent | 7f55a9a3bbec144718a3df24d30fc0a98534667d (diff) | |
download | spmc-70b7285967f9d5e6f8a8c4624b69ebf1adedca76.tar.gz |
Merge pull request #8 from jhunkeler/shell-test
Add shell test
Diffstat (limited to 'lib/shell.c')
-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); |