static struct call_counts *countv[SUPPORTED_PERSONALITIES];
#define counts (countv[current_personality])
-static struct timeval shortest = { 1000000, 0 };
+static struct timeval overhead;
void
count_syscall(struct tcb *tcp, const struct timeval *syscall_exiting_tv)
{
- struct timeval wtv;
- struct timeval *tv = &wtv;
- struct call_counts *cc;
-
if (!scno_in_range(tcp->scno))
return;
if (!counts)
counts = xcalloc(nsyscalls, sizeof(*counts));
- cc = &counts[tcp->scno];
+ struct call_counts *cc = &counts[tcp->scno];
cc->calls++;
if (syserror(tcp))
cc->errors++;
- /* tv = wall clock time spent while in syscall */
- tv_sub(tv, syscall_exiting_tv, &tcp->etime);
-
- /* Spent more wall clock time than spent system time? (usually yes) */
- if (tv_cmp(tv, &tcp->dtime) > 0) {
- static struct timeval one_tick = { -1, 0 };
+ if (count_wallclock) {
+ /* wall clock time spent while in syscall */
+ struct timeval wtv;
+ tv_sub(&wtv, syscall_exiting_tv, &tcp->etime);
- if (one_tick.tv_sec == -1) {
- /* Initialize it. */
- struct itimerval it;
-
- memset(&it, 0, sizeof(it));
- it.it_interval.tv_usec = 1;
- setitimer(ITIMER_REAL, &it, NULL);
- getitimer(ITIMER_REAL, &it);
- one_tick = it.it_interval;
-//FIXME: this hack doesn't work (tested on linux-3.6.11): one_tick = 0.000000
-//tprintf(" one_tick.tv_usec:%u\n", (unsigned)one_tick.tv_usec);
- }
-
- if (tv_nz(&tcp->dtime))
- /* tv = system time spent, if it isn't 0 */
- tv = &tcp->dtime;
- else if (tv_cmp(tv, &one_tick) > 0) {
- /* tv = smallest "sane" time interval */
- if (tv_cmp(&shortest, &one_tick) < 0)
- tv = &shortest;
- else
- tv = &one_tick;
- }
+ tv_add(&cc->time, &cc->time, &wtv);
+ } else {
+ /* system CPU time spent while in syscall */
+ tv_add(&cc->time, &cc->time, &tcp->dtime);
}
- if (tv_cmp(tv, &shortest) < 0)
- shortest = *tv;
- tv_add(&cc->time, &cc->time, count_wallclock ? &wtv : tv);
}
static int
}
static int (*sortfun)();
-static struct timeval overhead = { -1, -1 };
void
set_sortby(const char *sortby)
sorted_count = xcalloc(sizeof(sorted_count[0]), nsyscalls);
call_cum = error_cum = tv_cum.tv_sec = tv_cum.tv_usec = 0;
- if (overhead.tv_sec == -1) {
- tv_mul(&overhead, &shortest, 8);
- tv_div(&overhead, &overhead, 10);
- }
for (i = 0; i < nsyscalls; i++) {
sorted_count[i] = i;
if (counts == NULL || counts[i].calls == 0)