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.
|
|
|
|
|
|
|
|
#include "metrics_daemon.h"
|
|
|
|
|
2010-04-27 20:02:18 +02:00
|
|
|
#include <dbus/dbus-glib-lowlevel.h>
|
2010-04-14 22:32:20 +02:00
|
|
|
|
|
|
|
#include <base/logging.h>
|
|
|
|
|
2010-06-11 00:59:53 +02:00
|
|
|
#include "counter.h"
|
|
|
|
|
2010-06-04 22:14:19 +02:00
|
|
|
using base::Time;
|
|
|
|
using base::TimeDelta;
|
|
|
|
using base::TimeTicks;
|
|
|
|
|
2010-04-27 20:02:18 +02:00
|
|
|
#define SAFE_MESSAGE(e) (e.message ? e.message : "unknown error")
|
2010-06-04 23:07:41 +02:00
|
|
|
#define DBUS_IFACE_FLIMFLAM_MANAGER "org.chromium.flimflam.Manager"
|
2010-06-07 03:52:40 +02:00
|
|
|
#define DBUS_IFACE_POWER_MANAGER "org.chromium.PowerManager"
|
2010-05-04 01:45:37 +02:00
|
|
|
#define DBUS_IFACE_SESSION_MANAGER "org.chromium.SessionManagerInterface"
|
|
|
|
|
|
|
|
// File to aggregate daily usage before sending to UMA.
|
|
|
|
// TODO(petkov): This file should probably live in a user-specific stateful
|
|
|
|
// location, e.g., /home/chronos/user.
|
|
|
|
static const char kDailyUseRecordFile[] = "/var/log/metrics/daily-usage";
|
|
|
|
|
|
|
|
static const int kSecondsPerMinute = 60;
|
|
|
|
static const int kMinutesPerHour = 60;
|
|
|
|
static const int kHoursPerDay = 24;
|
|
|
|
static const int kMinutesPerDay = kHoursPerDay * kMinutesPerHour;
|
|
|
|
|
|
|
|
// The daily use monitor is scheduled to a 1-minute interval after
|
|
|
|
// initial user activity and then it's exponentially backed off to
|
|
|
|
// 10-minute intervals. Although not required, the back off is
|
|
|
|
// implemented because the histogram buckets are spaced exponentially
|
|
|
|
// anyway and to avoid too frequent metrics daemon process wake-ups
|
|
|
|
// and file I/O.
|
|
|
|
static const int kUseMonitorIntervalInit = 1 * kSecondsPerMinute;
|
|
|
|
static const int kUseMonitorIntervalMax = 10 * kSecondsPerMinute;
|
2010-04-27 20:02:18 +02:00
|
|
|
|
2010-05-06 01:06:37 +02:00
|
|
|
// static metrics parameters.
|
|
|
|
const char MetricsDaemon::kMetricDailyUseTimeName[] =
|
|
|
|
"Logging.DailyUseTime";
|
|
|
|
const int MetricsDaemon::kMetricDailyUseTimeMin = 1;
|
|
|
|
const int MetricsDaemon::kMetricDailyUseTimeMax = kMinutesPerDay;
|
|
|
|
const int MetricsDaemon::kMetricDailyUseTimeBuckets = 50;
|
|
|
|
|
|
|
|
const char MetricsDaemon::kMetricTimeToNetworkDropName[] =
|
|
|
|
"Network.TimeToDrop";
|
|
|
|
const int MetricsDaemon::kMetricTimeToNetworkDropMin = 1;
|
|
|
|
const int MetricsDaemon::kMetricTimeToNetworkDropMax =
|
|
|
|
8 /* hours */ * kMinutesPerHour * kSecondsPerMinute;
|
|
|
|
const int MetricsDaemon::kMetricTimeToNetworkDropBuckets = 50;
|
|
|
|
|
2010-04-27 20:02:18 +02:00
|
|
|
// static
|
2010-05-04 01:45:37 +02:00
|
|
|
const char* MetricsDaemon::kDBusMatches_[] = {
|
2010-04-27 20:02:18 +02:00
|
|
|
"type='signal',"
|
2010-06-04 23:07:41 +02:00
|
|
|
"sender='org.chromium.flimflam',"
|
|
|
|
"interface='" DBUS_IFACE_FLIMFLAM_MANAGER "',"
|
2010-04-27 20:02:18 +02:00
|
|
|
"path='/',"
|
|
|
|
"member='StateChanged'",
|
|
|
|
|
|
|
|
"type='signal',"
|
|
|
|
"interface='" DBUS_IFACE_POWER_MANAGER "',"
|
2010-06-09 00:59:13 +02:00
|
|
|
"path='/'",
|
2010-05-04 01:45:37 +02:00
|
|
|
|
|
|
|
"type='signal',"
|
|
|
|
"sender='org.chromium.SessionManager',"
|
|
|
|
"interface='" DBUS_IFACE_SESSION_MANAGER "',"
|
|
|
|
"path='/org/chromium/SessionManager',"
|
|
|
|
"member='SessionStateChanged'",
|
2010-04-27 20:02:18 +02:00
|
|
|
};
|
2010-04-14 22:32:20 +02:00
|
|
|
|
2010-04-27 20:02:18 +02:00
|
|
|
// static
|
2010-05-04 01:45:37 +02:00
|
|
|
const char* MetricsDaemon::kNetworkStates_[] = {
|
2010-04-27 20:02:18 +02:00
|
|
|
#define STATE(name, capname) #name,
|
2010-04-14 22:32:20 +02:00
|
|
|
#include "network_states.h"
|
|
|
|
};
|
|
|
|
|
2010-04-27 20:02:18 +02:00
|
|
|
// static
|
2010-05-04 01:45:37 +02:00
|
|
|
const char* MetricsDaemon::kPowerStates_[] = {
|
2010-04-27 20:02:18 +02:00
|
|
|
#define STATE(name, capname) #name,
|
|
|
|
#include "power_states.h"
|
|
|
|
};
|
|
|
|
|
2010-05-04 01:45:37 +02:00
|
|
|
// static
|
|
|
|
const char* MetricsDaemon::kSessionStates_[] = {
|
|
|
|
#define STATE(name, capname) #name,
|
|
|
|
#include "session_states.h"
|
|
|
|
};
|
|
|
|
|
2010-06-11 00:59:53 +02:00
|
|
|
MetricsDaemon::MetricsDaemon()
|
|
|
|
: network_state_(kUnknownNetworkState),
|
|
|
|
power_state_(kUnknownPowerState),
|
|
|
|
session_state_(kUnknownSessionState),
|
|
|
|
user_active_(false),
|
|
|
|
usemon_interval_(0),
|
|
|
|
usemon_source_(NULL) {}
|
|
|
|
|
|
|
|
MetricsDaemon::~MetricsDaemon() {}
|
|
|
|
|
2010-05-06 01:06:37 +02:00
|
|
|
void MetricsDaemon::Run(bool run_as_daemon) {
|
2010-04-14 22:32:20 +02:00
|
|
|
if (!run_as_daemon || daemon(0, 0) == 0) {
|
|
|
|
Loop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-12 22:05:45 +02:00
|
|
|
void MetricsDaemon::Init(bool testing, MetricsLibraryInterface* metrics_lib) {
|
2010-04-14 22:32:20 +02:00
|
|
|
testing_ = testing;
|
2010-05-12 22:05:45 +02:00
|
|
|
DCHECK(metrics_lib != NULL);
|
|
|
|
metrics_lib_ = metrics_lib;
|
2010-06-11 00:59:53 +02:00
|
|
|
daily_use_.reset(new chromeos_metrics::TaggedCounter());
|
|
|
|
daily_use_->Init(kDailyUseRecordFile, &DailyUseReporter, this);
|
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_thread_init(NULL);
|
|
|
|
g_type_init();
|
|
|
|
dbus_g_thread_init();
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
dbus_connection_setup_with_g_main(connection, NULL);
|
|
|
|
|
|
|
|
// Registers D-Bus matches for the signals we would like to catch.
|
2010-06-05 00:01:19 +02:00
|
|
|
for (unsigned int m = 0; m < sizeof(kDBusMatches_) / sizeof(char*); m++) {
|
2010-05-04 01:45:37 +02:00
|
|
|
const char* match = kDBusMatches_[m];
|
|
|
|
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.
|
|
|
|
CHECK(dbus_connection_add_filter(connection, MessageFilter, this, NULL));
|
2010-04-14 22:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetricsDaemon::Loop() {
|
2010-04-27 20:02:18 +02:00
|
|
|
GMainLoop* loop = g_main_loop_new(NULL, false);
|
|
|
|
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) {
|
2010-06-04 22:14:19 +02:00
|
|
|
Time now = Time::Now();
|
|
|
|
TimeTicks ticks = TimeTicks::Now();
|
|
|
|
DLOG(INFO) << "message intercepted @ " << now.ToInternalValue();
|
2010-04-14 22:32:20 +02:00
|
|
|
|
2010-04-27 20:02:18 +02:00
|
|
|
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.
|
|
|
|
const char* interface = dbus_message_get_interface(message);
|
|
|
|
CHECK(interface != NULL);
|
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);
|
2010-06-04 23:07:41 +02:00
|
|
|
if (strcmp(interface, DBUS_IFACE_FLIMFLAM_MANAGER) == 0) {
|
2010-05-04 01:45:37 +02:00
|
|
|
CHECK(strcmp(dbus_message_get_member(message),
|
|
|
|
"StateChanged") == 0);
|
2010-04-27 20:02:18 +02:00
|
|
|
|
2010-06-05 00:01:19 +02:00
|
|
|
char* state_name;
|
2010-04-27 20:02:18 +02:00
|
|
|
dbus_message_iter_get_basic(&iter, &state_name);
|
2010-06-04 22:14:19 +02:00
|
|
|
daemon->NetStateChanged(state_name, ticks);
|
2010-04-27 20:02:18 +02:00
|
|
|
} else if (strcmp(interface, DBUS_IFACE_POWER_MANAGER) == 0) {
|
2010-06-07 03:52:40 +02:00
|
|
|
const char* member = dbus_message_get_member(message);
|
|
|
|
if (strcmp(member, "ScreenIsLocked") == 0) {
|
|
|
|
daemon->SetUserActiveState(false, now);
|
|
|
|
} else if (strcmp(member, "ScreenIsUnlocked") == 0) {
|
|
|
|
daemon->SetUserActiveState(true, now);
|
|
|
|
} else if (strcmp(member, "PowerStateChanged") == 0) {
|
|
|
|
char* state_name;
|
|
|
|
dbus_message_iter_get_basic(&iter, &state_name);
|
|
|
|
daemon->PowerStateChanged(state_name, now);
|
|
|
|
}
|
2010-05-04 01:45:37 +02:00
|
|
|
} else if (strcmp(interface, DBUS_IFACE_SESSION_MANAGER) == 0) {
|
|
|
|
CHECK(strcmp(dbus_message_get_member(message),
|
|
|
|
"SessionStateChanged") == 0);
|
|
|
|
|
2010-06-05 00:01:19 +02:00
|
|
|
char* state_name;
|
2010-05-04 01:45:37 +02:00
|
|
|
dbus_message_iter_get_basic(&iter, &state_name);
|
|
|
|
daemon->SessionStateChanged(state_name, now);
|
2010-04-27 20:02:18 +02:00
|
|
|
} else {
|
2010-05-04 01:45:37 +02:00
|
|
|
DLOG(WARNING) << "unexpected interface: " << interface;
|
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;
|
|
|
|
}
|
|
|
|
|
2010-06-04 22:14:19 +02:00
|
|
|
void MetricsDaemon::NetStateChanged(const char* state_name, TimeTicks ticks) {
|
2010-05-04 01:45:37 +02:00
|
|
|
DLOG(INFO) << "network state: " << state_name;
|
2010-04-27 20:02:18 +02:00
|
|
|
|
|
|
|
NetworkState state = LookupNetworkState(state_name);
|
|
|
|
|
|
|
|
// Logs the time in seconds between the network going online to
|
2010-05-06 01:06:37 +02:00
|
|
|
// going offline (or, more precisely, going not online) in order to
|
|
|
|
// measure the mean time to network dropping. Going offline as part
|
|
|
|
// of suspend-to-RAM is not logged as network drop -- the assumption
|
|
|
|
// is that the message for suspend-to-RAM comes before the network
|
|
|
|
// offline message which seems to and should be the case.
|
|
|
|
if (state != kNetworkStateOnline &&
|
2010-04-27 20:02:18 +02:00
|
|
|
network_state_ == kNetworkStateOnline &&
|
|
|
|
power_state_ != kPowerStateMem) {
|
2010-06-04 22:14:19 +02:00
|
|
|
TimeDelta since_online = ticks - network_state_last_;
|
|
|
|
int online_time = static_cast<int>(since_online.InSeconds());
|
2010-05-18 20:00:59 +02:00
|
|
|
SendMetric(kMetricTimeToNetworkDropName, online_time,
|
|
|
|
kMetricTimeToNetworkDropMin,
|
|
|
|
kMetricTimeToNetworkDropMax,
|
|
|
|
kMetricTimeToNetworkDropBuckets);
|
2010-04-14 22:32:20 +02:00
|
|
|
}
|
2010-04-27 20:02:18 +02:00
|
|
|
|
|
|
|
network_state_ = state;
|
2010-06-04 22:14:19 +02:00
|
|
|
network_state_last_ = ticks;
|
2010-04-27 20:02:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MetricsDaemon::NetworkState
|
|
|
|
MetricsDaemon::LookupNetworkState(const char* state_name) {
|
|
|
|
for (int i = 0; i < kNumberNetworkStates; i++) {
|
2010-05-04 01:45:37 +02:00
|
|
|
if (strcmp(state_name, kNetworkStates_[i]) == 0) {
|
2010-04-27 20:02:18 +02:00
|
|
|
return static_cast<NetworkState>(i);
|
2010-04-14 22:32:20 +02:00
|
|
|
}
|
|
|
|
}
|
2010-05-04 01:45:37 +02:00
|
|
|
DLOG(WARNING) << "unknown network connection state: " << state_name;
|
2010-04-27 20:02:18 +02:00
|
|
|
return kUnknownNetworkState;
|
2010-04-14 22:32:20 +02:00
|
|
|
}
|
|
|
|
|
2010-06-04 22:14:19 +02:00
|
|
|
void MetricsDaemon::PowerStateChanged(const char* state_name, Time now) {
|
2010-05-04 01:45:37 +02:00
|
|
|
DLOG(INFO) << "power state: " << state_name;
|
2010-04-27 20:02:18 +02:00
|
|
|
power_state_ = LookupPowerState(state_name);
|
2010-05-04 01:45:37 +02:00
|
|
|
|
|
|
|
if (power_state_ != kPowerStateOn)
|
|
|
|
SetUserActiveState(false, now);
|
2010-04-27 20:02:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MetricsDaemon::PowerState
|
|
|
|
MetricsDaemon::LookupPowerState(const char* state_name) {
|
|
|
|
for (int i = 0; i < kNumberPowerStates; i++) {
|
2010-05-04 01:45:37 +02:00
|
|
|
if (strcmp(state_name, kPowerStates_[i]) == 0) {
|
2010-04-27 20:02:18 +02:00
|
|
|
return static_cast<PowerState>(i);
|
2010-04-14 22:32:20 +02:00
|
|
|
}
|
|
|
|
}
|
2010-05-04 01:45:37 +02:00
|
|
|
DLOG(WARNING) << "unknown power state: " << state_name;
|
2010-04-27 20:02:18 +02:00
|
|
|
return kUnknownPowerState;
|
2010-04-14 22:32:20 +02:00
|
|
|
}
|
|
|
|
|
2010-06-04 22:14:19 +02:00
|
|
|
void MetricsDaemon::SessionStateChanged(const char* state_name, Time now) {
|
2010-05-04 01:45:37 +02:00
|
|
|
DLOG(INFO) << "user session state: " << state_name;
|
|
|
|
session_state_ = LookupSessionState(state_name);
|
|
|
|
SetUserActiveState(session_state_ == kSessionStateStarted, now);
|
|
|
|
}
|
|
|
|
|
|
|
|
MetricsDaemon::SessionState
|
|
|
|
MetricsDaemon::LookupSessionState(const char* state_name) {
|
|
|
|
for (int i = 0; i < kNumberSessionStates; i++) {
|
|
|
|
if (strcmp(state_name, kSessionStates_[i]) == 0) {
|
|
|
|
return static_cast<SessionState>(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DLOG(WARNING) << "unknown user session state: " << state_name;
|
|
|
|
return kUnknownSessionState;
|
|
|
|
}
|
|
|
|
|
2010-06-04 22:14:19 +02:00
|
|
|
void MetricsDaemon::SetUserActiveState(bool active, Time now) {
|
2010-05-04 01:45:37 +02:00
|
|
|
DLOG(INFO) << "user: " << (active ? "active" : "inactive");
|
|
|
|
|
|
|
|
// Calculates the seconds of active use since the last update and
|
2010-06-04 22:14:19 +02:00
|
|
|
// the day since Epoch, and logs the usage data. Guards against the
|
|
|
|
// time jumping back and forth due to the user changing it by
|
|
|
|
// discarding the new use time.
|
|
|
|
int seconds = 0;
|
|
|
|
if (user_active_ && now > user_active_last_) {
|
|
|
|
TimeDelta since_active = now - user_active_last_;
|
|
|
|
if (since_active < TimeDelta::FromSeconds(
|
|
|
|
kUseMonitorIntervalMax + kSecondsPerMinute)) {
|
|
|
|
seconds = static_cast<int>(since_active.InSeconds());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TimeDelta since_epoch = now - Time();
|
|
|
|
int day = since_epoch.InDays();
|
2010-06-11 00:59:53 +02:00
|
|
|
daily_use_->Update(day, seconds);
|
2010-05-04 01:45:37 +02:00
|
|
|
|
|
|
|
// Schedules a use monitor on inactive->active transitions and
|
|
|
|
// unschedules it on active->inactive transitions.
|
|
|
|
if (!user_active_ && active)
|
|
|
|
ScheduleUseMonitor(kUseMonitorIntervalInit, /* backoff */ false);
|
|
|
|
else if (user_active_ && !active)
|
|
|
|
UnscheduleUseMonitor();
|
|
|
|
|
|
|
|
// Remembers the current active state and the time of the last
|
|
|
|
// activity update.
|
|
|
|
user_active_ = active;
|
|
|
|
user_active_last_ = now;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
gboolean MetricsDaemon::UseMonitorStatic(gpointer data) {
|
|
|
|
return static_cast<MetricsDaemon*>(data)->UseMonitor() ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MetricsDaemon::UseMonitor() {
|
2010-06-04 22:14:19 +02:00
|
|
|
SetUserActiveState(user_active_, Time::Now());
|
2010-05-04 01:45:37 +02:00
|
|
|
|
|
|
|
// If a new monitor source/instance is scheduled, returns false to
|
|
|
|
// tell GLib to destroy this monitor source/instance. Returns true
|
|
|
|
// otherwise to keep calling back this monitor.
|
|
|
|
return !ScheduleUseMonitor(usemon_interval_ * 2, /* backoff */ true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MetricsDaemon::ScheduleUseMonitor(int interval, bool backoff)
|
|
|
|
{
|
2010-05-06 01:06:37 +02:00
|
|
|
if (testing_)
|
|
|
|
return false;
|
|
|
|
|
2010-05-04 01:45:37 +02:00
|
|
|
// Caps the interval -- the bigger the interval, the more active use
|
|
|
|
// time will be potentially dropped on system shutdown.
|
|
|
|
if (interval > kUseMonitorIntervalMax)
|
|
|
|
interval = kUseMonitorIntervalMax;
|
|
|
|
|
|
|
|
if (backoff) {
|
|
|
|
// Back-off mode is used by the use monitor to reschedule itself
|
|
|
|
// with exponential back-off in time. This mode doesn't create a
|
|
|
|
// new timeout source if the new interval is the same as the old
|
|
|
|
// one. Also, if a new timeout source is created, the old one is
|
|
|
|
// not destroyed explicitly here -- it will be destroyed by GLib
|
|
|
|
// when the monitor returns FALSE (see UseMonitor and
|
|
|
|
// UseMonitorStatic).
|
|
|
|
if (interval == usemon_interval_)
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
UnscheduleUseMonitor();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Schedules a new use monitor for |interval| seconds from now.
|
|
|
|
DLOG(INFO) << "scheduling use monitor in " << interval << " seconds";
|
|
|
|
usemon_source_ = g_timeout_source_new_seconds(interval);
|
|
|
|
g_source_set_callback(usemon_source_, UseMonitorStatic, this,
|
|
|
|
NULL); // No destroy notification.
|
|
|
|
g_source_attach(usemon_source_,
|
|
|
|
NULL); // Default context.
|
|
|
|
usemon_interval_ = interval;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetricsDaemon::UnscheduleUseMonitor() {
|
|
|
|
// If there's a use monitor scheduled already, destroys it.
|
|
|
|
if (usemon_source_ == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
DLOG(INFO) << "destroying use monitor";
|
|
|
|
g_source_destroy(usemon_source_);
|
|
|
|
usemon_source_ = NULL;
|
|
|
|
usemon_interval_ = 0;
|
|
|
|
}
|
|
|
|
|
2010-06-11 00:59:53 +02:00
|
|
|
// static
|
|
|
|
void MetricsDaemon::DailyUseReporter(void* handle, int tag, int count) {
|
|
|
|
MetricsDaemon* daemon = static_cast<MetricsDaemon*>(handle);
|
|
|
|
int minutes = (count + kSecondsPerMinute / 2) / kSecondsPerMinute;
|
|
|
|
daemon->SendMetric(kMetricDailyUseTimeName, minutes,
|
|
|
|
kMetricDailyUseTimeMin,
|
|
|
|
kMetricDailyUseTimeMax,
|
|
|
|
kMetricDailyUseTimeBuckets);
|
|
|
|
}
|
|
|
|
|
2010-05-18 20:00:59 +02:00
|
|
|
void MetricsDaemon::SendMetric(const std::string& name, int sample,
|
|
|
|
int min, int max, int nbuckets) {
|
2010-05-12 22:05:45 +02:00
|
|
|
DLOG(INFO) << "received metric: " << name << " " << sample << " "
|
|
|
|
<< min << " " << max << " " << nbuckets;
|
|
|
|
metrics_lib_->SendToUMA(name, sample, min, max, nbuckets);
|
2010-04-14 22:32:20 +02:00
|
|
|
}
|