source: rtems/cpukit/sapi/include/rtems/profiling.h @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 9.4 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup Profiling
5 *
6 * @brief Profiling API
7 */
8
9/*
10 * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Dornierstr. 4
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.org/license/LICENSE.
21 */
22
23#ifndef _RTEMS_PROFILING_H
24#define _RTEMS_PROFILING_H
25
26#include <stdint.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif /* __cplusplus */
31
32/**
33 * @defgroup Profiling Profiling Support
34 *
35 * @brief The profiling support offers functions to report profiling
36 * information available in the system.
37 *
38 * Profiling support is by default disabled.  It must be enabled via the
39 * configure command line with the <tt>--enable-profiling</tt> option.  In this
40 * case the RTEMS_PROFILING pre-processor symbol is defined and profiling
41 * statistics will be gathered during system run-time.  The profiling support
42 * increases the time of critical sections and has some memory overhead.  The
43 * overhead should be acceptable for most applications.  The aim of the
44 * profiling implementation is to be available even for production systems so
45 * that verification is simplified.
46 *
47 * Profiling information includes critical timing values such as the maximum
48 * time of disabled thread dispatching which is a measure for the thread
49 * dispatch latency.  On SMP configurations statistics of all SMP locks in the
50 * system are available.
51 *
52 * Profiling information can be retrieved via rtems_profiling_iterate() and
53 * reported as an XML dump via rtems_profiling_report_xml().  These functions
54 * are always available, but actual profiling data is only available if enabled
55 * at build configuration time.
56 *
57 * @{
58 */
59
60/**
61 * @brief Type of profiling data.
62 */
63typedef enum {
64  /**
65   * @brief Type of per-CPU profiling data.
66   *
67   * @see rtems_profiling_per_cpu.
68   */
69  RTEMS_PROFILING_PER_CPU,
70
71  /**
72   * @brief Type of SMP lock profiling data.
73   *
74   * @see rtems_profiling_smp_lock.
75   */
76  RTEMS_PROFILING_SMP_LOCK
77} rtems_profiling_type;
78
79/**
80 * @brief The profiling data header.
81 */
82typedef struct {
83  /**
84   * @brief The profiling data type.
85   */
86  rtems_profiling_type type;
87} rtems_profiling_header;
88
89/**
90 * @brief Per-CPU profiling data.
91 *
92 * Theoretically all values in this structure can overflow, but the integer
93 * types are chosen so that they cannot overflow in practice.  On systems with
94 * a 1GHz CPU counter, the 64-bit integers can overflow in about 58 years.
95 * Since the system should not spend most of the time in critical sections the
96 * actual system run-time is much longer.  Several other counters in the system
97 * will overflow before we get a problem in the profiling area.
98 */
99typedef struct {
100  /**
101   * @brief The profiling data header.
102   */
103  rtems_profiling_header header;
104
105  /**
106   * @brief The processor index of this profiling data.
107   */
108  uint32_t processor_index;
109
110  /**
111   * @brief The maximum time of disabled thread dispatching in nanoseconds.
112   */
113  uint32_t max_thread_dispatch_disabled_time;
114
115  /**
116   * @brief Count of times when the thread dispatch disable level changes from
117   * zero to one in thread context.
118   *
119   * This value may overflow.
120   */
121  uint64_t thread_dispatch_disabled_count;
122
123  /**
124   * @brief Total time of disabled thread dispatching in nanoseconds.
125   *
126   * The average time of disabled thread dispatching is the total time of
127   * disabled thread dispatching divided by the thread dispatch disabled
128   * count.
129   *
130   * This value may overflow.
131   */
132  uint64_t total_thread_dispatch_disabled_time;
133
134  /**
135   * @brief The maximum interrupt delay in nanoseconds if supported by the
136   * hardware.
137   *
138   * The interrupt delay is the time interval from the recognition of an
139   * interrupt signal by the hardware up to the execution start of the
140   * corresponding high-level handler.  The interrupt delay is the main
141   * contributor to the interrupt latency.  To measure this time hardware
142   * support is required.  A time stamp unit must capture the interrupt signal
143   * recognition time.  If no hardware support is available, then this field
144   * will have a constant value of zero.
145   */
146  uint32_t max_interrupt_delay;
147
148  /**
149   * @brief The maximum time spent to process a single sequence of nested
150   * interrupts in nanoseconds.
151   *
152   * This is the time interval between the change of the interrupt nest level
153   * from zero to one and the change back from one to zero.  It is the measured
154   * worst-case execution time of interrupt service routines.  Please note that
155   * in case of nested interrupts this time includes the combined execution
156   * time and not the maximum time of an individual interrupt service routine.
157   */
158  uint32_t max_interrupt_time;
159
160  /**
161   * @brief Count of times when the interrupt nest level changes from zero to
162   * one.
163   *
164   * This value may overflow.
165   */
166  uint64_t interrupt_count;
167
168  /**
169   * @brief Total time of interrupt processing in nanoseconds.
170   *
171   * The average time of interrupt processing is the total time of interrupt
172   * processing divided by the interrupt count.
173   *
174   * This value may overflow.
175   */
176  uint64_t total_interrupt_time;
177} rtems_profiling_per_cpu;
178
179/**
180 * @brief Count of lock contention counters for SMP lock profiling.
181 */
182#define RTEMS_PROFILING_SMP_LOCK_CONTENTION_COUNTS 4
183
184/**
185 * @brief SMP lock profiling data.
186 *
187 * The lock acquire attempt instant is the point in time right after the
188 * interrupt disable action in the lock acquire sequence.
189 *
190 * The lock acquire instant is the point in time right after the lock
191 * acquisition.  This is the begin of the critical section code execution.
192 *
193 * The lock acquire time is the time elapsed between the lock acquire attempt
194 * instant and the lock acquire instant.
195 *
196 * The lock release instant is the point in time right before the interrupt
197 * enable action in the lock release sequence.
198 *
199 * The lock section time is the time elapsed between the lock acquire instant
200 * and the lock release instant.
201 */
202typedef struct {
203  /**
204   * @brief The profiling data header.
205   */
206  rtems_profiling_header header;
207
208  /**
209   * @brief The lock name.
210   */
211  const char *name;
212
213  /**
214   * @brief The maximum lock acquire time in nanoseconds.
215   */
216  uint32_t max_acquire_time;
217
218  /**
219   * @brief The maximum lock section time in nanoseconds.
220   */
221  uint32_t max_section_time;
222
223  /**
224   * @brief The count of lock uses.
225   *
226   * This value may overflow.
227   */
228  uint64_t usage_count;
229
230  /**
231   * @brief Total lock acquire time in nanoseconds.
232   *
233   * The average lock acquire time is the total acquire time divided by the
234   * lock usage count.  The ration of the total section and total acquire times
235   * gives a measure for the lock contention.
236   *
237   * This value may overflow.
238   */
239  uint64_t total_acquire_time;
240
241  /**
242   * @brief Total lock section time in nanoseconds.
243   *
244   * The average lock section time is the total section time divided by the
245   * lock usage count.
246   *
247   * This value may overflow.
248   */
249  uint64_t total_section_time;
250
251  /**
252   * @brief The counts of lock acquire operations by contention.
253   *
254   * The contention count for index N corresponds to a lock acquire attempt
255   * with an initial queue length of N.  The last index corresponds to all
256   * lock acquire attempts with an initial queue length greater than or equal
257   * to RTEMS_PROFILING_SMP_LOCK_CONTENTION_COUNTS minus one.
258   *
259   * The values may overflow.
260   */
261  uint64_t contention_counts[RTEMS_PROFILING_SMP_LOCK_CONTENTION_COUNTS];
262} rtems_profiling_smp_lock;
263
264/**
265 * @brief Collection of profiling data.
266 */
267typedef union {
268  /**
269   * @brief Header to specify the actual profiling data.
270   */
271  rtems_profiling_header header;
272
273  /**
274   * @brief Per-CPU profiling data if indicated by the header.
275   */
276  rtems_profiling_per_cpu per_cpu;
277
278  /**
279   * @brief SMP lock profiling data if indicated by the header.
280   */
281  rtems_profiling_smp_lock smp_lock;
282} rtems_profiling_data;
283
284/**
285 * @brief Visitor function for the profiling iteration.
286 *
287 * @param[in, out] arg The visitor argument.
288 * @param[in] data The current profiling data.
289 *
290 * @see rtems_profiling_iterate().
291 */
292typedef void (*rtems_profiling_visitor)(
293  void *arg,
294  const rtems_profiling_data *data
295);
296
297/**
298 * @brief Iterates through all profiling data of the system.
299 *
300 * @param[in] visitor The visitor.
301 * @param[in, out] visitor_arg The visitor argument.
302 */
303void rtems_profiling_iterate(
304  rtems_profiling_visitor visitor,
305  void *visitor_arg
306);
307
308/**
309 * @brief Function for formatted output.
310 *
311 * @param[in, out] arg Some argument.
312 * @param[in] format The output format as specified by printf().
313 * @param[in] ... More parameters according to format.
314 *
315 * @returns As specified by printf().
316 *
317 * @see rtems_profiling_report_xml().
318 */
319typedef int (*rtems_profiling_printf)(void *arg, const char *format, ...);
320
321/**
322 * @brief Reports profiling data as XML.
323 *
324 * @param[in] name The name of the profiling report.
325 * @param[in] printf_func The formatted output function.
326 * @param[in, out] printf_arg The formatted output function argument.
327 * @param[in] indentation_level The current indentation level.
328 * @param[in] indentation The string used for indentation.
329 *
330 * @returns As specified by printf().
331 */
332int rtems_profiling_report_xml(
333  const char *name,
334  rtems_profiling_printf printf_func,
335  void *printf_arg,
336  uint32_t indentation_level,
337  const char *indentation
338);
339
340/** @} */
341
342#ifdef __cplusplus
343}
344#endif /* __cplusplus */
345
346#endif /* _RTEMS_PROFILING_H */
Note: See TracBrowser for help on using the repository browser.