]> granicus.if.org Git - strace/commitdiff
Optimize tabto()
authorDenys Vlasenko <dvlasenk@redhat.com>
Wed, 24 Aug 2011 23:27:59 +0000 (01:27 +0200)
committerDenys Vlasenko <dvlasenk@redhat.com>
Wed, 24 Aug 2011 23:27:59 +0000 (01:27 +0200)
tabto is used in many lines of strace output.
On glibc, tprintf("%*s", col - curcol, "") is noticeably slow
compared to tprintf("                 "). Use the latter.
Observed ~15% reduction of time spent in userspace.

* defs.h: Drop extern declaration of acolumn. Make tabto()
take no parameters.
* process.c (sys_exit): Call tabto() with no parameters.
* syscall.c (trace_syscall_exiting): Call tabto() with no parameters.
* strace.c: Make acolumn static, add static char *acolumn_spaces.
(main): Allocate acolumn_spaces as a string of spaces.
(printleader): Call tabto() with no parameters.
(tabto): Use simpler method to print lots of spaces.

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
defs.h
process.c
strace.c
syscall.c

diff --git a/defs.h b/defs.h
index d0cb058f010f45712eeff79e54fa7e80b96051f3..90b4bbc307991a2c46cd67e8e5eda6adb5989ed1 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -564,7 +564,6 @@ extern int debug, followfork;
 extern unsigned int ptrace_setoptions;
 extern int dtime, xflag, qflag;
 extern cflag_t cflag;
-extern int acolumn;
 extern int max_strlen;
 extern struct tcb *tcp_last;
 
@@ -639,7 +638,7 @@ extern void print_sigset(struct tcb *, long, int);
 extern void printsignal(int);
 extern void printleader(struct tcb *);
 extern void printtrailer(void);
-extern void tabto(int);
+extern void tabto(void);
 extern void call_summary(FILE *);
 extern void tprint_iov(struct tcb *, unsigned long, unsigned long, int decode_iov);
 extern void tprint_open_modes(mode_t);
index aba2f5655824303dd50f77ba7f36d460079ece31..4bab7268008f23e17310fa040a38530b04e8b405 100644 (file)
--- a/process.c
+++ b/process.c
@@ -429,7 +429,7 @@ sys_exit(struct tcb *tcp)
        }
        /* special case: we stop tracing this process, finish line now */
        tprintf("%ld) ", tcp->u_arg[0]);
-       tabto(acolumn);
+       tabto();
        tprintf("= ?");
        printtrailer();
        return 0;
index 04af6b568263ed5bc70a8ffb263d5f2d6ca9684d..02324f70aa657784e266c1bcafa48766e6fd3299 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -119,8 +119,9 @@ static char *username = NULL;
 static uid_t run_uid;
 static gid_t run_gid;
 
-int acolumn = DEFAULT_ACOLUMN;
 int max_strlen = DEFAULT_STRLEN;
+static int acolumn = DEFAULT_ACOLUMN;
+static char *acolumn_spaces;
 static char *outfname = NULL;
 static FILE *outf;
 static int curcol;
@@ -1033,6 +1034,8 @@ main(int argc, char *argv[])
                        break;
                case 'a':
                        acolumn = atoi(optarg);
+                       if (acolumn < 0)
+                               error_msg_and_die("Bad column width '%s'", optarg);
                        break;
                case 'e':
                        qualify(optarg);
@@ -1086,6 +1089,12 @@ main(int argc, char *argv[])
                }
        }
 
+       acolumn_spaces = malloc(acolumn + 1);
+       if (!acolumn_spaces)
+               error_msg_and_die("Out of memory");
+       memset(acolumn_spaces, ' ', acolumn);
+       acolumn_spaces[acolumn] = '\0';
+
        if ((optind == argc) == !pflag_seen)
                usage(stderr, 1);
 
@@ -2641,7 +2650,7 @@ printleader(struct tcb *tcp)
                if (tcp_last->ptrace_errno) {
                        if (tcp_last->flags & TCB_INSYSCALL) {
                                tprintf(" <unavailable>) ");
-                               tabto(acolumn);
+                               tabto();
                        }
                        tprintf("= ? <unavailable>\n");
                        tcp_last->ptrace_errno = 0;
@@ -2687,10 +2696,10 @@ printleader(struct tcb *tcp)
 }
 
 void
-tabto(int col)
+tabto(void)
 {
-       if (curcol < col)
-               tprintf("%*s", col - curcol, "");
+       if (curcol < acolumn)
+               tprintf(acolumn_spaces + curcol);
 }
 
 void
index 10c27d30a0987cfd5632d2fd5678271fc1f4e963..d1f0cf22efb3b71fd5cc30651a507b56a6173cdc 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -2334,7 +2334,7 @@ trace_syscall_exiting(struct tcb *tcp)
 
        if (res != 1) {
                tprintf(") ");
-               tabto(acolumn);
+               tabto();
                tprintf("= ? <unavailable>");
                printtrailer();
                tcp->flags &= ~TCB_INSYSCALL;
@@ -2359,7 +2359,7 @@ trace_syscall_exiting(struct tcb *tcp)
        }
 
        tprintf(") ");
-       tabto(acolumn);
+       tabto();
        u_error = tcp->u_error;
        if (!SCNO_IN_RANGE(tcp->scno) ||
            qual_flags[tcp->scno] & QUAL_RAW) {