diff options
author | Paul Jakma <paul@quagga.net> | 2010-01-09 16:15:00 +0000 |
---|---|---|
committer | Paul Jakma <paul@quagga.net> | 2010-12-08 16:53:09 +0000 |
commit | e276eb82820eb92d221f183496e28da4ffe0fe68 (patch) | |
tree | 33f8ab85f1bd68874589ca804049d2ec4958478a /lib/thread.c | |
parent | 2613abe64fe48761d798942af8dc0ec90c804b22 (diff) |
lib: Add a command to clear the thread CPU history data
* (general) this can be useful when investigating thread latency problems,
when you don't want to have to restart a daemon between tests.
* thread.c: (cpu_record_(hash_)clear) wipe the stored thread cpu history
data, according to the filter, similar to the vty print code.
(clear_thread_cpu_cmd) new command to clear data.
* thread.h: export new command
* command.c: install it
Diffstat (limited to 'lib/thread.c')
-rw-r--r-- | lib/thread.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/lib/thread.c b/lib/thread.c index fb6fe375..fd841c21 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -382,6 +382,89 @@ DEFUN(show_thread_cpu, cpu_record_print(vty, filter); return CMD_SUCCESS; } + +static void +cpu_record_hash_clear (struct hash_backet *bucket, + void *args) +{ + thread_type *filter = args; + struct cpu_thread_history *a = bucket->data; + + a = bucket->data; + if ( !(a->types & *filter) ) + return; + + hash_release (cpu_record, bucket->data); +} + +static void +cpu_record_clear (thread_type filter) +{ + thread_type *tmp = &filter; + hash_iterate (cpu_record, + (void (*) (struct hash_backet*,void*)) cpu_record_hash_clear, + tmp); +} + +DEFUN(clear_thread_cpu, + clear_thread_cpu_cmd, + "clear thread cpu [FILTER]", + "Clear stored data\n" + "Thread information\n" + "Thread CPU usage\n" + "Display filter (rwtexb)\n") +{ + int i = 0; + thread_type filter = (thread_type) -1U; + + if (argc > 0) + { + filter = 0; + while (argv[0][i] != '\0') + { + switch ( argv[0][i] ) + { + case 'r': + case 'R': + filter |= (1 << THREAD_READ); + break; + case 'w': + case 'W': + filter |= (1 << THREAD_WRITE); + break; + case 't': + case 'T': + filter |= (1 << THREAD_TIMER); + break; + case 'e': + case 'E': + filter |= (1 << THREAD_EVENT); + break; + case 'x': + case 'X': + filter |= (1 << THREAD_EXECUTE); + break; + case 'b': + case 'B': + filter |= (1 << THREAD_BACKGROUND); + break; + default: + break; + } + ++i; + } + if (filter == 0) + { + vty_out(vty, "Invalid filter \"%s\" specified," + " must contain at least one of 'RWTEXB'%s", + argv[0], VTY_NEWLINE); + return CMD_WARNING; + } + } + + cpu_record_clear (filter); + return CMD_SUCCESS; +} /* List allocation and head/tail print out. */ static void |