CPUSegment.cpp
Go to the documentation of this file.
1 // BaseClass
2 #include "CPUSegment.h"
3 
4 // ArmarX
8 
11 
13 
15 {
17  Base(iceMemory, "LightweightSystemMonitor", "CPUUsage", 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  cpuMonitoring->initCpuUsage();
33 
34  float sleepTime = (1000.f / pollFrequencyHz);
35 
36  runningTask = new PeriodicTask<LightweightCpuMonitorProviderSegment>(this, &LightweightCpuMonitorProviderSegment::loop, sleepTime);
37  runningTask->start();
38  }
39 
40  void LightweightCpuMonitorProviderSegment::loop()
41  {
43 
44  MemoryID providerId = segmentPtr->id();
45 
46  double usage = cpuMonitoring->getCurrentCpuUsage();
47  std::string model = cpuMonitoring->getCPUName();
48  std::vector<double> cores = cpuMonitoring->getCurrentMultiCoreUsage();
49 
50  auto data = std::make_shared<aron::data::Dict>();
51  data->addElement("model", std::make_shared<aron::data::String>(model)); // TODO in seperate segment?
52  data->addElement("load", std::make_shared<aron::data::Double>(usage));
53 
54  auto list = std::make_shared<aron::data::List>();
55  for (const auto core : cores)
56  {
57  list->addElement(std::make_shared<aron::data::Double>(core));
58  }
59  data->addElement("coresLoad", list);
60 
61  ARMARX_DEBUG << "Current CPU load: " << usage << " (of model: " << model << ")";
62 
64  update.entityID = providerId.withEntityName("CurrentCpuLoad");
65  update.confidence = 1.0;
66  update.referencedTime = armem::Time::Now();
67  update.instancesData = { data };
68 
70  }
71 }
MotionFinder.h
armarx::armem::server::systemstate::segment::LightweightCpuMonitorProviderSegment::LightweightCpuMonitorProviderSegment
LightweightCpuMonitorProviderSegment(armem::server::MemoryToIceAdapter &iceMemory)
Definition: CPUSegment.cpp:16
armarx::armem::server::MemoryToIceAdapter
Helps connecting a Memory server to the Ice interface.
Definition: MemoryToIceAdapter.h:19
CPUSegment.h
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:55
list
list(APPEND SOURCES ${QT_RESOURCES}) set(COMPONENT_LIBS ArmarXGui ArmarXCoreObservers ArmarXCoreEigen3Variants PlotterController $
Definition: CMakeLists.txt:49
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
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::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::server::systemstate::segment::LightweightCpuMonitorProviderSegment::init
void init() override
Definition: CPUSegment.cpp:27
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
armarx::armem::server::systemstate::segment::LightweightCpuMonitorProviderSegment::defineProperties
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="") override
Definition: CPUSegment.cpp:22
IceUtil::Handle< class PropertyDefinitionContainer >
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
Definition: CPUSegment.cpp:14