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
This commit is contained in:
parent
bb67ec8f00
commit
1a04d8c9f0
|
@ -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_kernhist_print_cmd(db_expr_t addr, bool have_addr,
|
|||
db_expr_t count, const char *modif)
|
||||
{
|
||||
|
||||
kernhist_print(db_printf);
|
||||
kernhist_print((void *)(uintptr_t)addr, db_printf);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -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 @@ int kernhist_print_enabled = 1;
|
|||
* 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 @@ static void kernhist_dump_histories(struct kern_history *[]);
|
|||
* 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 @@ kernhist_dump(struct kern_history *l)
|
|||
* 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 @@ restart:
|
|||
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 @@ kernhist_dumpmask(u_int32_t bitmask) /* XXX only support 32 hists */
|
|||
|
||||
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
|
||||
|
|
|
@ -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 @@ extern int kernhist_print_enabled;
|
|||
#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 @@ do { \
|
|||
#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 */
|
||||
|
|
Loading…
Reference in New Issue