diff options
| author | uwe <uwe@NetBSD.org> | 2017-09-08 21:09:29 +0000 |
|---|---|---|
| committer | uwe <uwe@NetBSD.org> | 2017-09-08 21:09:29 +0000 |
| commit | c7b8beec64c9d2c08f3fb919656d7fed1405cb61 (patch) | |
| tree | afae3550c3807ba35ddbede1ca9d8c2460d92a35 /usr.bin | |
| parent | b4081ef863ef6084eb794f5966c0c94b33fe80b9 (diff) | |
Option -E to display elapsed timestamps (time since beginning of trace).
Option name from FreeBSD. While here, make it possible to use a
combination of -T -E and -R to display timestamps in several formats.
Idea also from FreeBSD.
Diffstat (limited to 'usr.bin')
| -rw-r--r-- | usr.bin/kdump/kdump.1 | 8 | ||||
| -rw-r--r-- | usr.bin/kdump/kdump.c | 52 |
2 files changed, 43 insertions, 17 deletions
diff --git a/usr.bin/kdump/kdump.1 b/usr.bin/kdump/kdump.1 index 21bd3655415..f4b7a64be73 100644 --- a/usr.bin/kdump/kdump.1 +++ b/usr.bin/kdump/kdump.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: kdump.1,v 1.26 2003/11/16 23:10:00 wiz Exp $ +.\" $NetBSD: kdump.1,v 1.27 2017/09/08 21:09:29 uwe Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)kdump.1 8.1 (Berkeley) 6/6/93 .\" -.Dd November 15, 2003 +.Dd September 9, 2017 .Dt KDUMP 1 .Os .Sh NAME @@ -37,7 +37,7 @@ .Nd display kernel trace data .Sh SYNOPSIS .Nm -.Op Fl dlNnRT +.Op Fl EdlNnRT .Op Fl e Ar emulation .Op Fl f Ar file .Op Fl m Ar maxdata @@ -60,6 +60,8 @@ The options are as follows: .Bl -tag -width Fl .It Fl d Display all numbers in decimal. +.It Fl E +Display elapsed timestamps (time since beginning of trace). .It Fl e Ar emulation If an emulation of a process is unknown, interpret system call maps assuming the named emulation instead of diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c index 492c914b04b..b9569e7e698 100644 --- a/usr.bin/kdump/kdump.c +++ b/usr.bin/kdump/kdump.c @@ -1,4 +1,4 @@ -/* $NetBSD: kdump.c,v 1.126 2017/09/08 20:36:56 uwe Exp $ */ +/* $NetBSD: kdump.c,v 1.127 2017/09/08 21:09:29 uwe Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1993\ #if 0 static char sccsid[] = "@(#)kdump.c 8.4 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: kdump.c,v 1.126 2017/09/08 20:36:56 uwe Exp $"); +__RCSID("$NetBSD: kdump.c,v 1.127 2017/09/08 21:09:29 uwe Exp $"); #endif #endif /* not lint */ @@ -72,6 +72,11 @@ __RCSID("$NetBSD: kdump.c,v 1.126 2017/09/08 20:36:56 uwe Exp $"); #include <sys/syscall.h> +#define TIMESTAMP_NONE 0x0 +#define TIMESTAMP_ABSOLUTE 0x1 +#define TIMESTAMP_ELAPSED 0x2 +#define TIMESTAMP_RELATIVE 0x4 + static int timestamp, decimal, plain, tail, maxdata = -1, numeric; static int word_size = 0; static pid_t do_pid = -1; @@ -162,9 +167,14 @@ main(int argc, char **argv) } return 0; } - - while ((ch = getopt(argc, argv, "e:f:dlm:Nnp:RTt:xX:")) != -1) { + + timestamp = TIMESTAMP_NONE; + + while ((ch = getopt(argc, argv, "Ee:f:dlm:Nnp:RTt:xX:")) != -1) { switch (ch) { + case 'E': + timestamp |= TIMESTAMP_ELAPSED; + break; case 'e': emul_name = strdup(optarg); /* it's safer to copy it */ break; @@ -194,10 +204,10 @@ main(int argc, char **argv) plain++; break; case 'R': - timestamp = 2; /* relative timestamp */ + timestamp |= TIMESTAMP_RELATIVE; break; case 'T': - timestamp = 1; + timestamp |= TIMESTAMP_ABSOLUTE; break; case 't': trset = 1; @@ -329,7 +339,7 @@ dumpheader(struct ktr_header *kth) { char unknown[64]; const char *type; - static struct timespec prevtime; + static struct timespec starttime, prevtime; struct timespec temp; int col; @@ -386,20 +396,34 @@ dumpheader(struct ktr_header *kth) col = printf("%6d %6d ", kth->ktr_pid, kth->ktr_lid); col += printf("%-8.*s ", MAXCOMLEN, kth->ktr_comm); if (timestamp) { - if (timestamp == 2) { + if (timestamp & TIMESTAMP_ABSOLUTE) { + temp.tv_sec = kth->ktr_ts.tv_sec; + temp.tv_nsec = kth->ktr_ts.tv_nsec; + col += printf("%lld.%09ld ", + (long long)temp.tv_sec, (long)temp.tv_nsec); + } + + if (timestamp & TIMESTAMP_ELAPSED) { + if (starttime.tv_sec == 0) { + starttime.tv_sec = kth->ktr_ts.tv_sec; + starttime.tv_nsec = kth->ktr_ts.tv_nsec; + temp.tv_sec = temp.tv_nsec = 0; + } else + timespecsub(&kth->ktr_ts, &starttime, &temp); + col += printf("%lld.%09ld ", + (long long)temp.tv_sec, (long)temp.tv_nsec); + } + + if (timestamp & TIMESTAMP_RELATIVE) { if (prevtime.tv_sec == 0) temp.tv_sec = temp.tv_nsec = 0; else timespecsub(&kth->ktr_ts, &prevtime, &temp); prevtime.tv_sec = kth->ktr_ts.tv_sec; prevtime.tv_nsec = kth->ktr_ts.tv_nsec; - } else { - temp.tv_sec = kth->ktr_ts.tv_sec; - temp.tv_nsec = kth->ktr_ts.tv_nsec; + col += printf("%lld.%09ld ", + (long long)temp.tv_sec, (long)temp.tv_nsec); } - - col += printf("%lld.%09ld ", - (long long)temp.tv_sec, (long)temp.tv_nsec); } col += printf("%-4s ", type); return col; |
