Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Unified Diff: components/metrics/metrics_service_unittest.cc

Issue 558653002: Allow MetricsProviders to request an initial stability log. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Address Alexei's comments, round deux. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/metrics/metrics_service.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/metrics/metrics_service_unittest.cc
diff --git a/components/metrics/metrics_service_unittest.cc b/components/metrics/metrics_service_unittest.cc
index c580287ba11a1fbee1debb150b4168e1d5b7813f..1ec396cfdeab1b9cf67b87edd65fab8311f8dd91 100644
--- a/components/metrics/metrics_service_unittest.cc
+++ b/components/metrics/metrics_service_unittest.cc
@@ -32,6 +32,30 @@ scoped_ptr<metrics::ClientInfo> ReturnNoBackup() {
return scoped_ptr<metrics::ClientInfo>();
}
+class TestMetricsProvider : public metrics::MetricsProvider {
+ public:
+ explicit TestMetricsProvider(bool has_stability_metrics) :
+ has_stability_metrics_(has_stability_metrics),
+ provide_stability_metrics_called_(false) {
+ }
+
+ virtual bool HasStabilityMetrics() OVERRIDE { return has_stability_metrics_; }
+ virtual void ProvideStabilityMetrics(
+ metrics::SystemProfileProto* system_profile_proto) OVERRIDE {
+ provide_stability_metrics_called_ = true;
+ }
+
+ bool provide_stability_metrics_called() const {
+ return provide_stability_metrics_called_;
+ }
+
+ private:
+ bool has_stability_metrics_;
+ bool provide_stability_metrics_called_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestMetricsProvider);
+};
+
class TestMetricsService : public MetricsService {
public:
TestMetricsService(metrics::MetricsStateManager* state_manager,
@@ -155,10 +179,83 @@ TEST_F(MetricsServiceTest, InitialStabilityLogAfterCleanShutDown) {
metrics::TestMetricsServiceClient client;
TestMetricsService service(
GetMetricsStateManager(), &client, GetLocalState());
+
+ TestMetricsProvider* test_provider = new TestMetricsProvider(false);
+ service.RegisterMetricsProvider(
+ scoped_ptr<metrics::MetricsProvider>(test_provider));
+
service.InitializeMetricsRecordingState();
// No initial stability log should be generated.
EXPECT_FALSE(service.log_manager()->has_unsent_logs());
EXPECT_FALSE(service.log_manager()->has_staged_log());
+
+ // The test provider should not have been called upon to provide stability
+ // metrics.
+ EXPECT_FALSE(test_provider->provide_stability_metrics_called());
+}
+
+TEST_F(MetricsServiceTest, InitialStabilityLogAtProviderRequest) {
+ EnableMetricsReporting();
+
+ // Save an existing system profile to prefs, to correspond to what would be
+ // saved from a previous session.
+ metrics::TestMetricsServiceClient client;
+ TestMetricsLog log("client", 1, &client, GetLocalState());
+ log.RecordEnvironment(std::vector<metrics::MetricsProvider*>(),
+ std::vector<variations::ActiveGroupId>(),
+ 0);
+
+ // Record stability build time and version from previous session, so that
+ // stability metrics (including exited cleanly flag) won't be cleared.
+ GetLocalState()->SetInt64(metrics::prefs::kStabilityStatsBuildTime,
+ MetricsLog::GetBuildTime());
+ GetLocalState()->SetString(metrics::prefs::kStabilityStatsVersion,
+ client.GetVersionString());
+
+ // Set the clean exit flag, as that will otherwise cause a stabilty
+ // log to be produced, irrespective provider requests.
+ GetLocalState()->SetBoolean(metrics::prefs::kStabilityExitedCleanly, true);
+
+ TestMetricsService service(
+ GetMetricsStateManager(), &client, GetLocalState());
+ // Add a metrics provider that requests a stability log.
+ TestMetricsProvider* test_provider = new TestMetricsProvider(true);
+ service.RegisterMetricsProvider(
+ scoped_ptr<metrics::MetricsProvider>(test_provider));
+
+ service.InitializeMetricsRecordingState();
+
+ // The initial stability log should be generated and persisted in unsent logs.
+ MetricsLogManager* log_manager = service.log_manager();
+ EXPECT_TRUE(log_manager->has_unsent_logs());
+ EXPECT_FALSE(log_manager->has_staged_log());
+
+ // The test provider should have been called upon to provide stabilit
Alexei Svitkine (slow) 2014/09/09 19:28:26 Nit: stability
Sigurður Ásgeirsson 2014/09/09 21:13:14 Done.
+ // metrics.
+ EXPECT_TRUE(test_provider->provide_stability_metrics_called());
+
+ // Stage the log and retrieve it.
+ log_manager->StageNextLogForUpload();
+ EXPECT_TRUE(log_manager->has_staged_log());
+
+ std::string uncompressed_log;
+ EXPECT_TRUE(metrics::GzipUncompress(log_manager->staged_log(),
+ &uncompressed_log));
+
+ metrics::ChromeUserMetricsExtension uma_log;
+ EXPECT_TRUE(uma_log.ParseFromString(uncompressed_log));
+
+ EXPECT_TRUE(uma_log.has_client_id());
+ EXPECT_TRUE(uma_log.has_session_id());
+ EXPECT_TRUE(uma_log.has_system_profile());
+ EXPECT_EQ(0, uma_log.user_action_event_size());
+ EXPECT_EQ(0, uma_log.omnibox_event_size());
+ EXPECT_EQ(0, uma_log.histogram_event_size());
+ EXPECT_EQ(0, uma_log.profiler_event_size());
+ EXPECT_EQ(0, uma_log.perf_data_size());
+
+ // As there wasn't an unclean shutdown, this log has zero crash count.
+ EXPECT_EQ(0, uma_log.system_profile().stability().crash_count());
}
TEST_F(MetricsServiceTest, InitialStabilityLogAfterCrash) {
@@ -178,9 +275,9 @@ TEST_F(MetricsServiceTest, InitialStabilityLogAfterCrash) {
// Record stability build time and version from previous session, so that
// stability metrics (including exited cleanly flag) won't be cleared.
GetLocalState()->SetInt64(metrics::prefs::kStabilityStatsBuildTime,
- MetricsLog::GetBuildTime());
+ MetricsLog::GetBuildTime());
GetLocalState()->SetString(metrics::prefs::kStabilityStatsVersion,
- client.GetVersionString());
+ client.GetVersionString());
GetLocalState()->SetBoolean(metrics::prefs::kStabilityExitedCleanly, false);
« no previous file with comments | « components/metrics/metrics_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698