# HG changeset patch # User Bakul Shah # Date 1317319550 -7200 # Node ID 9c93e936f28e4066db82d2198b1b30e293ac97b9 # Parent 0984ccf0ffe686ae3ab3e06653f86493501667c5 ratrace: Added option -o to send trace output to a file. R=nix-dev, nemo, john, noah.evans CC=nix-dev http://codereview.appspot.com/5152044 Committer: Francisco J Ballesteros diff -r 0984ccf0ffe6 -r 9c93e936f28e sys/man/1/ratrace --- a/sys/man/1/ratrace Thu Sep 29 19:08:29 2011 +0200 +++ b/sys/man/1/ratrace Thu Sep 29 20:05:50 2011 +0200 @@ -4,6 +4,9 @@ .SH SYNOPSIS .B ratrace [ +.I -o tracefile +] +[ .I pid ] | [ .I -c command @@ -19,6 +22,9 @@ Trace output is determined by the kernel, not .IR ratrace . Certain fixed rules apply. +Trace output by default goes to file descriptor 2. +Option \fB-o\fP can be used to switch trace output to \fItracefile\fP. +.PP The first four fields of the output are pid, text name, system call name, and the PC of the user program. Data is always printed as diff -r 0984ccf0ffe6 -r 9c93e936f28e sys/src/cmd/ratrace.c --- a/sys/src/cmd/ratrace.c Thu Sep 29 19:08:29 2011 +0200 +++ b/sys/src/cmd/ratrace.c Thu Sep 29 20:05:50 2011 +0200 @@ -12,6 +12,7 @@ Channel *quit; Channel *forkc; int nread = 0; +int trace = 2; /* trace out fd */ typedef struct Str Str; struct Str { @@ -141,7 +142,7 @@ break; case 1: /* out */ /* it's a nice null terminated thing */ - fprint(2, "%s", s->buf); + fprint(trace, "%s", s->buf); free(s); break; case 2: /* forkc */ @@ -156,7 +157,7 @@ void usage(void) { - fprint(2, "Usage: ratrace [-c cmd [arg...]] | [pid]\n"); + fprint(2, "Usage: ratrace [-o tracefile] [-c cmd [arg...]] | [pid]\n"); exits("usage"); } @@ -182,6 +183,7 @@ int pid; char *cmd = nil; char **args = nil; + char *tracefile = nil; /* * don't bother with fancy arg processing, because it picks up options @@ -198,12 +200,27 @@ cmd = strdup(argv[2]); args = &argv[2]; break; + case 'o': + if (!argv[1][2]) { + tracefile = argv[2]; + ++argv; + --argc; + } else + tracefile = &argv[1][2]; + break; + default: usage(); } ++argv; --argc; } + + if (tracefile) { + trace = create(tracefile, OWRITE, 0666); + if (trace < 0) + sysfatal("%s: %r", tracefile); + } /* run a command? */ if(cmd) {