summaryrefslogtreecommitdiff
path: root/syscall.c
diff options
context:
space:
mode:
authorDmitry V. Levin <ldv@altlinux.org>2018-03-16 00:55:58 +0000
committerDmitry V. Levin <ldv@altlinux.org>2018-03-20 02:30:24 +0000
commit17935497e2f4e78b183026e1a49f4c279d0f276e (patch)
tree66de6bded848dd874567c306c21136e811829f88 /syscall.c
parentdfccb60a75643a4db345f8bfa3ad6f9fbc5560e6 (diff)
downloadstrace-17935497e2f4e78b183026e1a49f4c279d0f276e.tar.gz
Replace struct timeval with struct timespec in time measurements
This is required to implement more precise time measurements. * Makefile.am (strace_LDADD): Add $(clock_LIBS). * defs.h (struct tcb): Change the type of stime, dtime, and etime fields from struct timeval to struct timespec, all users updated. (syscall_exiting_decode, syscall_exiting_trace, count_syscall): Change the type of "struct timeval *" argument to "struct timespec *", all users updated. (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_div, tv_mul): Rename to ts_nz, ts_cmp, ts_float, ts_add, ts_sub, ts_div, and ts_mul. Change the type of all "struct timeval *" arguments to "struct timespec *", all users updated. * util.c (tv_nz, tv_cmp, tv_float, tv_add, tv_sub, tv_div, tv_mul): Rename to ts_nz, ts_cmp, ts_float, ts_add, ts_sub, ts_div, and ts_mul. Change the type of all "struct timeval *" arguments to "struct timespec *". * count.c (struct call_counts): Change the type of "time" field from struct timeval to struct timespec, all users updated. (overhead): Change type from struct timeval to struct timespec, all users updated. (count_syscall): Change the type of "struct timeval *" argument to "struct timespec *". * strace.c (printleader): Change the type of struct timeval variables to struct timespec, call clock_gettime instead of gettimeofday. (next_event, trace_syscall): Change the type of struct timeval variables to struct timespec. * syscall.c (syscall_entering_finish, syscall_exiting_decode): Call clock_gettime instead of gettimeofday.
Diffstat (limited to 'syscall.c')
-rw-r--r--syscall.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/syscall.c b/syscall.c
index 24263b692..75e15b6e1 100644
--- a/syscall.c
+++ b/syscall.c
@@ -711,7 +711,7 @@ syscall_entering_finish(struct tcb *tcp, int res)
tcp->sys_func_rval = res;
/* Measure the entrance time as late as possible to avoid errors. */
if ((Tflag || cflag) && !filtered(tcp))
- gettimeofday(&tcp->etime, NULL);
+ clock_gettime(CLOCK_MONOTONIC, &tcp->etime);
}
/* Returns:
@@ -723,11 +723,11 @@ syscall_entering_finish(struct tcb *tcp, int res)
* value. Anyway, call syscall_exiting_finish(tcp) then.
*/
int
-syscall_exiting_decode(struct tcb *tcp, struct timeval *ptv)
+syscall_exiting_decode(struct tcb *tcp, struct timespec *pts)
{
/* Measure the exit time as early as possible to avoid errors. */
if ((Tflag || cflag) && !(filtered(tcp) || hide_log(tcp)))
- gettimeofday(ptv, NULL);
+ clock_gettime(CLOCK_MONOTONIC, pts);
if (mmap_cache_is_enabled()) {
if (tcp->s_ent->sys_flags & STACKTRACE_INVALIDATE_CACHE)
@@ -745,13 +745,13 @@ syscall_exiting_decode(struct tcb *tcp, struct timeval *ptv)
}
int
-syscall_exiting_trace(struct tcb *tcp, struct timeval tv, int res)
+syscall_exiting_trace(struct tcb *tcp, struct timespec *ts, int res)
{
if (syscall_tampered(tcp))
tamper_with_syscall_exiting(tcp);
if (cflag) {
- count_syscall(tcp, &tv);
+ count_syscall(tcp, ts);
if (cflag == CFLAG_ONLY_STATS) {
return 0;
}
@@ -942,9 +942,9 @@ syscall_exiting_trace(struct tcb *tcp, struct timeval tv, int res)
tprints(" (INJECTED)");
}
if (Tflag) {
- tv_sub(&tv, &tv, &tcp->etime);
+ ts_sub(ts, ts, &tcp->etime);
tprintf(" <%ld.%06ld>",
- (long) tv.tv_sec, (long) tv.tv_usec);
+ (long) ts->tv_sec, (long) ts->tv_nsec / 1000);
}
tprints("\n");
dumpio(tcp);