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