diff options
author | px4dev <px4@purgatory.org> | 2013-08-04 19:42:16 -0700 |
---|---|---|
committer | px4dev <px4@purgatory.org> | 2013-08-04 19:42:16 -0700 |
commit | c33048b52186b88ddab2a9c9fdad24c7b64e7e22 (patch) | |
tree | f342f1e7063753554d9b2bc8a88a2f8886bbf92c /src | |
parent | 97e4909d9e7c835b73c2eebdf4991d395c4ffb3f (diff) | |
download | px4-firmware-c33048b52186b88ddab2a9c9fdad24c7b64e7e22.tar.gz px4-firmware-c33048b52186b88ddab2a9c9fdad24c7b64e7e22.tar.bz2 px4-firmware-c33048b52186b88ddab2a9c9fdad24c7b64e7e22.zip |
Add the ability to cancel a begin/end perf counter if the begin turns out to have been in error.
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/systemlib/perf_counter.c | 41 | ||||
-rw-r--r-- | src/modules/systemlib/perf_counter.h | 14 |
2 files changed, 47 insertions, 8 deletions
diff --git a/src/modules/systemlib/perf_counter.c b/src/modules/systemlib/perf_counter.c index 879f4715a..3c1e10287 100644 --- a/src/modules/systemlib/perf_counter.c +++ b/src/modules/systemlib/perf_counter.c @@ -201,23 +201,50 @@ perf_end(perf_counter_t handle) switch (handle->type) { case PC_ELAPSED: { struct perf_ctr_elapsed *pce = (struct perf_ctr_elapsed *)handle; - hrt_abstime elapsed = hrt_absolute_time() - pce->time_start; - pce->event_count++; - pce->time_total += elapsed; + if (pce->time_start != 0) { + hrt_abstime elapsed = hrt_absolute_time() - pce->time_start; - if ((pce->time_least > elapsed) || (pce->time_least == 0)) - pce->time_least = elapsed; + pce->event_count++; + pce->time_total += elapsed; - if (pce->time_most < elapsed) - pce->time_most = elapsed; + if ((pce->time_least > elapsed) || (pce->time_least == 0)) + pce->time_least = elapsed; + + if (pce->time_most < elapsed) + pce->time_most = elapsed; + + pce->time_start = 0; + } + } + break; + + default: + break; + } +} + +void +perf_cancel(perf_counter_t handle) +{ + if (handle == NULL) + return; + + switch (handle->type) { + case PC_ELAPSED: { + struct perf_ctr_elapsed *pce = (struct perf_ctr_elapsed *)handle; + + pce->time_start = 0; } + break; default: break; } } + + void perf_reset(perf_counter_t handle) { diff --git a/src/modules/systemlib/perf_counter.h b/src/modules/systemlib/perf_counter.h index 5c2cb15b2..4cd8b67a1 100644 --- a/src/modules/systemlib/perf_counter.h +++ b/src/modules/systemlib/perf_counter.h @@ -92,13 +92,25 @@ __EXPORT extern void perf_begin(perf_counter_t handle); * End a performance event. * * This call applies to counters that operate over ranges of time; PC_ELAPSED etc. + * If a call is made without a corresopnding perf_begin call, or if perf_cancel + * has been called subsequently, no change is made to the counter. * * @param handle The handle returned from perf_alloc. */ __EXPORT extern void perf_end(perf_counter_t handle); /** - * Reset a performance event. + * Cancel a performance event. + * + * This call applies to counters that operate over ranges of time; PC_ELAPSED etc. + * It reverts the effect of a previous perf_begin. + * + * @param handle The handle returned from perf_alloc. + */ +__EXPORT extern void perf_cancel(perf_counter_t handle); + +/** + * Reset a performance counter. * * This call resets performance counter to initial state * |