@@ -28,6 +28,15 @@ ProcessMonitor::ProcessMonitor()
2828#endif
2929}
3030
31+ Metric ProcessMonitor::getPerformanceMetrics ()
32+ {
33+ auto metric = getCpuAndContexts ();
34+ #ifdef O2_MONITORING_OS_LINUX
35+ metric.addValue (getMemoryUsage (), " memory_pct" );
36+ #endif
37+ return metric;
38+ }
39+
3140void ProcessMonitor::setTotalMemory ()
3241{
3342 std::ifstream memInfo (" /proc/meminfo" );
@@ -39,7 +48,7 @@ void ProcessMonitor::setTotalMemory()
3948 mTotalMemory = std::stoi (tokens[1 ]);
4049}
4150
42- Metric ProcessMonitor::getMemoryUsage ()
51+ double ProcessMonitor::getMemoryUsage ()
4352{
4453 std::ifstream statusStream (" /proc/self/status" );
4554 std::string rssString;
@@ -52,30 +61,28 @@ Metric ProcessMonitor::getMemoryUsage()
5261 std::istringstream iss (rssString);
5362 std::vector<std::string> tokens{std::istream_iterator<std::string>{iss},
5463 std::istream_iterator<std::string>{}};
55- return Metric{ (std::stod (tokens[1 ]) * 100 ) / mTotalMemory , " memoryUsagePercentage " } ;
64+ return (std::stod (tokens[1 ]) * 100 ) / mTotalMemory ;
5665}
5766
58- std::vector< Metric> ProcessMonitor::getCpuAndContexts ()
67+ Metric ProcessMonitor::getCpuAndContexts ()
5968{
60- std::vector<Metric> metrics;
6169 struct rusage currentUsage;
6270 getrusage (RUSAGE_SELF, ¤tUsage);
6371 auto timeNow = std::chrono::high_resolution_clock::now ();
6472 double timePassed = std::chrono::duration_cast<std::chrono::microseconds>(timeNow - mTimeLastRun ).count ();
6573 if (timePassed < 950 ) {
6674 MonLogger::Get () << " [WARN] Do not invoke Process Monitor more frequent then every 1s" << MonLogger::End ();
67- return {};
75+ return {" processPerformance " };
6876 }
6977 double fractionCpuUsed = (currentUsage.ru_utime .tv_sec * 1000000.0 + currentUsage.ru_utime .tv_usec - (mPreviousGetrUsage .ru_utime .tv_sec * 1000000.0 + mPreviousGetrUsage .ru_utime .tv_usec ) + currentUsage.ru_stime .tv_sec * 1000000.0 + currentUsage.ru_stime .tv_usec - (mPreviousGetrUsage .ru_stime .tv_sec * 1000000.0 + mPreviousGetrUsage .ru_stime .tv_usec )) / timePassed;
7078
71- metrics.emplace_back (Metric{
72- static_cast <double >(std::round (fractionCpuUsed * 100.0 * 100.0 ) / 100.0 ), " cpuUsedPercentage" });
73- metrics.emplace_back (Metric{
74- static_cast <uint64_t >(currentUsage.ru_nivcsw - mPreviousGetrUsage .ru_nivcsw ), " involuntaryContextSwitches" });
79+ Metric metric{" processPerformance" };
80+ metric.addValue (static_cast <double >(std::round (fractionCpuUsed * 100.0 * 100.0 ) / 100.0 ), " cpu_user_pct" );
81+ metric.addValue (static_cast <uint64_t >(currentUsage.ru_nivcsw - mPreviousGetrUsage .ru_nivcsw ), " involuntary_context_switches" );
7582
7683 mTimeLastRun = timeNow;
7784 mPreviousGetrUsage = currentUsage;
78- return metrics ;
85+ return metric ;
7986}
8087
8188} // namespace monitoring
0 commit comments