diff options
author | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-11 02:23:44 +0000 |
---|---|---|
committer | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-11 02:23:44 +0000 |
commit | 897b2627d88109e5280e20b6658d702b43468617 (patch) | |
tree | 76271ef33d000294ba9ce7b6d2b6e1aec94da610 /chrome_frame/crash_metrics.cc | |
parent | 943d8120c51e2ed0146d85a15298d7fa30f316e0 (diff) | |
download | chromium_src-897b2627d88109e5280e20b6658d702b43468617.zip chromium_src-897b2627d88109e5280e20b6658d702b43468617.tar.gz chromium_src-897b2627d88109e5280e20b6658d702b43468617.tar.bz2 |
Add support for uploading UMA metrics data from ChromeFrame. Added support for tracking chrome frame crash metrics via
2 new counters which track successful navigations and crashes. These counters are persisted in the registry under
HKCU\Software\Google\ChromeFrameMetrics.
Any other histogram data like AutomationServer launch time, IE versions etc are simply dropped if IE is shutdown before
they are sent out. The metrics data is uploaded on similar lines as Chrome.
Bug=46057
Review URL: http://codereview.chromium.org/2714003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49493 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/crash_metrics.cc')
-rw-r--r-- | chrome_frame/crash_metrics.cc | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/chrome_frame/crash_metrics.cc b/chrome_frame/crash_metrics.cc new file mode 100644 index 0000000..8b1a97a --- /dev/null +++ b/chrome_frame/crash_metrics.cc @@ -0,0 +1,92 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome_frame/crash_metrics.h" + +#include "base/histogram.h" +#include "base/registry.h" +#include "chrome_frame/utils.h" + +static const wchar_t kChromeFrameMetricsKey[] = + L"Software\\Google\\ChromeFrameMetrics"; + +base::LazyInstance<CrashMetricsReporter> + g_crash_metrics_instance_(base::LINKER_INITIALIZED); + +wchar_t* CrashMetricsReporter::g_metric_names[LAST_METRIC] = { + L"navigationcount", + L"crashcount", + L"chrome_frame_navigationcount", + L"sessionid", +}; + +CrashMetricsReporter* CrashMetricsReporter::GetInstance() { + return &g_crash_metrics_instance_.Get(); +} + +bool CrashMetricsReporter::SetMetric(Metric metric, int value) { + DCHECK(metric >= NAVIGATION_COUNT && metric <= LAST_METRIC); + + RegKey metric_key; + if (metric_key.Create(HKEY_CURRENT_USER, kChromeFrameMetricsKey, + KEY_SET_VALUE)) { + if (metric_key.WriteValue(g_metric_names[metric], value)) { + return true; + } else { + DLOG(ERROR) << "Failed to read ChromeFrame metric:" + << g_metric_names[metric]; + } + } else { + DLOG(ERROR) << "Failed to create ChromeFrame metrics key"; + } + return false; +} + +int CrashMetricsReporter::GetMetric(Metric metric) { + DCHECK(metric >= NAVIGATION_COUNT && metric <= LAST_METRIC); + + int ret = 0; + RegKey metric_key; + if (metric_key.Open(HKEY_CURRENT_USER, kChromeFrameMetricsKey, + KEY_QUERY_VALUE)) { + int value = 0; + if (metric_key.ReadValueDW(g_metric_names[metric], + reinterpret_cast<DWORD*>(&value))) { + ret = value; + } + } + return ret; +} + +int CrashMetricsReporter::IncrementMetric(Metric metric) { + DCHECK(metric >= NAVIGATION_COUNT && metric <= LAST_METRIC); + int metric_value = GetMetric(metric); + metric_value++; + SetMetric(metric, metric_value); + return metric_value; +} + +void CrashMetricsReporter::RecordCrashMetrics() { + int navigation_count = GetMetric(NAVIGATION_COUNT); + if (navigation_count > 0) { + THREAD_SAFE_UMA_HISTOGRAM_COUNTS("ChromeFrame.HostNavigationCount", + navigation_count); + SetMetric(NAVIGATION_COUNT, 0); + } + + int chrome_frame_navigation_count = GetMetric(CHROME_FRAME_NAVIGATION_COUNT); + if (chrome_frame_navigation_count > 0) { + THREAD_SAFE_UMA_HISTOGRAM_COUNTS("ChromeFrame.CFNavigationCount", + chrome_frame_navigation_count); + SetMetric(CHROME_FRAME_NAVIGATION_COUNT, 0); + } + + int crash_count = GetMetric(CRASH_COUNT); + if (crash_count > 0) { + THREAD_SAFE_UMA_HISTOGRAM_COUNTS("ChromeFrame.HostCrashCount", + crash_count); + SetMetric(CRASH_COUNT, 0); + } +} + |