CPUSegment.cpp
Go to the documentation of this file.
1// BaseClass
2#include "CPUSegment.h"
3
4// ArmarX
7
12
14{
17 Base(iceMemory, "LightweightSystemMonitor", "CPUUsage", nullptr, nullptr, 1000)
18 {
19 }
20
21 void
23 const std::string& prefix)
24 {
25 defs->optional(pollFrequencyHz, prefix + "pollFrequencyHz", "The poll frequency in Hz");
26 }
27
28 void
30 {
31 Base::init();
32
33 pollFrequencyHz = std::clamp(pollFrequencyHz, 0.1f, 100.f);
34 cpuMonitoring->initCpuUsage();
35
36 float sleepTime = (1000.f / pollFrequencyHz);
37
39 this, &LightweightCpuMonitorProviderSegment::loop, sleepTime);
40 runningTask->start();
41 }
42
43 void
44 LightweightCpuMonitorProviderSegment::loop()
45 {
47
48 MemoryID providerId = segmentPtr->id();
49
50 double usage = cpuMonitoring->getCurrentCpuUsage();
51 std::string model = cpuMonitoring->getCPUName();
52 std::vector<double> cores = cpuMonitoring->getCurrentMultiCoreUsage();
53
54 auto data = std::make_shared<aron::data::Dict>();
55 data->addElement("model",
56 std::make_shared<aron::data::String>(model)); // TODO in seperate segment?
57 data->addElement("load", std::make_shared<aron::data::Double>(usage));
58
59 auto list = std::make_shared<aron::data::List>();
60 for (const auto core : cores)
61 {
62 list->addElement(std::make_shared<aron::data::Double>(core));
63 }
64 data->addElement("coresLoad", list);
65
66 ARMARX_DEBUG << "Current CPU load: " << usage << " (of model: " << model << ")";
67
68 EntityUpdate update;
69 update.entityID = providerId.withEntityName("CurrentCpuLoad");
70 update.confidence = 1.0;
71 update.referencedTime = armem::Time::Now();
72 update.instancesData = {data};
73
74 segmentPtr->update(update);
75 }
76} // namespace armarx::armem::server::systemstate::segment
The periodic task executes one thread method repeatedly using the time period specified in the constr...
MemoryID withEntityName(const std::string &name) const
Definition MemoryID.cpp:425
UpdateResult update(const EntityUpdate &update)
Updates an entity's history.
Helps connecting a Memory server to the Ice interface.
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="") override
LightweightCpuMonitorProviderSegment(armem::server::MemoryToIceAdapter &iceMemory)
static DateTime Now()
Definition DateTime.cpp:51
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
An update of an entity for a specific point in time.
Definition Commit.h:26