2010-04-14 22:32:20 +02:00
|
|
|
// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef METRICS_DAEMON_H_
|
|
|
|
#define METRICS_DAEMON_H_
|
|
|
|
|
2010-04-27 20:02:18 +02:00
|
|
|
#include <dbus/dbus.h>
|
2010-05-04 01:45:37 +02:00
|
|
|
#include <glib.h>
|
2010-08-27 03:35:06 +02:00
|
|
|
#include <map>
|
2010-04-14 22:32:20 +02:00
|
|
|
|
2010-08-27 03:35:06 +02:00
|
|
|
#include <base/file_path.h>
|
2011-05-12 23:14:48 +02:00
|
|
|
#include <base/memory/scoped_ptr.h>
|
2010-06-11 00:59:53 +02:00
|
|
|
#include <base/time.h>
|
|
|
|
#include <gtest/gtest_prod.h> // for FRIEND_TEST
|
|
|
|
|
2010-05-12 22:05:45 +02:00
|
|
|
#include "metrics_library.h"
|
|
|
|
|
2010-08-17 04:57:13 +02:00
|
|
|
namespace chromeos_metrics {
|
|
|
|
class FrequencyCounter;
|
2010-08-27 03:35:06 +02:00
|
|
|
class TaggedCounter;
|
|
|
|
class TaggedCounterReporter;
|
2010-08-17 04:57:13 +02:00
|
|
|
}
|
2010-05-06 01:06:37 +02:00
|
|
|
|
2010-04-14 22:32:20 +02:00
|
|
|
class MetricsDaemon {
|
|
|
|
|
|
|
|
public:
|
2010-06-11 00:59:53 +02:00
|
|
|
MetricsDaemon();
|
|
|
|
~MetricsDaemon();
|
2010-04-14 22:32:20 +02:00
|
|
|
|
2010-05-18 20:00:59 +02:00
|
|
|
// Initializes.
|
2011-02-17 19:21:16 +01:00
|
|
|
void Init(bool testing, MetricsLibraryInterface* metrics_lib,
|
2011-10-14 21:03:35 +02:00
|
|
|
const std::string& diskstats_path,
|
2013-05-08 01:55:00 +02:00
|
|
|
const std::string& vmstats_path,
|
|
|
|
const std::string& cpuinfo_max_freq_path,
|
|
|
|
const std::string& scaling_max_freq_path);
|
2010-05-18 20:00:59 +02:00
|
|
|
|
2010-04-27 20:02:18 +02:00
|
|
|
// Does all the work. If |run_as_daemon| is true, daemonizes by
|
2010-05-06 01:06:37 +02:00
|
|
|
// forking.
|
|
|
|
void Run(bool run_as_daemon);
|
2010-04-14 22:32:20 +02:00
|
|
|
|
|
|
|
private:
|
2010-05-06 01:06:37 +02:00
|
|
|
friend class MetricsDaemonTest;
|
2010-08-17 04:57:13 +02:00
|
|
|
FRIEND_TEST(MetricsDaemonTest, CheckSystemCrash);
|
2010-08-27 03:35:06 +02:00
|
|
|
FRIEND_TEST(MetricsDaemonTest, ComputeEpochNoCurrent);
|
|
|
|
FRIEND_TEST(MetricsDaemonTest, ComputeEpochNoLast);
|
|
|
|
FRIEND_TEST(MetricsDaemonTest, GetHistogramPath);
|
|
|
|
FRIEND_TEST(MetricsDaemonTest, IsNewEpoch);
|
2010-05-06 01:06:37 +02:00
|
|
|
FRIEND_TEST(MetricsDaemonTest, LookupPowerState);
|
|
|
|
FRIEND_TEST(MetricsDaemonTest, LookupScreenSaverState);
|
|
|
|
FRIEND_TEST(MetricsDaemonTest, LookupSessionState);
|
2010-05-06 01:19:39 +02:00
|
|
|
FRIEND_TEST(MetricsDaemonTest, MessageFilter);
|
2011-10-14 21:03:35 +02:00
|
|
|
FRIEND_TEST(MetricsDaemonTest, ParseVmStats);
|
2010-05-06 01:06:37 +02:00
|
|
|
FRIEND_TEST(MetricsDaemonTest, PowerStateChanged);
|
2010-06-24 21:10:26 +02:00
|
|
|
FRIEND_TEST(MetricsDaemonTest, ProcessKernelCrash);
|
2011-04-12 23:12:35 +02:00
|
|
|
FRIEND_TEST(MetricsDaemonTest, ProcessMeminfo);
|
|
|
|
FRIEND_TEST(MetricsDaemonTest, ProcessMeminfo2);
|
2010-08-17 04:57:13 +02:00
|
|
|
FRIEND_TEST(MetricsDaemonTest, ProcessUncleanShutdown);
|
2010-06-17 00:58:06 +02:00
|
|
|
FRIEND_TEST(MetricsDaemonTest, ProcessUserCrash);
|
2010-08-17 04:57:13 +02:00
|
|
|
FRIEND_TEST(MetricsDaemonTest, ReportCrashesDailyFrequency);
|
2013-05-08 01:55:00 +02:00
|
|
|
FRIEND_TEST(MetricsDaemonTest, ReadFreqToInt);
|
2010-08-17 04:57:13 +02:00
|
|
|
FRIEND_TEST(MetricsDaemonTest, ReportDailyUse);
|
2011-02-17 19:21:16 +01:00
|
|
|
FRIEND_TEST(MetricsDaemonTest, ReportDiskStats);
|
2010-08-17 04:57:13 +02:00
|
|
|
FRIEND_TEST(MetricsDaemonTest, ReportKernelCrashInterval);
|
|
|
|
FRIEND_TEST(MetricsDaemonTest, ReportUncleanShutdownInterval);
|
|
|
|
FRIEND_TEST(MetricsDaemonTest, ReportUserCrashInterval);
|
2010-05-06 01:06:37 +02:00
|
|
|
FRIEND_TEST(MetricsDaemonTest, ScreenSaverStateChanged);
|
2010-05-18 20:00:59 +02:00
|
|
|
FRIEND_TEST(MetricsDaemonTest, SendMetric);
|
2013-05-08 01:55:00 +02:00
|
|
|
FRIEND_TEST(MetricsDaemonTest, SendCpuThrottleMetrics);
|
2010-05-06 01:06:37 +02:00
|
|
|
FRIEND_TEST(MetricsDaemonTest, SessionStateChanged);
|
2010-06-11 00:59:53 +02:00
|
|
|
FRIEND_TEST(MetricsDaemonTest, SetUserActiveState);
|
2010-06-04 22:14:19 +02:00
|
|
|
FRIEND_TEST(MetricsDaemonTest, SetUserActiveStateTimeJump);
|
2010-05-06 01:06:37 +02:00
|
|
|
|
2010-04-27 20:02:18 +02:00
|
|
|
// The power states (see power_states.h).
|
|
|
|
enum PowerState {
|
|
|
|
kUnknownPowerState = -1, // Initial/unknown power state.
|
|
|
|
#define STATE(name, capname) kPowerState ## capname,
|
|
|
|
#include "power_states.h"
|
|
|
|
kNumberPowerStates
|
|
|
|
};
|
2010-04-14 22:32:20 +02:00
|
|
|
|
2010-05-04 01:45:37 +02:00
|
|
|
// The user session states (see session_states.h).
|
|
|
|
enum SessionState {
|
|
|
|
kUnknownSessionState = -1, // Initial/unknown user session state.
|
|
|
|
#define STATE(name, capname) kSessionState ## capname,
|
|
|
|
#include "session_states.h"
|
|
|
|
kNumberSessionStates
|
|
|
|
};
|
|
|
|
|
2011-02-17 19:21:16 +01:00
|
|
|
// State for disk stats collector callback.
|
2011-10-14 21:03:35 +02:00
|
|
|
enum StatsState {
|
|
|
|
kStatsShort, // short wait before short interval collection
|
|
|
|
kStatsLong, // final wait before new collection
|
2011-02-17 19:21:16 +01:00
|
|
|
};
|
|
|
|
|
2010-05-04 01:45:37 +02:00
|
|
|
// Data record for aggregating daily usage.
|
|
|
|
class UseRecord {
|
|
|
|
public:
|
|
|
|
UseRecord() : day_(0), seconds_(0) {}
|
|
|
|
int day_;
|
|
|
|
int seconds_;
|
|
|
|
};
|
|
|
|
|
2013-02-05 04:50:45 +01:00
|
|
|
// 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).
|
2013-02-12 22:17:07 +01:00
|
|
|
enum MeminfoOp {
|
|
|
|
kMeminfoOp_HistPercent = 0,
|
|
|
|
kMeminfoOp_HistLog,
|
|
|
|
kMeminfoOp_SwapTotal,
|
|
|
|
kMeminfoOp_SwapFree,
|
2013-02-05 04:50:45 +01:00
|
|
|
};
|
|
|
|
|
2011-05-18 01:37:18 +02:00
|
|
|
// Record for retrieving and reporting values from /proc/meminfo.
|
|
|
|
struct MeminfoRecord {
|
2013-02-05 04:50:45 +01:00
|
|
|
const char* name; // print name
|
|
|
|
const char* match; // string to match in output of /proc/meminfo
|
2013-02-12 22:17:07 +01:00
|
|
|
MeminfoOp op; // histogram scale selector, or other operator
|
2013-02-05 04:50:45 +01:00
|
|
|
int value; // value from /proc/meminfo
|
2011-05-18 01:37:18 +02:00
|
|
|
};
|
|
|
|
|
2013-08-01 08:18:31 +02:00
|
|
|
// Record for retrieving and reporting values from /proc/vmstat
|
|
|
|
struct VmstatRecord {
|
|
|
|
uint64_t page_faults_; // major faults
|
|
|
|
uint64_t swap_in_; // pages swapped in
|
|
|
|
uint64_t swap_out_; // pages swapped out
|
|
|
|
};
|
|
|
|
|
2010-08-27 03:35:06 +02:00
|
|
|
typedef std::map<std::string, chromeos_metrics::FrequencyCounter*>
|
|
|
|
FrequencyCounters;
|
|
|
|
|
2010-05-06 01:06:37 +02:00
|
|
|
// Metric parameters.
|
2010-08-17 04:57:13 +02:00
|
|
|
static const char kMetricAnyCrashesDailyName[];
|
2010-08-27 03:35:06 +02:00
|
|
|
static const char kMetricAnyCrashesWeeklyName[];
|
|
|
|
static const char kMetricCrashFrequencyBuckets;
|
|
|
|
static const char kMetricCrashFrequencyMax;
|
|
|
|
static const char kMetricCrashFrequencyMin;
|
2010-08-17 04:57:13 +02:00
|
|
|
static const int kMetricCrashIntervalBuckets;
|
|
|
|
static const int kMetricCrashIntervalMax;
|
|
|
|
static const int kMetricCrashIntervalMin;
|
|
|
|
static const int kMetricDailyUseTimeBuckets;
|
|
|
|
static const int kMetricDailyUseTimeMax;
|
|
|
|
static const int kMetricDailyUseTimeMin;
|
2010-05-06 01:06:37 +02:00
|
|
|
static const char kMetricDailyUseTimeName[];
|
2010-08-17 04:57:13 +02:00
|
|
|
static const char kMetricKernelCrashesDailyName[];
|
2010-08-27 03:35:06 +02:00
|
|
|
static const char kMetricKernelCrashesWeeklyName[];
|
2010-06-24 21:10:26 +02:00
|
|
|
static const char kMetricKernelCrashIntervalName[];
|
2010-08-27 03:35:06 +02:00
|
|
|
static const char kMetricsPath[];
|
2010-08-17 04:57:13 +02:00
|
|
|
static const char kMetricUncleanShutdownIntervalName[];
|
|
|
|
static const char kMetricUncleanShutdownsDailyName[];
|
2010-08-27 03:35:06 +02:00
|
|
|
static const char kMetricUncleanShutdownsWeeklyName[];
|
2010-08-17 04:57:13 +02:00
|
|
|
static const char kMetricUserCrashesDailyName[];
|
2010-08-27 03:35:06 +02:00
|
|
|
static const char kMetricUserCrashesWeeklyName[];
|
2010-06-17 00:58:06 +02:00
|
|
|
static const char kMetricUserCrashIntervalName[];
|
2011-02-17 19:21:16 +01:00
|
|
|
static const char kMetricReadSectorsLongName[];
|
|
|
|
static const char kMetricReadSectorsShortName[];
|
|
|
|
static const char kMetricWriteSectorsLongName[];
|
|
|
|
static const char kMetricWriteSectorsShortName[];
|
2011-10-14 21:03:35 +02:00
|
|
|
static const char kMetricPageFaultsShortName[];
|
|
|
|
static const char kMetricPageFaultsLongName[];
|
2013-08-01 08:18:31 +02:00
|
|
|
static const char kMetricSwapInLongName[];
|
|
|
|
static const char kMetricSwapInShortName[];
|
|
|
|
static const char kMetricSwapOutLongName[];
|
|
|
|
static const char kMetricSwapOutShortName[];
|
2013-05-08 01:55:00 +02:00
|
|
|
static const char kMetricScaledCpuFrequencyName[];
|
2011-10-14 21:03:35 +02:00
|
|
|
static const int kMetricStatsShortInterval;
|
|
|
|
static const int kMetricStatsLongInterval;
|
2011-04-12 23:12:35 +02:00
|
|
|
static const int kMetricMeminfoInterval;
|
2011-02-17 19:21:16 +01:00
|
|
|
static const int kMetricSectorsIOMax;
|
|
|
|
static const int kMetricSectorsBuckets;
|
2011-10-14 21:03:35 +02:00
|
|
|
static const int kMetricPageFaultsMax;
|
|
|
|
static const int kMetricPageFaultsBuckets;
|
2011-02-17 19:21:16 +01:00
|
|
|
static const char kMetricsDiskStatsPath[];
|
2011-10-14 21:03:35 +02:00
|
|
|
static const char kMetricsVmStatsPath[];
|
2010-05-06 01:06:37 +02:00
|
|
|
|
2010-05-04 01:45:37 +02:00
|
|
|
// Array of power states.
|
|
|
|
static const char* kPowerStates_[kNumberPowerStates];
|
|
|
|
|
|
|
|
// Array of user session states.
|
|
|
|
static const char* kSessionStates_[kNumberSessionStates];
|
|
|
|
|
2011-05-18 01:37:18 +02:00
|
|
|
// Returns the active time since boot (uptime minus sleep time) in seconds.
|
|
|
|
double GetActiveTime();
|
|
|
|
|
2010-08-27 03:35:06 +02:00
|
|
|
// Clears and deletes the data contained in frequency_counters_.
|
|
|
|
void DeleteFrequencyCounters();
|
|
|
|
|
|
|
|
// Configures the given crash interval reporter.
|
|
|
|
void ConfigureCrashIntervalReporter(
|
|
|
|
const char* histogram_name,
|
|
|
|
scoped_ptr<chromeos_metrics::TaggedCounterReporter>* reporter);
|
|
|
|
|
|
|
|
// Configures the given frequency counter reporter.
|
|
|
|
void ConfigureCrashFrequencyReporter(const char* histogram_name);
|
|
|
|
|
|
|
|
// Returns file path to persistent file for generating given histogram.
|
|
|
|
FilePath GetHistogramPath(const char* histogram_name);
|
|
|
|
|
2010-04-14 22:32:20 +02:00
|
|
|
// Creates the event loop and enters it.
|
|
|
|
void Loop();
|
|
|
|
|
2010-04-27 20:02:18 +02:00
|
|
|
// D-Bus filter callback.
|
|
|
|
static DBusHandlerResult MessageFilter(DBusConnection* connection,
|
|
|
|
DBusMessage* message,
|
|
|
|
void* user_data);
|
2010-04-14 22:32:20 +02:00
|
|
|
|
2010-04-27 20:02:18 +02:00
|
|
|
// Processes power state change.
|
2010-06-04 22:14:19 +02:00
|
|
|
void PowerStateChanged(const char* state_name, base::Time now);
|
2010-04-27 20:02:18 +02:00
|
|
|
|
|
|
|
// Given the state name, returns the state id.
|
|
|
|
PowerState LookupPowerState(const char* state_name);
|
2010-04-14 22:32:20 +02:00
|
|
|
|
2010-05-04 01:45:37 +02:00
|
|
|
// Processes user session state change.
|
2010-06-04 22:14:19 +02:00
|
|
|
void SessionStateChanged(const char* state_name, base::Time now);
|
2010-05-04 01:45:37 +02:00
|
|
|
|
|
|
|
// Given the state name, returns the state id.
|
|
|
|
SessionState LookupSessionState(const char* state_name);
|
|
|
|
|
|
|
|
// Updates the user-active state to |active| and logs the usage data
|
|
|
|
// since the last update. If the user has just become active,
|
|
|
|
// reschedule the daily use monitor for more frequent updates --
|
|
|
|
// this is followed by an exponential back-off (see UseMonitor).
|
2010-06-04 22:14:19 +02:00
|
|
|
// While in active use, this method should be called at intervals no
|
|
|
|
// longer than kUseMonitorIntervalMax otherwise new use time will be
|
|
|
|
// discarded.
|
|
|
|
void SetUserActiveState(bool active, base::Time now);
|
2010-05-04 01:45:37 +02:00
|
|
|
|
|
|
|
// Updates the daily usage file, if necessary, by adding |seconds|
|
|
|
|
// of active use to the |day| since Epoch. If there's usage data for
|
|
|
|
// day in the past in the usage file, that data is sent to UMA and
|
|
|
|
// removed from the file. If there's already usage data for |day| in
|
|
|
|
// the usage file, the |seconds| are accumulated.
|
|
|
|
void LogDailyUseRecord(int day, int seconds);
|
|
|
|
|
2010-06-17 00:58:06 +02:00
|
|
|
// Updates the active use time and logs time between user-space
|
|
|
|
// process crashes.
|
|
|
|
void ProcessUserCrash();
|
|
|
|
|
2010-06-24 21:10:26 +02:00
|
|
|
// Updates the active use time and logs time between kernel crashes.
|
|
|
|
void ProcessKernelCrash();
|
|
|
|
|
2010-08-17 04:57:13 +02:00
|
|
|
// Updates the active use time and logs time between unclean shutdowns.
|
|
|
|
void ProcessUncleanShutdown();
|
|
|
|
|
|
|
|
// Checks if a kernel crash has been detected and returns true if
|
|
|
|
// so. The method assumes that a kernel crash has happened if
|
|
|
|
// |crash_file| exists. It removes the file immediately if it
|
|
|
|
// exists, so it must not be called more than once.
|
|
|
|
bool CheckSystemCrash(const std::string& crash_file);
|
2010-06-24 21:10:26 +02:00
|
|
|
|
2010-05-04 01:45:37 +02:00
|
|
|
// Callbacks for the daily use monitor. The daily use monitor uses
|
|
|
|
// LogDailyUseRecord to aggregate current usage data and send it to
|
|
|
|
// UMA, if necessary. It also reschedules itself using an
|
|
|
|
// exponentially bigger interval (up to a certain maximum) -- so
|
|
|
|
// usage is monitored less frequently with longer active use.
|
|
|
|
static gboolean UseMonitorStatic(gpointer data);
|
|
|
|
bool UseMonitor();
|
|
|
|
|
|
|
|
// Schedules or reschedules a daily use monitor for |interval|
|
|
|
|
// seconds from now. |backoff| mode is used by the use monitor to
|
|
|
|
// reschedule itself. If there's a monitor scheduled already and
|
|
|
|
// |backoff| is false, unschedules it first. Doesn't schedule a
|
|
|
|
// monitor for more than kUseMonitorIntervalMax seconds in the
|
|
|
|
// future (see metrics_daemon.cc). Returns true if a new use monitor
|
|
|
|
// was scheduled, false otherwise (note that if |backoff| is false a
|
|
|
|
// new use monitor will always be scheduled).
|
|
|
|
bool ScheduleUseMonitor(int interval, bool backoff);
|
|
|
|
|
|
|
|
// Unschedules a scheduled use monitor, if any.
|
|
|
|
void UnscheduleUseMonitor();
|
|
|
|
|
2010-08-27 03:35:06 +02:00
|
|
|
// Report daily use through UMA.
|
|
|
|
static void ReportDailyUse(void* handle, int tag, int count);
|
|
|
|
|
2010-05-18 20:00:59 +02:00
|
|
|
// Sends a regular (exponential) histogram sample to Chrome for
|
|
|
|
// transport to UMA. See MetricsLibrary::SendToUMA in
|
|
|
|
// metrics_library.h for a description of the arguments.
|
|
|
|
void SendMetric(const std::string& name, int sample,
|
|
|
|
int min, int max, int nbuckets);
|
2010-04-14 22:32:20 +02:00
|
|
|
|
2011-04-12 23:12:35 +02:00
|
|
|
// Sends a linear histogram sample to Chrome for transport to UMA. See
|
|
|
|
// MetricsLibrary::SendToUMA in metrics_library.h for a description of the
|
|
|
|
// arguments.
|
|
|
|
void SendLinearMetric(const std::string& name, int sample,
|
|
|
|
int max, int nbuckets);
|
|
|
|
|
2011-10-14 21:03:35 +02:00
|
|
|
// Initializes vm and disk stats reporting.
|
|
|
|
void StatsReporterInit();
|
2011-02-17 19:21:16 +01:00
|
|
|
|
2011-10-14 21:03:35 +02:00
|
|
|
// Schedules a callback for the next vm and disk stats collection.
|
|
|
|
void ScheduleStatsCallback(int wait);
|
2011-02-17 19:21:16 +01:00
|
|
|
|
2011-10-14 21:03:35 +02:00
|
|
|
// Reads cumulative disk statistics from sysfs. Returns true for success.
|
|
|
|
bool DiskStatsReadStats(long int* read_sectors, long int* write_sectors);
|
2011-02-17 19:21:16 +01:00
|
|
|
|
2011-10-14 21:03:35 +02:00
|
|
|
// Reads cumulative vm statistics from procfs. Returns true for success.
|
2013-08-01 08:18:31 +02:00
|
|
|
bool VmStatsReadStats(struct VmstatRecord* stats);
|
2011-10-14 21:03:35 +02:00
|
|
|
|
|
|
|
// Parse cumulative vm statistics from a C string. Returns true for success.
|
2013-08-01 08:18:31 +02:00
|
|
|
bool VmStatsParseStats(const char* stats, struct VmstatRecord* record);
|
2011-02-17 19:21:16 +01:00
|
|
|
|
2011-10-14 21:03:35 +02:00
|
|
|
// Reports disk and vm statistics (static version for glib). Arguments are a
|
|
|
|
// glib artifact.
|
|
|
|
static gboolean StatsCallbackStatic(void* handle);
|
|
|
|
|
|
|
|
// Reports disk and vm statistics.
|
|
|
|
void StatsCallback();
|
2011-02-17 19:21:16 +01:00
|
|
|
|
2011-04-12 23:12:35 +02:00
|
|
|
// Schedules meminfo collection callback.
|
|
|
|
void ScheduleMeminfoCallback(int wait);
|
|
|
|
|
|
|
|
// Reports memory statistics (static version for glib). Argument is a glib
|
|
|
|
// artifact.
|
|
|
|
static gboolean MeminfoCallbackStatic(void* handle);
|
|
|
|
|
|
|
|
// Reports memory statistics. Returns false on failure.
|
2011-10-14 21:03:35 +02:00
|
|
|
bool MeminfoCallback();
|
2011-04-12 23:12:35 +02:00
|
|
|
|
|
|
|
// Parses content of /proc/meminfo and sends fields of interest to UMA.
|
2011-05-18 01:37:18 +02:00
|
|
|
// Returns false on errors. |meminfo_raw| contains the content of
|
|
|
|
// /proc/meminfo.
|
2011-10-14 21:03:35 +02:00
|
|
|
bool ProcessMeminfo(const std::string& meminfo_raw);
|
2011-05-18 01:37:18 +02:00
|
|
|
|
|
|
|
// Parses meminfo data from |meminfo_raw|. |fields| is a vector containing
|
|
|
|
// the fields of interest. The order of the fields must be the same in which
|
|
|
|
// /proc/meminfo prints them. The result of parsing fields[i] is placed in
|
|
|
|
// fields[i].value.
|
2011-10-14 21:03:35 +02:00
|
|
|
bool FillMeminfo(const std::string& meminfo_raw,
|
|
|
|
std::vector<MeminfoRecord>* fields);
|
2011-05-18 01:37:18 +02:00
|
|
|
|
2013-12-06 00:55:12 +01:00
|
|
|
// Schedule a memory use callback in |interval| seconds.
|
|
|
|
void ScheduleMemuseCallback(double interval);
|
2011-05-18 01:37:18 +02:00
|
|
|
|
|
|
|
// Static wrapper for MemuseCallback. Always returns false.
|
|
|
|
static gboolean MemuseCallbackStatic(void* handle);
|
|
|
|
|
|
|
|
// Calls MemuseCallbackWork, and possibly schedules next callback, if enough
|
|
|
|
// active time has passed. Otherwise reschedules itself to simulate active
|
|
|
|
// time callbacks (i.e. wall clock time minus sleep time).
|
|
|
|
void MemuseCallback();
|
|
|
|
|
|
|
|
// Reads /proc/meminfo and sends total anonymous memory usage to UMA.
|
2011-10-14 21:03:35 +02:00
|
|
|
bool MemuseCallbackWork();
|
2011-05-18 01:37:18 +02:00
|
|
|
|
2013-05-08 01:55:00 +02:00
|
|
|
// Parses meminfo data and sends it to UMA.
|
2011-10-14 21:03:35 +02:00
|
|
|
bool ProcessMemuse(const std::string& meminfo_raw);
|
2011-04-12 23:12:35 +02:00
|
|
|
|
2013-05-08 01:55:00 +02:00
|
|
|
// Sends stats for thermal CPU throttling.
|
|
|
|
void SendCpuThrottleMetrics();
|
|
|
|
|
|
|
|
// Reads an integer CPU frequency value from sysfs.
|
|
|
|
bool ReadFreqToInt(const std::string& sysfs_file_name, int* value);
|
|
|
|
|
2010-05-06 01:06:37 +02:00
|
|
|
// Test mode.
|
2010-05-04 01:45:37 +02:00
|
|
|
bool testing_;
|
2010-04-14 22:32:20 +02:00
|
|
|
|
2010-05-12 22:05:45 +02:00
|
|
|
// The metrics library handle.
|
|
|
|
MetricsLibraryInterface* metrics_lib_;
|
|
|
|
|
2010-06-04 22:14:19 +02:00
|
|
|
// Timestamps last network state update. This timestamp is used to
|
|
|
|
// sample the time from the network going online to going offline so
|
|
|
|
// TimeTicks ensures a monotonically increasing TimeDelta.
|
|
|
|
base::TimeTicks network_state_last_;
|
2010-05-04 01:45:37 +02:00
|
|
|
|
|
|
|
// Current power state.
|
|
|
|
PowerState power_state_;
|
|
|
|
|
|
|
|
// Current user session state.
|
|
|
|
SessionState session_state_;
|
|
|
|
|
|
|
|
// Is the user currently active: power is on, user session has
|
|
|
|
// started, screen is not locked.
|
|
|
|
bool user_active_;
|
|
|
|
|
2010-06-17 00:58:06 +02:00
|
|
|
// Timestamps last user active update. Active use time is aggregated
|
|
|
|
// each day before sending to UMA so using time since the epoch as
|
|
|
|
// the timestamp.
|
2010-06-04 22:14:19 +02:00
|
|
|
base::Time user_active_last_;
|
2010-05-04 01:45:37 +02:00
|
|
|
|
2010-06-17 00:58:06 +02:00
|
|
|
// Daily active use time in seconds.
|
2010-08-27 03:35:06 +02:00
|
|
|
scoped_ptr<chromeos_metrics::TaggedCounter> daily_use_;
|
2010-05-04 01:45:37 +02:00
|
|
|
|
2010-06-17 00:58:06 +02:00
|
|
|
// Active use time between user-space process crashes.
|
2010-08-27 03:35:06 +02:00
|
|
|
scoped_ptr<chromeos_metrics::TaggedCounterReporter> user_crash_interval_;
|
2010-06-17 00:58:06 +02:00
|
|
|
|
2010-06-24 21:10:26 +02:00
|
|
|
// Active use time between kernel crashes.
|
2010-08-27 03:35:06 +02:00
|
|
|
scoped_ptr<chromeos_metrics::TaggedCounterReporter> kernel_crash_interval_;
|
2010-06-24 21:10:26 +02:00
|
|
|
|
2010-08-17 04:57:13 +02:00
|
|
|
// Active use time between unclean shutdowns crashes.
|
2010-08-27 03:35:06 +02:00
|
|
|
scoped_ptr<chromeos_metrics::TaggedCounterReporter>
|
2010-08-17 04:57:13 +02:00
|
|
|
unclean_shutdown_interval_;
|
|
|
|
|
2010-08-27 03:35:06 +02:00
|
|
|
// Map of all frequency counters, to simplify flushing them.
|
|
|
|
FrequencyCounters frequency_counters_;
|
2010-08-17 04:57:13 +02:00
|
|
|
|
2010-05-04 01:45:37 +02:00
|
|
|
// Sleep period until the next daily usage aggregation performed by
|
|
|
|
// the daily use monitor (see ScheduleUseMonitor).
|
|
|
|
int usemon_interval_;
|
2010-04-14 22:32:20 +02:00
|
|
|
|
2010-05-04 01:45:37 +02:00
|
|
|
// Scheduled daily use monitor source (see ScheduleUseMonitor).
|
|
|
|
GSource* usemon_source_;
|
2011-02-17 19:21:16 +01:00
|
|
|
|
2013-12-06 00:55:12 +01:00
|
|
|
// End time of current memuse stat collection interval.
|
|
|
|
double memuse_final_time_;
|
2011-05-18 01:37:18 +02:00
|
|
|
|
|
|
|
// Selects the wait time for the next memory use callback.
|
|
|
|
unsigned int memuse_interval_index_;
|
|
|
|
|
2011-10-14 21:03:35 +02:00
|
|
|
// Contain the most recent disk and vm cumulative stats.
|
2011-02-17 19:21:16 +01:00
|
|
|
long int read_sectors_;
|
|
|
|
long int write_sectors_;
|
2013-08-01 08:18:31 +02:00
|
|
|
struct VmstatRecord vmstats_;
|
2011-10-14 21:03:35 +02:00
|
|
|
|
|
|
|
StatsState stats_state_;
|
|
|
|
double stats_initial_time_;
|
2011-02-17 19:21:16 +01:00
|
|
|
|
2011-02-28 20:17:43 +01:00
|
|
|
std::string diskstats_path_;
|
2011-10-14 21:03:35 +02:00
|
|
|
std::string vmstats_path_;
|
2013-05-08 01:55:00 +02:00
|
|
|
std::string scaling_max_freq_path_;
|
|
|
|
std::string cpuinfo_max_freq_path_;
|
2010-04-14 22:32:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // METRICS_DAEMON_H_
|