Skip to content

Commit 9d1cf8b

Browse files
authored
Add Private_Clean and Private_Dirty memory mapping metrics (#224)
1 parent 75fcae4 commit 9d1cf8b

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ endif()
1717

1818
# Define project
1919
project(Monitoring
20-
VERSION 3.4.0
20+
VERSION 3.5.0
2121
DESCRIPTION "O2 Monitoring library"
2222
LANGUAGES CXX
2323
)

include/Monitoring/ProcessMonitor.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class ProcessMonitor
5050
AVG_CPU_USED_PERCENTAGE,
5151
ACCUMULATED_CPU_TIME,
5252
PSS,
53+
PRIVATE_CLEAN,
54+
PRIVATE_DIRTY,
5355
AVAILABLE_METRICS_SIZE
5456
};
5557

@@ -75,7 +77,7 @@ class ProcessMonitor
7577
static constexpr const char* metricsNames[] = {"memoryUsagePercentage", "virtualMemorySize", "residentSetSize",
7678
"cpuUsedPercentage", "involuntaryContextSwitches", "voluntaryContextSwitches", "cpuUsedAbsolute",
7779
"averageResidentSetSize", "averageVirtualMemorySize", "averageCpuUsedPercentage",
78-
"cpuTimeConsumedByProcess", "proportionalSetSize"};
80+
"cpuTimeConsumedByProcess", "proportionalSetSize", "memPrivateClean", "memPrivateDirty"};
7981

8082
static constexpr unsigned int VM_SIZE_INDEX = 18;
8183
static constexpr unsigned int VM_RSS_INDEX = 22;
@@ -101,8 +103,8 @@ class ProcessMonitor
101103
/// Retrieves virtual memory and resident set size usage
102104
std::vector<Metric> getMemoryUsage();
103105

104-
/// Retrieves proportional set size
105-
Metric getPss();
106+
/// Retrieves memory maping metrics
107+
std::vector<Metric> getSmaps();
106108

107109
/// Retrieves CPU usage (%) and number of context switches during the interval
108110
std::vector<Metric> getCpuAndContexts();

src/ProcessMonitor.cxx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,26 @@ std::vector<Metric> ProcessMonitor::getMemoryUsage()
7272
return metrics;
7373
}
7474

75-
Metric ProcessMonitor::getPss()
75+
std::vector<Metric> ProcessMonitor::getSmaps()
7676
{
7777
std::ifstream statusStream("/proc/self/smaps");
7878
double pssTotal = 0;
79-
std::string pssString;
79+
double cleanTotal = 0;
80+
double dirtyTotal = 0;
81+
std::string smapsString;
8082

81-
while (std::getline(statusStream, pssString)) {
82-
if (pssString.rfind("Pss:", 0) == 0) {
83-
pssTotal += splitStatusLineAndRetriveValue(pssString);
83+
while (std::getline(statusStream, smapsString)) {
84+
if (smapsString.rfind("Pss:", 0) == 0) {
85+
pssTotal += splitStatusLineAndRetriveValue(smapsString);
86+
}
87+
if (smapsString.rfind("Private_Clean:", 0) == 0) {
88+
cleanTotal += splitStatusLineAndRetriveValue(smapsString);
89+
}
90+
if (smapsString.rfind("Private_Dirty:", 0) == 0) {
91+
dirtyTotal += splitStatusLineAndRetriveValue(smapsString);
8492
}
8593
}
86-
return {pssTotal, metricsNames[PSS]};
94+
return {{pssTotal, metricsNames[PSS]}, {cleanTotal, metricsNames[PRIVATE_CLEAN]}, {dirtyTotal, metricsNames[PRIVATE_DIRTY]}};
8795
}
8896

8997
std::vector<Metric> ProcessMonitor::getCpuAndContexts()
@@ -132,7 +140,8 @@ std::vector<Metric> ProcessMonitor::getPerformanceMetrics()
132140
#ifdef O2_MONITORING_OS_LINUX
133141
auto memoryMetrics = getMemoryUsage();
134142
std::move(memoryMetrics.begin(), memoryMetrics.end(), std::back_inserter(metrics));
135-
metrics.emplace_back(getPss());
143+
auto smapMetrics = getSmaps();
144+
std::move(smapMetrics.begin(), smapMetrics.end(), std::back_inserter(metrics));
136145
#endif
137146
return metrics;
138147
}

0 commit comments

Comments
 (0)