Add a "-r" flag to ktrdump(1) to print relative timestamps when used

with "-t" rather than absolute timestamps.  This allows the reader
to get a better sense of latency between events, such as time to
schedule an interrupt thread from time the interrupt occurred.  Assert
a copyright on ktrdump.c since I seem to be modifying it more than I
thought.
This commit is contained in:
Robert Watson 2004-05-22 08:26:10 +00:00
parent 4be14af9cf
commit 7d8c7fe102
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=129574
2 changed files with 22 additions and 6 deletions

View File

@ -33,7 +33,7 @@
.Nd print kernel ktr trace buffer
.Sh SYNOPSIS
.Nm
.Op Fl cfqt
.Op Fl cfqrt
.Op Fl e Ar execfile
.Op Fl m Ar corefile
.Op Fl o Ar outfile
@ -50,6 +50,8 @@ Print the CPU 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 r
Print relative timestamps rather than absolute timestamps.
.It Fl t
Print the timestamp for each entry.
.It Fl e Ar execfile

View File

@ -1,5 +1,6 @@
/*-
* Copyright (c) 2002 Jake Burkholder
* Copyright (c) 2004 Robert Watson
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -45,7 +46,7 @@ __FBSDID("$FreeBSD$");
#define SBUFLEN 128
#define USAGE \
"usage: ktrdump [-c] [-f] [-q] [-t] [-e execfile] [-i ktrfile ] [-m corefile] [-o outfile]"
"usage: ktrdump [-c] [-f] [-q] [-r] [-t] [-e execfile] [-i ktrfile ] [-m corefile] [-o outfile]"
extern char *optarg;
extern int optind;
@ -65,6 +66,7 @@ static int eflag;
static int fflag;
static int mflag;
static int qflag;
static int rflag;
static int tflag;
static int iflag;
@ -85,6 +87,7 @@ main(int ac, char **av)
{
u_long parms[KTR_PARMS];
struct ktr_entry *buf;
uintmax_t tlast, tnow;
struct stat sb;
kvm_t *kd;
FILE *out;
@ -101,7 +104,7 @@ main(int ac, char **av)
* Parse commandline arguments.
*/
out = stdout;
while ((c = getopt(ac, av, "cfqte:i:m:o:")) != -1)
while ((c = getopt(ac, av, "cfqrte:i:m:o:")) != -1)
switch (c) {
case 'c':
cflag = 1;
@ -133,6 +136,9 @@ main(int ac, char **av)
case 'q':
qflag++;
break;
case 'r':
rflag = 1;
break;
case 't':
tflag = 1;
break;
@ -208,6 +214,7 @@ main(int ac, char **av)
*/
if (!iflag)
i = (index - 1) & (entries - 1);
tlast = -1;
for (;;) {
if (buf[i].ktr_desc == NULL)
break;
@ -241,9 +248,16 @@ main(int ac, char **av)
fprintf(out, "%6d ", i);
if (cflag)
fprintf(out, "%3d ", buf[i].ktr_cpu);
if (tflag)
fprintf(out, "%16ju ",
(uintmax_t)buf[i].ktr_timestamp);
if (tflag) {
tnow = (uintmax_t)buf[i].ktr_timestamp;
if (rflag) {
if (tlast == -1)
tlast = tnow;
fprintf(out, "%16ju ", tlast - tnow);
tlast = tnow;
} else
fprintf(out, "%16ju ", tnow);
}
if (fflag) {
if (kvm_read(kd, (u_long)buf[i].ktr_file, fbuf,
sizeof(fbuf)) == -1)