diff options
author | px4dev <px4@purgatory.org> | 2012-11-12 01:35:51 -0800 |
---|---|---|
committer | px4dev <px4@purgatory.org> | 2012-11-12 01:35:51 -0800 |
commit | dca3bce1ca89595f5df3788da34afe3b30bfb35a (patch) | |
tree | 8e9fe8a7b09c1cd33d5250a0f74b8adb6d33e015 | |
parent | 7d8d7a76b986e7acefb4a61f3da3625db1f6dd11 (diff) | |
download | px4-firmware-dca3bce1ca89595f5df3788da34afe3b30bfb35a.tar.gz px4-firmware-dca3bce1ca89595f5df3788da34afe3b30bfb35a.tar.bz2 px4-firmware-dca3bce1ca89595f5df3788da34afe3b30bfb35a.zip |
Add a new performance counter for measuring periodic/interval events.
-rw-r--r-- | apps/systemlib/perf_counter.c | 70 | ||||
-rw-r--r-- | apps/systemlib/perf_counter.h | 3 |
2 files changed, 67 insertions, 6 deletions
diff --git a/apps/systemlib/perf_counter.c b/apps/systemlib/perf_counter.c index e6c49d432..ff15ef479 100644 --- a/apps/systemlib/perf_counter.c +++ b/apps/systemlib/perf_counter.c @@ -74,6 +74,20 @@ struct perf_ctr_elapsed { }; /** + * PC_INTERVAL counter. + */ +struct perf_ctr_interval { + struct perf_ctr_header hdr; + uint64_t event_count; + uint64_t time_event; + uint64_t time_first; + uint64_t time_last; + uint64_t time_least; + uint64_t time_most; + +}; + +/** * List of all known counters. */ static sq_queue_t perf_counters; @@ -93,6 +107,10 @@ perf_alloc(enum perf_counter_type type, const char *name) ctr = (perf_counter_t)calloc(sizeof(struct perf_ctr_elapsed), 1); break; + case PC_INTERVAL: + ctr = (perf_counter_t)calloc(sizeof(struct perf_ctr_interval), 1); + break; + default: break; } @@ -127,6 +145,32 @@ perf_count(perf_counter_t handle) ((struct perf_ctr_count *)handle)->event_count++; break; + case PC_INTERVAL: { + struct perf_ctr_interval *pci = (struct perf_ctr_interval *)handle; + hrt_abstime now = hrt_absolute_time(); + + switch (pci->event_count) { + case 0: + pci->time_first = now; + break; + case 1: + pci->time_least = now - pci->time_last; + pci->time_most = now - pci->time_last; + break; + default: { + hrt_abstime interval = now - pci->time_last; + if (interval < pci->time_least) + pci->time_least = interval; + if (interval > pci->time_most) + pci->time_most = interval; + break; + } + } + pci->time_last = now; + pci->event_count++; + break; + } + default: break; } @@ -187,13 +231,29 @@ perf_print_counter(perf_counter_t handle) ((struct perf_ctr_count *)handle)->event_count); break; - case PC_ELAPSED: + case PC_ELAPSED: { + struct perf_ctr_elapsed *pce = (struct perf_ctr_elapsed *)handle; + printf("%s: %llu events, %lluus elapsed, min %lluus max %lluus\n", handle->name, - ((struct perf_ctr_elapsed *)handle)->event_count, - ((struct perf_ctr_elapsed *)handle)->time_total, - ((struct perf_ctr_elapsed *)handle)->time_least, - ((struct perf_ctr_elapsed *)handle)->time_most); + pce->event_count, + pce->time_total, + pce->time_least, + pce->time_most); + break; + } + + case PC_INTERVAL: { + struct perf_ctr_interval *pci = (struct perf_ctr_interval *)handle; + + printf("%s: %llu events, %llu avg, min %lluus max %lluus\n", + handle->name, + pci->event_count, + (pci->time_last - pci->time_first) / pci->event_count, + pci->time_least, + pci->time_most); + break; + } default: break; diff --git a/apps/systemlib/perf_counter.h b/apps/systemlib/perf_counter.h index 5dc441056..6e6c80d5b 100644 --- a/apps/systemlib/perf_counter.h +++ b/apps/systemlib/perf_counter.h @@ -44,7 +44,8 @@ */ enum perf_counter_type { PC_COUNT, /**< count the number of times an event occurs */ - PC_ELAPSED /**< measure the time elapsed performing an event */ + PC_ELAPSED, /**< measure the time elapsed performing an event */ + PC_INTERVAL /**< measure the interval between instances of an event */ }; struct perf_ctr_header; |