|
|
|
@ -33,6 +33,7 @@
@@ -33,6 +33,7 @@
|
|
|
|
|
|
|
|
|
|
#include "LoadMon.hpp" |
|
|
|
|
|
|
|
|
|
#if defined(__PX4_NUTTX) |
|
|
|
|
// if free stack space falls below this, print a warning
|
|
|
|
|
#if defined(CONFIG_ARMV7M_STACKCHECK) |
|
|
|
|
static constexpr unsigned STACK_LOW_WARNING_THRESHOLD = 100; |
|
|
|
@ -41,6 +42,7 @@ static constexpr unsigned STACK_LOW_WARNING_THRESHOLD = 300;
@@ -41,6 +42,7 @@ static constexpr unsigned STACK_LOW_WARNING_THRESHOLD = 300;
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
static constexpr unsigned FDS_LOW_WARNING_THRESHOLD = 2; ///< if free file descriptors fall below this, print a warning
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
using namespace time_literals; |
|
|
|
|
|
|
|
|
@ -88,10 +90,14 @@ void LoadMon::Run()
@@ -88,10 +90,14 @@ void LoadMon::Run()
|
|
|
|
|
|
|
|
|
|
cpuload(); |
|
|
|
|
|
|
|
|
|
#if defined(__PX4_NUTTX) |
|
|
|
|
|
|
|
|
|
if (_param_sys_stck_en.get()) { |
|
|
|
|
stack_usage(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
if (should_exit()) { |
|
|
|
|
ScheduleClear(); |
|
|
|
|
exit_and_cleanup(); |
|
|
|
@ -102,6 +108,23 @@ void LoadMon::Run()
@@ -102,6 +108,23 @@ void LoadMon::Run()
|
|
|
|
|
|
|
|
|
|
void LoadMon::cpuload() |
|
|
|
|
{ |
|
|
|
|
#if defined(__PX4_LINUX) |
|
|
|
|
tms spent_time_stamp_struct; |
|
|
|
|
clock_t total_time_stamp = times(&spent_time_stamp_struct); |
|
|
|
|
clock_t spent_time_stamp = spent_time_stamp_struct.tms_utime + spent_time_stamp_struct.tms_stime; |
|
|
|
|
|
|
|
|
|
if (_last_total_time_stamp == 0 || _last_spent_time_stamp == 0) { |
|
|
|
|
// Just get the time in the first iteration */
|
|
|
|
|
_last_total_time_stamp = total_time_stamp; |
|
|
|
|
_last_spent_time_stamp = spent_time_stamp; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// compute system load
|
|
|
|
|
const float interval = total_time_stamp - _last_total_time_stamp; |
|
|
|
|
const float interval_spent_time = spent_time_stamp - _last_spent_time_stamp; |
|
|
|
|
#elif defined(__PX4_NUTTX) |
|
|
|
|
|
|
|
|
|
if (_last_idle_time == 0) { |
|
|
|
|
// Just get the time in the first iteration */
|
|
|
|
|
_last_idle_time = system_load.tasks[0].total_runtime; |
|
|
|
@ -117,23 +140,34 @@ void LoadMon::cpuload()
@@ -117,23 +140,34 @@ void LoadMon::cpuload()
|
|
|
|
|
// compute system load
|
|
|
|
|
const float interval = now - _last_idle_time_sample; |
|
|
|
|
const float interval_idletime = total_runtime - _last_idle_time; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// get ram usage
|
|
|
|
|
struct mallinfo mem = mallinfo(); |
|
|
|
|
float ram_usage = (float)mem.uordblks / mem.arena; |
|
|
|
|
|
|
|
|
|
cpuload_s cpuload{}; |
|
|
|
|
#if defined(__PX4_LINUX) |
|
|
|
|
cpuload.load = interval_spent_time / interval; |
|
|
|
|
#elif defined(__PX4_NUTTX) |
|
|
|
|
cpuload.load = 1.f - interval_idletime / interval; |
|
|
|
|
#endif |
|
|
|
|
cpuload.ram_usage = ram_usage; |
|
|
|
|
cpuload.timestamp = hrt_absolute_time(); |
|
|
|
|
|
|
|
|
|
_cpuload_pub.publish(cpuload); |
|
|
|
|
|
|
|
|
|
// store for next iteration
|
|
|
|
|
#if defined(__PX4_LINUX) |
|
|
|
|
_last_total_time_stamp = total_time_stamp; |
|
|
|
|
_last_spent_time_stamp = spent_time_stamp; |
|
|
|
|
#elif defined(__PX4_NUTTX) |
|
|
|
|
_last_idle_time = total_runtime; |
|
|
|
|
_last_idle_time_sample = now; |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#if defined(__PX4_NUTTX) |
|
|
|
|
void LoadMon::stack_usage() |
|
|
|
|
{ |
|
|
|
|
unsigned stack_free = 0; |
|
|
|
@ -196,6 +230,7 @@ void LoadMon::stack_usage()
@@ -196,6 +230,7 @@ void LoadMon::stack_usage()
|
|
|
|
|
// Continue after last checked task next cycle
|
|
|
|
|
_stack_task_index = (_stack_task_index + 1) % CONFIG_MAX_TASKS; |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
int LoadMon::print_usage(const char *reason) |
|
|
|
|
{ |
|
|
|
|