Source-Changes-HG archive

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

[src/trunk]: src/sys Improve ddb(4) show kernhist



details:   https://anonhg.NetBSD.org/src/rev/876de065ba1b
branches:  trunk
changeset: 344607:876de065ba1b
user:      skrll <skrll%NetBSD.org@localhost>
date:      Wed Apr 06 21:56:24 2016 +0000

description:
Improve ddb(4) show kernhist

1) really prints all the histories merged together (rather than just the
   "first" when no argument specified
2) dumps a single history when an argument is given, e.g.
   "show kernhist usbhist"
3) uses db_printf correctly

diffstat:

 sys/ddb/db_command.c    |   6 ++--
 sys/kern/kern_history.c |  52 ++++++++++++++++++++++++++++++++++++++----------
 sys/sys/kernhist.h      |  21 ++++++++-----------
 3 files changed, 53 insertions(+), 26 deletions(-)

diffs (189 lines):

diff -r e949510c33ba -r 876de065ba1b sys/ddb/db_command.c
--- a/sys/ddb/db_command.c      Wed Apr 06 19:45:45 2016 +0000
+++ b/sys/ddb/db_command.c      Wed Apr 06 21:56:24 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_command.c,v 1.145 2015/05/21 08:23:22 mrg Exp $     */
+/*     $NetBSD: db_command.c,v 1.146 2016/04/06 21:56:24 skrll Exp $   */
 
 /*
  * Copyright (c) 1996, 1997, 1998, 1999, 2002, 2009 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.145 2015/05/21 08:23:22 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.146 2016/04/06 21:56:24 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_aio.h"
@@ -1189,7 +1189,7 @@
     db_expr_t count, const char *modif)
 {
 
-       kernhist_print(db_printf);
+       kernhist_print((void *)(uintptr_t)addr, db_printf);
 }
 #endif
 
diff -r e949510c33ba -r 876de065ba1b sys/kern/kern_history.c
--- a/sys/kern/kern_history.c   Wed Apr 06 19:45:45 2016 +0000
+++ b/sys/kern/kern_history.c   Wed Apr 06 21:56:24 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_history.c,v 1.3 2015/10/29 18:40:19 mrg Exp $      */
+/*     $NetBSD: kern_history.c,v 1.4 2016/04/06 21:56:24 skrll Exp $    */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_history.c,v 1.3 2015/10/29 18:40:19 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_history.c,v 1.4 2016/04/06 21:56:24 skrll Exp $");
 
 #include "opt_kernhist.h"
 #include "opt_ddb.h"
@@ -77,9 +77,11 @@
  * prototypes
  */
 
-void kernhist_dump(struct kern_history *);
+void kernhist_dump(struct kern_history *,
+    void (*)(const char *, ...) __printflike(1, 2));
 void kernhist_dumpmask(u_int32_t);
-static void kernhist_dump_histories(struct kern_history *[]);
+static void kernhist_dump_histories(struct kern_history *[],
+    void (*)(const char *, ...) __printflike(1, 2));
 
 
 /*
@@ -88,14 +90,14 @@
  * expects the system to be quiesced, no locking
  */
 void
-kernhist_dump(struct kern_history *l)
+kernhist_dump(struct kern_history *l, void (*pr)(const char *, ...))
 {
        int lcv;
 
        lcv = l->f;
        do {
                if (l->e[lcv].fmt)
-                       kernhist_entry_print(&l->e[lcv]);
+                       kernhist_entry_print(&l->e[lcv], pr);
                lcv = (lcv + 1) % l->n;
        } while (lcv != l->f);
 }
@@ -104,7 +106,7 @@
  * print a merged list of kern_history structures
  */
 static void
-kernhist_dump_histories(struct kern_history *hists[])
+kernhist_dump_histories(struct kern_history *hists[], void (*pr)(const char *, ...))
 {
        struct timeval  tv;
        int     cur[MAXHISTS];
@@ -160,7 +162,7 @@
                        break;
 
                /* print and move to the next entry */
-               kernhist_entry_print(&hists[hi]->e[cur[hi]]);
+               kernhist_entry_print(&hists[hi]->e[cur[hi]], pr);
                cur[hi] = (cur[hi] + 1) % (hists[hi]->n);
                if (cur[hi] == hists[hi]->f)
                        cur[hi] = -1;
@@ -205,16 +207,44 @@
 
        hists[i] = NULL;
 
-       kernhist_dump_histories(hists);
+       kernhist_dump_histories(hists, printf);
 }
 
 /*
  * kernhist_print: ddb hook to print kern history
  */
 void
-kernhist_print(void (*pr)(const char *, ...))
+kernhist_print(void *addr, void (*pr)(const char *, ...) __printflike(1,2))
 {
-       kernhist_dump(LIST_FIRST(&kern_histories));
+       struct kern_history *h;
+
+       LIST_FOREACH(h, &kern_histories, list) {
+               if (h == addr)
+                       break;
+       }
+
+       if (h == NULL) {
+               struct kern_history *hists[MAXHISTS + 1];
+               int i = 0;
+#ifdef UVMHIST
+               hists[i++] = &maphist;
+               hists[i++] = &pdhist;
+               hists[i++] = &ubchist;
+               hists[i++] = &loanhist;
+#endif
+#ifdef USB_DEBUG
+               hists[i++] = &usbhist;
+#endif
+
+#ifdef SYSCALL_DEBUG
+               hists[i++] = &scdebughist;
+#endif
+               hists[i] = NULL;
+
+               kernhist_dump_histories(hists, pr);
+       } else {
+               kernhist_dump(h, pr);
+       }
 }
 
 #endif
diff -r e949510c33ba -r 876de065ba1b sys/sys/kernhist.h
--- a/sys/sys/kernhist.h        Wed Apr 06 19:45:45 2016 +0000
+++ b/sys/sys/kernhist.h        Wed Apr 06 21:56:24 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kernhist.h,v 1.10 2015/10/29 00:27:08 mrg Exp $        */
+/*     $NetBSD: kernhist.h,v 1.11 2016/04/06 21:56:24 skrll Exp $      */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -158,7 +158,7 @@
 #define KERNHIST_PRINTNOW(E) \
 do { \
                if (kernhist_print_enabled) { \
-                       kernhist_entry_print(E); \
+                       kernhist_entry_print(E, printf); \
                        if (KERNHIST_DELAY != 0) \
                                DELAY(KERNHIST_DELAY); \
                } \
@@ -217,21 +217,18 @@
 #define KERNHIST_DUMP(NAME)
 #endif
 
-
-static inline void kernhist_entry_print(const struct kern_history_ent *);
-
 static inline void
-kernhist_entry_print(const struct kern_history_ent *e)
+kernhist_entry_print(const struct kern_history_ent *e, void (*pr)(const char *, ...) __printflike(1, 2))
 {
-       printf("%06" PRIu64 ".%06d ", e->tv.tv_sec, e->tv.tv_usec);
-       printf("%s#%ld@%d: ", e->fn, e->call, e->cpunum);
-       printf(e->fmt, e->v[0], e->v[1], e->v[2], e->v[3]);
-       printf("\n");
+       pr("%06" PRIu64 ".%06d ", e->tv.tv_sec, e->tv.tv_usec);
+       pr("%s#%ld@%d: ", e->fn, e->call, e->cpunum);
+       pr(e->fmt, e->v[0], e->v[1], e->v[2], e->v[3]);
+       pr("\n");
 }
 
 #if defined(DDB)
-void   kernhist_dump(struct kern_history *);
-void   kernhist_print(void (*)(const char *, ...) __printflike(1, 2));
+void   kernhist_dump(struct kern_history *, void (*)(const char *, ...) __printflike(1, 2));
+void   kernhist_print(void *, void (*)(const char *, ...) __printflike(1, 2));
 #endif /* DDB */
 
 #endif /* KERNHIST */



Home | Main Index | Thread Index | Old Index