Skip to content

Commit

Permalink
Add Private_Clean and Private_Dirty memory mapping metrics (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
awegrzyn authored Jan 7, 2021
1 parent 75fcae4 commit 9d1cf8b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ endif()

# Define project
project(Monitoring
VERSION 3.4.0
VERSION 3.5.0
DESCRIPTION "O2 Monitoring library"
LANGUAGES CXX
)
Expand Down
8 changes: 5 additions & 3 deletions include/Monitoring/ProcessMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class ProcessMonitor
AVG_CPU_USED_PERCENTAGE,
ACCUMULATED_CPU_TIME,
PSS,
PRIVATE_CLEAN,
PRIVATE_DIRTY,
AVAILABLE_METRICS_SIZE
};

Expand All @@ -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;
Expand All @@ -101,8 +103,8 @@ class ProcessMonitor
/// Retrieves virtual memory and resident set size usage
std::vector<Metric> getMemoryUsage();

/// Retrieves proportional set size
Metric getPss();
/// Retrieves memory maping metrics
std::vector<Metric> getSmaps();

/// Retrieves CPU usage (%) and number of context switches during the interval
std::vector<Metric> getCpuAndContexts();
Expand Down
23 changes: 16 additions & 7 deletions src/ProcessMonitor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,26 @@ std::vector<Metric> ProcessMonitor::getMemoryUsage()
return metrics;
}

Metric ProcessMonitor::getPss()
std::vector<Metric> 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<Metric> ProcessMonitor::getCpuAndContexts()
Expand Down Expand Up @@ -132,7 +140,8 @@ std::vector<Metric> 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;
}
Expand Down

0 comments on commit 9d1cf8b

Please sign in to comment.