diff options
author | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-27 02:35:44 +0000 |
---|---|---|
committer | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-27 02:35:44 +0000 |
commit | e182be01e1e6f8db4644ed4e8fc28b2cf8d981f4 (patch) | |
tree | 79577e39b5d98372b99a20112585df522f78b88d | |
parent | 863f70aa8b46421f442a089b21e1bd97a446785c (diff) | |
download | chromium_src-e182be01e1e6f8db4644ed4e8fc28b2cf8d981f4.zip chromium_src-e182be01e1e6f8db4644ed4e8fc28b2cf8d981f4.tar.gz chromium_src-e182be01e1e6f8db4644ed4e8fc28b2cf8d981f4.tar.bz2 |
Separate chrome/common/metrics/metrics_helpers.{h,cc} into files for the constituent classes.
BUG=none
TEST=none (code cleanup)
TBR=ananta@chromium.org
Review URL: http://codereview.chromium.org/9159004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119345 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/metrics/metrics_log.h | 2 | ||||
-rw-r--r-- | chrome/browser/metrics/metrics_service.h | 2 | ||||
-rw-r--r-- | chrome/chrome_common.gypi | 8 | ||||
-rw-r--r-- | chrome/common/metrics/histogram_sender.cc | 95 | ||||
-rw-r--r-- | chrome/common/metrics/histogram_sender.h | 67 | ||||
-rw-r--r-- | chrome/common/metrics/metrics_log_base.cc (renamed from chrome/common/metrics/metrics_helpers.cc) | 128 | ||||
-rw-r--r-- | chrome/common/metrics/metrics_log_base.h (renamed from chrome/common/metrics/metrics_helpers.h) | 91 | ||||
-rw-r--r-- | chrome/common/metrics/metrics_log_manager.cc | 2 | ||||
-rw-r--r-- | chrome/common/metrics/metrics_log_manager_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/common/metrics/metrics_service_base.cc | 43 | ||||
-rw-r--r-- | chrome/common/metrics/metrics_service_base.h | 41 | ||||
-rw-r--r-- | chrome/renderer/renderer_histogram_snapshots.h | 2 | ||||
-rw-r--r-- | chrome_frame/metrics_service.cc | 1 | ||||
-rw-r--r-- | chrome_frame/metrics_service.h | 2 |
14 files changed, 265 insertions, 221 deletions
diff --git a/chrome/browser/metrics/metrics_log.h b/chrome/browser/metrics/metrics_log.h index 6a75b67..a5a3504 100644 --- a/chrome/browser/metrics/metrics_log.h +++ b/chrome/browser/metrics/metrics_log.h @@ -13,7 +13,7 @@ #include <vector> #include "base/basictypes.h" -#include "chrome/common/metrics/metrics_helpers.h" +#include "chrome/common/metrics/metrics_log_base.h" struct AutocompleteLog; class PrefService; diff --git a/chrome/browser/metrics/metrics_service.h b/chrome/browser/metrics/metrics_service.h index cb60f65..c740191 100644 --- a/chrome/browser/metrics/metrics_service.h +++ b/chrome/browser/metrics/metrics_service.h @@ -20,7 +20,7 @@ #include "base/memory/weak_ptr.h" #include "base/process_util.h" #include "chrome/browser/io_thread.h" -#include "chrome/common/metrics/metrics_helpers.h" +#include "chrome/common/metrics/metrics_service_base.h" #include "content/public/common/process_type.h" #include "content/public/common/url_fetcher_delegate.h" #include "content/public/browser/notification_observer.h" diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index 63d0b1e..8587b3f 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -182,10 +182,14 @@ 'common/mac/objc_method_swizzle.mm', 'common/mac/objc_zombie.h', 'common/mac/objc_zombie.mm', - 'common/metrics/metrics_helpers.cc', - 'common/metrics/metrics_helpers.h', + 'common/metrics/histogram_sender.cc', + 'common/metrics/histogram_sender.h', + 'common/metrics/metrics_log_base.cc', + 'common/metrics/metrics_log_base.h', 'common/metrics/metrics_log_manager.cc', 'common/metrics/metrics_log_manager.h', + 'common/metrics/metrics_service_base.cc', + 'common/metrics/metrics_service_base.h', 'common/multi_process_lock.h', 'common/multi_process_lock_linux.cc', 'common/multi_process_lock_mac.cc', diff --git a/chrome/common/metrics/histogram_sender.cc b/chrome/common/metrics/histogram_sender.cc new file mode 100644 index 0000000..dfb513a --- /dev/null +++ b/chrome/common/metrics/histogram_sender.cc @@ -0,0 +1,95 @@ +// Copyright (c) 2012 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/common/metrics/histogram_sender.h" + +using base::Histogram; +using base::StatisticsRecorder; + +HistogramSender::HistogramSender() {} + +HistogramSender::~HistogramSender() {} + +void HistogramSender::TransmitAllHistograms(Histogram::Flags flag_to_set, + bool send_only_uma) { + StatisticsRecorder::Histograms histograms; + StatisticsRecorder::GetHistograms(&histograms); + for (StatisticsRecorder::Histograms::const_iterator it = histograms.begin(); + histograms.end() != it; + ++it) { + (*it)->SetFlags(flag_to_set); + if (send_only_uma && + 0 == ((*it)->flags() & Histogram::kUmaTargetedHistogramFlag)) + continue; + TransmitHistogram(**it); + } +} + +void HistogramSender::TransmitHistogram(const Histogram& histogram) { + // Get up-to-date snapshot of sample stats. + Histogram::SampleSet snapshot; + histogram.SnapshotSample(&snapshot); + const std::string& histogram_name = histogram.histogram_name(); + + int corruption = histogram.FindCorruption(snapshot); + + // Crash if we detect that our histograms have been overwritten. This may be + // a fair distance from the memory smasher, but we hope to correlate these + // crashes with other events, such as plugins, or usage patterns, etc. + if (Histogram::BUCKET_ORDER_ERROR & corruption) { + // The checksum should have caught this, so crash separately if it didn't. + CHECK_NE(0, Histogram::RANGE_CHECKSUM_ERROR & corruption); + CHECK(false); // Crash for the bucket order corruption. + } + // Checksum corruption might not have caused order corruption. + CHECK_EQ(0, Histogram::RANGE_CHECKSUM_ERROR & corruption); + + if (corruption) { + NOTREACHED(); + InconsistencyDetected(corruption); + // Don't send corrupt data to metrics survices. + if (NULL == inconsistencies_.get()) + inconsistencies_.reset(new ProblemMap); + int old_corruption = (*inconsistencies_)[histogram_name]; + if (old_corruption == (corruption | old_corruption)) + return; // We've already seen this corruption for this histogram. + (*inconsistencies_)[histogram_name] |= corruption; + UniqueInconsistencyDetected(corruption); + return; + } + + // Find the already sent stats, or create an empty set. Remove from our + // snapshot anything that we've already sent. + LoggedSampleMap::iterator it = logged_samples_.find(histogram_name); + Histogram::SampleSet* already_logged; + if (logged_samples_.end() == it) { + // Add new entry + already_logged = &logged_samples_[histogram.histogram_name()]; + already_logged->Resize(histogram); // Complete initialization. + } else { + already_logged = &(it->second); + int64 discrepancy(already_logged->TotalCount() - + already_logged->redundant_count()); + if (discrepancy) { + NOTREACHED(); // Already_logged has become corrupt. + int problem = static_cast<int>(discrepancy); + if (problem != discrepancy) + problem = INT_MAX; + SnapshotProblemResolved(problem); + // With no valid baseline, we'll act like we've sent everything in our + // snapshot. + already_logged->Subtract(*already_logged); + already_logged->Add(snapshot); + } + // Deduct any stats we've already logged from our snapshot. + snapshot.Subtract(*already_logged); + } + + // Snapshot now contains only a delta to what we've already_logged. + if (snapshot.redundant_count() > 0) { + TransmitHistogramDelta(histogram, snapshot); + // Add new data into our running total. + already_logged->Add(snapshot); + } +} diff --git a/chrome/common/metrics/histogram_sender.h b/chrome/common/metrics/histogram_sender.h new file mode 100644 index 0000000..ac4af67 --- /dev/null +++ b/chrome/common/metrics/histogram_sender.h @@ -0,0 +1,67 @@ +// Copyright (c) 2012 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. + +#ifndef CHROME_COMMON_METRICS_HISTOGRAM_SENDER_H_ +#define CHROME_COMMON_METRICS_HISTOGRAM_SENDER_H_ +#pragma once + +#include <map> +#include <string> + +#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" +#include "base/metrics/histogram.h" + +// HistogramSender handles the logistics of gathering up available histograms +// for transmission (such as from renderer to browser, or from browser to UMA +// upload). It has several pure virtual functions that are replaced in +// derived classes to allow the exact lower level transmission mechanism, +// or error report mechanism, to be replaced. Since histograms can sit in +// memory for an extended period of time, and are vulnerable to memory +// corruption, this class also validates as much rendundancy as it can before +// calling for the marginal change (a.k.a., delta) in a histogram to be sent +// onward. +class HistogramSender { + protected: + HistogramSender(); + virtual ~HistogramSender(); + + // Snapshot all histograms, and transmit the delta. + // The arguments allow a derived class to select only a subset for + // transmission, or to set a flag in each transmitted histogram. + void TransmitAllHistograms(base::Histogram::Flags flags_to_set, + bool send_only_uma); + + // Send the histograms onward, as defined in a derived class. + // This is only called with a delta, listing samples that have not previously + // been transmitted. + virtual void TransmitHistogramDelta( + const base::Histogram& histogram, + const base::Histogram::SampleSet& snapshot) = 0; + + // Record various errors found during attempts to send histograms. + virtual void InconsistencyDetected(int problem) = 0; + virtual void UniqueInconsistencyDetected(int problem) = 0; + virtual void SnapshotProblemResolved(int amount) = 0; + + private: + // Maintain a map of histogram names to the sample stats we've sent. + typedef std::map<std::string, base::Histogram::SampleSet> LoggedSampleMap; + // List of histograms names, and their encontered corruptions. + typedef std::map<std::string, int> ProblemMap; + + // Snapshot this histogram, and transmit the delta. + void TransmitHistogram(const base::Histogram& histogram); + + // For histograms, record what we've already transmitted (as a sample for each + // histogram) so that we can send only the delta with the next log. + LoggedSampleMap logged_samples_; + + // List of histograms found corrupt to be corrupt, and their problems. + scoped_ptr<ProblemMap> inconsistencies_; + + DISALLOW_COPY_AND_ASSIGN(HistogramSender); +}; + +#endif // CHROME_COMMON_METRICS_HISTOGRAM_SENDER_H_ diff --git a/chrome/common/metrics/metrics_helpers.cc b/chrome/common/metrics/metrics_log_base.cc index 01da129..b2c42f6 100644 --- a/chrome/common/metrics/metrics_helpers.cc +++ b/chrome/common/metrics/metrics_log_base.cc @@ -2,27 +2,22 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/common/metrics/metrics_helpers.h" +#include "chrome/common/metrics/metrics_log_base.h" #include "base/base64.h" #include "base/basictypes.h" -#include "base/file_util.h" #include "base/md5.h" #include "base/perftimer.h" #include "base/string_number_conversions.h" #include "base/sys_info.h" #include "base/third_party/nspr/prtime.h" -#include "base/time.h" #include "base/utf_string_conversions.h" #include "chrome/common/logging_chrome.h" -#include "chrome/common/metrics/metrics_log_manager.h" -#include "googleurl/src/gurl.h" #include "libxml/xmlwriter.h" #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name) using base::Histogram; -using base::StatisticsRecorder; using base::Time; using base::TimeDelta; @@ -407,124 +402,3 @@ void MetricsLogBase::RecordHistogramDelta( } } } - - -// MetricsServiceBase -MetricsServiceBase::MetricsServiceBase() { -} - -MetricsServiceBase::~MetricsServiceBase() { -} - -void MetricsServiceBase::RecordCurrentHistograms() { - DCHECK(log_manager_.current_log()); - TransmitAllHistograms(base::Histogram::kNoFlags, true); -} - -void MetricsServiceBase::TransmitHistogramDelta( - const base::Histogram& histogram, - const base::Histogram::SampleSet& snapshot) { - log_manager_.current_log()->RecordHistogramDelta(histogram, snapshot); -} - -void MetricsServiceBase::InconsistencyDetected(int problem) { - UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowser", - problem, Histogram::NEVER_EXCEEDED_VALUE); -} - -void MetricsServiceBase::UniqueInconsistencyDetected(int problem) { - UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowserUnique", - problem, Histogram::NEVER_EXCEEDED_VALUE); -} - -void MetricsServiceBase::SnapshotProblemResolved(int amount) { - UMA_HISTOGRAM_COUNTS("Histogram.InconsistentSnapshotBrowser", - std::abs(amount)); -} - -HistogramSender::HistogramSender() {} - -HistogramSender::~HistogramSender() {} - -void HistogramSender::TransmitAllHistograms(Histogram::Flags flag_to_set, - bool send_only_uma) { - StatisticsRecorder::Histograms histograms; - StatisticsRecorder::GetHistograms(&histograms); - for (StatisticsRecorder::Histograms::const_iterator it = histograms.begin(); - histograms.end() != it; - ++it) { - (*it)->SetFlags(flag_to_set); - if (send_only_uma && - 0 == ((*it)->flags() & Histogram::kUmaTargetedHistogramFlag)) - continue; - TransmitHistogram(**it); - } -} - -void HistogramSender::TransmitHistogram(const Histogram& histogram) { - // Get up-to-date snapshot of sample stats. - Histogram::SampleSet snapshot; - histogram.SnapshotSample(&snapshot); - const std::string& histogram_name = histogram.histogram_name(); - - int corruption = histogram.FindCorruption(snapshot); - - // Crash if we detect that our histograms have been overwritten. This may be - // a fair distance from the memory smasher, but we hope to correlate these - // crashes with other events, such as plugins, or usage patterns, etc. - if (Histogram::BUCKET_ORDER_ERROR & corruption) { - // The checksum should have caught this, so crash separately if it didn't. - CHECK_NE(0, Histogram::RANGE_CHECKSUM_ERROR & corruption); - CHECK(false); // Crash for the bucket order corruption. - } - // Checksum corruption might not have caused order corruption. - CHECK_EQ(0, Histogram::RANGE_CHECKSUM_ERROR & corruption); - - if (corruption) { - NOTREACHED(); - InconsistencyDetected(corruption); - // Don't send corrupt data to metrics survices. - if (NULL == inconsistencies_.get()) - inconsistencies_.reset(new ProblemMap); - int old_corruption = (*inconsistencies_)[histogram_name]; - if (old_corruption == (corruption | old_corruption)) - return; // We've already seen this corruption for this histogram. - (*inconsistencies_)[histogram_name] |= corruption; - UniqueInconsistencyDetected(corruption); - return; - } - - // Find the already sent stats, or create an empty set. Remove from our - // snapshot anything that we've already sent. - LoggedSampleMap::iterator it = logged_samples_.find(histogram_name); - Histogram::SampleSet* already_logged; - if (logged_samples_.end() == it) { - // Add new entry - already_logged = &logged_samples_[histogram.histogram_name()]; - already_logged->Resize(histogram); // Complete initialization. - } else { - already_logged = &(it->second); - int64 discrepancy(already_logged->TotalCount() - - already_logged->redundant_count()); - if (discrepancy) { - NOTREACHED(); // Already_logged has become corrupt. - int problem = static_cast<int>(discrepancy); - if (problem != discrepancy) - problem = INT_MAX; - SnapshotProblemResolved(problem); - // With no valid baseline, we'll act like we've sent everything in our - // snapshot. - already_logged->Subtract(*already_logged); - already_logged->Add(snapshot); - } - // Deduct any stats we've already logged from our snapshot. - snapshot.Subtract(*already_logged); - } - - // Snapshot now contains only a delta to what we've already_logged. - if (snapshot.redundant_count() > 0) { - TransmitHistogramDelta(histogram, snapshot); - // Add new data into our running total. - already_logged->Add(snapshot); - } -} diff --git a/chrome/common/metrics/metrics_helpers.h b/chrome/common/metrics/metrics_log_base.h index 1938bb8..62981be 100644 --- a/chrome/common/metrics/metrics_helpers.h +++ b/chrome/common/metrics/metrics_log_base.h @@ -5,18 +5,15 @@ // This file defines a set of user experience metrics data recorded by // the MetricsService. This is the unit of data that is sent to the server. -#ifndef CHROME_COMMON_METRICS_METRICS_HELPERS_H_ -#define CHROME_COMMON_METRICS_METRICS_HELPERS_H_ +#ifndef CHROME_COMMON_METRICS_METRICS_LOG_BASE_H_ +#define CHROME_COMMON_METRICS_METRICS_LOG_BASE_H_ #pragma once -#include <map> #include <string> #include "base/basictypes.h" -#include "base/memory/scoped_ptr.h" #include "base/metrics/histogram.h" #include "base/time.h" -#include "chrome/common/metrics/metrics_log_manager.h" #include "content/public/common/page_transition_types.h" class GURL; @@ -27,7 +24,8 @@ class MetricsLogBase { // Creates a new metrics log // client_id is the identifier for this profile on this installation // session_id is an integer that's incremented on each application launch - MetricsLogBase(const std::string& client_id, int session_id, + MetricsLogBase(const std::string& client_id, + int session_id, const std::string& version_string); virtual ~MetricsLogBase(); @@ -162,83 +160,4 @@ class MetricsLogBase { DISALLOW_COPY_AND_ASSIGN(MetricsLogBase); }; -// HistogramSender handles the logistics of gathering up available histograms -// for transmission (such as from renderer to browser, or from browser to UMA -// upload). It has several pure virtual functions that are replaced in -// derived classes to allow the exact lower level transmission mechanism, -// or error report mechanism, to be replaced. Since histograms can sit in -// memory for an extended period of time, and are vulnerable to memory -// corruption, this class also validates as much rendundancy as it can before -// calling for the marginal change (a.k.a., delta) in a histogram to be sent -// onward. -class HistogramSender { - protected: - HistogramSender(); - virtual ~HistogramSender(); - - // Snapshot all histograms, and transmit the delta. - // The arguments allow a derived class to select only a subset for - // transmission, or to set a flag in each transmitted histogram. - void TransmitAllHistograms(base::Histogram::Flags flags_to_set, - bool send_only_uma); - - // Send the histograms onward, as defined in a derived class. - // This is only called with a delta, listing samples that have not previously - // been transmitted. - virtual void TransmitHistogramDelta( - const base::Histogram& histogram, - const base::Histogram::SampleSet& snapshot) = 0; - - // Record various errors found during attempts to send histograms. - virtual void InconsistencyDetected(int problem) = 0; - virtual void UniqueInconsistencyDetected(int problem) = 0; - virtual void SnapshotProblemResolved(int amount) = 0; - - private: - // Maintain a map of histogram names to the sample stats we've sent. - typedef std::map<std::string, base::Histogram::SampleSet> LoggedSampleMap; - // List of histograms names, and their encontered corruptions. - typedef std::map<std::string, int> ProblemMap; - - // Snapshot this histogram, and transmit the delta. - void TransmitHistogram(const base::Histogram& histogram); - - // For histograms, record what we've already transmitted (as a sample for each - // histogram) so that we can send only the delta with the next log. - LoggedSampleMap logged_samples_; - - // List of histograms found corrupt to be corrupt, and their problems. - scoped_ptr<ProblemMap> inconsistencies_; - - DISALLOW_COPY_AND_ASSIGN(HistogramSender); -}; - -// This class provides base functionality for logging metrics data. -// TODO(ananta) -// Factor out more common code from chrome and chrome frame metrics service -// into this class. -class MetricsServiceBase : public HistogramSender { - protected: - MetricsServiceBase(); - virtual ~MetricsServiceBase(); - - // Record complete list of histograms into the current log. - // Called when we close a log. - void RecordCurrentHistograms(); - - // Manager for the various in-flight logs. - MetricsLogManager log_manager_; - - private: - // HistogramSender interface (override) methods. - virtual void TransmitHistogramDelta( - const base::Histogram& histogram, - const base::Histogram::SampleSet& snapshot) OVERRIDE; - virtual void InconsistencyDetected(int problem) OVERRIDE; - virtual void UniqueInconsistencyDetected(int problem) OVERRIDE; - virtual void SnapshotProblemResolved(int amount) OVERRIDE; - - DISALLOW_COPY_AND_ASSIGN(MetricsServiceBase); -}; - -#endif // CHROME_COMMON_METRICS_METRICS_HELPERS_H_ +#endif // CHROME_COMMON_METRICS_METRICS_LOG_BASE_H_ diff --git a/chrome/common/metrics/metrics_log_manager.cc b/chrome/common/metrics/metrics_log_manager.cc index 47278a0..32fe51c 100644 --- a/chrome/common/metrics/metrics_log_manager.cc +++ b/chrome/common/metrics/metrics_log_manager.cc @@ -12,7 +12,7 @@ #include "base/metrics/histogram.h" #include "base/string_util.h" -#include "chrome/common/metrics/metrics_helpers.h" +#include "chrome/common/metrics/metrics_log_base.h" MetricsLogManager::MetricsLogManager() : max_ongoing_log_store_size_(0) {} diff --git a/chrome/common/metrics/metrics_log_manager_unittest.cc b/chrome/common/metrics/metrics_log_manager_unittest.cc index 141925a..0373186 100644 --- a/chrome/common/metrics/metrics_log_manager_unittest.cc +++ b/chrome/common/metrics/metrics_log_manager_unittest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/common/metrics/metrics_helpers.h" +#include "chrome/common/metrics/metrics_log_base.h" #include "chrome/common/metrics/metrics_log_manager.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chrome/common/metrics/metrics_service_base.cc b/chrome/common/metrics/metrics_service_base.cc new file mode 100644 index 0000000..f6471f3 --- /dev/null +++ b/chrome/common/metrics/metrics_service_base.cc @@ -0,0 +1,43 @@ +// Copyright (c) 2012 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/common/metrics/metrics_service_base.h" + +#include <cstdlib> + +#include "chrome/common/metrics/metrics_log_base.h" + +using base::Histogram; + +MetricsServiceBase::MetricsServiceBase() { +} + +MetricsServiceBase::~MetricsServiceBase() { +} + +void MetricsServiceBase::RecordCurrentHistograms() { + DCHECK(log_manager_.current_log()); + TransmitAllHistograms(base::Histogram::kNoFlags, true); +} + +void MetricsServiceBase::TransmitHistogramDelta( + const base::Histogram& histogram, + const base::Histogram::SampleSet& snapshot) { + log_manager_.current_log()->RecordHistogramDelta(histogram, snapshot); +} + +void MetricsServiceBase::InconsistencyDetected(int problem) { + UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowser", + problem, Histogram::NEVER_EXCEEDED_VALUE); +} + +void MetricsServiceBase::UniqueInconsistencyDetected(int problem) { + UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesBrowserUnique", + problem, Histogram::NEVER_EXCEEDED_VALUE); +} + +void MetricsServiceBase::SnapshotProblemResolved(int amount) { + UMA_HISTOGRAM_COUNTS("Histogram.InconsistentSnapshotBrowser", + std::abs(amount)); +} diff --git a/chrome/common/metrics/metrics_service_base.h b/chrome/common/metrics/metrics_service_base.h new file mode 100644 index 0000000..780f8c6 --- /dev/null +++ b/chrome/common/metrics/metrics_service_base.h @@ -0,0 +1,41 @@ +// Copyright (c) 2012 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. + +#ifndef CHROME_COMMON_METRICS_METRICS_SERVICE_BASE_H_ +#define CHROME_COMMON_METRICS_METRICS_SERVICE_BASE_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/metrics/histogram.h" +#include "chrome/common/metrics/histogram_sender.h" +#include "chrome/common/metrics/metrics_log_manager.h" + +// This class provides base functionality for logging metrics data. +// TODO(ananta): Factor out more common code from chrome and chrome frame +// metrics service into this class. +class MetricsServiceBase : public HistogramSender { + protected: + MetricsServiceBase(); + virtual ~MetricsServiceBase(); + + // Record complete list of histograms into the current log. + // Called when we close a log. + void RecordCurrentHistograms(); + + // Manager for the various in-flight logs. + MetricsLogManager log_manager_; + + private: + // HistogramSender interface (override) methods. + virtual void TransmitHistogramDelta( + const base::Histogram& histogram, + const base::Histogram::SampleSet& snapshot) OVERRIDE; + virtual void InconsistencyDetected(int problem) OVERRIDE; + virtual void UniqueInconsistencyDetected(int problem) OVERRIDE; + virtual void SnapshotProblemResolved(int amount) OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(MetricsServiceBase); +}; + +#endif // CHROME_COMMON_METRICS_METRICS_SERVICE_BASE_H_ diff --git a/chrome/renderer/renderer_histogram_snapshots.h b/chrome/renderer/renderer_histogram_snapshots.h index 38b5790..d29d3c5 100644 --- a/chrome/renderer/renderer_histogram_snapshots.h +++ b/chrome/renderer/renderer_histogram_snapshots.h @@ -14,7 +14,7 @@ #include "base/memory/weak_ptr.h" #include "base/metrics/histogram.h" #include "base/process.h" -#include "chrome/common/metrics/metrics_helpers.h" +#include "chrome/common/metrics/histogram_sender.h" #include "content/public/renderer/render_process_observer.h" class RendererHistogramSnapshots : public HistogramSender, diff --git a/chrome_frame/metrics_service.cc b/chrome_frame/metrics_service.cc index 3e60fbc..01e3c50 100644 --- a/chrome_frame/metrics_service.cc +++ b/chrome_frame/metrics_service.cc @@ -57,6 +57,7 @@ #include "base/utf_string_conversions.h" #include "base/win/scoped_comptr.h" #include "chrome/common/chrome_version_info.h" +#include "chrome/common/metrics/metrics_log_base.h" #include "chrome/common/metrics/metrics_log_manager.h" #include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/google_update_settings.h" diff --git a/chrome_frame/metrics_service.h b/chrome_frame/metrics_service.h index 686474a..bcf4026 100644 --- a/chrome_frame/metrics_service.h +++ b/chrome_frame/metrics_service.h @@ -18,7 +18,7 @@ #include "base/synchronization/lock.h" #include "base/threading/platform_thread.h" #include "base/threading/thread_local.h" -#include "chrome/common/metrics/metrics_helpers.h" +#include "chrome/common/metrics/metrics_service_base.h" // TODO(ananta) // Refactor more common code from chrome/browser/metrics/metrics_service.h into |