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 
60  update.entityID = providerId.withEntityName("CurrentMemoryLoad");
61  update.confidence = 1.0;
62  update.referencedTime = armem::Time::Now();
63  update.instancesData = {data};
64 
66  }
67 } // namespace armarx::armem::server::systemstate::segment
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:51
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:136
armarx::armem::server::systemstate::segment::LightweightRamMonitorProviderSegment::LightweightRamMonitorProviderSegment
LightweightRamMonitorProviderSegment(armem::server::MemoryToIceAdapter &iceMemory)
Definition: RAMSegment.cpp:15
memory_definitions.h
armarx::armem::server::segment::detail::SegmentBase< server::wm::ProviderSegment >::segmentPtr
server::wm::ProviderSegment * segmentPtr
Definition: SpecializedSegment.h:53
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::armem::server::systemstate::segment::LightweightRamMonitorProviderSegment::init
void init() override
Definition: RAMSegment.cpp:29
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:184
armarx::armem::EntityUpdate
An update of an entity for a specific point in time.
Definition: Commit.h:25
All.h
armarx::armem::base::detail::MemoryItem::id
MemoryID & id()
Definition: MemoryItem.h:25
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:68
memory_definitions.h
armarx::armem::MemoryID::withEntityName
MemoryID withEntityName(const std::string &name) const
Definition: MemoryID.cpp:425
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:13