summaryrefslogtreecommitdiffstats
path: root/chrome/common/metrics
diff options
context:
space:
mode:
authorkaiwang@chromium.org <kaiwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-22 03:42:12 +0000
committerkaiwang@chromium.org <kaiwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-22 03:42:12 +0000
commit2f7d9cdf62cb6729838a9c67e1a6efea7c739302 (patch)
tree01b27817539910ecffacfceb0f3b27b6d7deb092 /chrome/common/metrics
parent00b8ae882e96f41c41c27d3070897f02dd75d30b (diff)
downloadchromium_src-2f7d9cdf62cb6729838a9c67e1a6efea7c739302.zip
chromium_src-2f7d9cdf62cb6729838a9c67e1a6efea7c739302.tar.gz
chromium_src-2f7d9cdf62cb6729838a9c67e1a6efea7c739302.tar.bz2
SampleSet -> HistogramSamples which can be reused by SparseHistogram
BUG=139612 Review URL: https://chromiumcodereview.appspot.com/10829466 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@158166 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/metrics')
-rw-r--r--chrome/common/metrics/metrics_log_base.cc49
-rw-r--r--chrome/common/metrics/metrics_log_base.h6
-rw-r--r--chrome/common/metrics/metrics_service_base.cc2
-rw-r--r--chrome/common/metrics/metrics_service_base.h6
4 files changed, 43 insertions, 20 deletions
diff --git a/chrome/common/metrics/metrics_log_base.cc b/chrome/common/metrics/metrics_log_base.cc
index 5b12cfd..938828f 100644
--- a/chrome/common/metrics/metrics_log_base.cc
+++ b/chrome/common/metrics/metrics_log_base.cc
@@ -7,6 +7,8 @@
#include "base/base64.h"
#include "base/basictypes.h"
#include "base/md5.h"
+#include "base/metrics/histogram_base.h"
+#include "base/metrics/histogram_samples.h"
#include "base/perftimer.h"
#include "base/string_number_conversions.h"
#include "base/sys_byteorder.h"
@@ -23,6 +25,9 @@
#define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
using base::Histogram;
+using base::HistogramBase;
+using base::HistogramSamples;
+using base::SampleCountIterator;
using base::Time;
using base::TimeDelta;
using metrics::HistogramEventProto;
@@ -449,10 +454,9 @@ void MetricsLogBase::EndElement() {
// the same infrastructure for logging StatsCounters, RatesCounters, etc.
void MetricsLogBase::RecordHistogramDelta(
const Histogram& histogram,
- const Histogram::SampleSet& snapshot) {
+ const HistogramSamples& snapshot) {
DCHECK(!locked_);
DCHECK_NE(0, snapshot.TotalCount());
- DCHECK_EQ(histogram.bucket_count(), snapshot.size());
// We will ignore the MAX_INT/infinite value in the last element of range[].
@@ -471,13 +475,17 @@ void MetricsLogBase::RecordHistogramDelta(
// TODO(jar): Remove sumsquares when protobuffer accepts this as optional.
WriteInt64Attribute("sumsquares", 0);
- for (size_t i = 0; i < histogram.bucket_count(); i++) {
- if (snapshot.counts(i)) {
- OPEN_ELEMENT_FOR_SCOPE("histogrambucket");
- WriteIntAttribute("min", histogram.ranges(i));
- WriteIntAttribute("max", histogram.ranges(i + 1));
- WriteIntAttribute("count", snapshot.counts(i));
- }
+ for (scoped_ptr<SampleCountIterator> it = snapshot.Iterator();
+ !it->Done();
+ it->Next()) {
+ OPEN_ELEMENT_FOR_SCOPE("histogrambucket");
+ HistogramBase::Sample min;
+ HistogramBase::Sample max;
+ HistogramBase::Count count;
+ it->Get(&min, &max, &count);
+ WriteIntAttribute("min", min);
+ WriteIntAttribute("max", max);
+ WriteIntAttribute("count", count);
}
// Write the protobuf version.
@@ -485,13 +493,20 @@ void MetricsLogBase::RecordHistogramDelta(
histogram_proto->set_name_hash(numeric_name_hash);
histogram_proto->set_sum(snapshot.sum());
- for (size_t i = 0; i < histogram.bucket_count(); ++i) {
- if (snapshot.counts(i)) {
- HistogramEventProto::Bucket* bucket = histogram_proto->add_bucket();
- bucket->set_min(histogram.ranges(i));
- bucket->set_max(histogram.ranges(i + 1));
- bucket->set_bucket_index(i);
- bucket->set_count(snapshot.counts(i));
- }
+ for (scoped_ptr<SampleCountIterator> it = snapshot.Iterator();
+ !it->Done();
+ it->Next()) {
+ HistogramBase::Sample min;
+ HistogramBase::Sample max;
+ HistogramBase::Count count;
+ it->Get(&min, &max, &count);
+ HistogramEventProto::Bucket* bucket = histogram_proto->add_bucket();
+ bucket->set_min(min);
+ bucket->set_max(max);
+ bucket->set_count(count);
+
+ size_t index;
+ if (it->GetBucketIndex(&index))
+ bucket->set_bucket_index(index);
}
}
diff --git a/chrome/common/metrics/metrics_log_base.h b/chrome/common/metrics/metrics_log_base.h
index 0fb43e9..b11f032 100644
--- a/chrome/common/metrics/metrics_log_base.h
+++ b/chrome/common/metrics/metrics_log_base.h
@@ -18,6 +18,10 @@
class GURL;
+namespace base {
+class HistogramSamples;
+} // namespace base
+
// This class provides base functionality for logging metrics data.
class MetricsLogBase {
public:
@@ -72,7 +76,7 @@ class MetricsLogBase {
// Record any changes in a given histogram for transmission.
void RecordHistogramDelta(const base::Histogram& histogram,
- const base::Histogram::SampleSet& snapshot);
+ const base::HistogramSamples& snapshot);
// Stop writing to this record and generate the encoded representation.
// None of the Record* methods can be called after this is called.
diff --git a/chrome/common/metrics/metrics_service_base.cc b/chrome/common/metrics/metrics_service_base.cc
index bffe971..84410c4 100644
--- a/chrome/common/metrics/metrics_service_base.cc
+++ b/chrome/common/metrics/metrics_service_base.cc
@@ -37,7 +37,7 @@ void MetricsServiceBase::RecordCurrentHistograms() {
void MetricsServiceBase::RecordDelta(
const base::Histogram& histogram,
- const base::Histogram::SampleSet& snapshot) {
+ const base::HistogramSamples& snapshot) {
log_manager_.current_log()->RecordHistogramDelta(histogram, snapshot);
}
diff --git a/chrome/common/metrics/metrics_service_base.h b/chrome/common/metrics/metrics_service_base.h
index 753cc26..fb72377 100644
--- a/chrome/common/metrics/metrics_service_base.h
+++ b/chrome/common/metrics/metrics_service_base.h
@@ -11,6 +11,10 @@
#include "base/metrics/histogram_snapshot_manager.h"
#include "chrome/common/metrics/metrics_log_manager.h"
+namespace base {
+class HistogramSamples;
+} // namespace base
+
// 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.
@@ -18,7 +22,7 @@ class MetricsServiceBase : public base::HistogramFlattener {
public:
// HistogramFlattener interface (override) methods.
virtual void RecordDelta(const base::Histogram& histogram,
- const base::Histogram::SampleSet& snapshot) OVERRIDE;
+ const base::HistogramSamples& snapshot) OVERRIDE;
virtual void InconsistencyDetected(
base::Histogram::Inconsistencies problem) OVERRIDE;
virtual void UniqueInconsistencyDetected(