Add meminfo swap metrics.
The current metrics don't show how much swap we're using at a given
time. We only have indirect measures (page faults rate for instance).
We also need to add one type of histogram scale, since compressed swap
can exceed total RAM, and all current histograms are on a scale from
zero to total RAM.
BUG=chromium-os:38583
TEST=stared at the code really hard and compiled it
BRANCH=none
Change-Id: Icb9dce5efe5dbd78123aad51ffd369cb46721096
Reviewed-on: https://gerrit.chromium.org/gerrit/42598
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
Commit-Queue: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
diff --git a/metrics/metrics_daemon.cc b/metrics/metrics_daemon.cc
index 7d564d4..d7c12c4 100644
--- a/metrics/metrics_daemon.cc
+++ b/metrics/metrics_daemon.cc
@@ -806,16 +806,16 @@
{ "InactiveAnon", "Inactive(anon)" },
{ "ActiveFile" , "Active(file)" },
{ "InactiveFile", "Inactive(file)" },
- { "Unevictable", "Unevictable", 1 },
+ { "Unevictable", "Unevictable", kMeminfoScaleLog },
// { "Mlocked", "Mlocked" },
// { "SwapTotal", "SwapTotal" },
- // { "SwapFree", "SwapFree" },
+ { "SwapFree", "SwapFree", kMeminfoScaleLogLarge },
// { "Dirty", "Dirty" },
// { "Writeback", "Writeback" },
{ "AnonPages", "AnonPages" },
{ "Mapped", "Mapped" },
- { "Shmem", "Shmem", 1 },
- { "Slab", "Slab", 1 },
+ { "Shmem", "Shmem", kMeminfoScaleLog },
+ { "Slab", "Slab", kMeminfoScaleLog },
// { "SReclaimable", "SReclaimable" },
// { "SUnreclaim", "SUnreclaim" },
};
@@ -833,13 +833,21 @@
// Send all fields retrieved, except total memory.
for (unsigned int i = 1; i < fields.size(); i++) {
string metrics_name = StringPrintf("Platform.Meminfo%s", fields[i].name);
- if (fields[i].log_scale) {
- // report value in kbytes, log scale, 4Gb max
- SendMetric(metrics_name, fields[i].value, 1, 4 * 1000 * 1000, 100);
- } else {
- // report value as percent of total memory
- int percent = fields[i].value * 100 / total_memory;
- SendLinearMetric(metrics_name, percent, 100, 101);
+ int percent;
+ switch (fields[i].scale) {
+ case kMeminfoScalePercent:
+ // report value as percent of total memory
+ percent = fields[i].value * 100 / total_memory;
+ SendLinearMetric(metrics_name, percent, 100, 101);
+ break;
+ case kMeminfoScaleLog:
+ // report value in kbytes, log scale, 4Gb max
+ SendMetric(metrics_name, fields[i].value, 1, 4 * 1000 * 1000, 100);
+ break;
+ case kMeminfoScaleLogLarge:
+ // report value in kbytes, log scale, 8Gb max
+ SendMetric(metrics_name, fields[i].value, 1, 8 * 1000 * 1000, 100);
+ break;
}
}
return true;
diff --git a/metrics/metrics_daemon.h b/metrics/metrics_daemon.h
index 0197bd1..b93a2bc 100644
--- a/metrics/metrics_daemon.h
+++ b/metrics/metrics_daemon.h
@@ -97,12 +97,22 @@
int seconds_;
};
+ // Type of scale to use for meminfo histograms. For most of them we use
+ // percent of total RAM, but for some we use absolute numbers, usually in
+ // megabytes, on a log scale from 0 to 4000, and 0 to 8000 for compressed
+ // swap (since it can be larger than total RAM).
+ enum MeminfoScaleType {
+ kMeminfoScalePercent = 0,
+ kMeminfoScaleLog,
+ kMeminfoScaleLogLarge,
+ };
+
// Record for retrieving and reporting values from /proc/meminfo.
struct MeminfoRecord {
- const char* name; // print name
- const char* match; // string to match in output of /proc/meminfo
- int log_scale; // report with log scale instead of linear percent
- int value; // value from /proc/meminfo
+ const char* name; // print name
+ const char* match; // string to match in output of /proc/meminfo
+ MeminfoScaleType scale; // histogram scale selector
+ int value; // value from /proc/meminfo
};
typedef std::map<std::string, chromeos_metrics::FrequencyCounter*>