From 7d8c7fe10285d91a21a21b00f69b2bc0902352ac Mon Sep 17 00:00:00 2001 From: Robert Watson Date: Sat, 22 May 2004 08:26:10 +0000 Subject: [PATCH] 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. --- usr.bin/ktrdump/ktrdump.8 | 4 +++- usr.bin/ktrdump/ktrdump.c | 24 +++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/usr.bin/ktrdump/ktrdump.8 b/usr.bin/ktrdump/ktrdump.8 index db931a62ad0c..ec235e5cbd41 100644 --- a/usr.bin/ktrdump/ktrdump.8 +++ b/usr.bin/ktrdump/ktrdump.8 @@ -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 diff --git a/usr.bin/ktrdump/ktrdump.c b/usr.bin/ktrdump/ktrdump.c index a4319d348b57..f18772366e5a 100644 --- a/usr.bin/ktrdump/ktrdump.c +++ b/usr.bin/ktrdump/ktrdump.c @@ -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)