| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/metrics/stability_metrics_helper.h" | 5 #include "components/metrics/stability_metrics_helper.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/test/histogram_tester.h" |
| 8 #include "components/metrics/proto/system_profile.pb.h" | 9 #include "components/metrics/proto/system_profile.pb.h" |
| 9 #include "components/prefs/pref_service.h" | 10 #include "components/prefs/pref_service.h" |
| 10 #include "components/prefs/scoped_user_pref_update.h" | 11 #include "components/prefs/scoped_user_pref_update.h" |
| 11 #include "components/prefs/testing_pref_service.h" | 12 #include "components/prefs/testing_pref_service.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 namespace metrics { | 15 namespace metrics { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 19 enum RendererType { |
| 20 RENDERER_TYPE_RENDERER = 1, |
| 21 RENDERER_TYPE_EXTENSION, |
| 22 // NOTE: Add new action types only immediately above this line. Also, |
| 23 // make sure the enum list in tools/metrics/histograms/histograms.xml is |
| 24 // updated with any change in here. |
| 25 RENDERER_TYPE_COUNT |
| 26 }; |
| 27 |
| 18 class StabilityMetricsHelperTest : public testing::Test { | 28 class StabilityMetricsHelperTest : public testing::Test { |
| 19 protected: | 29 protected: |
| 20 StabilityMetricsHelperTest() : prefs_(new TestingPrefServiceSimple) { | 30 StabilityMetricsHelperTest() : prefs_(new TestingPrefServiceSimple) { |
| 21 StabilityMetricsHelper::RegisterPrefs(prefs()->registry()); | 31 StabilityMetricsHelper::RegisterPrefs(prefs()->registry()); |
| 22 } | 32 } |
| 23 | 33 |
| 24 TestingPrefServiceSimple* prefs() { return prefs_.get(); } | 34 TestingPrefServiceSimple* prefs() { return prefs_.get(); } |
| 25 | 35 |
| 26 private: | 36 private: |
| 27 std::unique_ptr<TestingPrefServiceSimple> prefs_; | 37 std::unique_ptr<TestingPrefServiceSimple> prefs_; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 45 | 55 |
| 46 // Check current number of instances created. | 56 // Check current number of instances created. |
| 47 const metrics::SystemProfileProto_Stability& stability = | 57 const metrics::SystemProfileProto_Stability& stability = |
| 48 system_profile.stability(); | 58 system_profile.stability(); |
| 49 | 59 |
| 50 EXPECT_EQ(2, stability.child_process_crash_count()); | 60 EXPECT_EQ(2, stability.child_process_crash_count()); |
| 51 } | 61 } |
| 52 | 62 |
| 53 TEST_F(StabilityMetricsHelperTest, LogRendererCrash) { | 63 TEST_F(StabilityMetricsHelperTest, LogRendererCrash) { |
| 54 StabilityMetricsHelper helper(prefs()); | 64 StabilityMetricsHelper helper(prefs()); |
| 65 base::HistogramTester histogram_tester; |
| 55 | 66 |
| 56 // Crash and abnormal termination should increment renderer crash count. | 67 // Crash and abnormal termination should increment renderer crash count. |
| 57 helper.LogRendererCrash(false, base::TERMINATION_STATUS_PROCESS_CRASHED, 1); | 68 helper.LogRendererCrash(false, base::TERMINATION_STATUS_PROCESS_CRASHED, 1); |
| 58 | 69 |
| 59 helper.LogRendererCrash(false, base::TERMINATION_STATUS_ABNORMAL_TERMINATION, | 70 helper.LogRendererCrash(false, base::TERMINATION_STATUS_ABNORMAL_TERMINATION, |
| 60 1); | 71 1); |
| 61 | 72 |
| 73 // OOM should increment renderer crash count. |
| 74 helper.LogRendererCrash(false, base::TERMINATION_STATUS_OOM, 1); |
| 75 |
| 62 // Kill does not increment renderer crash count. | 76 // Kill does not increment renderer crash count. |
| 63 helper.LogRendererCrash(false, base::TERMINATION_STATUS_PROCESS_WAS_KILLED, | 77 helper.LogRendererCrash(false, base::TERMINATION_STATUS_PROCESS_WAS_KILLED, |
| 64 1); | 78 1); |
| 65 | 79 |
| 66 // Failed launch increments failed launch count. | 80 // Failed launch increments failed launch count. |
| 67 helper.LogRendererCrash(false, base::TERMINATION_STATUS_LAUNCH_FAILED, 1); | 81 helper.LogRendererCrash(false, base::TERMINATION_STATUS_LAUNCH_FAILED, 1); |
| 68 | 82 |
| 69 metrics::SystemProfileProto system_profile; | 83 metrics::SystemProfileProto system_profile; |
| 70 | 84 |
| 71 // Call ProvideStabilityMetrics to check that it will force pending tasks to | 85 // Call ProvideStabilityMetrics to check that it will force pending tasks to |
| 72 // be executed immediately. | 86 // be executed immediately. |
| 73 helper.ProvideStabilityMetrics(&system_profile); | 87 helper.ProvideStabilityMetrics(&system_profile); |
| 74 | 88 |
| 75 EXPECT_EQ(2, system_profile.stability().renderer_crash_count()); | 89 EXPECT_EQ(3, system_profile.stability().renderer_crash_count()); |
| 76 EXPECT_EQ(1, system_profile.stability().renderer_failed_launch_count()); | 90 EXPECT_EQ(1, system_profile.stability().renderer_failed_launch_count()); |
| 77 EXPECT_EQ(0, system_profile.stability().extension_renderer_crash_count()); | 91 EXPECT_EQ(0, system_profile.stability().extension_renderer_crash_count()); |
| 78 | 92 |
| 79 helper.ClearSavedStabilityMetrics(); | 93 helper.ClearSavedStabilityMetrics(); |
| 80 | 94 |
| 81 // Crash and abnormal termination should increment extension crash count. | 95 // Crash and abnormal termination should increment extension crash count. |
| 82 helper.LogRendererCrash(true, base::TERMINATION_STATUS_PROCESS_CRASHED, 1); | 96 helper.LogRendererCrash(true, base::TERMINATION_STATUS_PROCESS_CRASHED, 1); |
| 83 | 97 |
| 98 // OOM should increment extension renderer crash count. |
| 99 helper.LogRendererCrash(true, base::TERMINATION_STATUS_OOM, 1); |
| 100 |
| 84 // Failed launch increments extension failed launch count. | 101 // Failed launch increments extension failed launch count. |
| 85 helper.LogRendererCrash(true, base::TERMINATION_STATUS_LAUNCH_FAILED, 1); | 102 helper.LogRendererCrash(true, base::TERMINATION_STATUS_LAUNCH_FAILED, 1); |
| 86 | 103 |
| 87 system_profile.Clear(); | 104 system_profile.Clear(); |
| 88 helper.ProvideStabilityMetrics(&system_profile); | 105 helper.ProvideStabilityMetrics(&system_profile); |
| 89 | 106 |
| 90 EXPECT_EQ(0, system_profile.stability().renderer_crash_count()); | 107 EXPECT_EQ(0, system_profile.stability().renderer_crash_count()); |
| 91 EXPECT_EQ(1, system_profile.stability().extension_renderer_crash_count()); | 108 EXPECT_EQ(2, system_profile.stability().extension_renderer_crash_count()); |
| 92 EXPECT_EQ( | 109 EXPECT_EQ( |
| 93 1, system_profile.stability().extension_renderer_failed_launch_count()); | 110 1, system_profile.stability().extension_renderer_failed_launch_count()); |
| 111 |
| 112 // TERMINATION_STATUS_PROCESS_CRASHED, TERMINATION_STATUS_ABNORMAL_TERMINATION |
| 113 // and TERMINATION_STATUS_OOM = 3. |
| 114 histogram_tester.ExpectUniqueSample("CrashExitCodes.Renderer", 1, 3); |
| 115 histogram_tester.ExpectBucketCount("BrowserRenderProcessHost.ChildCrashes", |
| 116 RENDERER_TYPE_RENDERER, 3); |
| 117 |
| 118 // TERMINATION_STATUS_PROCESS_CRASHED and TERMINATION_STATUS_OOM = 2. |
| 119 histogram_tester.ExpectUniqueSample("CrashExitCodes.Extension", 1, 2); |
| 120 histogram_tester.ExpectBucketCount("BrowserRenderProcessHost.ChildCrashes", |
| 121 RENDERER_TYPE_EXTENSION, 2); |
| 122 |
| 123 // One launch failure each. |
| 124 histogram_tester.ExpectBucketCount( |
| 125 "BrowserRenderProcessHost.ChildLaunchFailures", RENDERER_TYPE_RENDERER, |
| 126 1); |
| 127 histogram_tester.ExpectBucketCount( |
| 128 "BrowserRenderProcessHost.ChildLaunchFailures", RENDERER_TYPE_EXTENSION, |
| 129 1); |
| 130 histogram_tester.ExpectBucketCount( |
| 131 "BrowserRenderProcessHost.ChildLaunchFailureCodes", 1, 2); |
| 132 |
| 133 // TERMINATION_STATUS_PROCESS_WAS_KILLED for a renderer. |
| 134 histogram_tester.ExpectBucketCount("BrowserRenderProcessHost.ChildKills", |
| 135 RENDERER_TYPE_RENDERER, 1); |
| 136 histogram_tester.ExpectBucketCount("BrowserRenderProcessHost.ChildKills", |
| 137 RENDERER_TYPE_EXTENSION, 0); |
| 94 } | 138 } |
| 95 | 139 |
| 96 } // namespace metrics | 140 } // namespace metrics |
| OLD | NEW |