RAMSegment.cpp
Go to the documentation of this file.
1 // BaseClass
2 #include "RAMSegment.h"
3 
4 // ArmarX
8 
11 
13 
15 {
17  Base(iceMemory, "LightweightSystemMonitor", "MemoryUsage", nullptr, nullptr, 1000)
18  {
19 
20  }
21 
23  {
24  defs->optional(pollFrequencyHz, prefix + "pollFrequencyHz", "The poll frequency in Hz");
25  }
26 
28  {
29  Base::init();
30 
31  pollFrequencyHz = std::clamp(pollFrequencyHz, 0.1f, 100.f);
32 
33  usleep(200 * 1000.f); // sleep for 100ms to ensure the monitor is ready
34 
35  runningTask = new PeriodicTask<LightweightRamMonitorProviderSegment>(this, &LightweightRamMonitorProviderSegment::loop, (1000.f / pollFrequencyHz));
36  runningTask->start();
37  }
38 
39  void LightweightRamMonitorProviderSegment::loop()
40  {
42 
43  MemoryID providerId = segmentPtr->id();
44 
45  long total = memoryMonitoring->getTotalMemoryInKB();
46  double usage = memoryMonitoring->getCurrentMemUsageInPercent();
47 
48  auto data = std::make_shared<aron::data::Dict>();
49  data->addElement("total", std::make_shared<aron::data::Long>(total)); // TODO in seperate segment?
50  data->addElement("load", std::make_shared<aron::data::Double>(usage));
51 
52  ARMARX_DEBUG << "RAM Usage is: " << usage << "% (of " << total << "KB max)";
53 
55  update.entityID = providerId.withEntityName("CurrentMemoryLoad");
56  update.confidence = 1.0;
57  update.referencedTime = armem::Time::Now();
58  update.instancesData = { data };
59 
61  }
62 }
MotionFinder.h
armarx::armem::server::MemoryToIceAdapter
Helps connecting a Memory server to the Ice interface.
Definition: MemoryToIceAdapter.h:19
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:55
ARMARX_CHECK_NOT_NULL
#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...
Definition: ExpressionException.h:206
clamp
double clamp(double x, double a, double b)
Definition: point.hpp:125
armarx::armem::server::systemstate::segment::LightweightRamMonitorProviderSegment::LightweightRamMonitorProviderSegment
LightweightRamMonitorProviderSegment(armem::server::MemoryToIceAdapter &iceMemory)
Definition: RAMSegment.cpp:16
memory_definitions.h
armarx::armem::server::segment::detail::SegmentBase< server::wm::ProviderSegment >::segmentPtr
server::wm::ProviderSegment * segmentPtr
Definition: SpecializedSegment.h:54
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::armem::server::systemstate::segment::LightweightRamMonitorProviderSegment::init
void init() override
Definition: RAMSegment.cpp:27
armarx::armem::server::segment::detail::SegmentBase< server::wm::ProviderSegment >
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
armarx::armem::EntityUpdate
An update of an entity for a specific point in time.
Definition: Commit.h:27
All.h
armarx::armem::base::detail::MemoryItem::id
MemoryID & id()
Definition: MemoryItem.h:27
armarx::armem::server::segment::SpecializedProviderSegment::init
virtual void init() override
Definition: SpecializedProviderSegment.cpp:56
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:67
memory_definitions.h
armarx::armem::MemoryID::withEntityName
MemoryID withEntityName(const std::string &name) const
Definition: MemoryID.cpp:420
PropertyDefinitionContainer.h
IceUtil::Handle< class PropertyDefinitionContainer >
RAMSegment.h
armarx::PeriodicTask
Definition: ArmarXManager.h:70
ProxyPropertyDefinition.h
armarx::armem::base::ProviderSegmentBase::update
UpdateResult update(const EntityUpdate &update)
Updates an entity's history.
Definition: ProviderSegmentBase.h:252
armarx::armem::server::systemstate::segment::LightweightRamMonitorProviderSegment::defineProperties
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="") override
Definition: RAMSegment.cpp:22
armarx::armem::server::systemstate::segment
Definition: CPUSegment.cpp:14