From 9d1cf8bac9ec677fe1e4283681d65e1f4fb47972 Mon Sep 17 00:00:00 2001 From: Adam Wegrzynek Date: Thu, 7 Jan 2021 11:51:56 +0100 Subject: [PATCH] Add Private_Clean and Private_Dirty memory mapping metrics (#224) --- CMakeLists.txt | 2 +- include/Monitoring/ProcessMonitor.h | 8 +++++--- src/ProcessMonitor.cxx | 23 ++++++++++++++++------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 480739ffd..8c03767e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ endif() # Define project project(Monitoring - VERSION 3.4.0 + VERSION 3.5.0 DESCRIPTION "O2 Monitoring library" LANGUAGES CXX ) diff --git a/include/Monitoring/ProcessMonitor.h b/include/Monitoring/ProcessMonitor.h index 32508fddd..1e956dacc 100644 --- a/include/Monitoring/ProcessMonitor.h +++ b/include/Monitoring/ProcessMonitor.h @@ -50,6 +50,8 @@ class ProcessMonitor AVG_CPU_USED_PERCENTAGE, ACCUMULATED_CPU_TIME, PSS, + PRIVATE_CLEAN, + PRIVATE_DIRTY, AVAILABLE_METRICS_SIZE }; @@ -75,7 +77,7 @@ class ProcessMonitor static constexpr const char* metricsNames[] = {"memoryUsagePercentage", "virtualMemorySize", "residentSetSize", "cpuUsedPercentage", "involuntaryContextSwitches", "voluntaryContextSwitches", "cpuUsedAbsolute", "averageResidentSetSize", "averageVirtualMemorySize", "averageCpuUsedPercentage", - "cpuTimeConsumedByProcess", "proportionalSetSize"}; + "cpuTimeConsumedByProcess", "proportionalSetSize", "memPrivateClean", "memPrivateDirty"}; static constexpr unsigned int VM_SIZE_INDEX = 18; static constexpr unsigned int VM_RSS_INDEX = 22; @@ -101,8 +103,8 @@ class ProcessMonitor /// Retrieves virtual memory and resident set size usage std::vector getMemoryUsage(); - /// Retrieves proportional set size - Metric getPss(); + /// Retrieves memory maping metrics + std::vector getSmaps(); /// Retrieves CPU usage (%) and number of context switches during the interval std::vector getCpuAndContexts(); diff --git a/src/ProcessMonitor.cxx b/src/ProcessMonitor.cxx index 9f7a9ac5f..153388733 100644 --- a/src/ProcessMonitor.cxx +++ b/src/ProcessMonitor.cxx @@ -72,18 +72,26 @@ std::vector ProcessMonitor::getMemoryUsage() return metrics; } -Metric ProcessMonitor::getPss() +std::vector ProcessMonitor::getSmaps() { std::ifstream statusStream("/proc/self/smaps"); double pssTotal = 0; - std::string pssString; + double cleanTotal = 0; + double dirtyTotal = 0; + std::string smapsString; - while (std::getline(statusStream, pssString)) { - if (pssString.rfind("Pss:", 0) == 0) { - pssTotal += splitStatusLineAndRetriveValue(pssString); + while (std::getline(statusStream, smapsString)) { + if (smapsString.rfind("Pss:", 0) == 0) { + pssTotal += splitStatusLineAndRetriveValue(smapsString); + } + if (smapsString.rfind("Private_Clean:", 0) == 0) { + cleanTotal += splitStatusLineAndRetriveValue(smapsString); + } + if (smapsString.rfind("Private_Dirty:", 0) == 0) { + dirtyTotal += splitStatusLineAndRetriveValue(smapsString); } } - return {pssTotal, metricsNames[PSS]}; + return {{pssTotal, metricsNames[PSS]}, {cleanTotal, metricsNames[PRIVATE_CLEAN]}, {dirtyTotal, metricsNames[PRIVATE_DIRTY]}}; } std::vector ProcessMonitor::getCpuAndContexts() @@ -132,7 +140,8 @@ std::vector ProcessMonitor::getPerformanceMetrics() #ifdef O2_MONITORING_OS_LINUX auto memoryMetrics = getMemoryUsage(); std::move(memoryMetrics.begin(), memoryMetrics.end(), std::back_inserter(metrics)); - metrics.emplace_back(getPss()); + auto smapMetrics = getSmaps(); + std::move(smapMetrics.begin(), smapMetrics.end(), std::back_inserter(metrics)); #endif return metrics; }