| 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_registry_simple.h" |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "chrome/browser/browser_process.h" | |
| 15 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/common/chrome_constants.h" | 15 #include "chrome/common/chrome_constants.h" |
| 17 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 18 #include "components/metrics/proto/system_profile.pb.h" | 17 #include "components/metrics/proto/system_profile.pb.h" |
| 19 #include "content/public/browser/child_process_data.h" | 18 #include "content/public/browser/child_process_data.h" |
| 20 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
| 22 #include "content/public/browser/user_metrics.h" | 21 #include "content/public/browser/user_metrics.h" |
| 23 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 24 | 23 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 35 #include "chrome/installer/util/install_util.h" | 34 #include "chrome/installer/util/install_util.h" |
| 36 #include "components/browser_watcher/crash_reporting_metrics_win.h" | 35 #include "components/browser_watcher/crash_reporting_metrics_win.h" |
| 37 #endif | 36 #endif |
| 38 | 37 |
| 39 #if defined(OS_CHROMEOS) | 38 #if defined(OS_CHROMEOS) |
| 40 #include "chrome/browser/memory/system_memory_stats_recorder.h" | 39 #include "chrome/browser/memory/system_memory_stats_recorder.h" |
| 41 #endif | 40 #endif |
| 42 | 41 |
| 43 namespace { | 42 namespace { |
| 44 | 43 |
| 45 void IncrementPrefValue(const char* path) { | |
| 46 PrefService* pref = g_browser_process->local_state(); | |
| 47 DCHECK(pref); | |
| 48 int value = pref->GetInteger(path); | |
| 49 pref->SetInteger(path, value + 1); | |
| 50 } | |
| 51 | |
| 52 void IncrementLongPrefsValue(const char* path) { | |
| 53 PrefService* pref = g_browser_process->local_state(); | |
| 54 DCHECK(pref); | |
| 55 int64 value = pref->GetInt64(path); | |
| 56 pref->SetInt64(path, value + 1); | |
| 57 } | |
| 58 | |
| 59 // Converts an exit code into something that can be inserted into our | 44 // Converts an exit code into something that can be inserted into our |
| 60 // histograms (which expect non-negative numbers less than MAX_INT). | 45 // histograms (which expect non-negative numbers less than MAX_INT). |
| 61 int MapCrashExitCodeForHistogram(int exit_code) { | 46 int MapCrashExitCodeForHistogram(int exit_code) { |
| 62 #if defined(OS_WIN) | 47 #if defined(OS_WIN) |
| 63 // Since |abs(STATUS_GUARD_PAGE_VIOLATION) == MAX_INT| it causes problems in | 48 // Since |abs(STATUS_GUARD_PAGE_VIOLATION) == MAX_INT| it causes problems in |
| 64 // histograms.cc. Solve this by remapping it to a smaller value, which | 49 // histograms.cc. Solve this by remapping it to a smaller value, which |
| 65 // hopefully doesn't conflict with other codes. | 50 // hopefully doesn't conflict with other codes. |
| 66 if (exit_code == STATUS_GUARD_PAGE_VIOLATION) | 51 if (exit_code == STATUS_GUARD_PAGE_VIOLATION) |
| 67 return 0x1FCF7EC3; // Randomly picked number. | 52 return 0x1FCF7EC3; // Randomly picked number. |
| 68 #endif | 53 #endif |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 98 } |
| 114 #endif // defined(OS_WIN) | 99 #endif // defined(OS_WIN) |
| 115 | 100 |
| 116 void RecordChildKills(bool was_extension_process) { | 101 void RecordChildKills(bool was_extension_process) { |
| 117 UMA_HISTOGRAM_PERCENTAGE("BrowserRenderProcessHost.ChildKills", | 102 UMA_HISTOGRAM_PERCENTAGE("BrowserRenderProcessHost.ChildKills", |
| 118 was_extension_process ? 2 : 1); | 103 was_extension_process ? 2 : 1); |
| 119 } | 104 } |
| 120 | 105 |
| 121 } // namespace | 106 } // namespace |
| 122 | 107 |
| 123 ChromeStabilityMetricsProvider::ChromeStabilityMetricsProvider() { | 108 ChromeStabilityMetricsProvider::ChromeStabilityMetricsProvider( |
| 109 PrefService* local_state) |
| 110 : local_state_(local_state) { |
| 111 DCHECK(local_state_); |
| 124 BrowserChildProcessObserver::Add(this); | 112 BrowserChildProcessObserver::Add(this); |
| 125 } | 113 } |
| 126 | 114 |
| 127 ChromeStabilityMetricsProvider::~ChromeStabilityMetricsProvider() { | 115 ChromeStabilityMetricsProvider::~ChromeStabilityMetricsProvider() { |
| 128 BrowserChildProcessObserver::Remove(this); | 116 BrowserChildProcessObserver::Remove(this); |
| 129 } | 117 } |
| 130 | 118 |
| 131 void ChromeStabilityMetricsProvider::OnRecordingEnabled() { | 119 void ChromeStabilityMetricsProvider::OnRecordingEnabled() { |
| 132 registrar_.Add(this, | 120 registrar_.Add(this, |
| 133 content::NOTIFICATION_LOAD_START, | 121 content::NOTIFICATION_LOAD_START, |
| 134 content::NotificationService::AllSources()); | 122 content::NotificationService::AllSources()); |
| 135 registrar_.Add(this, | 123 registrar_.Add(this, |
| 136 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 124 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 137 content::NotificationService::AllSources()); | 125 content::NotificationService::AllSources()); |
| 138 registrar_.Add(this, | 126 registrar_.Add(this, |
| 139 content::NOTIFICATION_RENDER_WIDGET_HOST_HANG, | 127 content::NOTIFICATION_RENDER_WIDGET_HOST_HANG, |
| 140 content::NotificationService::AllSources()); | 128 content::NotificationService::AllSources()); |
| 141 } | 129 } |
| 142 | 130 |
| 143 void ChromeStabilityMetricsProvider::OnRecordingDisabled() { | 131 void ChromeStabilityMetricsProvider::OnRecordingDisabled() { |
| 144 registrar_.RemoveAll(); | 132 registrar_.RemoveAll(); |
| 145 } | 133 } |
| 146 | 134 |
| 147 void ChromeStabilityMetricsProvider::ProvideStabilityMetrics( | 135 void ChromeStabilityMetricsProvider::ProvideStabilityMetrics( |
| 148 metrics::SystemProfileProto* system_profile_proto) { | 136 metrics::SystemProfileProto* system_profile_proto) { |
| 149 PrefService* pref = g_browser_process->local_state(); | |
| 150 metrics::SystemProfileProto_Stability* stability_proto = | 137 metrics::SystemProfileProto_Stability* stability_proto = |
| 151 system_profile_proto->mutable_stability(); | 138 system_profile_proto->mutable_stability(); |
| 152 | 139 |
| 153 int count = pref->GetInteger(prefs::kStabilityPageLoadCount); | 140 int count = local_state_->GetInteger(prefs::kStabilityPageLoadCount); |
| 154 if (count) { | 141 if (count) { |
| 155 stability_proto->set_page_load_count(count); | 142 stability_proto->set_page_load_count(count); |
| 156 pref->SetInteger(prefs::kStabilityPageLoadCount, 0); | 143 local_state_->SetInteger(prefs::kStabilityPageLoadCount, 0); |
| 157 } | 144 } |
| 158 | 145 |
| 159 count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount); | 146 count = local_state_->GetInteger(prefs::kStabilityChildProcessCrashCount); |
| 160 if (count) { | 147 if (count) { |
| 161 stability_proto->set_child_process_crash_count(count); | 148 stability_proto->set_child_process_crash_count(count); |
| 162 pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0); | 149 local_state_->SetInteger(prefs::kStabilityChildProcessCrashCount, 0); |
| 163 } | 150 } |
| 164 | 151 |
| 165 count = pref->GetInteger(prefs::kStabilityRendererCrashCount); | 152 count = local_state_->GetInteger(prefs::kStabilityRendererCrashCount); |
| 166 if (count) { | 153 if (count) { |
| 167 stability_proto->set_renderer_crash_count(count); | 154 stability_proto->set_renderer_crash_count(count); |
| 168 pref->SetInteger(prefs::kStabilityRendererCrashCount, 0); | 155 local_state_->SetInteger(prefs::kStabilityRendererCrashCount, 0); |
| 169 } | 156 } |
| 170 | 157 |
| 171 count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount); | 158 count = |
| 159 local_state_->GetInteger(prefs::kStabilityExtensionRendererCrashCount); |
| 172 if (count) { | 160 if (count) { |
| 173 stability_proto->set_extension_renderer_crash_count(count); | 161 stability_proto->set_extension_renderer_crash_count(count); |
| 174 pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0); | 162 local_state_->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0); |
| 175 } | 163 } |
| 176 | 164 |
| 177 count = pref->GetInteger(prefs::kStabilityRendererHangCount); | 165 count = local_state_->GetInteger(prefs::kStabilityRendererHangCount); |
| 178 if (count) { | 166 if (count) { |
| 179 stability_proto->set_renderer_hang_count(count); | 167 stability_proto->set_renderer_hang_count(count); |
| 180 pref->SetInteger(prefs::kStabilityRendererHangCount, 0); | 168 local_state_->SetInteger(prefs::kStabilityRendererHangCount, 0); |
| 181 } | 169 } |
| 182 | 170 |
| 183 #if defined(OS_WIN) | 171 #if defined(OS_WIN) |
| 184 CountBrowserCrashDumpAttempts(); | 172 CountBrowserCrashDumpAttempts(); |
| 185 #endif // defined(OS_WIN) | 173 #endif // defined(OS_WIN) |
| 186 } | 174 } |
| 187 | 175 |
| 188 void ChromeStabilityMetricsProvider::ClearSavedStabilityMetrics() { | 176 void ChromeStabilityMetricsProvider::ClearSavedStabilityMetrics() { |
| 189 PrefService* local_state = g_browser_process->local_state(); | |
| 190 | |
| 191 // Clear all the prefs used in this class in UMA reports (which doesn't | 177 // Clear all the prefs used in this class in UMA reports (which doesn't |
| 192 // include |kUninstallMetricsPageLoadCount| as it's not sent up by UMA). | 178 // include |kUninstallMetricsPageLoadCount| as it's not sent up by UMA). |
| 193 local_state->SetInteger(prefs::kStabilityChildProcessCrashCount, 0); | 179 local_state_->SetInteger(prefs::kStabilityChildProcessCrashCount, 0); |
| 194 local_state->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0); | 180 local_state_->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0); |
| 195 local_state->SetInteger(prefs::kStabilityPageLoadCount, 0); | 181 local_state_->SetInteger(prefs::kStabilityPageLoadCount, 0); |
| 196 local_state->SetInteger(prefs::kStabilityRendererCrashCount, 0); | 182 local_state_->SetInteger(prefs::kStabilityRendererCrashCount, 0); |
| 197 local_state->SetInteger(prefs::kStabilityRendererHangCount, 0); | 183 local_state_->SetInteger(prefs::kStabilityRendererHangCount, 0); |
| 198 } | 184 } |
| 199 | 185 |
| 200 // static | 186 // static |
| 201 void ChromeStabilityMetricsProvider::RegisterPrefs( | 187 void ChromeStabilityMetricsProvider::RegisterPrefs( |
| 202 PrefRegistrySimple* registry) { | 188 PrefRegistrySimple* registry) { |
| 203 registry->RegisterIntegerPref(prefs::kStabilityChildProcessCrashCount, 0); | 189 registry->RegisterIntegerPref(prefs::kStabilityChildProcessCrashCount, 0); |
| 204 registry->RegisterIntegerPref(prefs::kStabilityExtensionRendererCrashCount, | 190 registry->RegisterIntegerPref(prefs::kStabilityExtensionRendererCrashCount, |
| 205 0); | 191 0); |
| 206 registry->RegisterIntegerPref(prefs::kStabilityPageLoadCount, 0); | 192 registry->RegisterIntegerPref(prefs::kStabilityPageLoadCount, 0); |
| 207 registry->RegisterIntegerPref(prefs::kStabilityRendererCrashCount, 0); | 193 registry->RegisterIntegerPref(prefs::kStabilityRendererCrashCount, 0); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 was_extension_process | 292 was_extension_process |
| 307 ? memory::RECORD_MEMORY_STATS_EXTENSIONS_OOM_KILLED | 293 ? memory::RECORD_MEMORY_STATS_EXTENSIONS_OOM_KILLED |
| 308 : memory::RECORD_MEMORY_STATS_CONTENTS_OOM_KILLED); | 294 : memory::RECORD_MEMORY_STATS_CONTENTS_OOM_KILLED); |
| 309 #endif | 295 #endif |
| 310 } else if (status == base::TERMINATION_STATUS_STILL_RUNNING) { | 296 } else if (status == base::TERMINATION_STATUS_STILL_RUNNING) { |
| 311 UMA_HISTOGRAM_PERCENTAGE("BrowserRenderProcessHost.DisconnectedAlive", | 297 UMA_HISTOGRAM_PERCENTAGE("BrowserRenderProcessHost.DisconnectedAlive", |
| 312 was_extension_process ? 2 : 1); | 298 was_extension_process ? 2 : 1); |
| 313 } | 299 } |
| 314 } | 300 } |
| 315 | 301 |
| 302 void ChromeStabilityMetricsProvider::IncrementPrefValue(const char* path) { |
| 303 int value = local_state_->GetInteger(path); |
| 304 local_state_->SetInteger(path, value + 1); |
| 305 } |
| 306 |
| 307 void ChromeStabilityMetricsProvider::IncrementLongPrefsValue(const char* path) { |
| 308 int64 value = local_state_->GetInt64(path); |
| 309 local_state_->SetInt64(path, value + 1); |
| 310 } |
| 311 |
| 316 void ChromeStabilityMetricsProvider::LogRendererHang() { | 312 void ChromeStabilityMetricsProvider::LogRendererHang() { |
| 317 IncrementPrefValue(prefs::kStabilityRendererHangCount); | 313 IncrementPrefValue(prefs::kStabilityRendererHangCount); |
| 318 } | 314 } |
| OLD | NEW |