Firmware
Macros | Typedefs | Enumerations | Functions | Variables
perf_counter.h File Reference

Performance measuring tools. More...

#include <stdint.h>
#include <px4_defines.h>

Go to the source code of this file.

Macros

#define _SYSTEMLIB_PERF_COUNTER_H   value
 
#define LATENCY_BUCKET_COUNT   8
 

Typedefs

typedef struct perf_ctr_headerperf_counter_t
 
typedef void(* perf_callback) (perf_counter_t handle, void *user)
 

Enumerations

enum  perf_counter_type { PC_COUNT, PC_ELAPSED, PC_INTERVAL }
 Counter types. More...
 

Functions

__BEGIN_DECLS __EXPORT perf_counter_t perf_alloc (enum perf_counter_type type, const char *name)
 Create a new local counter. More...
 
__EXPORT 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. More...
 
__EXPORT void perf_free (perf_counter_t handle)
 Free a counter. More...
 
__EXPORT void perf_count (perf_counter_t handle)
 Count a performance event. More...
 
__EXPORT void perf_begin (perf_counter_t handle)
 Begin a performance event. More...
 
__EXPORT void perf_end (perf_counter_t handle)
 End a performance event. More...
 
__EXPORT void perf_set_elapsed (perf_counter_t handle, int64_t elapsed)
 Register a measurement. More...
 
__EXPORT void perf_set_count (perf_counter_t handle, uint64_t count)
 Set a counter. More...
 
__EXPORT void perf_cancel (perf_counter_t handle)
 Cancel a performance event. More...
 
__EXPORT void perf_reset (perf_counter_t handle)
 Reset a performance counter. More...
 
__EXPORT void perf_print_counter (perf_counter_t handle)
 Print one performance counter to stdout. More...
 
__EXPORT void perf_print_counter_fd (int fd, perf_counter_t handle)
 Print one performance counter to a fd. More...
 
__EXPORT int perf_print_counter_buffer (char *buffer, int length, perf_counter_t handle)
 Print one performance counter to a buffer. More...
 
__EXPORT void perf_print_all (int fd)
 Print all of the performance counters. More...
 
__EXPORT void perf_iterate_all (perf_callback cb, void *user)
 Iterate over all performance counters using a callback. More...
 
__EXPORT void perf_print_latency (int fd)
 Print hrt latency counters. More...
 
__EXPORT void perf_reset_all (void)
 Reset all of the performance counters.
 
__EXPORT uint64_t perf_event_count (perf_counter_t handle)
 Return current event_count. More...
 

Variables

const uint16_t latency_bucket_count
 
const uint16_t latency_buckets [LATENCY_BUCKET_COUNT]
 
uint32_t latency_counters [LATENCY_BUCKET_COUNT+1]
 

Detailed Description

Performance measuring tools.

Enumeration Type Documentation

§ perf_counter_type

Counter types.

Enumerator
PC_COUNT 

count the number of times an event occurs

PC_ELAPSED 

measure the time elapsed performing an event

PC_INTERVAL 

measure the interval between instances of an event

Function Documentation

§ perf_alloc()

__BEGIN_DECLS __EXPORT perf_counter_t perf_alloc ( enum perf_counter_type  type,
const char *  name 
)

Create a new local counter.

Parameters
typeThe type of the new counter.
nameThe counter name.
Returns
Handle for the new counter, or NULL if a counter could not be allocated.

§ perf_alloc_once()

__EXPORT 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.

Parameters
typeThe type of the counter.
nameThe counter name.
Returns
Handle for the counter, or NULL if a counter could not be allocated.

§ perf_begin()

__EXPORT void perf_begin ( perf_counter_t  handle)

Begin a performance event.

This call applies to counters that operate over ranges of time; PC_ELAPSED etc.

Parameters
handleThe handle returned from perf_alloc.

§ perf_cancel()

__EXPORT void perf_cancel ( perf_counter_t  handle)

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.

Parameters
handleThe handle returned from perf_alloc.

§ perf_count()

__EXPORT void perf_count ( perf_counter_t  handle)

Count a performance event.

This call only affects counters that take single events; PC_COUNT, PC_INTERVAL etc.

Parameters
handleThe handle returned from perf_alloc.

§ perf_end()

__EXPORT void perf_end ( 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 corresponding perf_begin call, or if perf_cancel has been called subsequently, no change is made to the counter.

Parameters
handleThe handle returned from perf_alloc.

§ perf_event_count()

__EXPORT uint64_t perf_event_count ( perf_counter_t  handle)

Return current event_count.

Parameters
handleThe counter returned from perf_alloc.
Returns
event_count

§ perf_free()

__EXPORT void perf_free ( perf_counter_t  handle)

Free a counter.

Parameters
handleThe performance counter's handle.

§ perf_iterate_all()

__EXPORT void perf_iterate_all ( perf_callback  cb,
void *  user 
)

Iterate over all performance counters using a callback.

Caution: This will aquire the mutex, so do not call any other perf_* method that aquire the mutex as well from the callback (If this is needed, configure the mutex to be reentrant).

Parameters
cbcallback method
usercustom argument for the callback

§ perf_print_all()

__EXPORT void perf_print_all ( int  fd)

Print all of the performance counters.

Parameters
fdFile descriptor to print to - e.g. 0 for stdout

§ perf_print_counter()

__EXPORT void perf_print_counter ( perf_counter_t  handle)

Print one performance counter to stdout.

Parameters
handleThe counter to print.

§ perf_print_counter_buffer()

__EXPORT int perf_print_counter_buffer ( char *  buffer,
int  length,
perf_counter_t  handle 
)

Print one performance counter to a buffer.

Parameters
bufferbuffer to write to
lengthbuffer length
handleThe counter to print.
returnnumber of bytes written

§ perf_print_counter_fd()

__EXPORT void perf_print_counter_fd ( int  fd,
perf_counter_t  handle 
)

Print one performance counter to a fd.

Parameters
fdFile descriptor to print to - e.g. 0 for stdout
handleThe counter to print.

§ perf_print_latency()

__EXPORT void perf_print_latency ( int  fd)

Print hrt latency counters.

Parameters
fdFile descriptor to print to - e.g. 0 for stdout

§ perf_reset()

__EXPORT void perf_reset ( perf_counter_t  handle)

Reset a performance counter.

This call resets performance counter to initial state

Parameters
handleThe handle returned from perf_alloc.

§ perf_set_count()

__EXPORT void perf_set_count ( perf_counter_t  handle,
uint64_t  count 
)

Set a counter.

This call applies to counters of type PC_COUNT. It (re-)sets the count.

Parameters
handleThe handle returned from perf_alloc.
countThe counter value to be set.

§ perf_set_elapsed()

__EXPORT void perf_set_elapsed ( perf_counter_t  handle,
int64_t  elapsed 
)

Register a measurement.

This call applies to counters that operate over ranges of time; PC_ELAPSED etc. If a call is made without a corresponding perf_begin call. It sets the value provided as argument as a new measurement.

Parameters
handleThe handle returned from perf_alloc.
elapsedThe time elapsed. Negative values lead to incrementing the overrun counter.