int
count_syscall(struct tcb *tcp, struct timeval *tv)
{
- tcp->flags &= ~TCB_INSYSCALL;
if (tcp->scno < 0 || tcp->scno >= nsyscalls)
return 0;
- if (!counts)
- {
+ if (!counts) {
counts = calloc(nsyscalls, sizeof(*counts));
- if (!counts)
- {
+ if (!counts) {
fprintf(stderr,
"strace: out of memory for call counts\n");
exit(1);
tv_sub(tv, tv, &tcp->etime);
#ifdef LINUX
- if (tv_cmp(tv, &tcp->dtime) > 0)
- {
+ if (tv_cmp(tv, &tcp->dtime) > 0) {
static struct timeval one_tick;
- if (one_tick.tv_usec == 0)
- {
+ if (one_tick.tv_usec == 0) {
/* Initialize it. */
struct itimerval it;
if (tv_nz(&tcp->dtime))
*tv = tcp->dtime;
- else if (tv_cmp(tv, &one_tick) > 0)
- {
+ else if (tv_cmp(tv, &one_tick) > 0) {
if (tv_cmp(&shortest, &one_tick) < 0)
*tv = shortest;
else
static struct timeval overhead = { -1, -1 };
void
-set_sortby(char *sortby)
+set_sortby(const char *sortby)
{
if (strcmp(sortby, "time") == 0)
sortfun = time_cmp;
sortfun = syscall_cmp;
else if (strcmp(sortby, "nothing") == 0)
sortfun = NULL;
- else
- {
+ else {
fprintf(stderr, "invalid sortby: `%s'\n", sortby);
exit(1);
}
int call_cum, error_cum;
struct timeval tv_cum, dtv;
double percent;
- char *dashes = "-------------------------";
+ const char *dashes = "-------------------------";
char error_str[16];
-
int *sorted_count = calloc(sizeof(int), nsyscalls);
+ if (!sorted_count) {
+ fprintf(stderr, "strace: out of memory for call summary\n");
+ return;
+ }
+
call_cum = error_cum = tv_cum.tv_sec = tv_cum.tv_usec = 0;
- if (overhead.tv_sec == -1)
- {
+ if (overhead.tv_sec == -1) {
tv_mul(&overhead, &shortest, 8);
tv_div(&overhead, &overhead, 10);
}
- for (i = 0; i < nsyscalls; i++)
- {
+ for (i = 0; i < nsyscalls; i++) {
sorted_count[i] = i;
if (counts == NULL || counts[i].calls == 0)
continue;
"calls", "errors", "syscall");
fprintf(outf, "%6.6s %11.11s %11.11s %9.9s %9.9s %-16.16s\n",
dashes, dashes, dashes, dashes, dashes, dashes);
- if (counts)
- {
- for (i = 0; i < nsyscalls; i++)
- {
+ if (counts) {
+ for (i = 0; i < nsyscalls; i++) {
j = sorted_count[i];
if (counts[j].calls == 0)
continue;
error_str[0] = '\0';
percent = (100.0 * tv_float(&counts[j].time)
/ tv_float(&tv_cum));
- fprintf(outf, "%6.2f %4ld.%06ld %11ld %9d %9.9s %s\n",
- percent, (long) counts[j].time.tv_sec,
- (long) counts[j].time.tv_usec,
+ fprintf(outf, "%6.2f %11.6f %11ld %9d %9.9s %s\n",
+ percent, tv_float(&counts[j].time),
(long) 1000000 * dtv.tv_sec + dtv.tv_usec,
counts[j].calls,
error_str, sysent[j].sys_name);
sprintf(error_str, "%d", error_cum);
else
error_str[0] = '\0';
- fprintf(outf, "%6.6s %4ld.%06ld %11.11s %9d %9.9s %s\n",
- "100.00", (long) tv_cum.tv_sec, (long) tv_cum.tv_usec, "",
+ fprintf(outf, "%6.6s %11.6f %11.11s %9d %9.9s %s\n",
+ "100.00", tv_float(&tv_cum), "",
call_cum, error_str, "total");
}
void
call_summary(FILE *outf)
{
- int i, old_pers = current_personality;
+ int i, old_pers = current_personality;
- for (i = 0; i < SUPPORTED_PERSONALITIES; ++i)
- {
+ for (i = 0; i < SUPPORTED_PERSONALITIES; ++i) {
if (!countv[i])
continue;