remove TimeToDrop support
Now that flimflam has native support this can be purged.
TEST=run FEATURES=test emerge-x86-generic metrics; verify TimeToDrop is still being recorded w/ about:histograms/Network
Review URL: http://codereview.chromium.org/3233004
diff --git a/metrics/metrics_daemon.cc b/metrics/metrics_daemon.cc
index 4d50cb5..2f62330 100644
--- a/metrics/metrics_daemon.cc
+++ b/metrics/metrics_daemon.cc
@@ -19,7 +19,6 @@
#define SAFE_MESSAGE(e) (e.message ? e.message : "unknown error")
#define DBUS_IFACE_CRASH_REPORTER "org.chromium.CrashReporter"
-#define DBUS_IFACE_FLIMFLAM_MANAGER "org.chromium.flimflam.Manager"
#define DBUS_IFACE_POWER_MANAGER "org.chromium.PowerManager"
#define DBUS_IFACE_SESSION_MANAGER "org.chromium.SessionManagerInterface"
@@ -51,13 +50,6 @@
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;
-
// crash interval metrics
const char MetricsDaemon::kMetricKernelCrashIntervalName[] =
"Logging.KernelCrashInterval";
@@ -104,12 +96,6 @@
"member='UserCrash'",
"type='signal',"
- "sender='org.chromium.flimflam',"
- "interface='" DBUS_IFACE_FLIMFLAM_MANAGER "',"
- "path='/',"
- "member='StateChanged'",
-
- "type='signal',"
"interface='" DBUS_IFACE_POWER_MANAGER "',"
"path='/'",
@@ -121,12 +107,6 @@
};
// static
-const char* MetricsDaemon::kNetworkStates_[] = {
-#define STATE(name, capname) #name,
-#include "network_states.h"
-};
-
-// static
const char* MetricsDaemon::kPowerStates_[] = {
#define STATE(name, capname) #name,
#include "power_states.h"
@@ -138,56 +118,8 @@
#include "session_states.h"
};
-// Invokes a remote method over D-Bus that takes no input arguments
-// and returns a string result. The method call is issued with a 2
-// second blocking timeout. Returns an empty string on failure or
-// timeout.
-static string DBusGetString(DBusConnection* connection,
- const string& destination,
- const string& path,
- const string& interface,
- const string& method) {
- DBusMessage* message =
- dbus_message_new_method_call(destination.c_str(),
- path.c_str(),
- interface.c_str(),
- method.c_str());
- if (!message) {
- DLOG(WARNING) << "DBusGetString: unable to allocate a message";
- return "";
- }
-
- DBusError error;
- dbus_error_init(&error);
- const int kTimeout = 2000; // ms
- DLOG(INFO) << "DBusGetString: dest=" << destination << " path=" << path
- << " iface=" << interface << " method=" << method;
- DBusMessage* reply =
- dbus_connection_send_with_reply_and_block(connection, message, kTimeout,
- &error);
- dbus_message_unref(message);
- if (dbus_error_is_set(&error) || !reply) {
- DLOG(WARNING) << "DBusGetString: call failed";
- return "";
- }
- DBusMessageIter iter;
- dbus_message_iter_init(reply, &iter);
- if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) {
- NOTREACHED();
- dbus_message_unref(reply);
- return "";
- }
- const char* c_result = "";
- dbus_message_iter_get_basic(&iter, &c_result);
- string result = c_result;
- DLOG(INFO) << "DBusGetString: result=" << result;
- dbus_message_unref(reply);
- return result;
-}
-
MetricsDaemon::MetricsDaemon()
- : network_state_(kUnknownNetworkState),
- power_state_(kUnknownPowerState),
+ : power_state_(kUnknownPowerState),
session_state_(kUnknownSessionState),
user_active_(false),
usemon_interval_(0),
@@ -317,11 +249,6 @@
// 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));
-
- // Initializes the current network state by retrieving it from flimflam.
- string state_name = DBusGetString(connection, "org.chromium.flimflam", "/",
- DBUS_IFACE_FLIMFLAM_MANAGER, "GetState");
- NetStateChanged(state_name.c_str(), TimeTicks::Now());
}
void MetricsDaemon::Loop() {
@@ -355,13 +282,6 @@
CHECK(strcmp(dbus_message_get_member(message),
"UserCrash") == 0);
daemon->ProcessUserCrash();
- } else if (strcmp(interface, DBUS_IFACE_FLIMFLAM_MANAGER) == 0) {
- CHECK(strcmp(dbus_message_get_member(message),
- "StateChanged") == 0);
-
- char* state_name;
- dbus_message_iter_get_basic(&iter, &state_name);
- daemon->NetStateChanged(state_name, ticks);
} else if (strcmp(interface, DBUS_IFACE_POWER_MANAGER) == 0) {
const char* member = dbus_message_get_member(message);
if (strcmp(member, "ScreenIsLocked") == 0) {
@@ -388,43 +308,6 @@
return DBUS_HANDLER_RESULT_HANDLED;
}
-void MetricsDaemon::NetStateChanged(const char* state_name, TimeTicks ticks) {
- DLOG(INFO) << "network state: " << state_name;
-
- NetworkState state = LookupNetworkState(state_name);
-
- // Logs the time in seconds between the network going online to
- // 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 &&
- network_state_ == kNetworkStateOnline &&
- power_state_ != kPowerStateMem) {
- TimeDelta since_online = ticks - network_state_last_;
- int online_time = static_cast<int>(since_online.InSeconds());
- SendMetric(kMetricTimeToNetworkDropName, online_time,
- kMetricTimeToNetworkDropMin,
- kMetricTimeToNetworkDropMax,
- kMetricTimeToNetworkDropBuckets);
- }
-
- network_state_ = state;
- network_state_last_ = ticks;
-}
-
-MetricsDaemon::NetworkState
-MetricsDaemon::LookupNetworkState(const char* state_name) {
- for (int i = 0; i < kNumberNetworkStates; i++) {
- if (strcmp(state_name, kNetworkStates_[i]) == 0) {
- return static_cast<NetworkState>(i);
- }
- }
- DLOG(WARNING) << "unknown network connection state: " << state_name;
- return kUnknownNetworkState;
-}
-
void MetricsDaemon::PowerStateChanged(const char* state_name, Time now) {
DLOG(INFO) << "power state: " << state_name;
power_state_ = LookupPowerState(state_name);
diff --git a/metrics/metrics_daemon.h b/metrics/metrics_daemon.h
index d400bf0..5f2e786 100644
--- a/metrics/metrics_daemon.h
+++ b/metrics/metrics_daemon.h
@@ -42,13 +42,10 @@
FRIEND_TEST(MetricsDaemonTest, ComputeEpochNoLast);
FRIEND_TEST(MetricsDaemonTest, GetHistogramPath);
FRIEND_TEST(MetricsDaemonTest, IsNewEpoch);
- FRIEND_TEST(MetricsDaemonTest, LookupNetworkState);
FRIEND_TEST(MetricsDaemonTest, LookupPowerState);
FRIEND_TEST(MetricsDaemonTest, LookupScreenSaverState);
FRIEND_TEST(MetricsDaemonTest, LookupSessionState);
FRIEND_TEST(MetricsDaemonTest, MessageFilter);
- FRIEND_TEST(MetricsDaemonTest, NetStateChangedSimpleDrop);
- FRIEND_TEST(MetricsDaemonTest, NetStateChangedSuspend);
FRIEND_TEST(MetricsDaemonTest, PowerStateChanged);
FRIEND_TEST(MetricsDaemonTest, ProcessKernelCrash);
FRIEND_TEST(MetricsDaemonTest, ProcessUncleanShutdown);
@@ -64,14 +61,6 @@
FRIEND_TEST(MetricsDaemonTest, SetUserActiveState);
FRIEND_TEST(MetricsDaemonTest, SetUserActiveStateTimeJump);
- // The network states (see network_states.h).
- enum NetworkState {
- kUnknownNetworkState = -1, // Initial/unknown network state.
-#define STATE(name, capname) kNetworkState ## capname,
-#include "network_states.h"
- kNumberNetworkStates
- };
-
// The power states (see power_states.h).
enum PowerState {
kUnknownPowerState = -1, // Initial/unknown power state.
@@ -116,10 +105,6 @@
static const char kMetricKernelCrashesWeeklyName[];
static const char kMetricKernelCrashIntervalName[];
static const char kMetricsPath[];
- static const int kMetricTimeToNetworkDropBuckets;
- static const int kMetricTimeToNetworkDropMax;
- static const int kMetricTimeToNetworkDropMin;
- static const char kMetricTimeToNetworkDropName[];
static const char kMetricUncleanShutdownIntervalName[];
static const char kMetricUncleanShutdownsDailyName[];
static const char kMetricUncleanShutdownsWeeklyName[];
@@ -130,9 +115,6 @@
// D-Bus message match strings.
static const char* kDBusMatches_[];
- // Array of network states.
- static const char* kNetworkStates_[kNumberNetworkStates];
-
// Array of power states.
static const char* kPowerStates_[kNumberPowerStates];
@@ -161,12 +143,6 @@
DBusMessage* message,
void* user_data);
- // Processes network state change.
- void NetStateChanged(const char* state_name, base::TimeTicks ticks);
-
- // Given the state name, returns the state id.
- NetworkState LookupNetworkState(const char* state_name);
-
// Processes power state change.
void PowerStateChanged(const char* state_name, base::Time now);
@@ -247,9 +223,6 @@
// The metrics library handle.
MetricsLibraryInterface* metrics_lib_;
- // Current network state.
- NetworkState network_state_;
-
// 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.
diff --git a/metrics/metrics_daemon_test.cc b/metrics/metrics_daemon_test.cc
index 9ba63e8..40edf1f 100644
--- a/metrics/metrics_daemon_test.cc
+++ b/metrics/metrics_daemon_test.cc
@@ -38,12 +38,6 @@
};
// Overloaded for test failure printing purposes.
-static std::ostream& operator<<(std::ostream& o, const TimeTicks& ticks) {
- o << ticks.ToInternalValue() << "us";
- return o;
-};
-
-// Overloaded for test failure printing purposes.
static std::ostream& operator<<(std::ostream& o, const Time& time) {
o << time.ToInternalValue() << "us";
return o;
@@ -114,8 +108,6 @@
EXPECT_FALSE(daemon_.user_active_);
EXPECT_TRUE(daemon_.user_active_last_.is_null());
- EXPECT_EQ(MetricsDaemon::kUnknownNetworkState, daemon_.network_state_);
- EXPECT_TRUE(daemon_.network_state_last_.is_null());
EXPECT_EQ(MetricsDaemon::kUnknownPowerState, daemon_.power_state_);
EXPECT_EQ(MetricsDaemon::kUnknownSessionState, daemon_.session_state_);
@@ -190,15 +182,6 @@
MetricsDaemon::kMetricDailyUseTimeBuckets);
}
- // Adds a metrics library mock expectation that the specified time
- // to network dropping metric will be generated.
- void ExpectTimeToNetworkDropMetric(int sample) {
- ExpectMetric(MetricsDaemon::kMetricTimeToNetworkDropName, sample,
- MetricsDaemon::kMetricTimeToNetworkDropMin,
- MetricsDaemon::kMetricTimeToNetworkDropMax,
- MetricsDaemon::kMetricTimeToNetworkDropBuckets);
- }
-
// Converts from seconds to a Time object.
Time TestTime(int64 seconds) {
return Time::FromInternalValue(seconds * Time::kMicrosecondsPerSecond);
@@ -280,15 +263,6 @@
MetricsDaemon::ReportDailyUse(&daemon_, /* tag */ 60, /* count */ -5);
}
-TEST_F(MetricsDaemonTest, LookupNetworkState) {
- EXPECT_EQ(MetricsDaemon::kNetworkStateOnline,
- daemon_.LookupNetworkState("online"));
- EXPECT_EQ(MetricsDaemon::kNetworkStateOffline,
- daemon_.LookupNetworkState("offline"));
- EXPECT_EQ(MetricsDaemon::kUnknownNetworkState,
- daemon_.LookupNetworkState("somestate"));
-}
-
TEST_F(MetricsDaemonTest, LookupPowerState) {
EXPECT_EQ(MetricsDaemon::kPowerStateOn,
daemon_.LookupPowerState("on"));
@@ -343,16 +317,6 @@
DeleteDBusMessage(msg);
msg = NewDBusSignalString("/",
- "org.chromium.flimflam.Manager",
- "StateChanged",
- "online");
- EXPECT_EQ(MetricsDaemon::kUnknownNetworkState, daemon_.network_state_);
- res = MetricsDaemon::MessageFilter(/* connection */ NULL, msg, &daemon_);
- EXPECT_EQ(MetricsDaemon::kNetworkStateOnline, daemon_.network_state_);
- EXPECT_EQ(DBUS_HANDLER_RESULT_HANDLED, res);
- DeleteDBusMessage(msg);
-
- msg = NewDBusSignalString("/",
"org.chromium.PowerManager",
"PowerStateChanged",
"on");
@@ -393,50 +357,6 @@
DeleteDBusMessage(msg);
}
-TEST_F(MetricsDaemonTest, NetStateChangedSimpleDrop) {
- daemon_.NetStateChanged("online", TestTicks(10));
- EXPECT_EQ(MetricsDaemon::kNetworkStateOnline, daemon_.network_state_);
- EXPECT_EQ(TestTicks(10), daemon_.network_state_last_);
-
- ExpectTimeToNetworkDropMetric(20);
- daemon_.NetStateChanged("offline", TestTicks(30));
- EXPECT_EQ(MetricsDaemon::kNetworkStateOffline, daemon_.network_state_);
- EXPECT_EQ(TestTicks(30), daemon_.network_state_last_);
-}
-
-TEST_F(MetricsDaemonTest, NetStateChangedSuspend) {
- daemon_.NetStateChanged("offline", TestTicks(30));
- EXPECT_EQ(MetricsDaemon::kNetworkStateOffline, daemon_.network_state_);
- EXPECT_EQ(TestTicks(30), daemon_.network_state_last_);
-
- daemon_.NetStateChanged("online", TestTicks(60));
- EXPECT_EQ(MetricsDaemon::kNetworkStateOnline, daemon_.network_state_);
- EXPECT_EQ(TestTicks(60), daemon_.network_state_last_);
-
- daemon_.power_state_ = MetricsDaemon::kPowerStateMem;
- daemon_.NetStateChanged("offline", TestTicks(85));
- EXPECT_EQ(MetricsDaemon::kNetworkStateOffline, daemon_.network_state_);
- EXPECT_EQ(TestTicks(85), daemon_.network_state_last_);
-
- daemon_.NetStateChanged("somestate", TestTicks(90));
- EXPECT_EQ(MetricsDaemon::kUnknownNetworkState, daemon_.network_state_);
- EXPECT_EQ(TestTicks(90), daemon_.network_state_last_);
-
- daemon_.NetStateChanged("offline", TestTicks(95));
- EXPECT_EQ(MetricsDaemon::kNetworkStateOffline, daemon_.network_state_);
- EXPECT_EQ(TestTicks(95), daemon_.network_state_last_);
-
- daemon_.power_state_ = MetricsDaemon::kPowerStateOn;
- daemon_.NetStateChanged("online", TestTicks(105));
- EXPECT_EQ(MetricsDaemon::kNetworkStateOnline, daemon_.network_state_);
- EXPECT_EQ(TestTicks(105), daemon_.network_state_last_);
-
- ExpectTimeToNetworkDropMetric(3);
- daemon_.NetStateChanged("offline", TestTicks(108));
- EXPECT_EQ(MetricsDaemon::kNetworkStateOffline, daemon_.network_state_);
- EXPECT_EQ(TestTicks(108), daemon_.network_state_last_);
-}
-
TEST_F(MetricsDaemonTest, PowerStateChanged) {
ExpectActiveUseUpdate(7, 0);
daemon_.SetUserActiveState(/* active */ true,
diff --git a/metrics/network_states.h b/metrics/network_states.h
deleted file mode 100644
index b02f64a..0000000
--- a/metrics/network_states.h
+++ /dev/null
@@ -1,28 +0,0 @@
-// 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.
-
-// A table of network states, to be included when building tabular things.
-//
-// This file is used to construct two things: an enumerated type in
-// metrics_daemon.h, and a table of structures with state names in
-// metrics_daemon.cc. Including this file ensures that the two tables are
-// always in sync (and saves typing). I don't know of other ways of achieving
-// the same result in C/C++, but it doesn't mean there isn't one.
-
-// Before you include this file, define STATE to do something useful, or else
-// if will be a no-op. STATE will be undefined on exit. Don't worry about
-// collisions for the STATE macro (as long as it's a macro) because the
-// compiler will flag them---in that case, just change the name. If someone is
-// misguided enough to use STATE for something other than a macro, the error
-// messages will be slightly more complicated.
-
-
-#ifndef STATE
-#define STATE(name, capname)
-#endif
-
-STATE(offline, Offline)
-STATE(online, Online)
-
-#undef STATE