43 #include <sys/queue.h> 59 #define dprintf(_fd, _text, ...) ((_fd) == 1 ? PX4_INFO((_text), ##__VA_ARGS__) : (void)(_fd)) 75 uint64_t event_count{0};
82 uint64_t event_count{0};
83 uint64_t time_start{0};
84 uint64_t time_total{0};
85 uint32_t time_least{0};
86 uint32_t time_most{0};
95 uint64_t event_count{0};
96 uint64_t time_event{0};
97 uint64_t time_first{0};
98 uint64_t time_last{0};
99 uint32_t time_least{0};
100 uint32_t time_most{0};
144 if (ctr !=
nullptr) {
161 while (handle !=
nullptr) {
162 if (!strcmp(handle->
name, name)) {
163 if (type == handle->
type) {
187 if (handle ==
nullptr) {
201 if (handle ==
nullptr) {
205 switch (handle->
type) {
233 if ((uint32_t)interval > pci->
time_most) {
239 float dt = interval / 1e6f;
240 float delta_intvl = dt - pci->
mean;
242 pci->
M2 += delta_intvl * (dt - pci->
mean);
260 if (handle ==
nullptr) {
264 switch (handle->
type) {
277 if (handle ==
nullptr) {
281 switch (handle->
type) {
297 if (pce->
time_most < (uint32_t)elapsed) {
303 float dt = elapsed / 1e6f;
304 float delta_intvl = dt - pce->
mean;
306 pce->
M2 += delta_intvl * (dt - pce->
mean);
322 if (handle ==
nullptr) {
326 switch (handle->
type) {
339 if (pce->
time_most < (uint32_t)elapsed) {
345 float dt = elapsed / 1e6f;
346 float delta_intvl = dt - pce->
mean;
348 pce->
M2 += delta_intvl * (dt - pce->
mean);
363 if (handle ==
nullptr) {
367 switch (handle->
type) {
382 if (handle ==
nullptr) {
386 switch (handle->
type) {
404 if (handle ==
nullptr) {
408 switch (handle->
type) {
439 if (handle ==
nullptr) {
449 if (handle ==
nullptr) {
453 switch (handle->
type) {
455 dprintf(fd,
"%s: %llu events\n",
457 (
unsigned long long)((
struct perf_ctr_count *)handle)->event_count);
463 dprintf(fd,
"%s: %llu events, %lluus elapsed, %.2fus avg, min %lluus max %lluus %5.3fus rms\n",
470 (
double)(1e6f * rms));
478 dprintf(fd,
"%s: %llu events, %.2fus avg, min %lluus max %lluus %5.3fus rms\n",
484 (
double)(1e6f * rms));
499 if (handle ==
nullptr) {
503 switch (handle->
type) {
505 num_written = snprintf(buffer, length,
"%s: %llu events",
507 (
unsigned long long)((
struct perf_ctr_count *)handle)->event_count);
513 num_written = snprintf(buffer, length,
"%s: %llu events, %lluus elapsed, %.2fus avg, min %lluus max %lluus %5.3fus rms",
520 (
double)(1e6f * rms));
528 num_written = snprintf(buffer, length,
"%s: %llu events, %.2f avg, min %lluus max %lluus %5.3fus rms",
534 (
double)(1e6f * rms));
542 buffer[length - 1] = 0;
549 if (handle ==
nullptr) {
553 switch (handle->
type) {
580 while (handle !=
nullptr) {
594 while (handle !=
nullptr) {
605 dprintf(fd,
"bucket [us] : events\n");
621 while (handle !=
nullptr) {
int perf_print_counter_buffer(char *buffer, int length, perf_counter_t handle)
Print one performance counter to a buffer.
#define LATENCY_BUCKET_COUNT
measure the time elapsed performing an event
void perf_print_counter_fd(int fd, perf_counter_t handle)
Print one performance counter to a fd.
static sq_queue_t perf_counters
List of all known counters.
pthread_mutex_t perf_counters_mutex
mutex protecting access to the perf_counters linked list (which is read from & written to by differen...
perf_counter_type
Counter types.
void perf_reset_all(void)
Reset all of the performance counters.
void perf_set_elapsed(perf_counter_t handle, int64_t elapsed)
Register a measurement.
count the number of times an event occurs
High-resolution timer with callouts and timekeeping.
perf_counter_t perf_alloc(enum perf_counter_type type, const char *name)
Create a new local counter.
void(* perf_callback)(perf_counter_t handle, void *user)
void perf_reset(perf_counter_t handle)
Reset a performance counter.
const uint16_t latency_bucket_count
void perf_count(perf_counter_t handle)
Count a performance event.
void perf_free(perf_counter_t handle)
Free a counter.
void perf_print_all(int fd)
Print all of the performance counters.
perf_counter_t perf_alloc_once(enum perf_counter_type type, const char *name)
Get the reference to an existing counter or create a new one if it does not exist.
Simple error/warning functions, heavily inspired by the BSD functions of the same names...
void perf_end(perf_counter_t handle)
End a performance event.
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
void perf_iterate_all(perf_callback cb, void *user)
Iterate over all performance counters using a callback.
struct perf_ctr_header * perf_counter_t
void perf_print_counter(perf_counter_t handle)
Print one performance counter to stdout.
uint64_t perf_event_count(perf_counter_t handle)
Return current event_count.
void perf_cancel(perf_counter_t handle)
Cancel a performance event.
void perf_set_count(perf_counter_t handle, uint64_t count)
Set a counter.
const uint16_t latency_buckets[LATENCY_BUCKET_COUNT]
void perf_print_latency(int fd)
Print hrt latency counters.
void perf_begin(perf_counter_t handle)
Begin a performance event.
__EXPORT uint32_t latency_counters[LATENCY_BUCKET_COUNT+1]
measure the interval between instances of an event
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
Performance measuring tools.