metrics_daemon: add zram stats collection
Memory compression stats are being collected by Chrome, but it
is more natural to do it here since they are system-wide rather than
Chrome-specific.
In addition, this provides better granularity for the compression ratio
(percents, from 100% to 600%) since we're especially interested in the
distribution of values between 1 and 2, and currently these all fall
in the same bucket.
Finally, we collect more interesting stats on zero pages.
BUG=chromium:315113
TEST=unit testing, checked about:histograms
Change-Id: I09c974989661d42f45d44afd428e8114e4ee1dbd
Reviewed-on: https://chromium-review.googlesource.com/202587
Reviewed-by: Luigi Semenzato <semenzato@chromium.org>
Commit-Queue: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
diff --git a/metrics/metrics_daemon.h b/metrics/metrics_daemon.h
index 81e5386..df85a2f 100644
--- a/metrics/metrics_daemon.h
+++ b/metrics/metrics_daemon.h
@@ -36,6 +36,12 @@
// forking.
void Run(bool run_as_daemon);
+ protected:
+ // Used also by the unit tests.
+ static const char kComprDataSizeName[];
+ static const char kOrigDataSizeName[];
+ static const char kZeroPagesName[];
+
private:
friend class MetricsDaemonTest;
FRIEND_TEST(MetricsDaemonTest, CheckSystemCrash);
@@ -59,6 +65,7 @@
FRIEND_TEST(MetricsDaemonTest, ReportUserCrashInterval);
FRIEND_TEST(MetricsDaemonTest, SendSample);
FRIEND_TEST(MetricsDaemonTest, SendCpuThrottleMetrics);
+ FRIEND_TEST(MetricsDaemonTest, SendZramMetrics);
// State for disk stats collector callback.
enum StatsState {
@@ -270,6 +277,14 @@
// Invoked periodically by |update_stats_timeout_id_| to call UpdateStats().
static gboolean HandleUpdateStatsTimeout(gpointer data);
+ // Reports zram statistics.
+ bool ReportZram(const base::FilePath& zram_dir);
+
+ // Reads a string from a file and converts it to uint64.
+ static bool ReadFileToUint64(const base::FilePath& path, uint64* value);
+
+ // VARIABLES
+
// Test mode.
bool testing_;