]> granicus.if.org Git - strace/blobdiff - count.c
Improve code readability by avoiding assignments inside if()
[strace] / count.c
diff --git a/count.c b/count.c
index 5c285fb14431b25aad65895987198fcc1d6cb5ec..625ed4e53d3e537a6ee616ee01761179ff2a7430 100644 (file)
--- a/count.c
+++ b/count.c
@@ -50,15 +50,12 @@ static struct timeval shortest = { 1000000, 0 };
 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);
@@ -71,12 +68,10 @@ count_syscall(struct tcb *tcp, struct timeval *tv)
 
        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;
 
@@ -89,8 +84,7 @@ count_syscall(struct tcb *tcp, struct timeval *tv)
 
                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
@@ -132,7 +126,7 @@ static int (*sortfun)();
 static struct timeval overhead = { -1, -1 };
 
 void
-set_sortby(char *sortby)
+set_sortby(const char *sortby)
 {
        if (strcmp(sortby, "time") == 0)
                sortfun = time_cmp;
@@ -142,8 +136,7 @@ set_sortby(char *sortby)
                sortfun = syscall_cmp;
        else if (strcmp(sortby, "nothing") == 0)
                sortfun = NULL;
-       else
-       {
+       else {
                fprintf(stderr, "invalid sortby: `%s'\n", sortby);
                exit(1);
        }
@@ -162,19 +155,21 @@ call_summary_pers(FILE *outf)
        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;
@@ -191,10 +186,8 @@ call_summary_pers(FILE *outf)
                "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;
@@ -205,9 +198,8 @@ call_summary_pers(FILE *outf)
                                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);
@@ -221,18 +213,17 @@ call_summary_pers(FILE *outf)
                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;