2011-05-10 01:33:19 +02:00
|
|
|
// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
|
2010-04-14 22:32:20 +02:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-07-01 03:12:28 +02:00
|
|
|
// For PRIu64 in inttypes.h, used by scanf. TODO(semenzato): replace
|
|
|
|
// with libchromeos methods.
|
|
|
|
#define __STDC_FORMAT_MACROS
|
|
|
|
|
|
|
|
#include "metrics/metrics_daemon.h"
|
2010-04-14 22:32:20 +02:00
|
|
|
|
2011-02-17 19:21:16 +01:00
|
|
|
#include <fcntl.h>
|
2014-07-01 03:12:28 +02:00
|
|
|
#include <inttypes.h>
|
2011-05-18 01:37:18 +02:00
|
|
|
#include <math.h>
|
2010-08-27 03:35:06 +02:00
|
|
|
#include <string.h>
|
2011-05-18 01:37:18 +02:00
|
|
|
#include <time.h>
|
2010-04-14 22:32:20 +02:00
|
|
|
|
2014-02-06 00:33:19 +01:00
|
|
|
#include <base/files/file_path.h>
|
2014-09-05 17:21:06 +02:00
|
|
|
#include <base/files/file_util.h>
|
2014-02-06 00:33:19 +01:00
|
|
|
#include <base/hash.h>
|
2010-04-14 22:32:20 +02:00
|
|
|
#include <base/logging.h>
|
2014-02-06 08:26:25 +01:00
|
|
|
#include <base/strings/string_number_conversions.h>
|
|
|
|
#include <base/strings/string_split.h>
|
|
|
|
#include <base/strings/string_util.h>
|
|
|
|
#include <base/strings/stringprintf.h>
|
2014-02-06 00:33:19 +01:00
|
|
|
#include <base/sys_info.h>
|
2013-04-29 15:07:31 +02:00
|
|
|
#include <chromeos/dbus/service_constants.h>
|
2010-08-27 03:35:06 +02:00
|
|
|
#include <dbus/dbus-glib-lowlevel.h>
|
2014-06-25 23:38:07 +02:00
|
|
|
#include "uploader/upload_service.h"
|
2010-04-14 22:32:20 +02:00
|
|
|
|
2014-02-06 08:26:25 +01:00
|
|
|
using base::FilePath;
|
|
|
|
using base::StringPrintf;
|
2010-06-04 22:14:19 +02:00
|
|
|
using base::Time;
|
|
|
|
using base::TimeDelta;
|
|
|
|
using base::TimeTicks;
|
2014-02-26 20:53:16 +01:00
|
|
|
using chromeos_metrics::PersistentInteger;
|
2011-05-18 01:37:18 +02:00
|
|
|
using std::map;
|
2010-06-24 21:10:26 +02:00
|
|
|
using std::string;
|
2011-05-18 01:37:18 +02:00
|
|
|
using std::vector;
|
|
|
|
|
2014-04-04 17:53:44 +02:00
|
|
|
namespace {
|
2010-06-04 22:14:19 +02:00
|
|
|
|
2010-04-27 20:02:18 +02:00
|
|
|
#define SAFE_MESSAGE(e) (e.message ? e.message : "unknown error")
|
2013-04-29 15:07:31 +02:00
|
|
|
|
2014-04-04 17:53:44 +02:00
|
|
|
const char kCrashReporterInterface[] = "org.chromium.CrashReporter";
|
|
|
|
const char kCrashReporterUserCrashSignal[] = "UserCrash";
|
|
|
|
|
|
|
|
const int kSecondsPerMinute = 60;
|
|
|
|
const int kMinutesPerHour = 60;
|
|
|
|
const int kHoursPerDay = 24;
|
|
|
|
const int kMinutesPerDay = kHoursPerDay * kMinutesPerHour;
|
|
|
|
const int kSecondsPerDay = kSecondsPerMinute * kMinutesPerDay;
|
|
|
|
const int kDaysPerWeek = 7;
|
|
|
|
const int kSecondsPerWeek = kSecondsPerDay * kDaysPerWeek;
|
|
|
|
|
|
|
|
// Interval between calls to UpdateStats().
|
|
|
|
const guint kUpdateStatsIntervalMs = 300000;
|
2010-04-27 20:02:18 +02:00
|
|
|
|
2014-02-15 00:05:51 +01:00
|
|
|
const char kKernelCrashDetectedFile[] = "/var/run/kernel-crash-detected";
|
2014-04-04 17:53:44 +02:00
|
|
|
const char kUncleanShutdownDetectedFile[] =
|
2014-02-26 20:53:16 +01:00
|
|
|
"/var/run/unclean-shutdown-detected";
|
2010-08-17 04:57:13 +02:00
|
|
|
|
2014-04-04 17:53:44 +02:00
|
|
|
} // namespace
|
|
|
|
|
2011-02-17 19:21:16 +01:00
|
|
|
// disk stats metrics
|
|
|
|
|
|
|
|
// The {Read,Write}Sectors numbers are in sectors/second.
|
|
|
|
// A sector is usually 512 bytes.
|
|
|
|
|
|
|
|
const char MetricsDaemon::kMetricReadSectorsLongName[] =
|
|
|
|
"Platform.ReadSectorsLong";
|
|
|
|
const char MetricsDaemon::kMetricWriteSectorsLongName[] =
|
|
|
|
"Platform.WriteSectorsLong";
|
|
|
|
const char MetricsDaemon::kMetricReadSectorsShortName[] =
|
|
|
|
"Platform.ReadSectorsShort";
|
|
|
|
const char MetricsDaemon::kMetricWriteSectorsShortName[] =
|
|
|
|
"Platform.WriteSectorsShort";
|
|
|
|
|
2011-10-14 21:03:35 +02:00
|
|
|
const int MetricsDaemon::kMetricStatsShortInterval = 1; // seconds
|
|
|
|
const int MetricsDaemon::kMetricStatsLongInterval = 30; // seconds
|
2011-02-17 19:21:16 +01:00
|
|
|
|
2011-04-12 23:12:35 +02:00
|
|
|
const int MetricsDaemon::kMetricMeminfoInterval = 30; // seconds
|
|
|
|
|
2011-02-17 19:21:16 +01:00
|
|
|
// Assume a max rate of 250Mb/s for reads (worse for writes) and 512 byte
|
|
|
|
// sectors.
|
|
|
|
const int MetricsDaemon::kMetricSectorsIOMax = 500000; // sectors/second
|
|
|
|
const int MetricsDaemon::kMetricSectorsBuckets = 50; // buckets
|
2011-10-14 21:03:35 +02:00
|
|
|
// Page size is 4k, sector size is 0.5k. We're not interested in page fault
|
|
|
|
// rates that the disk cannot sustain.
|
|
|
|
const int MetricsDaemon::kMetricPageFaultsMax = kMetricSectorsIOMax / 8;
|
|
|
|
const int MetricsDaemon::kMetricPageFaultsBuckets = 50;
|
|
|
|
|
|
|
|
// Major page faults, i.e. the ones that require data to be read from disk.
|
|
|
|
|
|
|
|
const char MetricsDaemon::kMetricPageFaultsLongName[] =
|
|
|
|
"Platform.PageFaultsLong";
|
|
|
|
const char MetricsDaemon::kMetricPageFaultsShortName[] =
|
|
|
|
"Platform.PageFaultsShort";
|
2011-02-17 19:21:16 +01:00
|
|
|
|
2013-08-01 08:18:31 +02:00
|
|
|
// Swap in and Swap out
|
|
|
|
|
|
|
|
const char MetricsDaemon::kMetricSwapInLongName[] =
|
|
|
|
"Platform.SwapInLong";
|
|
|
|
const char MetricsDaemon::kMetricSwapInShortName[] =
|
|
|
|
"Platform.SwapInShort";
|
|
|
|
|
|
|
|
const char MetricsDaemon::kMetricSwapOutLongName[] =
|
|
|
|
"Platform.SwapOutLong";
|
|
|
|
const char MetricsDaemon::kMetricSwapOutShortName[] =
|
|
|
|
"Platform.SwapOutShort";
|
|
|
|
|
2014-03-17 20:28:38 +01:00
|
|
|
const char MetricsDaemon::kMetricsProcStatFileName[] = "/proc/stat";
|
|
|
|
const int MetricsDaemon::kMetricsProcStatFirstLineItemsCount = 11;
|
|
|
|
|
2013-05-08 01:55:00 +02:00
|
|
|
// Thermal CPU throttling.
|
|
|
|
|
|
|
|
const char MetricsDaemon::kMetricScaledCpuFrequencyName[] =
|
|
|
|
"Platform.CpuFrequencyThermalScaling";
|
|
|
|
|
2014-06-04 19:53:35 +02:00
|
|
|
// Zram sysfs entries.
|
|
|
|
|
|
|
|
const char MetricsDaemon::kComprDataSizeName[] = "compr_data_size";
|
|
|
|
const char MetricsDaemon::kOrigDataSizeName[] = "orig_data_size";
|
|
|
|
const char MetricsDaemon::kZeroPagesName[] = "zero_pages";
|
|
|
|
|
2011-05-18 01:37:18 +02:00
|
|
|
// Memory use stats collection intervals. We collect some memory use interval
|
|
|
|
// at these intervals after boot, and we stop collecting after the last one,
|
|
|
|
// with the assumption that in most cases the memory use won't change much
|
|
|
|
// after that.
|
|
|
|
static const int kMemuseIntervals[] = {
|
|
|
|
1 * kSecondsPerMinute, // 1 minute mark
|
|
|
|
4 * kSecondsPerMinute, // 5 minute mark
|
|
|
|
25 * kSecondsPerMinute, // 0.5 hour mark
|
|
|
|
120 * kSecondsPerMinute, // 2.5 hour mark
|
|
|
|
600 * kSecondsPerMinute, // 12.5 hour mark
|
|
|
|
};
|
|
|
|
|
2010-06-11 00:59:53 +02:00
|
|
|
MetricsDaemon::MetricsDaemon()
|
2014-04-04 17:53:44 +02:00
|
|
|
: update_stats_timeout_id_(-1),
|
2013-12-06 00:55:12 +01:00
|
|
|
memuse_final_time_(0),
|
2011-05-18 01:37:18 +02:00
|
|
|
memuse_interval_index_(0),
|
|
|
|
read_sectors_(0),
|
|
|
|
write_sectors_(0),
|
2013-08-01 08:18:31 +02:00
|
|
|
vmstats_(),
|
2011-10-14 21:03:35 +02:00
|
|
|
stats_state_(kStatsShort),
|
2014-03-17 20:28:38 +01:00
|
|
|
stats_initial_time_(0),
|
|
|
|
ticks_per_second_(0),
|
|
|
|
latest_cpu_use_ticks_(0) {}
|
2010-06-11 00:59:53 +02:00
|
|
|
|
2010-08-27 03:35:06 +02:00
|
|
|
MetricsDaemon::~MetricsDaemon() {
|
2014-04-04 17:53:44 +02:00
|
|
|
if (update_stats_timeout_id_ > -1)
|
|
|
|
g_source_remove(update_stats_timeout_id_);
|
2010-08-27 03:35:06 +02:00
|
|
|
}
|
|
|
|
|
2011-05-18 01:37:18 +02:00
|
|
|
double MetricsDaemon::GetActiveTime() {
|
|
|
|
struct timespec ts;
|
|
|
|
int r = clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
|
|
if (r < 0) {
|
|
|
|
PLOG(WARNING) << "clock_gettime(CLOCK_MONOTONIC) failed";
|
|
|
|
return 0;
|
|
|
|
} else {
|
2014-07-01 03:12:28 +02:00
|
|
|
return ts.tv_sec + static_cast<double>(ts.tv_nsec) / (1000 * 1000 * 1000);
|
2011-05-18 01:37:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-06 01:06:37 +02:00
|
|
|
void MetricsDaemon::Run(bool run_as_daemon) {
|
2010-06-24 21:10:26 +02:00
|
|
|
if (run_as_daemon && daemon(0, 0) != 0)
|
|
|
|
return;
|
|
|
|
|
2010-08-17 04:57:13 +02:00
|
|
|
if (CheckSystemCrash(kKernelCrashDetectedFile)) {
|
|
|
|
ProcessKernelCrash();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CheckSystemCrash(kUncleanShutdownDetectedFile)) {
|
|
|
|
ProcessUncleanShutdown();
|
|
|
|
}
|
|
|
|
|
2014-02-26 20:53:16 +01:00
|
|
|
// On OS version change, clear version stats (which are reported daily).
|
2014-08-07 09:54:59 +02:00
|
|
|
int32_t version = GetOsVersionHash();
|
2014-02-26 20:53:16 +01:00
|
|
|
if (version_cycle_->Get() != version) {
|
|
|
|
version_cycle_->Set(version);
|
|
|
|
kernel_crashes_version_count_->Set(0);
|
2014-04-19 02:00:35 +02:00
|
|
|
version_cumulative_active_use_->Set(0);
|
2014-03-17 20:28:38 +01:00
|
|
|
version_cumulative_cpu_use_->Set(0);
|
2014-02-26 20:53:16 +01:00
|
|
|
}
|
2010-08-27 03:35:06 +02:00
|
|
|
|
2014-02-26 20:53:16 +01:00
|
|
|
Loop();
|
2014-02-06 00:33:19 +01:00
|
|
|
}
|
|
|
|
|
2014-06-25 23:38:07 +02:00
|
|
|
void MetricsDaemon::RunUploaderTest() {
|
2014-10-07 20:26:25 +02:00
|
|
|
upload_service_.reset(new UploadService(new SystemProfileCache(true,
|
|
|
|
config_root_),
|
|
|
|
server_));
|
2014-10-07 00:15:30 +02:00
|
|
|
upload_service_->Init(upload_interval_secs_, metrics_file_);
|
2014-06-25 23:38:07 +02:00
|
|
|
upload_service_->UploadEvent();
|
|
|
|
}
|
|
|
|
|
2014-08-07 09:54:59 +02:00
|
|
|
uint32_t MetricsDaemon::GetOsVersionHash() {
|
|
|
|
static uint32_t cached_version_hash = 0;
|
2014-02-06 00:33:19 +01:00
|
|
|
static bool version_hash_is_cached = false;
|
|
|
|
if (version_hash_is_cached)
|
|
|
|
return cached_version_hash;
|
|
|
|
version_hash_is_cached = true;
|
|
|
|
std::string version;
|
|
|
|
if (base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_VERSION", &version)) {
|
|
|
|
cached_version_hash = base::Hash(version);
|
|
|
|
} else if (testing_) {
|
|
|
|
cached_version_hash = 42; // return any plausible value for the hash
|
|
|
|
} else {
|
|
|
|
LOG(FATAL) << "could not find CHROMEOS_RELEASE_VERSION";
|
|
|
|
}
|
|
|
|
return cached_version_hash;
|
|
|
|
}
|
|
|
|
|
2014-06-25 23:38:07 +02:00
|
|
|
void MetricsDaemon::Init(bool testing,
|
|
|
|
bool uploader_active,
|
|
|
|
MetricsLibraryInterface* metrics_lib,
|
2011-10-14 21:03:35 +02:00
|
|
|
const string& diskstats_path,
|
2013-05-08 01:55:00 +02:00
|
|
|
const string& vmstats_path,
|
|
|
|
const string& scaling_max_freq_path,
|
2014-10-07 00:15:30 +02:00
|
|
|
const string& cpuinfo_max_freq_path,
|
|
|
|
int upload_interval_secs,
|
|
|
|
const string& server,
|
2014-10-07 20:26:25 +02:00
|
|
|
const string& metrics_file,
|
|
|
|
const string& config_root) {
|
2010-04-14 22:32:20 +02:00
|
|
|
testing_ = testing;
|
2014-10-07 20:26:25 +02:00
|
|
|
config_root_ = config_root;
|
2014-08-28 23:59:56 +02:00
|
|
|
DCHECK(metrics_lib != nullptr);
|
2010-05-12 22:05:45 +02:00
|
|
|
metrics_lib_ = metrics_lib;
|
2014-02-26 20:53:16 +01:00
|
|
|
|
2014-10-07 00:15:30 +02:00
|
|
|
upload_interval_secs_ = upload_interval_secs;
|
|
|
|
server_ = server;
|
|
|
|
metrics_file_ = metrics_file;
|
|
|
|
|
2014-03-17 20:28:38 +01:00
|
|
|
// Get ticks per second (HZ) on this system.
|
|
|
|
// Sysconf cannot fail, so no sanity checks are needed.
|
|
|
|
ticks_per_second_ = sysconf(_SC_CLK_TCK);
|
|
|
|
|
2014-04-19 02:00:35 +02:00
|
|
|
daily_active_use_.reset(
|
2014-02-26 20:53:16 +01:00
|
|
|
new PersistentInteger("Logging.DailyUseTime"));
|
2014-04-19 02:00:35 +02:00
|
|
|
version_cumulative_active_use_.reset(
|
|
|
|
new PersistentInteger("Logging.CumulativeDailyUseTime"));
|
2014-03-17 20:28:38 +01:00
|
|
|
version_cumulative_cpu_use_.reset(
|
|
|
|
new PersistentInteger("Logging.CumulativeCpuTime"));
|
2014-02-26 20:53:16 +01:00
|
|
|
|
|
|
|
kernel_crash_interval_.reset(
|
|
|
|
new PersistentInteger("Logging.KernelCrashInterval"));
|
|
|
|
unclean_shutdown_interval_.reset(
|
|
|
|
new PersistentInteger("Logging.UncleanShutdownInterval"));
|
|
|
|
user_crash_interval_.reset(
|
|
|
|
new PersistentInteger("Logging.UserCrashInterval"));
|
|
|
|
|
|
|
|
any_crashes_daily_count_.reset(
|
|
|
|
new PersistentInteger("Logging.AnyCrashesDaily"));
|
|
|
|
any_crashes_weekly_count_.reset(
|
|
|
|
new PersistentInteger("Logging.AnyCrashesWeekly"));
|
|
|
|
user_crashes_daily_count_.reset(
|
|
|
|
new PersistentInteger("Logging.UserCrashesDaily"));
|
|
|
|
user_crashes_weekly_count_.reset(
|
|
|
|
new PersistentInteger("Logging.UserCrashesWeekly"));
|
|
|
|
kernel_crashes_daily_count_.reset(
|
|
|
|
new PersistentInteger("Logging.KernelCrashesDaily"));
|
|
|
|
kernel_crashes_weekly_count_.reset(
|
|
|
|
new PersistentInteger("Logging.KernelCrashesWeekly"));
|
|
|
|
kernel_crashes_version_count_.reset(
|
|
|
|
new PersistentInteger("Logging.KernelCrashesSinceUpdate"));
|
|
|
|
unclean_shutdowns_daily_count_.reset(
|
|
|
|
new PersistentInteger("Logging.UncleanShutdownsDaily"));
|
|
|
|
unclean_shutdowns_weekly_count_.reset(
|
|
|
|
new PersistentInteger("Logging.UncleanShutdownsWeekly"));
|
|
|
|
|
|
|
|
daily_cycle_.reset(new PersistentInteger("daily.cycle"));
|
|
|
|
weekly_cycle_.reset(new PersistentInteger("weekly.cycle"));
|
|
|
|
version_cycle_.reset(new PersistentInteger("version.cycle"));
|
2014-02-06 00:33:19 +01:00
|
|
|
|
2011-10-14 21:03:35 +02:00
|
|
|
diskstats_path_ = diskstats_path;
|
|
|
|
vmstats_path_ = vmstats_path;
|
2013-05-08 01:55:00 +02:00
|
|
|
scaling_max_freq_path_ = scaling_max_freq_path;
|
|
|
|
cpuinfo_max_freq_path_ = cpuinfo_max_freq_path;
|
2011-10-14 21:03:35 +02:00
|
|
|
StatsReporterInit();
|
2011-02-17 19:21:16 +01:00
|
|
|
|
2011-04-12 23:12:35 +02:00
|
|
|
// Start collecting meminfo stats.
|
|
|
|
ScheduleMeminfoCallback(kMetricMeminfoInterval);
|
2013-12-06 00:55:12 +01:00
|
|
|
memuse_final_time_ = GetActiveTime() + kMemuseIntervals[0];
|
|
|
|
ScheduleMemuseCallback(kMemuseIntervals[0]);
|
2011-04-12 23:12:35 +02:00
|
|
|
|
2010-05-06 01:06:37 +02:00
|
|
|
// Don't setup D-Bus and GLib in test mode.
|
|
|
|
if (testing)
|
|
|
|
return;
|
2010-04-27 20:02:18 +02:00
|
|
|
|
|
|
|
g_type_init();
|
2013-06-22 15:29:36 +02:00
|
|
|
dbus_threads_init_default();
|
2010-04-27 20:02:18 +02:00
|
|
|
|
|
|
|
DBusError error;
|
|
|
|
dbus_error_init(&error);
|
|
|
|
|
2010-06-05 00:01:19 +02:00
|
|
|
DBusConnection* connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
|
2010-04-27 20:02:18 +02:00
|
|
|
LOG_IF(FATAL, dbus_error_is_set(&error)) <<
|
|
|
|
"No D-Bus connection: " << SAFE_MESSAGE(error);
|
|
|
|
|
2014-08-28 23:59:56 +02:00
|
|
|
dbus_connection_setup_with_g_main(connection, nullptr);
|
2010-04-27 20:02:18 +02:00
|
|
|
|
2013-04-29 15:07:31 +02:00
|
|
|
vector<string> matches;
|
|
|
|
matches.push_back(
|
2014-02-06 00:33:19 +01:00
|
|
|
base::StringPrintf("type='signal',interface='%s',path='/',member='%s'",
|
|
|
|
kCrashReporterInterface,
|
|
|
|
kCrashReporterUserCrashSignal));
|
2013-04-29 15:07:31 +02:00
|
|
|
|
2010-04-27 20:02:18 +02:00
|
|
|
// Registers D-Bus matches for the signals we would like to catch.
|
2013-04-29 15:07:31 +02:00
|
|
|
for (vector<string>::const_iterator it = matches.begin();
|
|
|
|
it != matches.end(); ++it) {
|
|
|
|
const char* match = it->c_str();
|
2010-05-04 01:45:37 +02:00
|
|
|
DLOG(INFO) << "adding dbus match: " << match;
|
2010-04-27 20:02:18 +02:00
|
|
|
dbus_bus_add_match(connection, match, &error);
|
|
|
|
LOG_IF(FATAL, dbus_error_is_set(&error)) <<
|
|
|
|
"unable to add a match: " << SAFE_MESSAGE(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adds the D-Bus filter routine to be called back whenever one of
|
|
|
|
// the registered D-Bus matches is successful. The daemon is not
|
|
|
|
// activated for D-Bus messages that don't match.
|
2014-08-28 23:59:56 +02:00
|
|
|
CHECK(dbus_connection_add_filter(connection, MessageFilter, this, nullptr));
|
2014-04-04 17:53:44 +02:00
|
|
|
|
|
|
|
update_stats_timeout_id_ =
|
|
|
|
g_timeout_add(kUpdateStatsIntervalMs, &HandleUpdateStatsTimeout, this);
|
2014-06-25 23:38:07 +02:00
|
|
|
|
|
|
|
if (uploader_active) {
|
2014-09-11 16:29:17 +02:00
|
|
|
LOG(INFO) << "uploader enabled";
|
2014-10-07 20:26:25 +02:00
|
|
|
upload_service_.reset(new UploadService(new SystemProfileCache(), server_));
|
2014-10-07 00:15:30 +02:00
|
|
|
upload_service_->Init(upload_interval_secs_, metrics_file_);
|
2014-06-25 23:38:07 +02:00
|
|
|
}
|
2010-04-14 22:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetricsDaemon::Loop() {
|
2014-08-28 23:59:56 +02:00
|
|
|
GMainLoop* loop = g_main_loop_new(nullptr, false);
|
2010-04-27 20:02:18 +02:00
|
|
|
g_main_loop_run(loop);
|
2010-04-14 22:32:20 +02:00
|
|
|
}
|
|
|
|
|
2010-04-27 20:02:18 +02:00
|
|
|
// static
|
|
|
|
DBusHandlerResult MetricsDaemon::MessageFilter(DBusConnection* connection,
|
|
|
|
DBusMessage* message,
|
|
|
|
void* user_data) {
|
|
|
|
int message_type = dbus_message_get_type(message);
|
|
|
|
if (message_type != DBUS_MESSAGE_TYPE_SIGNAL) {
|
2010-05-04 01:45:37 +02:00
|
|
|
DLOG(WARNING) << "unexpected message type " << message_type;
|
2010-04-27 20:02:18 +02:00
|
|
|
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
2010-04-14 22:32:20 +02:00
|
|
|
}
|
|
|
|
|
2010-04-27 20:02:18 +02:00
|
|
|
// Signal messages always have interfaces.
|
2014-04-04 17:53:44 +02:00
|
|
|
const std::string interface(dbus_message_get_interface(message));
|
|
|
|
const std::string member(dbus_message_get_member(message));
|
|
|
|
DLOG(INFO) << "Got " << interface << "." << member << " D-Bus signal";
|
2010-04-14 22:32:20 +02:00
|
|
|
|
2010-04-27 20:02:18 +02:00
|
|
|
MetricsDaemon* daemon = static_cast<MetricsDaemon*>(user_data);
|
|
|
|
|
|
|
|
DBusMessageIter iter;
|
|
|
|
dbus_message_iter_init(message, &iter);
|
2014-04-04 17:53:44 +02:00
|
|
|
if (interface == kCrashReporterInterface) {
|
|
|
|
CHECK_EQ(member, kCrashReporterUserCrashSignal);
|
2010-06-17 00:58:06 +02:00
|
|
|
daemon->ProcessUserCrash();
|
2010-04-27 20:02:18 +02:00
|
|
|
} else {
|
2014-04-04 17:53:44 +02:00
|
|
|
// Ignore messages from the bus itself.
|
2010-04-27 20:02:18 +02:00
|
|
|
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
2010-04-14 22:32:20 +02:00
|
|
|
}
|
2010-04-27 20:02:18 +02:00
|
|
|
|
|
|
|
return DBUS_HANDLER_RESULT_HANDLED;
|
|
|
|
}
|
|
|
|
|
2014-03-17 20:28:38 +01:00
|
|
|
// One might argue that parts of this should go into
|
|
|
|
// chromium/src/base/sys_info_chromeos.c instead, but put it here for now.
|
|
|
|
|
|
|
|
TimeDelta MetricsDaemon::GetIncrementalCpuUse() {
|
|
|
|
FilePath proc_stat_path = FilePath(kMetricsProcStatFileName);
|
|
|
|
std::string proc_stat_string;
|
|
|
|
if (!base::ReadFileToString(proc_stat_path, &proc_stat_string)) {
|
|
|
|
LOG(WARNING) << "cannot open " << kMetricsProcStatFileName;
|
|
|
|
return TimeDelta();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> proc_stat_lines;
|
|
|
|
base::SplitString(proc_stat_string, '\n', &proc_stat_lines);
|
|
|
|
if (proc_stat_lines.empty()) {
|
|
|
|
LOG(WARNING) << "cannot parse " << kMetricsProcStatFileName
|
|
|
|
<< ": " << proc_stat_string;
|
|
|
|
return TimeDelta();
|
|
|
|
}
|
|
|
|
std::vector<std::string> proc_stat_totals;
|
|
|
|
base::SplitStringAlongWhitespace(proc_stat_lines[0], &proc_stat_totals);
|
|
|
|
|
2014-08-07 09:54:59 +02:00
|
|
|
uint64_t user_ticks, user_nice_ticks, system_ticks;
|
2014-03-17 20:28:38 +01:00
|
|
|
if (proc_stat_totals.size() != kMetricsProcStatFirstLineItemsCount ||
|
|
|
|
proc_stat_totals[0] != "cpu" ||
|
|
|
|
!base::StringToUint64(proc_stat_totals[1], &user_ticks) ||
|
|
|
|
!base::StringToUint64(proc_stat_totals[2], &user_nice_ticks) ||
|
|
|
|
!base::StringToUint64(proc_stat_totals[3], &system_ticks)) {
|
|
|
|
LOG(WARNING) << "cannot parse first line: " << proc_stat_lines[0];
|
|
|
|
return TimeDelta(base::TimeDelta::FromSeconds(0));
|
|
|
|
}
|
|
|
|
|
2014-08-07 09:54:59 +02:00
|
|
|
uint64_t total_cpu_use_ticks = user_ticks + user_nice_ticks + system_ticks;
|
2014-03-17 20:28:38 +01:00
|
|
|
|
|
|
|
// Sanity check.
|
|
|
|
if (total_cpu_use_ticks < latest_cpu_use_ticks_) {
|
|
|
|
LOG(WARNING) << "CPU time decreasing from " << latest_cpu_use_ticks_
|
|
|
|
<< " to " << total_cpu_use_ticks;
|
|
|
|
return TimeDelta();
|
|
|
|
}
|
|
|
|
|
2014-08-07 09:54:59 +02:00
|
|
|
uint64_t diff = total_cpu_use_ticks - latest_cpu_use_ticks_;
|
2014-03-17 20:28:38 +01:00
|
|
|
latest_cpu_use_ticks_ = total_cpu_use_ticks;
|
|
|
|
// Use microseconds to avoid significant truncations.
|
|
|
|
return base::TimeDelta::FromMicroseconds(
|
|
|
|
diff * 1000 * 1000 / ticks_per_second_);
|
|
|
|
}
|
|
|
|
|
2010-06-17 00:58:06 +02:00
|
|
|
void MetricsDaemon::ProcessUserCrash() {
|
2014-04-04 17:53:44 +02:00
|
|
|
// Counts the active time up to now.
|
|
|
|
UpdateStats(TimeTicks::Now(), Time::Now());
|
2010-06-17 00:58:06 +02:00
|
|
|
|
|
|
|
// Reports the active use time since the last crash and resets it.
|
2014-02-26 20:53:16 +01:00
|
|
|
SendCrashIntervalSample(user_crash_interval_);
|
2010-08-17 04:57:13 +02:00
|
|
|
|
2014-02-26 20:53:16 +01:00
|
|
|
any_crashes_daily_count_->Add(1);
|
|
|
|
any_crashes_weekly_count_->Add(1);
|
|
|
|
user_crashes_daily_count_->Add(1);
|
|
|
|
user_crashes_weekly_count_->Add(1);
|
2010-06-17 00:58:06 +02:00
|
|
|
}
|
|
|
|
|
2010-06-24 21:10:26 +02:00
|
|
|
void MetricsDaemon::ProcessKernelCrash() {
|
2014-04-04 17:53:44 +02:00
|
|
|
// Counts the active time up to now.
|
|
|
|
UpdateStats(TimeTicks::Now(), Time::Now());
|
2010-06-24 21:10:26 +02:00
|
|
|
|
|
|
|
// Reports the active use time since the last crash and resets it.
|
2014-02-26 20:53:16 +01:00
|
|
|
SendCrashIntervalSample(kernel_crash_interval_);
|
2010-08-17 04:57:13 +02:00
|
|
|
|
2014-02-26 20:53:16 +01:00
|
|
|
any_crashes_daily_count_->Add(1);
|
|
|
|
any_crashes_weekly_count_->Add(1);
|
|
|
|
kernel_crashes_daily_count_->Add(1);
|
|
|
|
kernel_crashes_weekly_count_->Add(1);
|
2014-02-06 00:33:19 +01:00
|
|
|
|
2014-02-26 20:53:16 +01:00
|
|
|
kernel_crashes_version_count_->Add(1);
|
2010-08-17 04:57:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetricsDaemon::ProcessUncleanShutdown() {
|
2014-04-04 17:53:44 +02:00
|
|
|
// Counts the active time up to now.
|
|
|
|
UpdateStats(TimeTicks::Now(), Time::Now());
|
2010-08-17 04:57:13 +02:00
|
|
|
|
|
|
|
// Reports the active use time since the last crash and resets it.
|
2014-02-26 20:53:16 +01:00
|
|
|
SendCrashIntervalSample(unclean_shutdown_interval_);
|
2010-08-17 04:57:13 +02:00
|
|
|
|
2014-02-26 20:53:16 +01:00
|
|
|
unclean_shutdowns_daily_count_->Add(1);
|
|
|
|
unclean_shutdowns_weekly_count_->Add(1);
|
|
|
|
any_crashes_daily_count_->Add(1);
|
|
|
|
any_crashes_weekly_count_->Add(1);
|
2010-06-24 21:10:26 +02:00
|
|
|
}
|
|
|
|
|
2011-05-18 01:37:18 +02:00
|
|
|
bool MetricsDaemon::CheckSystemCrash(const string& crash_file) {
|
2010-06-24 21:10:26 +02:00
|
|
|
FilePath crash_detected(crash_file);
|
2014-02-06 08:26:25 +01:00
|
|
|
if (!base::PathExists(crash_detected))
|
2010-08-17 04:57:13 +02:00
|
|
|
return false;
|
2010-06-24 21:10:26 +02:00
|
|
|
|
|
|
|
// Deletes the crash-detected file so that the daemon doesn't report
|
|
|
|
// another kernel crash in case it's restarted.
|
2014-02-06 00:33:19 +01:00
|
|
|
base::DeleteFile(crash_detected, false); // not recursive
|
2010-08-17 04:57:13 +02:00
|
|
|
return true;
|
2010-06-24 21:10:26 +02:00
|
|
|
}
|
|
|
|
|
2011-10-14 21:03:35 +02:00
|
|
|
void MetricsDaemon::StatsReporterInit() {
|
2011-02-17 19:21:16 +01:00
|
|
|
DiskStatsReadStats(&read_sectors_, &write_sectors_);
|
2013-08-01 08:18:31 +02:00
|
|
|
VmStatsReadStats(&vmstats_);
|
2011-02-17 19:21:16 +01:00
|
|
|
// The first time around just run the long stat, so we don't delay boot.
|
2011-10-14 21:03:35 +02:00
|
|
|
stats_state_ = kStatsLong;
|
|
|
|
stats_initial_time_ = GetActiveTime();
|
|
|
|
if (stats_initial_time_ < 0) {
|
2011-05-18 01:37:18 +02:00
|
|
|
LOG(WARNING) << "not collecting disk stats";
|
|
|
|
} else {
|
2011-10-14 21:03:35 +02:00
|
|
|
ScheduleStatsCallback(kMetricStatsLongInterval);
|
2011-05-18 01:37:18 +02:00
|
|
|
}
|
2011-02-17 19:21:16 +01:00
|
|
|
}
|
|
|
|
|
2011-10-14 21:03:35 +02:00
|
|
|
void MetricsDaemon::ScheduleStatsCallback(int wait) {
|
2011-02-17 19:21:16 +01:00
|
|
|
if (testing_) {
|
|
|
|
return;
|
|
|
|
}
|
2011-10-14 21:03:35 +02:00
|
|
|
g_timeout_add_seconds(wait, StatsCallbackStatic, this);
|
2011-02-17 19:21:16 +01:00
|
|
|
}
|
|
|
|
|
2014-08-07 09:54:59 +02:00
|
|
|
bool MetricsDaemon::DiskStatsReadStats(uint64_t* read_sectors,
|
|
|
|
uint64_t* write_sectors) {
|
2011-02-17 19:21:16 +01:00
|
|
|
int nchars;
|
|
|
|
int nitems;
|
2011-10-14 21:03:35 +02:00
|
|
|
bool success = false;
|
2011-02-17 19:21:16 +01:00
|
|
|
char line[200];
|
2011-10-14 21:03:35 +02:00
|
|
|
if (diskstats_path_.empty()) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-02-28 20:17:43 +01:00
|
|
|
int file = HANDLE_EINTR(open(diskstats_path_.c_str(), O_RDONLY));
|
2011-02-17 19:21:16 +01:00
|
|
|
if (file < 0) {
|
|
|
|
PLOG(WARNING) << "cannot open " << diskstats_path_;
|
2011-10-14 21:03:35 +02:00
|
|
|
return false;
|
2011-02-17 19:21:16 +01:00
|
|
|
}
|
|
|
|
nchars = HANDLE_EINTR(read(file, line, sizeof(line)));
|
|
|
|
if (nchars < 0) {
|
|
|
|
PLOG(WARNING) << "cannot read from " << diskstats_path_;
|
2011-10-14 21:03:35 +02:00
|
|
|
return false;
|
2011-02-17 19:21:16 +01:00
|
|
|
} else {
|
2011-10-14 21:03:35 +02:00
|
|
|
LOG_IF(WARNING, nchars == sizeof(line))
|
|
|
|
<< "line too long in " << diskstats_path_;
|
2011-02-17 19:21:16 +01:00
|
|
|
line[nchars] = '\0';
|
2014-09-17 15:24:10 +02:00
|
|
|
nitems = sscanf(line, "%*d %*d %" PRIu64 " %*d %*d %*d %" PRIu64,
|
2011-02-17 19:21:16 +01:00
|
|
|
read_sectors, write_sectors);
|
2011-10-14 21:03:35 +02:00
|
|
|
if (nitems == 2) {
|
|
|
|
success = true;
|
|
|
|
} else {
|
|
|
|
LOG(WARNING) << "found " << nitems << " items in "
|
|
|
|
<< diskstats_path_ << ", expected 2";
|
|
|
|
}
|
|
|
|
}
|
2014-05-14 22:14:37 +02:00
|
|
|
IGNORE_EINTR(close(file));
|
2011-10-14 21:03:35 +02:00
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2013-08-01 08:18:31 +02:00
|
|
|
bool MetricsDaemon::VmStatsParseStats(const char* stats,
|
|
|
|
struct VmstatRecord* record) {
|
|
|
|
// a mapping of string name to field in VmstatRecord and whether we found it
|
|
|
|
struct mapping {
|
|
|
|
const string name;
|
|
|
|
uint64_t* value_p;
|
|
|
|
bool found;
|
|
|
|
} map[] =
|
|
|
|
{ { .name = "pgmajfault",
|
|
|
|
.value_p = &record->page_faults_,
|
|
|
|
.found = false },
|
|
|
|
{ .name = "pswpin",
|
|
|
|
.value_p = &record->swap_in_,
|
|
|
|
.found = false },
|
|
|
|
{ .name = "pswpout",
|
|
|
|
.value_p = &record->swap_out_,
|
|
|
|
.found = false }, };
|
|
|
|
|
2013-05-08 01:55:00 +02:00
|
|
|
// Each line in the file has the form
|
|
|
|
// <ID> <VALUE>
|
|
|
|
// for instance:
|
|
|
|
// nr_free_pages 213427
|
2013-08-01 08:18:31 +02:00
|
|
|
vector<string> lines;
|
|
|
|
Tokenize(stats, "\n", &lines);
|
|
|
|
for (vector<string>::iterator it = lines.begin();
|
|
|
|
it != lines.end(); ++it) {
|
|
|
|
vector<string> tokens;
|
|
|
|
base::SplitString(*it, ' ', &tokens);
|
|
|
|
if (tokens.size() == 2) {
|
|
|
|
for (unsigned int i = 0; i < sizeof(map)/sizeof(struct mapping); i++) {
|
|
|
|
if (!tokens[0].compare(map[i].name)) {
|
|
|
|
if (!base::StringToUint64(tokens[1], map[i].value_p))
|
|
|
|
return false;
|
|
|
|
map[i].found = true;
|
|
|
|
}
|
|
|
|
}
|
2011-10-14 21:03:35 +02:00
|
|
|
} else {
|
2013-08-01 08:18:31 +02:00
|
|
|
LOG(WARNING) << "unexpected vmstat format";
|
2011-10-14 21:03:35 +02:00
|
|
|
}
|
|
|
|
}
|
2013-08-01 08:18:31 +02:00
|
|
|
// make sure we got all the stats
|
|
|
|
for (unsigned i = 0; i < sizeof(map)/sizeof(struct mapping); i++) {
|
|
|
|
if (map[i].found == false) {
|
|
|
|
LOG(WARNING) << "vmstat missing " << map[i].name;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2011-10-14 21:03:35 +02:00
|
|
|
}
|
|
|
|
|
2013-08-01 08:18:31 +02:00
|
|
|
bool MetricsDaemon::VmStatsReadStats(struct VmstatRecord* stats) {
|
|
|
|
string value_string;
|
|
|
|
FilePath* path = new FilePath(vmstats_path_);
|
2014-02-06 08:26:25 +01:00
|
|
|
if (!base::ReadFileToString(*path, &value_string)) {
|
2013-08-01 08:18:31 +02:00
|
|
|
delete path;
|
|
|
|
LOG(WARNING) << "cannot read " << vmstats_path_;
|
2011-10-14 21:03:35 +02:00
|
|
|
return false;
|
|
|
|
}
|
2013-08-01 08:18:31 +02:00
|
|
|
delete path;
|
|
|
|
return VmStatsParseStats(value_string.c_str(), stats);
|
2011-02-17 19:21:16 +01:00
|
|
|
}
|
|
|
|
|
2013-05-08 01:55:00 +02:00
|
|
|
bool MetricsDaemon::ReadFreqToInt(const string& sysfs_file_name, int* value) {
|
2013-06-04 22:24:21 +02:00
|
|
|
const FilePath sysfs_path(sysfs_file_name);
|
2013-05-08 01:55:00 +02:00
|
|
|
string value_string;
|
2014-02-06 08:26:25 +01:00
|
|
|
if (!base::ReadFileToString(sysfs_path, &value_string)) {
|
2013-05-08 01:55:00 +02:00
|
|
|
LOG(WARNING) << "cannot read " << sysfs_path.value().c_str();
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-06 08:26:25 +01:00
|
|
|
if (!base::RemoveChars(value_string, "\n", &value_string)) {
|
2013-05-08 01:55:00 +02:00
|
|
|
LOG(WARNING) << "no newline in " << value_string;
|
|
|
|
// Continue even though the lack of newline is suspicious.
|
|
|
|
}
|
|
|
|
if (!base::StringToInt(value_string, value)) {
|
|
|
|
LOG(WARNING) << "cannot convert " << value_string << " to int";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetricsDaemon::SendCpuThrottleMetrics() {
|
|
|
|
// |max_freq| is 0 only the first time through.
|
|
|
|
static int max_freq = 0;
|
|
|
|
if (max_freq == -1)
|
|
|
|
// Give up, as sysfs did not report max_freq correctly.
|
|
|
|
return;
|
|
|
|
if (max_freq == 0 || testing_) {
|
|
|
|
// One-time initialization of max_freq. (Every time when testing.)
|
|
|
|
if (!ReadFreqToInt(cpuinfo_max_freq_path_, &max_freq)) {
|
|
|
|
max_freq = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (max_freq == 0) {
|
|
|
|
LOG(WARNING) << "sysfs reports 0 max CPU frequency\n";
|
|
|
|
max_freq = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (max_freq % 10000 == 1000) {
|
|
|
|
// Special case: system has turbo mode, and max non-turbo frequency is
|
|
|
|
// max_freq - 1000. This relies on "normal" (non-turbo) frequencies
|
|
|
|
// being multiples of (at least) 10 MHz. Although there is no guarantee
|
|
|
|
// of this, it seems a fairly reasonable assumption. Otherwise we should
|
|
|
|
// read scaling_available_frequencies, sort the frequencies, compare the
|
|
|
|
// two highest ones, and check if they differ by 1000 (kHz) (and that's a
|
|
|
|
// hack too, no telling when it will change).
|
|
|
|
max_freq -= 1000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int scaled_freq = 0;
|
|
|
|
if (!ReadFreqToInt(scaling_max_freq_path_, &scaled_freq))
|
|
|
|
return;
|
|
|
|
// Frequencies are in kHz. If scaled_freq > max_freq, turbo is on, but
|
|
|
|
// scaled_freq is not the actual turbo frequency. We indicate this situation
|
|
|
|
// with a 101% value.
|
|
|
|
int percent = scaled_freq > max_freq ? 101 : scaled_freq / (max_freq / 100);
|
2014-02-26 20:53:16 +01:00
|
|
|
SendLinearSample(kMetricScaledCpuFrequencyName, percent, 101, 102);
|
2013-05-08 01:55:00 +02:00
|
|
|
}
|
|
|
|
|
2011-02-17 19:21:16 +01:00
|
|
|
// static
|
2011-10-14 21:03:35 +02:00
|
|
|
gboolean MetricsDaemon::StatsCallbackStatic(void* handle) {
|
|
|
|
(static_cast<MetricsDaemon*>(handle))->StatsCallback();
|
2011-02-17 19:21:16 +01:00
|
|
|
return false; // one-time callback
|
|
|
|
}
|
|
|
|
|
2011-10-14 21:03:35 +02:00
|
|
|
// Collects disk and vm stats alternating over a short and a long interval.
|
2011-05-18 01:37:18 +02:00
|
|
|
|
2011-10-14 21:03:35 +02:00
|
|
|
void MetricsDaemon::StatsCallback() {
|
2014-08-07 09:54:59 +02:00
|
|
|
uint64_t read_sectors_now, write_sectors_now;
|
2013-08-01 08:18:31 +02:00
|
|
|
struct VmstatRecord vmstats_now;
|
2011-05-18 01:37:18 +02:00
|
|
|
double time_now = GetActiveTime();
|
2011-10-14 21:03:35 +02:00
|
|
|
double delta_time = time_now - stats_initial_time_;
|
2011-05-18 01:37:18 +02:00
|
|
|
if (testing_) {
|
|
|
|
// Fake the time when testing.
|
2011-10-14 21:03:35 +02:00
|
|
|
delta_time = stats_state_ == kStatsShort ?
|
|
|
|
kMetricStatsShortInterval : kMetricStatsLongInterval;
|
2011-05-18 01:37:18 +02:00
|
|
|
}
|
2011-10-14 21:03:35 +02:00
|
|
|
bool diskstats_success = DiskStatsReadStats(&read_sectors_now,
|
|
|
|
&write_sectors_now);
|
2011-05-18 01:37:18 +02:00
|
|
|
int delta_read = read_sectors_now - read_sectors_;
|
|
|
|
int delta_write = write_sectors_now - write_sectors_;
|
|
|
|
int read_sectors_per_second = delta_read / delta_time;
|
|
|
|
int write_sectors_per_second = delta_write / delta_time;
|
2013-08-01 08:18:31 +02:00
|
|
|
bool vmstats_success = VmStatsReadStats(&vmstats_now);
|
|
|
|
uint64_t delta_faults = vmstats_now.page_faults_ - vmstats_.page_faults_;
|
|
|
|
uint64_t delta_swap_in = vmstats_now.swap_in_ - vmstats_.swap_in_;
|
|
|
|
uint64_t delta_swap_out = vmstats_now.swap_out_ - vmstats_.swap_out_;
|
|
|
|
uint64_t page_faults_per_second = delta_faults / delta_time;
|
|
|
|
uint64_t swap_in_per_second = delta_swap_in / delta_time;
|
|
|
|
uint64_t swap_out_per_second = delta_swap_out / delta_time;
|
2011-10-14 21:03:35 +02:00
|
|
|
|
|
|
|
switch (stats_state_) {
|
|
|
|
case kStatsShort:
|
|
|
|
if (diskstats_success) {
|
2014-02-26 20:53:16 +01:00
|
|
|
SendSample(kMetricReadSectorsShortName,
|
2011-10-14 21:03:35 +02:00
|
|
|
read_sectors_per_second,
|
|
|
|
1,
|
|
|
|
kMetricSectorsIOMax,
|
|
|
|
kMetricSectorsBuckets);
|
2014-02-26 20:53:16 +01:00
|
|
|
SendSample(kMetricWriteSectorsShortName,
|
2011-10-14 21:03:35 +02:00
|
|
|
write_sectors_per_second,
|
|
|
|
1,
|
|
|
|
kMetricSectorsIOMax,
|
|
|
|
kMetricSectorsBuckets);
|
|
|
|
}
|
|
|
|
if (vmstats_success) {
|
2014-02-26 20:53:16 +01:00
|
|
|
SendSample(kMetricPageFaultsShortName,
|
2011-10-14 21:03:35 +02:00
|
|
|
page_faults_per_second,
|
|
|
|
1,
|
|
|
|
kMetricPageFaultsMax,
|
|
|
|
kMetricPageFaultsBuckets);
|
2014-02-26 20:53:16 +01:00
|
|
|
SendSample(kMetricSwapInShortName,
|
2013-08-01 08:18:31 +02:00
|
|
|
swap_in_per_second,
|
|
|
|
1,
|
|
|
|
kMetricPageFaultsMax,
|
|
|
|
kMetricPageFaultsBuckets);
|
2014-02-26 20:53:16 +01:00
|
|
|
SendSample(kMetricSwapOutShortName,
|
2013-08-01 08:18:31 +02:00
|
|
|
swap_out_per_second,
|
|
|
|
1,
|
|
|
|
kMetricPageFaultsMax,
|
|
|
|
kMetricPageFaultsBuckets);
|
2011-10-14 21:03:35 +02:00
|
|
|
}
|
2011-02-17 19:21:16 +01:00
|
|
|
// Schedule long callback.
|
2011-10-14 21:03:35 +02:00
|
|
|
stats_state_ = kStatsLong;
|
|
|
|
ScheduleStatsCallback(kMetricStatsLongInterval -
|
|
|
|
kMetricStatsShortInterval);
|
2011-02-17 19:21:16 +01:00
|
|
|
break;
|
2011-10-14 21:03:35 +02:00
|
|
|
case kStatsLong:
|
|
|
|
if (diskstats_success) {
|
2014-02-26 20:53:16 +01:00
|
|
|
SendSample(kMetricReadSectorsLongName,
|
2011-10-14 21:03:35 +02:00
|
|
|
read_sectors_per_second,
|
|
|
|
1,
|
|
|
|
kMetricSectorsIOMax,
|
|
|
|
kMetricSectorsBuckets);
|
2014-02-26 20:53:16 +01:00
|
|
|
SendSample(kMetricWriteSectorsLongName,
|
2011-10-14 21:03:35 +02:00
|
|
|
write_sectors_per_second,
|
|
|
|
1,
|
|
|
|
kMetricSectorsIOMax,
|
|
|
|
kMetricSectorsBuckets);
|
|
|
|
// Reset sector counters.
|
|
|
|
read_sectors_ = read_sectors_now;
|
|
|
|
write_sectors_ = write_sectors_now;
|
|
|
|
}
|
|
|
|
if (vmstats_success) {
|
2014-02-26 20:53:16 +01:00
|
|
|
SendSample(kMetricPageFaultsLongName,
|
2011-10-14 21:03:35 +02:00
|
|
|
page_faults_per_second,
|
|
|
|
1,
|
|
|
|
kMetricPageFaultsMax,
|
|
|
|
kMetricPageFaultsBuckets);
|
2014-02-26 20:53:16 +01:00
|
|
|
SendSample(kMetricSwapInLongName,
|
2013-08-01 08:18:31 +02:00
|
|
|
swap_in_per_second,
|
|
|
|
1,
|
|
|
|
kMetricPageFaultsMax,
|
|
|
|
kMetricPageFaultsBuckets);
|
2014-02-26 20:53:16 +01:00
|
|
|
SendSample(kMetricSwapOutLongName,
|
2013-08-01 08:18:31 +02:00
|
|
|
swap_out_per_second,
|
|
|
|
1,
|
|
|
|
kMetricPageFaultsMax,
|
|
|
|
kMetricPageFaultsBuckets);
|
|
|
|
|
|
|
|
vmstats_ = vmstats_now;
|
2011-10-14 21:03:35 +02:00
|
|
|
}
|
2013-05-08 01:55:00 +02:00
|
|
|
SendCpuThrottleMetrics();
|
2011-05-18 01:37:18 +02:00
|
|
|
// Set start time for new cycle.
|
2011-10-14 21:03:35 +02:00
|
|
|
stats_initial_time_ = time_now;
|
2011-02-17 19:21:16 +01:00
|
|
|
// Schedule short callback.
|
2011-10-14 21:03:35 +02:00
|
|
|
stats_state_ = kStatsShort;
|
|
|
|
ScheduleStatsCallback(kMetricStatsShortInterval);
|
2011-02-17 19:21:16 +01:00
|
|
|
break;
|
|
|
|
default:
|
2011-10-14 21:03:35 +02:00
|
|
|
LOG(FATAL) << "Invalid stats state";
|
2011-02-17 19:21:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-12 23:12:35 +02:00
|
|
|
void MetricsDaemon::ScheduleMeminfoCallback(int wait) {
|
|
|
|
if (testing_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
g_timeout_add_seconds(wait, MeminfoCallbackStatic, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
gboolean MetricsDaemon::MeminfoCallbackStatic(void* handle) {
|
|
|
|
return (static_cast<MetricsDaemon*>(handle))->MeminfoCallback();
|
|
|
|
}
|
|
|
|
|
2011-10-14 21:03:35 +02:00
|
|
|
bool MetricsDaemon::MeminfoCallback() {
|
2011-05-18 01:37:18 +02:00
|
|
|
string meminfo_raw;
|
2011-04-12 23:12:35 +02:00
|
|
|
const FilePath meminfo_path("/proc/meminfo");
|
2014-02-06 08:26:25 +01:00
|
|
|
if (!base::ReadFileToString(meminfo_path, &meminfo_raw)) {
|
2011-04-12 23:12:35 +02:00
|
|
|
LOG(WARNING) << "cannot read " << meminfo_path.value().c_str();
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-04 19:53:35 +02:00
|
|
|
// Make both calls even if the first one fails.
|
|
|
|
bool success = ProcessMeminfo(meminfo_raw);
|
|
|
|
return ReportZram(base::FilePath(FILE_PATH_LITERAL("/sys/block/zram0"))) &&
|
|
|
|
success;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool MetricsDaemon::ReadFileToUint64(const base::FilePath& path,
|
2014-08-07 09:54:59 +02:00
|
|
|
uint64_t* value) {
|
2014-06-04 19:53:35 +02:00
|
|
|
std::string content;
|
|
|
|
if (!base::ReadFileToString(path, &content)) {
|
|
|
|
PLOG(WARNING) << "cannot read " << path.MaybeAsASCII();
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-01 03:12:28 +02:00
|
|
|
// Remove final newline.
|
|
|
|
base::TrimWhitespaceASCII(content, base::TRIM_TRAILING, &content);
|
2014-06-04 19:53:35 +02:00
|
|
|
if (!base::StringToUint64(content, value)) {
|
|
|
|
LOG(WARNING) << "invalid integer: " << content;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MetricsDaemon::ReportZram(const base::FilePath& zram_dir) {
|
|
|
|
// Data sizes are in bytes. |zero_pages| is in number of pages.
|
2014-08-07 09:54:59 +02:00
|
|
|
uint64_t compr_data_size, orig_data_size, zero_pages;
|
2014-06-04 19:53:35 +02:00
|
|
|
const size_t page_size = 4096;
|
|
|
|
|
|
|
|
if (!ReadFileToUint64(zram_dir.Append(kComprDataSizeName),
|
|
|
|
&compr_data_size) ||
|
|
|
|
!ReadFileToUint64(zram_dir.Append(kOrigDataSizeName), &orig_data_size) ||
|
|
|
|
!ReadFileToUint64(zram_dir.Append(kZeroPagesName), &zero_pages)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// |orig_data_size| does not include zero-filled pages.
|
|
|
|
orig_data_size += zero_pages * page_size;
|
|
|
|
|
|
|
|
const int compr_data_size_mb = compr_data_size >> 20;
|
|
|
|
const int savings_mb = (orig_data_size - compr_data_size) >> 20;
|
|
|
|
const int zero_ratio_percent = zero_pages * page_size * 100 / orig_data_size;
|
|
|
|
|
|
|
|
// Report compressed size in megabytes. 100 MB or less has little impact.
|
|
|
|
SendSample("Platform.ZramCompressedSize", compr_data_size_mb, 100, 4000, 50);
|
|
|
|
SendSample("Platform.ZramSavings", savings_mb, 100, 4000, 50);
|
|
|
|
// The compression ratio is multiplied by 100 for better resolution. The
|
|
|
|
// ratios of interest are between 1 and 6 (100% and 600% as reported). We
|
|
|
|
// don't want samples when very little memory is being compressed.
|
|
|
|
if (compr_data_size_mb >= 1) {
|
|
|
|
SendSample("Platform.ZramCompressionRatioPercent",
|
|
|
|
orig_data_size * 100 / compr_data_size, 100, 600, 50);
|
|
|
|
}
|
|
|
|
// The values of interest for zero_pages are between 1MB and 1GB. The units
|
|
|
|
// are number of pages.
|
|
|
|
SendSample("Platform.ZramZeroPages", zero_pages, 256, 256 * 1024, 50);
|
|
|
|
SendSample("Platform.ZramZeroRatioPercent", zero_ratio_percent, 1, 50, 50);
|
|
|
|
|
|
|
|
return true;
|
2011-04-12 23:12:35 +02:00
|
|
|
}
|
|
|
|
|
2011-10-14 21:03:35 +02:00
|
|
|
bool MetricsDaemon::ProcessMeminfo(const string& meminfo_raw) {
|
2011-05-18 01:37:18 +02:00
|
|
|
static const MeminfoRecord fields_array[] = {
|
2011-04-12 23:12:35 +02:00
|
|
|
{ "MemTotal", "MemTotal" }, // SPECIAL CASE: total system memory
|
|
|
|
{ "MemFree", "MemFree" },
|
|
|
|
{ "Buffers", "Buffers" },
|
|
|
|
{ "Cached", "Cached" },
|
|
|
|
// { "SwapCached", "SwapCached" },
|
|
|
|
{ "Active", "Active" },
|
|
|
|
{ "Inactive", "Inactive" },
|
|
|
|
{ "ActiveAnon", "Active(anon)" },
|
|
|
|
{ "InactiveAnon", "Inactive(anon)" },
|
|
|
|
{ "ActiveFile" , "Active(file)" },
|
|
|
|
{ "InactiveFile", "Inactive(file)" },
|
2013-02-12 22:17:07 +01:00
|
|
|
{ "Unevictable", "Unevictable", kMeminfoOp_HistLog },
|
2011-04-12 23:12:35 +02:00
|
|
|
// { "Mlocked", "Mlocked" },
|
2013-02-12 22:17:07 +01:00
|
|
|
{ "SwapTotal", "SwapTotal", kMeminfoOp_SwapTotal },
|
|
|
|
{ "SwapFree", "SwapFree", kMeminfoOp_SwapFree },
|
2011-04-12 23:12:35 +02:00
|
|
|
// { "Dirty", "Dirty" },
|
|
|
|
// { "Writeback", "Writeback" },
|
|
|
|
{ "AnonPages", "AnonPages" },
|
|
|
|
{ "Mapped", "Mapped" },
|
2013-02-12 22:17:07 +01:00
|
|
|
{ "Shmem", "Shmem", kMeminfoOp_HistLog },
|
|
|
|
{ "Slab", "Slab", kMeminfoOp_HistLog },
|
2011-04-12 23:12:35 +02:00
|
|
|
// { "SReclaimable", "SReclaimable" },
|
|
|
|
// { "SUnreclaim", "SUnreclaim" },
|
|
|
|
};
|
2011-05-18 01:37:18 +02:00
|
|
|
vector<MeminfoRecord> fields(fields_array,
|
|
|
|
fields_array + arraysize(fields_array));
|
|
|
|
if (!FillMeminfo(meminfo_raw, &fields)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int total_memory = fields[0].value;
|
|
|
|
if (total_memory == 0) {
|
|
|
|
// this "cannot happen"
|
|
|
|
LOG(WARNING) << "borked meminfo parser";
|
|
|
|
return false;
|
|
|
|
}
|
2013-02-12 22:17:07 +01:00
|
|
|
int swap_total = 0;
|
|
|
|
int swap_free = 0;
|
2011-05-18 01:37:18 +02:00
|
|
|
// Send all fields retrieved, except total memory.
|
|
|
|
for (unsigned int i = 1; i < fields.size(); i++) {
|
2014-02-06 00:33:19 +01:00
|
|
|
string metrics_name = base::StringPrintf("Platform.Meminfo%s",
|
|
|
|
fields[i].name);
|
2013-02-05 04:50:45 +01:00
|
|
|
int percent;
|
2013-02-12 22:17:07 +01:00
|
|
|
switch (fields[i].op) {
|
|
|
|
case kMeminfoOp_HistPercent:
|
2013-02-05 04:50:45 +01:00
|
|
|
// report value as percent of total memory
|
|
|
|
percent = fields[i].value * 100 / total_memory;
|
2014-02-26 20:53:16 +01:00
|
|
|
SendLinearSample(metrics_name, percent, 100, 101);
|
2013-02-05 04:50:45 +01:00
|
|
|
break;
|
2013-02-12 22:17:07 +01:00
|
|
|
case kMeminfoOp_HistLog:
|
2013-02-05 04:50:45 +01:00
|
|
|
// report value in kbytes, log scale, 4Gb max
|
2014-02-26 20:53:16 +01:00
|
|
|
SendSample(metrics_name, fields[i].value, 1, 4 * 1000 * 1000, 100);
|
2013-02-05 04:50:45 +01:00
|
|
|
break;
|
2013-02-12 22:17:07 +01:00
|
|
|
case kMeminfoOp_SwapTotal:
|
|
|
|
swap_total = fields[i].value;
|
|
|
|
case kMeminfoOp_SwapFree:
|
|
|
|
swap_free = fields[i].value;
|
2013-02-05 04:50:45 +01:00
|
|
|
break;
|
2011-05-18 01:37:18 +02:00
|
|
|
}
|
|
|
|
}
|
2013-02-12 22:17:07 +01:00
|
|
|
if (swap_total > 0) {
|
|
|
|
int swap_used = swap_total - swap_free;
|
|
|
|
int swap_used_percent = swap_used * 100 / swap_total;
|
2014-02-26 20:53:16 +01:00
|
|
|
SendSample("Platform.MeminfoSwapUsed", swap_used, 1, 8 * 1000 * 1000, 100);
|
|
|
|
SendLinearSample("Platform.MeminfoSwapUsedPercent", swap_used_percent,
|
2013-02-12 22:17:07 +01:00
|
|
|
100, 101);
|
|
|
|
}
|
2011-05-18 01:37:18 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-14 21:03:35 +02:00
|
|
|
bool MetricsDaemon::FillMeminfo(const string& meminfo_raw,
|
|
|
|
vector<MeminfoRecord>* fields) {
|
2011-05-18 01:37:18 +02:00
|
|
|
vector<string> lines;
|
|
|
|
unsigned int nlines = Tokenize(meminfo_raw, "\n", &lines);
|
2011-04-12 23:12:35 +02:00
|
|
|
|
|
|
|
// Scan meminfo output and collect field values. Each field name has to
|
|
|
|
// match a meminfo entry (case insensitive) after removing non-alpha
|
|
|
|
// characters from the entry.
|
2011-05-18 01:37:18 +02:00
|
|
|
unsigned int ifield = 0;
|
|
|
|
for (unsigned int iline = 0;
|
|
|
|
iline < nlines && ifield < fields->size();
|
|
|
|
iline++) {
|
|
|
|
vector<string> tokens;
|
2011-04-12 23:12:35 +02:00
|
|
|
Tokenize(lines[iline], ": ", &tokens);
|
2011-05-18 01:37:18 +02:00
|
|
|
if (strcmp((*fields)[ifield].match, tokens[0].c_str()) == 0) {
|
|
|
|
// Name matches. Parse value and save.
|
2011-04-12 23:12:35 +02:00
|
|
|
char* rest;
|
2011-05-18 01:37:18 +02:00
|
|
|
(*fields)[ifield].value =
|
|
|
|
static_cast<int>(strtol(tokens[1].c_str(), &rest, 10));
|
2011-04-12 23:12:35 +02:00
|
|
|
if (*rest != '\0') {
|
|
|
|
LOG(WARNING) << "missing meminfo value";
|
|
|
|
return false;
|
|
|
|
}
|
2011-05-18 01:37:18 +02:00
|
|
|
ifield++;
|
2011-04-12 23:12:35 +02:00
|
|
|
}
|
|
|
|
}
|
2011-05-18 01:37:18 +02:00
|
|
|
if (ifield < fields->size()) {
|
|
|
|
// End of input reached while scanning.
|
|
|
|
LOG(WARNING) << "cannot find field " << (*fields)[ifield].match
|
|
|
|
<< " and following";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-06 00:55:12 +01:00
|
|
|
void MetricsDaemon::ScheduleMemuseCallback(double interval) {
|
2011-05-18 01:37:18 +02:00
|
|
|
if (testing_) {
|
|
|
|
return;
|
|
|
|
}
|
2013-12-06 00:55:12 +01:00
|
|
|
g_timeout_add_seconds(interval, MemuseCallbackStatic, this);
|
2011-05-18 01:37:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
gboolean MetricsDaemon::MemuseCallbackStatic(void* handle) {
|
|
|
|
MetricsDaemon* daemon = static_cast<MetricsDaemon*>(handle);
|
|
|
|
daemon->MemuseCallback();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetricsDaemon::MemuseCallback() {
|
|
|
|
// Since we only care about active time (i.e. uptime minus sleep time) but
|
|
|
|
// the callbacks are driven by real time (uptime), we check if we should
|
|
|
|
// reschedule this callback due to intervening sleep periods.
|
|
|
|
double now = GetActiveTime();
|
2013-12-06 00:55:12 +01:00
|
|
|
// Avoid intervals of less than one second.
|
|
|
|
double remaining_time = ceil(memuse_final_time_ - now);
|
|
|
|
if (remaining_time > 0) {
|
|
|
|
ScheduleMemuseCallback(remaining_time);
|
2011-05-18 01:37:18 +02:00
|
|
|
} else {
|
2013-12-06 00:55:12 +01:00
|
|
|
// Report stats and advance the measurement interval unless there are
|
|
|
|
// errors or we've completed the last interval.
|
2011-05-18 01:37:18 +02:00
|
|
|
if (MemuseCallbackWork() &&
|
2013-12-06 00:55:12 +01:00
|
|
|
memuse_interval_index_ < arraysize(kMemuseIntervals)) {
|
|
|
|
double interval = kMemuseIntervals[memuse_interval_index_++];
|
|
|
|
memuse_final_time_ = now + interval;
|
|
|
|
ScheduleMemuseCallback(interval);
|
2011-05-18 01:37:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-14 21:03:35 +02:00
|
|
|
bool MetricsDaemon::MemuseCallbackWork() {
|
2011-05-18 01:37:18 +02:00
|
|
|
string meminfo_raw;
|
|
|
|
const FilePath meminfo_path("/proc/meminfo");
|
2014-02-06 08:26:25 +01:00
|
|
|
if (!base::ReadFileToString(meminfo_path, &meminfo_raw)) {
|
2011-05-18 01:37:18 +02:00
|
|
|
LOG(WARNING) << "cannot read " << meminfo_path.value().c_str();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return ProcessMemuse(meminfo_raw);
|
|
|
|
}
|
|
|
|
|
2011-10-14 21:03:35 +02:00
|
|
|
bool MetricsDaemon::ProcessMemuse(const string& meminfo_raw) {
|
2011-05-18 01:37:18 +02:00
|
|
|
static const MeminfoRecord fields_array[] = {
|
|
|
|
{ "MemTotal", "MemTotal" }, // SPECIAL CASE: total system memory
|
|
|
|
{ "ActiveAnon", "Active(anon)" },
|
|
|
|
{ "InactiveAnon", "Inactive(anon)" },
|
|
|
|
};
|
|
|
|
vector<MeminfoRecord> fields(fields_array,
|
|
|
|
fields_array + arraysize(fields_array));
|
|
|
|
if (!FillMeminfo(meminfo_raw, &fields)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int total = fields[0].value;
|
|
|
|
int active_anon = fields[1].value;
|
|
|
|
int inactive_anon = fields[2].value;
|
|
|
|
if (total == 0) {
|
|
|
|
// this "cannot happen"
|
|
|
|
LOG(WARNING) << "borked meminfo parser";
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-06 00:33:19 +01:00
|
|
|
string metrics_name = base::StringPrintf("Platform.MemuseAnon%d",
|
|
|
|
memuse_interval_index_);
|
2014-02-26 20:53:16 +01:00
|
|
|
SendLinearSample(metrics_name, (active_anon + inactive_anon) * 100 / total,
|
2011-05-18 01:37:18 +02:00
|
|
|
100, 101);
|
|
|
|
return true;
|
2011-04-12 23:12:35 +02:00
|
|
|
}
|
|
|
|
|
2014-04-16 00:15:02 +02:00
|
|
|
void MetricsDaemon::ReportDailyUse(int use_seconds) {
|
|
|
|
if (use_seconds <= 0)
|
2010-06-17 00:58:06 +02:00
|
|
|
return;
|
|
|
|
|
2014-04-16 00:15:02 +02:00
|
|
|
int minutes = (use_seconds + kSecondsPerMinute / 2) / kSecondsPerMinute;
|
|
|
|
SendSample("Logging.DailyUseTime",
|
|
|
|
minutes,
|
|
|
|
1,
|
|
|
|
kMinutesPerDay * 30 * 2, // cumulative---two months worth
|
|
|
|
50);
|
2010-06-11 00:59:53 +02:00
|
|
|
}
|
|
|
|
|
2014-02-26 20:53:16 +01:00
|
|
|
void MetricsDaemon::SendSample(const string& name, int sample,
|
2010-05-18 20:00:59 +02:00
|
|
|
int min, int max, int nbuckets) {
|
2010-05-12 22:05:45 +02:00
|
|
|
metrics_lib_->SendToUMA(name, sample, min, max, nbuckets);
|
2010-04-14 22:32:20 +02:00
|
|
|
}
|
2011-04-12 23:12:35 +02:00
|
|
|
|
2014-04-19 02:00:35 +02:00
|
|
|
void MetricsDaemon::SendKernelCrashesCumulativeCountStats() {
|
2014-02-26 20:53:16 +01:00
|
|
|
// Report the number of crashes for this OS version, but don't clear the
|
|
|
|
// counter. It is cleared elsewhere on version change.
|
2014-08-07 09:54:59 +02:00
|
|
|
int64_t crashes_count = kernel_crashes_version_count_->Get();
|
2014-02-26 20:53:16 +01:00
|
|
|
SendSample(kernel_crashes_version_count_->Name(),
|
2014-03-17 20:28:38 +01:00
|
|
|
crashes_count,
|
|
|
|
1, // value of first bucket
|
|
|
|
500, // value of last bucket
|
|
|
|
100); // number of buckets
|
|
|
|
|
|
|
|
|
2014-08-07 09:54:59 +02:00
|
|
|
int64_t cpu_use_ms = version_cumulative_cpu_use_->Get();
|
2014-03-17 20:28:38 +01:00
|
|
|
SendSample(version_cumulative_cpu_use_->Name(),
|
|
|
|
cpu_use_ms / 1000, // stat is in seconds
|
|
|
|
1, // device may be used very little...
|
|
|
|
8 * 1000 * 1000, // ... or a lot (a little over 90 days)
|
|
|
|
100);
|
|
|
|
|
|
|
|
// On the first run after an autoupdate, cpu_use_ms and active_use_seconds
|
|
|
|
// can be zero. Avoid division by zero.
|
|
|
|
if (cpu_use_ms > 0) {
|
|
|
|
// Send the crash frequency since update in number of crashes per CPU year.
|
|
|
|
SendSample("Logging.KernelCrashesPerCpuYear",
|
|
|
|
crashes_count * kSecondsPerDay * 365 * 1000 / cpu_use_ms,
|
|
|
|
1,
|
|
|
|
1000 * 1000, // about one crash every 30s of CPU time
|
|
|
|
100);
|
|
|
|
}
|
|
|
|
|
2014-08-07 09:54:59 +02:00
|
|
|
int64_t active_use_seconds = version_cumulative_active_use_->Get();
|
2014-03-17 20:28:38 +01:00
|
|
|
if (active_use_seconds > 0) {
|
2014-04-19 02:00:35 +02:00
|
|
|
SendSample(version_cumulative_active_use_->Name(),
|
|
|
|
active_use_seconds / 1000, // stat is in seconds
|
|
|
|
1, // device may be used very little...
|
|
|
|
8 * 1000 * 1000, // ... or a lot (about 90 days)
|
|
|
|
100);
|
2014-03-17 20:28:38 +01:00
|
|
|
// Same as above, but per year of active time.
|
|
|
|
SendSample("Logging.KernelCrashesPerActiveYear",
|
|
|
|
crashes_count * kSecondsPerDay * 365 / active_use_seconds,
|
|
|
|
1,
|
|
|
|
1000 * 1000, // about one crash every 30s of active time
|
|
|
|
100);
|
|
|
|
}
|
2014-02-26 20:53:16 +01:00
|
|
|
}
|
|
|
|
|
2014-04-19 02:00:35 +02:00
|
|
|
void MetricsDaemon::SendDailyUseSample(
|
|
|
|
const scoped_ptr<PersistentInteger>& use) {
|
|
|
|
SendSample(use->Name(),
|
|
|
|
use->GetAndClear(),
|
|
|
|
1, // value of first bucket
|
|
|
|
kSecondsPerDay, // value of last bucket
|
|
|
|
50); // number of buckets
|
|
|
|
}
|
|
|
|
|
2014-02-26 20:53:16 +01:00
|
|
|
void MetricsDaemon::SendCrashIntervalSample(
|
|
|
|
const scoped_ptr<PersistentInteger>& interval) {
|
|
|
|
SendSample(interval->Name(),
|
|
|
|
interval->GetAndClear(),
|
|
|
|
1, // value of first bucket
|
|
|
|
4 * kSecondsPerWeek, // value of last bucket
|
|
|
|
50); // number of buckets
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetricsDaemon::SendCrashFrequencySample(
|
|
|
|
const scoped_ptr<PersistentInteger>& frequency) {
|
|
|
|
SendSample(frequency->Name(),
|
|
|
|
frequency->GetAndClear(),
|
|
|
|
1, // value of first bucket
|
|
|
|
100, // value of last bucket
|
|
|
|
50); // number of buckets
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetricsDaemon::SendLinearSample(const string& name, int sample,
|
2011-04-12 23:12:35 +02:00
|
|
|
int max, int nbuckets) {
|
|
|
|
// TODO(semenzato): add a proper linear histogram to the Chrome external
|
|
|
|
// metrics API.
|
|
|
|
LOG_IF(FATAL, nbuckets != max + 1) << "unsupported histogram scale";
|
|
|
|
metrics_lib_->SendEnumToUMA(name, sample, max);
|
|
|
|
}
|
2014-04-04 17:53:44 +02:00
|
|
|
|
|
|
|
void MetricsDaemon::UpdateStats(TimeTicks now_ticks,
|
|
|
|
Time now_wall_time) {
|
|
|
|
const int elapsed_seconds = (now_ticks - last_update_stats_time_).InSeconds();
|
2014-04-19 02:00:35 +02:00
|
|
|
daily_active_use_->Add(elapsed_seconds);
|
|
|
|
version_cumulative_active_use_->Add(elapsed_seconds);
|
2014-04-04 17:53:44 +02:00
|
|
|
user_crash_interval_->Add(elapsed_seconds);
|
|
|
|
kernel_crash_interval_->Add(elapsed_seconds);
|
|
|
|
version_cumulative_cpu_use_->Add(GetIncrementalCpuUse().InMilliseconds());
|
|
|
|
last_update_stats_time_ = now_ticks;
|
|
|
|
|
|
|
|
const TimeDelta since_epoch = now_wall_time - Time::UnixEpoch();
|
|
|
|
const int day = since_epoch.InDays();
|
|
|
|
const int week = day / 7;
|
|
|
|
|
|
|
|
if (daily_cycle_->Get() != day) {
|
|
|
|
daily_cycle_->Set(day);
|
2014-04-19 02:00:35 +02:00
|
|
|
SendDailyUseSample(daily_active_use_);
|
|
|
|
SendDailyUseSample(version_cumulative_active_use_);
|
2014-04-04 17:53:44 +02:00
|
|
|
SendCrashFrequencySample(any_crashes_daily_count_);
|
|
|
|
SendCrashFrequencySample(user_crashes_daily_count_);
|
|
|
|
SendCrashFrequencySample(kernel_crashes_daily_count_);
|
|
|
|
SendCrashFrequencySample(unclean_shutdowns_daily_count_);
|
2014-04-19 02:00:35 +02:00
|
|
|
SendKernelCrashesCumulativeCountStats();
|
2014-04-04 17:53:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (weekly_cycle_->Get() != week) {
|
|
|
|
weekly_cycle_->Set(week);
|
|
|
|
SendCrashFrequencySample(any_crashes_weekly_count_);
|
|
|
|
SendCrashFrequencySample(user_crashes_weekly_count_);
|
|
|
|
SendCrashFrequencySample(kernel_crashes_weekly_count_);
|
|
|
|
SendCrashFrequencySample(unclean_shutdowns_weekly_count_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
gboolean MetricsDaemon::HandleUpdateStatsTimeout(gpointer data) {
|
|
|
|
static_cast<MetricsDaemon*>(data)->UpdateStats(TimeTicks::Now(), Time::Now());
|
|
|
|
return TRUE;
|
|
|
|
}
|