Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/kdump Option -E to display elapsed timestamps (time ...



details:   https://anonhg.NetBSD.org/src/rev/0a69d7813c7a
branches:  trunk
changeset: 826502:0a69d7813c7a
user:      uwe <uwe%NetBSD.org@localhost>
date:      Fri Sep 08 21:09:29 2017 +0000

description:
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:

 usr.bin/kdump/kdump.1 |   8 ++++--
 usr.bin/kdump/kdump.c |  52 +++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 43 insertions(+), 17 deletions(-)

diffs (147 lines):

diff -r 12acb0c82bbd -r 0a69d7813c7a usr.bin/kdump/kdump.1
--- a/usr.bin/kdump/kdump.1     Fri Sep 08 20:36:56 2017 +0000
+++ b/usr.bin/kdump/kdump.1     Fri Sep 08 21:09:29 2017 +0000
@@ -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 @@
 .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 -r 12acb0c82bbd -r 0a69d7813c7a usr.bin/kdump/kdump.c
--- a/usr.bin/kdump/kdump.c     Fri Sep 08 20:36:56 2017 +0000
+++ b/usr.bin/kdump/kdump.c     Fri Sep 08 21:09:29 2017 +0000
@@ -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 @@
 #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 @@
 
 #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 @@
                }
                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 @@
                        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 @@
 {
        char unknown[64];
        const char *type;
-       static struct timespec prevtime;
+       static struct timespec starttime, prevtime;
        struct timespec temp;
        int col;
 
@@ -386,20 +396,34 @@
        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;



Home | Main Index | Thread Index | Old Index