2014-06-10 21:34:33 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file pios_instrumentation_helper.h
|
2016-08-31 05:59:34 +02:00
|
|
|
* @author The LibrePilot Project, http://www.librepilot.org, Copyright (C) 2016
|
2016-05-03 00:06:24 +02:00
|
|
|
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
|
2014-06-10 21:34:33 +02:00
|
|
|
* @brief Macros to easily add optional performance monitoring to a module
|
|
|
|
*
|
|
|
|
* @see The GNU Public License (GPL) Version 3
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2014-06-10 22:13:20 +02:00
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2014-06-10 21:34:33 +02:00
|
|
|
* (at your option) any later version.
|
2014-06-10 22:13:20 +02:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
2014-06-10 21:34:33 +02:00
|
|
|
* for more details.
|
2014-06-10 22:13:20 +02:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2014-06-10 21:34:33 +02:00
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2014-06-10 22:13:20 +02:00
|
|
|
/**
|
|
|
|
* @addtogroup PIOS PiOS Instrumentation Support
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-06-18 02:01:16 +02:00
|
|
|
* \par
|
|
|
|
* This is a collections of helper macros that ease adding instrumentation support.
|
|
|
|
* \par
|
|
|
|
* Step by step guide:
|
|
|
|
*
|
|
|
|
* Define PIOS_INSTRUMENT_MODULE before including this file to enable instrumentation for a module
|
|
|
|
*
|
|
|
|
* <pre>#define PIOS_INSTRUMENT_MODULE
|
|
|
|
* #include <pios_instrumentation_helper.h></pre>
|
|
|
|
*
|
|
|
|
* Declare the variables used to hold counter handlers.
|
|
|
|
* Place the following code along all module variables declaration.
|
|
|
|
* <pre>PERF_DEFINE_COUNTER(counterUpd);
|
|
|
|
* PERF_DEFINE_COUNTER(counterAccelSamples);
|
|
|
|
* PERF_DEFINE_COUNTER(counterPeriod);
|
|
|
|
* PERF_DEFINE_COUNTER(counterAtt);</pre>
|
|
|
|
*
|
|
|
|
* Counters needs to be initialized before they are used.
|
|
|
|
* The following code needs to be added to a function called at module initialization.
|
|
|
|
* the second parameter is a unique counter Id.
|
|
|
|
* A good pracice is to use the upper half word as module id and lower as counter id
|
2016-05-03 00:07:35 +02:00
|
|
|
* Optionally three strings containing Module Name, Counter description and unit of measure can be passed.
|
|
|
|
* Those strings will be used in future to automatically extract the list of counters from code to managed
|
|
|
|
* by GCS or some other custom tool.
|
|
|
|
*
|
|
|
|
* PERF_INIT_COUNTER(counterVariable, id, "MODULE NAME","COUNTER DESCRIPTION","UNIT OF MEASURE");
|
|
|
|
*
|
|
|
|
* <pre>PERF_INIT_COUNTER(counterUpd, 0xA7710001, "ATTITUDE", "Sensor update execution time", "us");
|
|
|
|
* PERF_INIT_COUNTER(counterAtt, 0xA7710002, "ATTITUDE", "Attitude estimation execution time", "us");
|
|
|
|
* PERF_INIT_COUNTER(counterPeriod, 0xA7710003, "ATTITUDE", "Sensor update period", "us");
|
|
|
|
* PERF_INIT_COUNTER(counterAccelSamples, 0xA7710004, "ATTITUDE", "Samples for each sensor cycle", "count");</pre>
|
2014-06-18 02:01:16 +02:00
|
|
|
*
|
|
|
|
* At this point you can start using the counters as in the following samples
|
|
|
|
*
|
|
|
|
* Track the time spent on a certain function:
|
|
|
|
* <pre>PERF_TIMED_SECTION_START(counterAtt);
|
|
|
|
* updateAttitude(&accelState, &gyros);
|
|
|
|
* PERF_TIMED_SECTION_END(counterAtt);</pre>
|
|
|
|
* PERF_TIMED_SECTION_[START!STOP] marks the beginning and the end of the code to monitor
|
|
|
|
*
|
|
|
|
* Measure the mean of the period a certain point is reached:
|
|
|
|
* <pre>PERF_MEASURE_PERIOD(counterPeriod);</pre>
|
|
|
|
* Note that the value stored in the counter is a long running mean while max and min are single point values
|
|
|
|
*
|
|
|
|
* Track an user defined int32_t value:
|
|
|
|
* <pre>PERF_TRACK_VALUE(counterAccelSamples, i);</pre>
|
|
|
|
* the counter is then updated with the value of i.
|
|
|
|
*
|
|
|
|
* \par
|
|
|
|
*/
|
2014-06-10 22:13:20 +02:00
|
|
|
|
2014-06-10 21:34:33 +02:00
|
|
|
#ifndef PIOS_INSTRUMENTATION_HELPER_H
|
|
|
|
#define PIOS_INSTRUMENTATION_HELPER_H
|
|
|
|
|
|
|
|
#if defined(PIOS_INCLUDE_INSTRUMENTATION) && defined(PIOS_INSTRUMENT_MODULE)
|
|
|
|
|
|
|
|
#include <pios_instrumentation.h>
|
|
|
|
/**
|
|
|
|
* include the following macro together with modules variable declaration
|
|
|
|
*/
|
2016-05-03 00:07:35 +02:00
|
|
|
#define PERF_DEFINE_COUNTER(x) static pios_counter_t x
|
2014-06-10 21:34:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* this mast be called at some module init code
|
|
|
|
*/
|
2016-05-03 00:07:35 +02:00
|
|
|
#define PERF_INIT_COUNTER(x, id, ...) x = PIOS_Instrumentation_CreateCounter(id)
|
2014-06-10 21:34:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* those are the monitoring macros
|
|
|
|
*/
|
2016-05-03 00:07:35 +02:00
|
|
|
#define PERF_TIMED_SECTION_START(x) PIOS_Instrumentation_TimeStart(x)
|
|
|
|
#define PERF_TIMED_SECTION_END(x) PIOS_Instrumentation_TimeEnd(x)
|
|
|
|
#define PERF_MEASURE_PERIOD(x) PIOS_Instrumentation_TrackPeriod(x)
|
|
|
|
#define PERF_TRACK_VALUE(x, y) PIOS_Instrumentation_updateCounter(x, y)
|
|
|
|
#define PERF_INCREMENT_VALUE(x) PIOS_Instrumentation_incrementCounter(x, 1)
|
|
|
|
#define PERF_DECREMENT_VALUE(x) PIOS_Instrumentation_incrementCounter(x, -1)
|
2014-06-10 21:34:33 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define PERF_DEFINE_COUNTER(x)
|
2016-05-03 00:07:35 +02:00
|
|
|
#define PERF_INIT_COUNTER(x, id, ...)
|
2014-06-10 21:34:33 +02:00
|
|
|
#define PERF_TIMED_SECTION_START(x)
|
|
|
|
#define PERF_TIMED_SECTION_END(x)
|
|
|
|
#define PERF_MEASURE_PERIOD(x)
|
2016-05-03 00:07:10 +02:00
|
|
|
#define PERF_TRACK_VALUE(x, y) (void)y
|
2015-04-26 14:33:25 +02:00
|
|
|
#define PERF_INCREMENT_VALUE(x)
|
|
|
|
#define PERF_DECREMENT_VALUE(x)
|
2014-06-10 21:34:33 +02:00
|
|
|
#endif /* PIOS_INCLUDE_INSTRUMENTATION */
|
|
|
|
#endif /* PIOS_INSTRUMENTATION_HELPER_H */
|