Firmware
perf_counter.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (C) 2012-2016 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
39 #ifndef _SYSTEMLIB_PERF_COUNTER_H
40 #define _SYSTEMLIB_PERF_COUNTER_H value
41 
42 #include <stdint.h>
43 #include <px4_defines.h>
44 
45 #define LATENCY_BUCKET_COUNT 8
46 
47 extern const uint16_t latency_bucket_count;
48 extern const uint16_t latency_buckets[LATENCY_BUCKET_COUNT];
49 extern uint32_t latency_counters[LATENCY_BUCKET_COUNT + 1];
50 
58 };
59 
60 struct perf_ctr_header;
61 typedef struct perf_ctr_header *perf_counter_t;
62 
63 __BEGIN_DECLS
64 
73 #ifndef perf_alloc // perf_alloc might be defined to be NULL in src/modules/px4iofirmware/px4io.h
74 __EXPORT extern perf_counter_t perf_alloc(enum perf_counter_type type, const char *name);
75 #endif
76 
85 __EXPORT extern perf_counter_t perf_alloc_once(enum perf_counter_type type, const char *name);
86 
92 __EXPORT extern void perf_free(perf_counter_t handle);
93 
101 __EXPORT extern void perf_count(perf_counter_t handle);
102 
110 __EXPORT extern void perf_begin(perf_counter_t handle);
111 
121 __EXPORT extern void perf_end(perf_counter_t handle);
122 
133 __EXPORT extern void perf_set_elapsed(perf_counter_t handle, int64_t elapsed);
134 
143 __EXPORT extern void perf_set_count(perf_counter_t handle, uint64_t count);
144 
153 __EXPORT extern void perf_cancel(perf_counter_t handle);
154 
162 __EXPORT extern void perf_reset(perf_counter_t handle);
163 
169 __EXPORT extern void perf_print_counter(perf_counter_t handle);
170 
177 __EXPORT extern void perf_print_counter_fd(int fd, perf_counter_t handle);
178 
187 __EXPORT extern int perf_print_counter_buffer(char *buffer, int length, perf_counter_t handle);
188 
194 __EXPORT extern void perf_print_all(int fd);
195 
196 
197 typedef void (*perf_callback)(perf_counter_t handle, void *user);
198 
209 __EXPORT extern void perf_iterate_all(perf_callback cb, void *user);
210 
216 __EXPORT extern void perf_print_latency(int fd);
217 
221 __EXPORT extern void perf_reset_all(void);
222 
229 __EXPORT extern uint64_t perf_event_count(perf_counter_t handle);
230 
231 __END_DECLS
232 
233 #endif
measure the time elapsed performing an event
Definition: perf_counter.h:56
__EXPORT void perf_print_counter_fd(int fd, perf_counter_t handle)
Print one performance counter to a fd.
Definition: perf_counter.cpp:447
__EXPORT void perf_print_latency(int fd)
Print hrt latency counters.
Definition: perf_counter.cpp:603
const char * name
counter name
Definition: perf_counter.cpp:68
__EXPORT void perf_set_count(perf_counter_t handle, uint64_t count)
Set a counter.
Definition: perf_counter.cpp:361
perf_counter_type
Counter types.
Definition: perf_counter.h:54
__EXPORT void perf_end(perf_counter_t handle)
End a performance event.
Definition: perf_counter.cpp:275
__EXPORT void perf_print_counter(perf_counter_t handle)
Print one performance counter to stdout.
Definition: perf_counter.cpp:437
count the number of times an event occurs
Definition: perf_counter.h:55
__EXPORT void perf_reset_all(void)
Reset all of the performance counters.
Definition: perf_counter.cpp:616
Generally used magic defines.
Header common to all counters.
Definition: perf_counter.cpp:65
Definition: I2C.hpp:51
__EXPORT void perf_iterate_all(perf_callback cb, void *user)
Iterate over all performance counters using a callback.
Definition: perf_counter.cpp:575
enum perf_counter_type type
counter type
Definition: perf_counter.cpp:67
__EXPORT uint64_t perf_event_count(perf_counter_t handle)
Return current event_count.
Definition: perf_counter.cpp:547
__EXPORT int perf_print_counter_buffer(char *buffer, int length, perf_counter_t handle)
Print one performance counter to a buffer.
Definition: perf_counter.cpp:495
__EXPORT void perf_cancel(perf_counter_t handle)
Cancel a performance event.
Definition: perf_counter.cpp:380
__EXPORT void perf_begin(perf_counter_t handle)
Begin a performance event.
Definition: perf_counter.cpp:258
Definition: video_device.h:50
__BEGIN_DECLS __EXPORT perf_counter_t perf_alloc(enum perf_counter_type type, const char *name)
Create a new local counter.
Definition: perf_counter.cpp:123
__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.
Definition: perf_counter.cpp:156
__EXPORT void perf_set_elapsed(perf_counter_t handle, int64_t elapsed)
Register a measurement.
Definition: perf_counter.cpp:320
__EXPORT void perf_count(perf_counter_t handle)
Count a performance event.
Definition: perf_counter.cpp:199
__EXPORT void perf_print_all(int fd)
Print all of the performance counters.
Definition: perf_counter.cpp:589
__EXPORT void perf_reset(perf_counter_t handle)
Reset a performance counter.
Definition: perf_counter.cpp:402
measure the interval between instances of an event
Definition: perf_counter.h:57
__EXPORT void perf_free(perf_counter_t handle)
Free a counter.
Definition: perf_counter.cpp:185