Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/metrics/chrome_stability_metrics_provider.h" | 5 #include "chrome/browser/metrics/chrome_stability_metrics_provider.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/metrics/sparse_histogram.h" | 11 #include "base/metrics/sparse_histogram.h" |
| 12 #include "base/prefs/pref_registry_simple.h" | |
| 12 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 16 #include "components/metrics/proto/system_profile.pb.h" | 17 #include "components/metrics/proto/system_profile.pb.h" |
| 18 #include "content/public/browser/child_process_data.h" | |
| 17 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
| 18 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
| 19 #include "content/public/browser/user_metrics.h" | 21 #include "content/public/browser/user_metrics.h" |
| 20 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 21 #include "extensions/browser/process_map.h" | 23 #include "extensions/browser/process_map.h" |
| 22 | 24 |
| 25 #if defined(ENABLE_PLUGINS) | |
| 26 #include "chrome/browser/metrics/plugin_metrics_provider.h" | |
| 27 #endif | |
|
Ilya Sherman
2014/05/23 11:42:01
Hmm, maybe it makes sense to move the IsPluginProc
Alexei Svitkine (slow)
2014/05/23 13:14:50
But then we'd need to add a chrome_stability_metri
Ilya Sherman
2014/05/23 14:21:16
Hrm, ok.
| |
| 28 | |
| 23 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
| 24 #include <windows.h> // Needed for STATUS_* codes | 30 #include <windows.h> // Needed for STATUS_* codes |
| 25 #endif | 31 #endif |
| 26 | 32 |
| 27 namespace { | 33 namespace { |
| 28 | 34 |
| 29 void IncrementPrefValue(const char* path) { | 35 void IncrementPrefValue(const char* path) { |
| 30 PrefService* pref = g_browser_process->local_state(); | 36 PrefService* pref = g_browser_process->local_state(); |
| 31 DCHECK(pref); | 37 DCHECK(pref); |
| 32 int value = pref->GetInteger(path); | 38 int value = pref->GetInteger(path); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 50 if (exit_code == STATUS_GUARD_PAGE_VIOLATION) | 56 if (exit_code == STATUS_GUARD_PAGE_VIOLATION) |
| 51 return 0x1FCF7EC3; // Randomly picked number. | 57 return 0x1FCF7EC3; // Randomly picked number. |
| 52 #endif | 58 #endif |
| 53 | 59 |
| 54 return std::abs(exit_code); | 60 return std::abs(exit_code); |
| 55 } | 61 } |
| 56 | 62 |
| 57 } // namespace | 63 } // namespace |
| 58 | 64 |
| 59 ChromeStabilityMetricsProvider::ChromeStabilityMetricsProvider() { | 65 ChromeStabilityMetricsProvider::ChromeStabilityMetricsProvider() { |
| 66 BrowserChildProcessObserver::Add(this); | |
| 60 } | 67 } |
| 61 | 68 |
| 62 ChromeStabilityMetricsProvider::~ChromeStabilityMetricsProvider() { | 69 ChromeStabilityMetricsProvider::~ChromeStabilityMetricsProvider() { |
| 70 BrowserChildProcessObserver::Remove(this); | |
| 63 } | 71 } |
| 64 | 72 |
| 65 void ChromeStabilityMetricsProvider::OnRecordingEnabled() { | 73 void ChromeStabilityMetricsProvider::OnRecordingEnabled() { |
| 66 registrar_.Add(this, | 74 registrar_.Add(this, |
| 67 content::NOTIFICATION_LOAD_START, | 75 content::NOTIFICATION_LOAD_START, |
| 68 content::NotificationService::AllSources()); | 76 content::NotificationService::AllSources()); |
| 69 registrar_.Add(this, | 77 registrar_.Add(this, |
| 70 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 78 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 71 content::NotificationService::AllSources()); | 79 content::NotificationService::AllSources()); |
| 72 registrar_.Add(this, | 80 registrar_.Add(this, |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 102 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0); | 110 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0); |
| 103 } | 111 } |
| 104 | 112 |
| 105 count = pref->GetInteger(prefs::kStabilityRendererHangCount); | 113 count = pref->GetInteger(prefs::kStabilityRendererHangCount); |
| 106 if (count) { | 114 if (count) { |
| 107 stability_proto->set_renderer_hang_count(count); | 115 stability_proto->set_renderer_hang_count(count); |
| 108 pref->SetInteger(prefs::kStabilityRendererHangCount, 0); | 116 pref->SetInteger(prefs::kStabilityRendererHangCount, 0); |
| 109 } | 117 } |
| 110 } | 118 } |
| 111 | 119 |
| 120 // static | |
| 121 void ChromeStabilityMetricsProvider::RegisterPrefs( | |
| 122 PrefRegistrySimple* registry) { | |
| 123 registry->RegisterIntegerPref(prefs::kStabilityPageLoadCount, 0); | |
| 124 registry->RegisterIntegerPref(prefs::kStabilityRendererCrashCount, 0); | |
| 125 registry->RegisterIntegerPref(prefs::kStabilityExtensionRendererCrashCount, | |
| 126 0); | |
| 127 registry->RegisterIntegerPref(prefs::kStabilityRendererHangCount, 0); | |
| 128 registry->RegisterIntegerPref(prefs::kStabilityChildProcessCrashCount, 0); | |
| 129 registry->RegisterInt64Pref(prefs::kUninstallMetricsPageLoadCount, 0); | |
| 130 } | |
| 131 | |
| 112 void ChromeStabilityMetricsProvider::Observe( | 132 void ChromeStabilityMetricsProvider::Observe( |
| 113 int type, | 133 int type, |
| 114 const content::NotificationSource& source, | 134 const content::NotificationSource& source, |
| 115 const content::NotificationDetails& details) { | 135 const content::NotificationDetails& details) { |
| 116 switch (type) { | 136 switch (type) { |
| 117 case content::NOTIFICATION_LOAD_START: { | 137 case content::NOTIFICATION_LOAD_START: { |
| 118 content::NavigationController* controller = | 138 content::NavigationController* controller = |
| 119 content::Source<content::NavigationController>(source).ptr(); | 139 content::Source<content::NavigationController>(source).ptr(); |
| 120 content::WebContents* web_contents = controller->GetWebContents(); | 140 content::WebContents* web_contents = controller->GetWebContents(); |
| 121 LogLoadStarted(web_contents); | 141 LogLoadStarted(web_contents); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 136 case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG: | 156 case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG: |
| 137 LogRendererHang(); | 157 LogRendererHang(); |
| 138 break; | 158 break; |
| 139 | 159 |
| 140 default: | 160 default: |
| 141 NOTREACHED(); | 161 NOTREACHED(); |
| 142 break; | 162 break; |
| 143 } | 163 } |
| 144 } | 164 } |
| 145 | 165 |
| 166 void ChromeStabilityMetricsProvider::BrowserChildProcessCrashed( | |
| 167 const content::ChildProcessData& data) { | |
| 168 #if defined(ENABLE_PLUGINS) | |
| 169 // Exclude plugin crashes from the count below because we report them via | |
| 170 // a separate UMA metric. | |
| 171 if (PluginMetricsProvider::IsPluginProcess(data.process_type)) | |
| 172 return; | |
| 173 #endif | |
| 174 | |
| 175 IncrementPrefValue(prefs::kStabilityChildProcessCrashCount); | |
| 176 } | |
| 177 | |
| 146 void ChromeStabilityMetricsProvider::LogLoadStarted( | 178 void ChromeStabilityMetricsProvider::LogLoadStarted( |
| 147 content::WebContents* web_contents) { | 179 content::WebContents* web_contents) { |
| 148 content::RecordAction(base::UserMetricsAction("PageLoad")); | 180 content::RecordAction(base::UserMetricsAction("PageLoad")); |
| 149 HISTOGRAM_ENUMERATION("Chrome.UmaPageloadCounter", 1, 2); | 181 HISTOGRAM_ENUMERATION("Chrome.UmaPageloadCounter", 1, 2); |
| 150 IncrementPrefValue(prefs::kStabilityPageLoadCount); | 182 IncrementPrefValue(prefs::kStabilityPageLoadCount); |
| 151 IncrementLongPrefsValue(prefs::kUninstallMetricsPageLoadCount); | 183 IncrementLongPrefsValue(prefs::kUninstallMetricsPageLoadCount); |
| 152 // We need to save the prefs, as page load count is a critical stat, and it | 184 // We need to save the prefs, as page load count is a critical stat, and it |
| 153 // might be lost due to a crash :-(. | 185 // might be lost due to a crash :-(. |
| 154 } | 186 } |
| 155 | 187 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 181 was_extension_process ? 2 : 1); | 213 was_extension_process ? 2 : 1); |
| 182 } else if (status == base::TERMINATION_STATUS_STILL_RUNNING) { | 214 } else if (status == base::TERMINATION_STATUS_STILL_RUNNING) { |
| 183 UMA_HISTOGRAM_PERCENTAGE("BrowserRenderProcessHost.DisconnectedAlive", | 215 UMA_HISTOGRAM_PERCENTAGE("BrowserRenderProcessHost.DisconnectedAlive", |
| 184 was_extension_process ? 2 : 1); | 216 was_extension_process ? 2 : 1); |
| 185 } | 217 } |
| 186 } | 218 } |
| 187 | 219 |
| 188 void ChromeStabilityMetricsProvider::LogRendererHang() { | 220 void ChromeStabilityMetricsProvider::LogRendererHang() { |
| 189 IncrementPrefValue(prefs::kStabilityRendererHangCount); | 221 IncrementPrefValue(prefs::kStabilityRendererHangCount); |
| 190 } | 222 } |
| OLD | NEW |