RAMSegment.cpp
Go to the documentation of this file.
1// BaseClass
2#include "RAMSegment.h"
3
4// ArmarX
7
12
14{
17 Base(iceMemory, "LightweightSystemMonitor", "MemoryUsage", 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
35 usleep(200 * 1000.f); // sleep for 100ms to ensure the monitor is ready
36
38 this, &LightweightRamMonitorProviderSegment::loop, (1000.f / pollFrequencyHz));
39 runningTask->start();
40 }
41
42 void
43 LightweightRamMonitorProviderSegment::loop()
44 {
46
47 MemoryID providerId = segmentPtr->id();
48
49 long total = memoryMonitoring->getTotalMemoryInKB();
50 double usage = memoryMonitoring->getCurrentMemUsageInPercent();
51
52 auto data = std::make_shared<aron::data::Dict>();
53 data->addElement("total",
54 std::make_shared<aron::data::Long>(total)); // TODO in seperate segment?
55 data->addElement("load", std::make_shared<aron::data::Double>(usage));
56
57 ARMARX_DEBUG << "RAM Usage is: " << usage << "% (of " << total << "KB max)";
58
59 EntityUpdate update;
60 update.entityID = providerId.withEntityName("CurrentMemoryLoad");
61 update.confidence = 1.0;
62 update.referencedTime = armem::Time::Now();
63 update.instancesData = {data};
64
65 segmentPtr->update(update);
66 }
67} // 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
LightweightRamMonitorProviderSegment(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