Skip to content

Commit b1509c1

Browse files
Merge branch 'system/caravel'
2 parents 118efb9 + 6494825 commit b1509c1

File tree

3 files changed

+115
-21
lines changed

3 files changed

+115
-21
lines changed

src/Monitors/HostResources/Task.cpp

Lines changed: 111 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ namespace Monitors
114114
DUNE::Tasks::Task(name, ctx),
115115
m_tstamp(0)
116116
{
117-
paramActive(Tasks::Parameter::SCOPE_GLOBAL, Tasks::Parameter::VISIBILITY_USER);
117+
paramActive(Tasks::Parameter::SCOPE_GLOBAL,
118+
Tasks::Parameter::VISIBILITY_USER);
119+
118120
m_num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
119121
if (m_num_cpus <= 0 || m_num_cpus > c_max_cpu)
120122
{
@@ -130,6 +132,7 @@ namespace Monitors
130132
setEntityState(IMC::EntityState::ESTA_NORMAL, Status::CODE_IDLE);
131133
}
132134

135+
//! Reserve entity identifiers.
133136
void
134137
onEntityReservation(void)
135138
{
@@ -493,20 +496,117 @@ namespace Monitors
493496
{
494497
while (!stopping())
495498
{
496-
try
497-
{
498-
waitForMessages(0.01);
499-
}
500-
catch (...)
501-
{
502-
war("waitForMessages error");
503-
}
499+
waitForMessages(0.01);
500+
504501
if (!isActive())
505502
continue;
506503

507-
if (m_reads_check.overflow())
504+
if (m_ram_check.overflow())
505+
{
506+
m_ram_check.reset();
507+
m_tstamp = Clock::get();
508+
uint8_t cpu = 0;
509+
try
510+
{
511+
cpu = (uint8_t)getDUNECPUUsage();
512+
if(m_num_cpus > 1 && cpu > 0)
513+
cpu /= m_num_cpus;
514+
}
515+
catch (std::exception& e)
516+
{
517+
war("Failed to get CPU usage: %s", e.what());
518+
cpu = 0;
519+
}
520+
catch (...)
521+
{
522+
war("Failed to get CPU usage: unknown error");
523+
cpu = 0;
524+
}
525+
526+
double ram = 0.0;
527+
try
528+
{
529+
ram = getDUNERAMUsage();
530+
}
531+
catch (std::exception& e)
532+
{
533+
war("Failed to get RAM usage: %s", e.what());
534+
ram = 0;
535+
}
536+
catch (...)
537+
{
538+
war("Failed to get RAM usage: unknown error");
539+
ram = 0;
540+
}
541+
542+
double swap = 0.0;
543+
try
544+
{
545+
swap = getDUNESwapUsage();
546+
}
547+
catch (std::exception& e)
548+
{
549+
war("Failed to get Swap usage: %s", e.what());
550+
swap = 0;
551+
}
552+
catch (...)
553+
{
554+
war("Failed to get Swap usage: unknown error");
555+
swap = 0;
556+
}
557+
558+
//dispatch CPU and RAM usage
559+
try{
560+
m_dune_cpu_usage[m_num_cpus].value = cpu;
561+
m_dune_cpu_usage[m_num_cpus].setTimeStamp(m_tstamp);
562+
dispatch(m_dune_cpu_usage[m_num_cpus]);
563+
}
564+
catch (std::exception& e)
565+
{
566+
war("Failed to dispatch CPU usage: %s", e.what());
567+
}
568+
catch (...)
569+
{
570+
war("Failed to dispatch CPU usage: unknown error");
571+
}
572+
#if IMC_RAM_USAGE_MESSAGE_EXISTS
573+
try{
574+
m_dune_ram_usage[0].value = ram * 1024.0f; // KB -> MB
575+
m_dune_ram_usage[0].setTimeStamp(m_tstamp);
576+
dispatch(m_dune_ram_usage[0]);
577+
m_dune_ram_usage[1].value = swap * 1024.0f; // KB -> MB
578+
m_dune_ram_usage[1].setTimeStamp(m_tstamp);
579+
dispatch(m_dune_ram_usage[1]);
580+
}
581+
catch (std::exception& e)
582+
{
583+
war("Failed to dispatch RAM usage: %s", e.what());
584+
}
585+
catch (...)
586+
{
587+
war("Failed to dispatch RAM usage: unknown error");
588+
}
589+
#endif
590+
try{
591+
//check if m_buffer_cpu_entity is empty
592+
const char* entity = m_buffer_cpu_entity.empty() ? "unknown" : m_buffer_cpu_entity.c_str();
593+
//set entity state with CPU, RAM and Swap usage
594+
trace("DUNE Process: CPU: %d%%, RAM: %.1fMB, Swap: %.1fMB | %s", cpu, ram, swap, entity);
595+
std::string msg = String::str("%s | DUNE (C:%d%%, R:%.1fMB, S:%.1fMB)", entity, cpu, ram, swap);
596+
setEntityState(IMC::EntityState::ESTA_NORMAL, msg);
597+
}
598+
catch (std::exception& e)
599+
{
600+
war("Failed to set entity state: %s", e.what());
601+
}
602+
catch (...)
603+
{
604+
war("Failed to set entity state: unknown error");
605+
}
606+
}
607+
else if (m_cpu_check.overflow())
508608
{
509-
m_reads_check.reset();
609+
m_cpu_check.reset();
510610
m_tstamp = Clock::getSinceEpoch();
511611
getDuneUsageResources(m_tstamp);
512612
getUsageOfCPU(m_tstamp);

src/Monitors/NavigationLight/Task.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ namespace Monitors
107107
if (msg->name != m_args.light_entity)
108108
return;
109109

110-
for (const auto& p: msg->params)
110+
for (const auto& param : msg->params)
111111
{
112-
if (p->name == m_args.light_parameter_label)
112+
if (param->name == m_args.light_parameter_label)
113113
{
114114
try
115115
{
116-
castLexical(p->value, m_state);
116+
castLexical(param->value, m_state);
117117
if (!isActive())
118118
m_idle_state = m_state;
119119
}
@@ -217,12 +217,6 @@ namespace Monitors
217217
inf("No AIS targets in the area.");
218218
setNavigationLight(m_args.light_state_no_targets);
219219
}
220-
221-
void
222-
onResourceAcquisition(void) override
223-
{
224-
setEntityState(IMC::EntityState::ESTA_NORMAL, CODE_IDLE);
225-
}
226220
};
227221
}
228222
}

src/Transports/SMS/PollThread.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ namespace Transports
9292
if(Poll::poll(*m_handle, 0.01))
9393
{
9494
size_t rv = m_handle->read(m_bfr, c_bfr_size);
95-
m_task->debug("[PollThread]:%zu bytes read from IO handle", rv);
95+
m_task->debug("[PollThread]:%ld bytes read from IO handle", rv);
9696
if(rv > 0)
9797
{
9898
m_new_line_timer.reset();

0 commit comments

Comments
 (0)