diff options
author | jhb <jhb@FreeBSD.org> | 2000-12-15 00:01:20 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2000-12-15 00:01:20 +0000 |
commit | e8ae57d5895cb9fdba78b05fcab36aed75053384 (patch) | |
tree | 95a629c0185a14844922395db5cf67eb4fe9c7d8 | |
parent | 473acfcf52df708f833ee0f6175699752807a31f (diff) | |
download | FreeBSD-src-e8ae57d5895cb9fdba78b05fcab36aed75053384.zip FreeBSD-src-e8ae57d5895cb9fdba78b05fcab36aed75053384.tar.gz |
Add in MI implementations of the KTR trace buffer ddb commands. The
commands have also been slightly updated as follows:
- Use ktr_idx to find the newest entry rather than walking the buffer
comparing timespecs. Timespecs are not always unique after the change
to use getnanotime(9).
- Add a new verbose setting. When the verbose setting is on, then the
timestamp is printed with each message. If KTR_EXTEND is on, then the
filename and line number are output as well. By default this option is
off. It can be turned on with the 'v' modifier passed to the 'tbuf'
and 'tall' commands. For the 'tnext' command, the 'v' modifier toggles
the verbose mode.
- Only display the cpu number for each message on SMP systems.
- Don't display anything for an empty entry that hasn't been used yet.
-rw-r--r-- | sys/kern/kern_ktr.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/sys/kern/kern_ktr.c b/sys/kern/kern_ktr.c index 63f80ef..01467d1 100644 --- a/sys/kern/kern_ktr.c +++ b/sys/kern/kern_ktr.c @@ -34,9 +34,12 @@ * function that does the actual tracing. */ +#include "opt_ddb.h" #include "opt_ktr.h" +#include <sys/param.h> #include <sys/types.h> +#include <sys/cons.h> #include <sys/time.h> #include <sys/ktr.h> #include <sys/libkern.h> @@ -46,6 +49,8 @@ #include <machine/globals.h> #include <machine/stdarg.h> +#include <ddb/ddb.h> + #ifndef KTR_MASK #define KTR_MASK (KTR_GEN) #endif @@ -152,4 +157,96 @@ ktr_tracepoint(u_int mask, char *format, u_long arg1, u_long arg2, u_long arg3, entry->ktr_parm5 = arg5; #endif } + +#ifdef DDB + +struct tstate { + int cur; + int first; +}; +static struct tstate tstate; +static int db_ktr_verbose; +static int db_mach_vtrace(void); + +DB_COMMAND(tbuf, db_mach_tbuf) +{ + + tstate.cur = (ktr_idx - 1) & (KTR_ENTRIES - 1); + tstate.first = -1; + if (strcmp(modif, "v") == 0) + db_ktr_verbose = 1; + else + db_ktr_verbose = 0; + db_mach_vtrace(); + + return; +} + +DB_COMMAND(tall, db_mach_tall) +{ + int c; + + db_mach_tbuf(addr, have_addr, count, modif); + while (db_mach_vtrace()) { + c = cncheckc(); + if (c != -1) + break; + } + + return; +} + +DB_COMMAND(tnext, db_mach_tnext) +{ + + if (strcmp(modif, "v") == 0) + db_ktr_verbose ^= 1; + db_mach_vtrace(); +} + +static int +db_mach_vtrace(void) +{ + struct ktr_entry *kp; + + if (tstate.cur == tstate.first) { + db_printf("--- End of trace buffer ---\n"); + return (0); + } + kp = &ktr_buf[tstate.cur]; + + /* Skip over unused entries. */ +#ifdef KTR_EXTEND + if (kp->ktr_desc[0] != '\0') { +#else + if (kp->ktr_desc != NULL) { +#endif + db_printf("%d: ", tstate.cur); + if (db_ktr_verbose) + db_printf("%4ld.%06ld ", kp->ktr_tv.tv_sec, + kp->ktr_tv.tv_nsec / 1000); +#ifdef KTR_EXTEND +#ifdef SMP + db_printf("cpu%d ", kp->ktr_cpu); +#endif + if (db_ktr_verbose) + db_printf("%s.%d\t", kp->ktr_filename, kp->ktr_line); + db_printf("%s", kp->ktr_desc); +#else + db_printf(kp->ktr_desc, kp->ktr_parm1, kp->ktr_parm2, + kp->ktr_parm3, kp->ktr_parm4, kp->ktr_parm5); +#endif + db_printf("\n"); + } + + if (tstate.first == -1) + tstate.first = tstate.cur; + + if (--tstate.cur < 0) + tstate.cur = KTR_ENTRIES - 1; + + return (1); +} + +#endif /* DDB */ #endif /* KTR */ |