Add a mechanism for cancelling begin/end perf counters.

This commit is contained in:
px4dev
2013-07-05 22:53:57 -07:00
parent 3c8c596ac7
commit 6871d2909b
2 changed files with 47 additions and 8 deletions
+34 -7
View File
@@ -201,23 +201,50 @@ perf_end(perf_counter_t handle)
switch (handle->type) { switch (handle->type) {
case PC_ELAPSED: { case PC_ELAPSED: {
struct perf_ctr_elapsed *pce = (struct perf_ctr_elapsed *)handle; struct perf_ctr_elapsed *pce = (struct perf_ctr_elapsed *)handle;
hrt_abstime elapsed = hrt_absolute_time() - pce->time_start;
pce->event_count++; if (pce->time_start != 0) {
pce->time_total += elapsed; hrt_abstime elapsed = hrt_absolute_time() - pce->time_start;
if ((pce->time_least > elapsed) || (pce->time_least == 0)) pce->event_count++;
pce->time_least = elapsed; pce->time_total += elapsed;
if (pce->time_most < elapsed) if ((pce->time_least > elapsed) || (pce->time_least == 0))
pce->time_most = elapsed; pce->time_least = elapsed;
if (pce->time_most < elapsed)
pce->time_most = elapsed;
pce->time_start = 0;
}
} }
break;
default: default:
break; 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 void
perf_reset(perf_counter_t handle) perf_reset(perf_counter_t handle)
{ {
+13 -1
View File
@@ -92,13 +92,25 @@ __EXPORT extern void perf_begin(perf_counter_t handle);
* End a performance event. * End a performance event.
* *
* This call applies to counters that operate over ranges of time; PC_ELAPSED etc. * 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. * @param handle The handle returned from perf_alloc.
*/ */
__EXPORT extern void perf_end(perf_counter_t handle); __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 * This call resets performance counter to initial state
* *