Add a quiet mode to ktrdump(1): if the "-q" flag is used, don't print

the pretty text header on top of the output.  Simplifies feeding the
results of tracing into a script for mechanical processing.
This commit is contained in:
Robert Watson 2004-05-21 21:24:58 +00:00
parent dd6cf019f3
commit 7ddc893717
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=129559
2 changed files with 30 additions and 21 deletions

View File

@ -33,7 +33,7 @@
.Nd print kernel ktr trace buffer .Nd print kernel ktr trace buffer
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl cft .Op Fl cfqt
.Op Fl e Ar execfile .Op Fl e Ar execfile
.Op Fl m Ar corefile .Op Fl m Ar corefile
.Op Fl o Ar outfile .Op Fl o Ar outfile
@ -48,6 +48,8 @@ The following options are available:
Print the CPU number that each entry was logged from. Print the CPU number that each entry was logged from.
.It Fl f .It Fl f
Print the file and line number that each entry was logged from. Print the file and line number that each entry was logged from.
.It Fl q
Quiet mode; don't print the column header.
.It Fl t .It Fl t
Print the timestamp for each entry. Print the timestamp for each entry.
.It Fl e Ar execfile .It Fl e Ar execfile

View File

@ -45,7 +45,7 @@ __FBSDID("$FreeBSD$");
#define SBUFLEN 128 #define SBUFLEN 128
#define USAGE \ #define USAGE \
"usage: ktrdump [-c] [-f] [-t] [-e execfile] [-i ktrfile ] [-m corefile] [-o outfile]" "usage: ktrdump [-c] [-f] [-q] [-t] [-e execfile] [-i ktrfile ] [-m corefile] [-o outfile]"
extern char *optarg; extern char *optarg;
extern int optind; extern int optind;
@ -64,6 +64,7 @@ static int cflag;
static int eflag; static int eflag;
static int fflag; static int fflag;
static int mflag; static int mflag;
static int qflag;
static int tflag; static int tflag;
static int iflag; static int iflag;
@ -100,7 +101,7 @@ main(int ac, char **av)
* Parse commandline arguments. * Parse commandline arguments.
*/ */
out = stdout; out = stdout;
while ((c = getopt(ac, av, "cfte:i:m:o:")) != -1) while ((c = getopt(ac, av, "cfqte:i:m:o:")) != -1)
switch (c) { switch (c) {
case 'c': case 'c':
cflag = 1; cflag = 1;
@ -129,6 +130,9 @@ main(int ac, char **av)
if ((out = fopen(optarg, "w")) == NULL) if ((out = fopen(optarg, "w")) == NULL)
err(1, "%s", optarg); err(1, "%s", optarg);
break; break;
case 'q':
qflag++;
break;
case 't': case 't':
tflag = 1; tflag = 1;
break; break;
@ -176,25 +180,28 @@ main(int ac, char **av)
/* /*
* Print a nice header. * Print a nice header.
*/ */
fprintf(out, "%-6s ", "index"); if (!qflag) {
if (cflag) fprintf(out, "%-6s ", "index");
fprintf(out, "%-3s ", "cpu"); if (cflag)
if (tflag) fprintf(out, "%-3s ", "cpu");
fprintf(out, "%-16s ", "timestamp"); if (tflag)
if (fflag) fprintf(out, "%-16s ", "timestamp");
fprintf(out, "%-40s ", "file and line"); if (fflag)
fprintf(out, "%s", "trace"); fprintf(out, "%-40s ", "file and line");
fprintf(out, "\n"); fprintf(out, "%s", "trace");
fprintf(out, "\n");
fprintf(out, "------ "); fprintf(out, "------ ");
if (cflag) if (cflag)
fprintf(out, "--- "); fprintf(out, "--- ");
if (tflag) if (tflag)
fprintf(out, "---------------- "); fprintf(out, "---------------- ");
if (fflag) if (fflag)
fprintf(out, "---------------------------------------- "); fprintf(out,
fprintf(out, "----- "); "---------------------------------------- ");
fprintf(out, "\n"); fprintf(out, "----- ");
fprintf(out, "\n");
}
/* /*
* Now tear through the trace buffer. * Now tear through the trace buffer.