diff --git a/flight/libraries/inc/instrumentation.h b/flight/libraries/inc/instrumentation.h new file mode 100644 index 000000000..f6734ab0b --- /dev/null +++ b/flight/libraries/inc/instrumentation.h @@ -0,0 +1,34 @@ +/** + ****************************************************************************** + * + * @file instrumentation.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014. + * @brief brief goes here. + * -- + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * 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 + * (at your option) any later version. + * + * 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 + * for more details. + * + * 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., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef INSTRUMENTATION_H +#define INSTRUMENTATION_H +#include + +void InstrumentationInit(); + +void InstrumentationPublishAllCounters(); + +#endif /* INSTRUMENTATION_H */ diff --git a/flight/libraries/instrumentation.c b/flight/libraries/instrumentation.c new file mode 100644 index 000000000..927fcc7af --- /dev/null +++ b/flight/libraries/instrumentation.c @@ -0,0 +1,62 @@ +/** + ****************************************************************************** + * + * @file instrumentation.c + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014. + * @brief brief goes here. + * -- + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * 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 + * (at your option) any later version. + * + * 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 + * for more details. + * + * 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., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include + +static uint8_t publishedCountersInstances = 0; +static void counterCallback(const pios_perf_counter_t *counter, const int8_t index, void *context); +static xSemaphoreHandle sem; +void InstrumentationInit() +{ + PerfCounterInitialize(); + publishedCountersInstances = 1; + vSemaphoreCreateBinary(sem); +} + +void InstrumentationPublishAllCounters() +{ + if (xSemaphoreTake(sem, 0) != pdTRUE) { + return; + } + PIOS_Instrumentation_ForEachCounter(&counterCallback, NULL); + xSemaphoreGive(sem); +} + +void counterCallback(const pios_perf_counter_t *counter, const int8_t index, __attribute__((unused)) void *context) +{ + if (publishedCountersInstances < index) { + PerfCounterCreateInstance(); + publishedCountersInstances++; + } + PerfCounterData data; + data.Id = counter->id; + data.Counter.Max = counter->max; + data.Counter.Min = counter->min; + data.Counter.Value = counter->value; + PerfCounterInstSet(index, &data); +} diff --git a/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro b/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro index 3b8a61432..0f08a3536 100644 --- a/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro +++ b/ground/openpilotgcs/src/plugins/uavobjects/uavobjects.pro @@ -126,7 +126,8 @@ HEADERS += \ $$UAVOBJECT_SYNTHETICS/waypoint.h \ $$UAVOBJECT_SYNTHETICS/waypointactive.h \ $$UAVOBJECT_SYNTHETICS/mpu6000settings.h \ - $$UAVOBJECT_SYNTHETICS/takeofflocation.h + $$UAVOBJECT_SYNTHETICS/takeofflocation.h \ + $$UAVOBJECT_SYNTHETICS/perfcounter.h SOURCES += \ $$UAVOBJECT_SYNTHETICS/accelgyrosettings.cpp \ @@ -229,4 +230,6 @@ SOURCES += \ $$UAVOBJECT_SYNTHETICS/waypoint.cpp \ $$UAVOBJECT_SYNTHETICS/waypointactive.cpp \ $$UAVOBJECT_SYNTHETICS/mpu6000settings.cpp \ - $$UAVOBJECT_SYNTHETICS/takeofflocation.cpp + $$UAVOBJECT_SYNTHETICS/takeofflocation.cpp \ + $$UAVOBJECT_SYNTHETICS/perfcounter.cpp + diff --git a/shared/uavobjectdefinition/perfcounter.xml b/shared/uavobjectdefinition/perfcounter.xml new file mode 100644 index 000000000..cad949197 --- /dev/null +++ b/shared/uavobjectdefinition/perfcounter.xml @@ -0,0 +1,11 @@ + + + A single performance counter, used to instrument flight code + + + + + + + +