diff options
author | Julian Oes <joes@student.ethz.ch> | 2012-11-13 14:18:59 -0800 |
---|---|---|
committer | Julian Oes <joes@student.ethz.ch> | 2012-11-13 14:18:59 -0800 |
commit | 359cc4bb86cae716d3d47dc888c836d04e920215 (patch) | |
tree | bb2158364b83fc511e5eef647eac650eb797fa7f /apps/systemlib | |
parent | a8dfcaace27aa0abee4b3c44bffee9f94e391628 (diff) | |
parent | e52c7e3c4ba4f909ae7ae51347c0c659c0c9cea7 (diff) | |
download | px4-firmware-359cc4bb86cae716d3d47dc888c836d04e920215.tar.gz px4-firmware-359cc4bb86cae716d3d47dc888c836d04e920215.tar.bz2 px4-firmware-359cc4bb86cae716d3d47dc888c836d04e920215.zip |
Merge remote-tracking branch 'upstream/master' into io
Diffstat (limited to 'apps/systemlib')
-rw-r--r-- | apps/systemlib/mixer/mixer_group.cpp | 1 | ||||
-rw-r--r-- | apps/systemlib/perf_counter.c | 70 | ||||
-rw-r--r-- | apps/systemlib/perf_counter.h | 3 |
3 files changed, 68 insertions, 6 deletions
diff --git a/apps/systemlib/mixer/mixer_group.cpp b/apps/systemlib/mixer/mixer_group.cpp index 004151235..19ce25553 100644 --- a/apps/systemlib/mixer/mixer_group.cpp +++ b/apps/systemlib/mixer/mixer_group.cpp @@ -168,6 +168,7 @@ mixer_load_simple(Mixer::ControlCallback control_cb, uintptr_t cb_handle, int fd /* let's assume we're going to read a simple mixer */ mixinfo = (mixer_simple_s *)malloc(MIXER_SIMPLE_SIZE(inputs)); + mixinfo->control_count = inputs; /* first, get the output scaler */ ret = mixer_getline(fd, buf, sizeof(buf)); 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; |