From f4da4bb8ca29a48e1bf10958cbc45fc9fb10e9f7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 24 Jan 2013 10:00:23 +1100 Subject: perf_counter: added perf_reset() and perf_reset_all() calls useful for watching counters after system reaches stable flight --- apps/systemlib/perf_counter.c | 45 +++++++++++++++++++++++++++++++++++++++++++ apps/systemlib/perf_counter.h | 13 +++++++++++++ 2 files changed, 58 insertions(+) (limited to 'apps/systemlib') diff --git a/apps/systemlib/perf_counter.c b/apps/systemlib/perf_counter.c index ff15ef479..879f4715a 100644 --- a/apps/systemlib/perf_counter.c +++ b/apps/systemlib/perf_counter.c @@ -218,6 +218,40 @@ perf_end(perf_counter_t handle) } } +void +perf_reset(perf_counter_t handle) +{ + if (handle == NULL) + return; + + switch (handle->type) { + case PC_COUNT: + ((struct perf_ctr_count *)handle)->event_count = 0; + break; + + case PC_ELAPSED: { + struct perf_ctr_elapsed *pce = (struct perf_ctr_elapsed *)handle; + pce->event_count = 0; + pce->time_start = 0; + pce->time_total = 0; + pce->time_least = 0; + pce->time_most = 0; + break; + } + + case PC_INTERVAL: { + struct perf_ctr_interval *pci = (struct perf_ctr_interval *)handle; + pci->event_count = 0; + pci->time_event = 0; + pci->time_first = 0; + pci->time_last = 0; + pci->time_least = 0; + pci->time_most = 0; + break; + } + } +} + void perf_print_counter(perf_counter_t handle) { @@ -270,3 +304,14 @@ perf_print_all(void) handle = (perf_counter_t)sq_next(&handle->link); } } + +void +perf_reset_all(void) +{ + perf_counter_t handle = (perf_counter_t)sq_peek(&perf_counters); + + while (handle != NULL) { + perf_reset(handle); + handle = (perf_counter_t)sq_next(&handle->link); + } +} diff --git a/apps/systemlib/perf_counter.h b/apps/systemlib/perf_counter.h index 6e6c80d5b..5c2cb15b2 100644 --- a/apps/systemlib/perf_counter.h +++ b/apps/systemlib/perf_counter.h @@ -97,6 +97,14 @@ __EXPORT extern void perf_begin(perf_counter_t handle); */ __EXPORT extern void perf_end(perf_counter_t handle); +/** + * Reset a performance event. + * + * This call resets performance counter to initial state + * + * @param handle The handle returned from perf_alloc. + */ +__EXPORT extern void perf_reset(perf_counter_t handle); /** * Print one performance counter. @@ -110,6 +118,11 @@ __EXPORT extern void perf_print_counter(perf_counter_t handle); */ __EXPORT extern void perf_print_all(void); +/** + * Reset all of the performance counters. + */ +__EXPORT extern void perf_reset_all(void); + __END_DECLS #endif -- cgit v1.2.3