mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-27 17:06:31 +08:00
combine sys_mon and rtos_mon modules (#1846)
Only one module (sys_mon) used - it will automatically detect if it is rtos, sim or bare-metal and will send the proper message (RTOS_MON or SYS_MON). Easier to use because the user don't have to change between sys_mon and rtos_mon anymore. Plus added support for CPU load on SIM targets
This commit is contained in:
committed by
Felix Ruess
parent
5d09b74ddd
commit
41b2e7ec47
@@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
|
<module name="sys_mon"/>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<servos driver="Pwm">
|
<servos driver="Pwm">
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
<!-- Sensors -->
|
<!-- Sensors -->
|
||||||
<module name="gps" type="ublox"/>
|
<module name="gps" type="ublox"/>
|
||||||
|
|
||||||
<!--module name="rtos_mon"/-->
|
<!--module name="sys_mon"/-->
|
||||||
|
|
||||||
<!--module name="spi_master"/-->
|
<!--module name="spi_master"/-->
|
||||||
<!-- <module name="mcp355x"> -->
|
<!-- <module name="mcp355x"> -->
|
||||||
|
|||||||
@@ -69,7 +69,7 @@
|
|||||||
<module name="current_sensor">
|
<module name="current_sensor">
|
||||||
<configure name="ADC_CURRENT_SENSOR" value="ADC_2"/>
|
<configure name="ADC_CURRENT_SENSOR" value="ADC_2"/>
|
||||||
</module>
|
</module>
|
||||||
<!--module name="rtos_mon"/-->
|
<!--module name="sys_mon"/-->
|
||||||
</firmware>
|
</firmware>
|
||||||
|
|
||||||
<!-- commands section -->
|
<!-- commands section -->
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
<!DOCTYPE module SYSTEM "module.dtd">
|
|
||||||
|
|
||||||
<module name="rtos_mon" dir="core">
|
|
||||||
<doc>
|
|
||||||
<description>
|
|
||||||
RTOS monitoring tool
|
|
||||||
|
|
||||||
Reports:
|
|
||||||
- CPU load
|
|
||||||
- core and heap free memory
|
|
||||||
- number of threads, their load and free stack.
|
|
||||||
|
|
||||||
Can be used with ChibiOS implementation
|
|
||||||
</description>
|
|
||||||
</doc>
|
|
||||||
<header>
|
|
||||||
<file name="rtos_mon.h"/>
|
|
||||||
</header>
|
|
||||||
<init fun="rtos_mon_init()"/>
|
|
||||||
<periodic fun="rtos_mon_periodic()" freq="1" autorun="TRUE"/>
|
|
||||||
<makefile target="!nps">
|
|
||||||
<file name="rtos_mon.c"/>
|
|
||||||
<file_arch name="rtos_mon_arch.c"/>
|
|
||||||
</makefile>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
@@ -5,8 +5,9 @@
|
|||||||
<description>
|
<description>
|
||||||
System monitor.
|
System monitor.
|
||||||
The sys_mon module gives you some information about the timing of the periodic tasks and a rough estimate of cpu load (averaged over 1 sec).
|
The sys_mon module gives you some information about the timing of the periodic tasks and a rough estimate of cpu load (averaged over 1 sec).
|
||||||
|
For systems with RTOS it also gives you stats about threads and memory usage.
|
||||||
|
|
||||||
The SYS_MON message contains the following information (all times are given in microseconds):
|
For bare-metal systems, the SYS_MON message contains the following information (all times are given in microseconds):
|
||||||
- @b periodic_time : time between two calls of the modules_periodic_task (averaged over 1s)
|
- @b periodic_time : time between two calls of the modules_periodic_task (averaged over 1s)
|
||||||
- @b periodic_time_min : minimum time between two calls of the modules_periodic_task() during the last second
|
- @b periodic_time_min : minimum time between two calls of the modules_periodic_task() during the last second
|
||||||
- @b periodic_time_max : maximum time between two calls of the modules_periodic_task() during the last second
|
- @b periodic_time_max : maximum time between two calls of the modules_periodic_task() during the last second
|
||||||
@@ -15,15 +16,22 @@ The SYS_MON message contains the following information (all times are given in m
|
|||||||
- @b periodic_cycle_max : maximum time it took to execute the main periodic functions during the last second
|
- @b periodic_cycle_max : maximum time it took to execute the main periodic functions during the last second
|
||||||
- @b event_number : number of times the event loop was called during the last second
|
- @b event_number : number of times the event loop was called during the last second
|
||||||
- @b cpu_load : rough estimate of cpu load (averaged over 1 sec)
|
- @b cpu_load : rough estimate of cpu load (averaged over 1 sec)
|
||||||
|
- @b cpu_time : time in seconds since start-up
|
||||||
|
|
||||||
So your periodic_time should be 1/MODULES_FREQUENCY, which should be the same as 1/PERIODIC_FREQUENCY
|
So your periodic_time should be 1/MODULES_FREQUENCY, which should be the same as 1/PERIODIC_FREQUENCY
|
||||||
The periodic_cycle_max should not be over the periodic_time, otherwise in at least one cycle it took longer to calculate everything and the next one was slightly delayed.
|
The periodic_cycle_max should not be over the periodic_time, otherwise in at least one cycle it took longer to calculate everything and the next one was slightly delayed.
|
||||||
|
|
||||||
|
|
||||||
The sys_mon module has to run at the full main frequency!
|
The sys_mon module has to run at the full main frequency!
|
||||||
|
|
||||||
So either don't specify a main_freq parameter for the modules node or set your actual main frequency
|
So either don't specify a main_freq parameter for the modules node or set your actual main frequency
|
||||||
|
|
||||||
|
|
||||||
|
For systems with RTOS, RTOS_MON message is sent instead and the following information are shown:
|
||||||
|
- @b nb_thread : number of threads running
|
||||||
|
- @b cpu_load : rough estimate of cpu load (averaged over 1 sec)
|
||||||
|
- @b core_free : Core free memory (bytes)
|
||||||
|
- @b heap_free : Heap free memory (bytes)
|
||||||
|
- @b cpu_time : time in seconds since start-up
|
||||||
|
|
||||||
|
Again, the sys_mon module has to run at the full main frequency (so the reports are generated at 1 second intervals).
|
||||||
</description>
|
</description>
|
||||||
</doc>
|
</doc>
|
||||||
<header>
|
<header>
|
||||||
@@ -33,8 +41,23 @@ So either don't specify a main_freq parameter for the modules node or set your a
|
|||||||
<periodic fun="periodic_report_sysmon()" freq="1."/>
|
<periodic fun="periodic_report_sysmon()" freq="1."/>
|
||||||
<periodic fun="periodic_sysmon()"/>
|
<periodic fun="periodic_sysmon()"/>
|
||||||
<event fun="event_sysmon()"/>
|
<event fun="event_sysmon()"/>
|
||||||
|
|
||||||
<makefile target="ap">
|
<makefile target="ap">
|
||||||
<file name="sys_mon.c"/>
|
<raw>
|
||||||
|
# for ChibiOS arch include rtos_mon.c and rtos_mon_arch.c
|
||||||
|
ifeq ($(ARCH), chibios)
|
||||||
|
$(TARGET).srcs += $(SRC_MODULES)/core/rtos_mon.c
|
||||||
|
$(TARGET).srcs += $(SRC_ARCH)/modules/core/rtos_mon_arch.c
|
||||||
|
else
|
||||||
|
# for all other architecture use existing sys_mon.c
|
||||||
|
$(TARGET).srcs += $(SRC_MODULES)/core/sys_mon.c
|
||||||
|
endif
|
||||||
|
</raw>
|
||||||
|
</makefile>
|
||||||
|
|
||||||
|
<makefile target="nps">
|
||||||
|
<file name="rtos_mon.c"/>
|
||||||
|
<file_arch name="rtos_mon_arch.c"/>
|
||||||
</makefile>
|
</makefile>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
|
|||||||
@@ -24,11 +24,8 @@
|
|||||||
* ChibiOS implementation
|
* ChibiOS implementation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "modules/core/rtos_mon.h"
|
#include "modules/core/sys_mon_rtos.h"
|
||||||
#include "modules/core/rtos_mon_arch.h"
|
|
||||||
#include "subsystems/datalink/downlink.h"
|
|
||||||
#include <ch.h>
|
#include <ch.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#if !CH_DBG_THREADS_PROFILING
|
#if !CH_DBG_THREADS_PROFILING
|
||||||
#error CH_DBG_THREADS_PROFILING should be defined to TRUE to use this monitoring tool
|
#error CH_DBG_THREADS_PROFILING should be defined to TRUE to use this monitoring tool
|
||||||
@@ -91,11 +88,9 @@ void rtos_mon_periodic_arch(void)
|
|||||||
|
|
||||||
// assume we call the counter once a second
|
// assume we call the counter once a second
|
||||||
// so the difference in seconds is always one
|
// so the difference in seconds is always one
|
||||||
// NOTE: not perfectly precise
|
// NOTE: not perfectly precise, +-5% on average so take it into consideration
|
||||||
// FIXME: add finer resolution than seconds?
|
|
||||||
rtos_mon.cpu_load = (1 - (float)(idle_counter - last_idle_counter) / CH_CFG_ST_FREQUENCY) * 100;
|
rtos_mon.cpu_load = (1 - (float)(idle_counter - last_idle_counter) / CH_CFG_ST_FREQUENCY) * 100;
|
||||||
last_idle_counter = idle_counter;
|
last_idle_counter = idle_counter;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16_t get_stack_free(const thread_t *tp)
|
static uint16_t get_stack_free(const thread_t *tp)
|
||||||
|
|||||||
+25
-11
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016 Gautier Hattenberger <gautier.hattenberger@enac.fr>
|
* Copyright (C) 2016 Gautier Hattenberger <gautier.hattenberger@enac.fr>
|
||||||
|
* Copyright (C) 2016 Michal Podhradsky <michal.podhradsky@aggiemail.usu.edu>
|
||||||
*
|
*
|
||||||
* This file is part of paparazzi
|
* This file is part of paparazzi
|
||||||
*
|
*
|
||||||
@@ -18,19 +19,32 @@
|
|||||||
* <http://www.gnu.org/licenses/>.
|
* <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @file "arch/chibios/modules/core/rtos_mon_arch.h"
|
* @file "arch/sim/modules/core/rtos_mon_arch.c"
|
||||||
* @author Gautier Hattenberger
|
* @author Michal Podhradsky
|
||||||
* RTOS monitoring tool
|
* System monitoring tool
|
||||||
* ChibiOS implementation
|
* SIM implementation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef RTOS_MON_ARCH_H
|
#include "modules/core/sys_mon_rtos.h"
|
||||||
#define RTOS_MON_ARCH_H
|
#include <stdlib.h> /* atof */
|
||||||
|
#include <stdio.h> /* printf, fgets */
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
// Init function
|
void rtos_mon_init_arch(void) {}
|
||||||
extern void rtos_mon_init_arch(void);
|
|
||||||
// Periodic report
|
|
||||||
extern void rtos_mon_periodic_arch(void);
|
|
||||||
|
|
||||||
#endif
|
// Ask for CPU usage of the process
|
||||||
|
void rtos_mon_periodic_arch(void)
|
||||||
|
{
|
||||||
|
char line[20];
|
||||||
|
FILE *cmd = popen("ps -C simsitl -o %CPU", "r");
|
||||||
|
|
||||||
|
char *ret;
|
||||||
|
ret = fgets(line, sizeof(line), cmd);
|
||||||
|
ret = fgets(line, sizeof(line), cmd);
|
||||||
|
if (ret != NULL) {
|
||||||
|
double cpu = atof(ret);
|
||||||
|
rtos_mon.cpu_load = (uint8_t)cpu;
|
||||||
|
}
|
||||||
|
pclose(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -23,14 +23,13 @@
|
|||||||
* RTOS monitoring tool
|
* RTOS monitoring tool
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "modules/core/rtos_mon.h"
|
#include "modules/core/sys_mon.h"
|
||||||
#include "modules/core/rtos_mon_arch.h"
|
#include "modules/core/sys_mon_rtos.h"
|
||||||
#include "subsystems/datalink/downlink.h"
|
#include "subsystems/datalink/downlink.h"
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
struct rtos_monitoring rtos_mon;
|
struct rtos_monitoring rtos_mon;
|
||||||
|
|
||||||
void rtos_mon_init(void)
|
void init_sysmon(void)
|
||||||
{
|
{
|
||||||
// zero structure
|
// zero structure
|
||||||
memset(&rtos_mon, 0, sizeof(struct rtos_monitoring));
|
memset(&rtos_mon, 0, sizeof(struct rtos_monitoring));
|
||||||
@@ -41,7 +40,7 @@ void rtos_mon_init(void)
|
|||||||
|
|
||||||
// Periodic report of RTOS parameters
|
// Periodic report of RTOS parameters
|
||||||
// This function is actually arch dependent
|
// This function is actually arch dependent
|
||||||
void rtos_mon_periodic(void)
|
void periodic_report_sysmon(void)
|
||||||
{
|
{
|
||||||
// update struct
|
// update struct
|
||||||
rtos_mon_periodic_arch();
|
rtos_mon_periodic_arch();
|
||||||
@@ -59,4 +58,6 @@ void rtos_mon_periodic(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void periodic_sysmon(void) {}
|
||||||
|
|
||||||
|
void event_sysmon(void) {}
|
||||||
|
|||||||
@@ -19,10 +19,20 @@
|
|||||||
* Boston, MA 02111-1307, USA.
|
* Boston, MA 02111-1307, USA.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
/** \file sys_mon.c
|
||||||
|
*
|
||||||
|
* System monitoring for bare metal targets
|
||||||
|
* return cpu load, average exec time, ...
|
||||||
|
*/
|
||||||
|
|
||||||
#include "core/sys_mon.h"
|
#include "core/sys_mon.h"
|
||||||
|
#include "core/sys_mon_bare_metal.h"
|
||||||
#include "mcu_periph/sys_time.h"
|
#include "mcu_periph/sys_time.h"
|
||||||
|
|
||||||
|
#include "mcu_periph/uart.h"
|
||||||
|
#include "pprzlink/messages.h"
|
||||||
|
#include "subsystems/datalink/downlink.h"
|
||||||
|
|
||||||
/** Global system monitor data (averaged over 1 sec) */
|
/** Global system monitor data (averaged over 1 sec) */
|
||||||
struct SysMon sys_mon;
|
struct SysMon sys_mon;
|
||||||
|
|
||||||
@@ -60,10 +70,6 @@ void init_sysmon(void)
|
|||||||
periodic_timer = 0;
|
periodic_timer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "mcu_periph/uart.h"
|
|
||||||
#include "pprzlink/messages.h"
|
|
||||||
#include "subsystems/datalink/downlink.h"
|
|
||||||
|
|
||||||
void periodic_report_sysmon(void)
|
void periodic_report_sysmon(void)
|
||||||
{
|
{
|
||||||
/** Report system status at low frequency */
|
/** Report system status at low frequency */
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
/** \file sys_mon.h
|
/** \file sys_mon.h
|
||||||
*
|
*
|
||||||
* System monitoring
|
* System monitoring common header
|
||||||
* return cpu load, average exec time, ...
|
* return cpu load, average exec time, ...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -31,20 +31,6 @@
|
|||||||
|
|
||||||
#include "std.h"
|
#include "std.h"
|
||||||
|
|
||||||
struct SysMon {
|
|
||||||
uint8_t cpu_load;
|
|
||||||
uint16_t periodic_time; ///< in usec
|
|
||||||
uint16_t periodic_time_min; ///< in usec
|
|
||||||
uint16_t periodic_time_max; ///< in usec
|
|
||||||
uint16_t periodic_cycle; ///< in usec
|
|
||||||
uint16_t periodic_cycle_min; ///< in usec
|
|
||||||
uint16_t periodic_cycle_max; ///< in usec
|
|
||||||
uint16_t event_number;
|
|
||||||
float cpu_time; // in secs since startup
|
|
||||||
};
|
|
||||||
|
|
||||||
extern struct SysMon sys_mon;
|
|
||||||
|
|
||||||
/** Init system monitoring
|
/** Init system monitoring
|
||||||
*/
|
*/
|
||||||
void init_sysmon(void);
|
void init_sysmon(void);
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Gautier Hattenberger <gautier.hattenberger@enac.fr>
|
||||||
|
*
|
||||||
|
* This file is part of paparazzi.
|
||||||
|
*
|
||||||
|
* paparazzi 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 2, or (at your option)
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* paparazzi 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 paparazzi; see the file COPYING. If not, write to
|
||||||
|
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** \file sys_mon.h
|
||||||
|
*
|
||||||
|
* System monitoring
|
||||||
|
* return cpu load, average exec time, ...
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SYS_MON_BARE_METAL_H
|
||||||
|
#define SYS_MON_BARE_METAL_H
|
||||||
|
|
||||||
|
#include "core/sys_mon.h"
|
||||||
|
|
||||||
|
struct SysMon {
|
||||||
|
uint8_t cpu_load;
|
||||||
|
uint16_t periodic_time; ///< in usec
|
||||||
|
uint16_t periodic_time_min; ///< in usec
|
||||||
|
uint16_t periodic_time_max; ///< in usec
|
||||||
|
uint16_t periodic_cycle; ///< in usec
|
||||||
|
uint16_t periodic_cycle_min; ///< in usec
|
||||||
|
uint16_t periodic_cycle_max; ///< in usec
|
||||||
|
uint16_t event_number;
|
||||||
|
float cpu_time; // in secs since startup
|
||||||
|
};
|
||||||
|
|
||||||
|
extern struct SysMon sys_mon;
|
||||||
|
|
||||||
|
#endif /* SYS_MON_BARE_METAL_H */
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016 Gautier Hattenberger <gautier.hattenberger@enac.fr>
|
* Copyright (C) 2016 Gautier Hattenberger <gautier.hattenberger@enac.fr>
|
||||||
*
|
*
|
||||||
* This file is part of paparazzi
|
* This file is part of paparazzi.
|
||||||
*
|
*
|
||||||
* paparazzi is free software; you can redistribute it and/or modify
|
* paparazzi is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -14,19 +14,22 @@
|
|||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with paparazzi; see the file COPYING. If not, see
|
* along with paparazzi; see the file COPYING. If not, write to
|
||||||
* <http://www.gnu.org/licenses/>.
|
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||||
*/
|
* Boston, MA 02111-1307, USA.
|
||||||
/**
|
*
|
||||||
* @file "modules/core/rtos_mon.h"
|
|
||||||
* @author Gautier Hattenberger
|
|
||||||
* RTOS monitoring tool
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef RTOS_MON_H
|
/** \file sys_mon_rtos.h
|
||||||
#define RTOS_MON_H
|
*
|
||||||
|
* System monitoring for RTOS targets
|
||||||
|
* return cpu load, average exec time, ...
|
||||||
|
*/
|
||||||
|
|
||||||
#include "std.h"
|
#ifndef SYS_MON_RTOS_H
|
||||||
|
#define SYS_MON_RTOS_H
|
||||||
|
|
||||||
|
#include "core/sys_mon.h"
|
||||||
|
|
||||||
// Maximum number of threads
|
// Maximum number of threads
|
||||||
// The limit is related to the max size of the report message
|
// The limit is related to the max size of the report message
|
||||||
@@ -55,9 +58,8 @@ struct rtos_monitoring {
|
|||||||
extern struct rtos_monitoring rtos_mon;
|
extern struct rtos_monitoring rtos_mon;
|
||||||
|
|
||||||
// Init function
|
// Init function
|
||||||
extern void rtos_mon_init(void);
|
extern void rtos_mon_init_arch(void);
|
||||||
// Periodic report
|
// Periodic report
|
||||||
extern void rtos_mon_periodic(void);
|
extern void rtos_mon_periodic_arch(void);
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#endif /* SYS_MON_RTOS_H */
|
||||||
Reference in New Issue
Block a user