Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(811)

Unified Diff: base/metrics/histogram.h

Issue 10829466: SampleSet -> HistogramSamples (will be reused by SparseHistogram) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/metrics/histogram.h
===================================================================
--- base/metrics/histogram.h (revision 152603)
+++ base/metrics/histogram.h (working copy)
@@ -68,8 +68,10 @@
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
#include "base/metrics/bucket_ranges.h"
#include "base/metrics/histogram_base.h"
+#include "base/metrics/histogram_samples.h"
#include "base/time.h"
class Pickle;
@@ -344,6 +346,61 @@
class Histogram;
class LinearHistogram;
+class BASE_EXPORT_PRIVATE BucketHistogramSamples : public HistogramSamples {
Ilya Sherman 2012/08/23 07:50:54 I don't really understand what a "BucketHistogram"
kaiwang 2012/08/24 04:17:58 SparseHistograms don't
Ilya Sherman 2012/08/29 08:48:16 SparseHistograms don't have *contiguous* buckets,
Ilya Sherman 2012/08/29 23:41:27 (bump)
kaiwang 2012/08/30 03:13:21 Original Histogram separates the whole sample valu
Ilya Sherman 2012/08/30 07:57:39 I think we disagree on what a histogram "bucket" m
jar (doing other things) 2012/08/30 22:54:38 I think perchance you meant ContiGuousHistogramSam
Ilya Sherman 2012/08/30 23:01:46 SGTM
+ public:
+ BucketHistogramSamples(const BucketRanges* bucket_ranges);
Ilya Sherman 2012/08/23 07:50:54 nit: explicit
Ilya Sherman 2012/08/23 07:50:54 nit: Can this be passed by const-ref rather than c
kaiwang 2012/08/24 04:17:58 Done.
+ virtual ~BucketHistogramSamples();
+
+ virtual void Accumulate(HistogramBase::Sample value,
Ilya Sherman 2012/08/23 07:50:54 nit: Please label these methods with something lik
kaiwang 2012/08/24 04:17:58 Done.
+ HistogramBase::Count count) OVERRIDE;
+ virtual HistogramBase::Count GetCount(
+ HistogramBase::Sample value) const OVERRIDE;
+ virtual HistogramBase::Count TotalCount() const OVERRIDE;
+
+ virtual scoped_ptr<SampleCountIterator> Iterator() const OVERRIDE;
+
+ // Get count of a specific bucket.
+ HistogramBase::Count GetCountFromBucketIndex(size_t bucket_index) const;
Ilya Sherman 2012/08/23 07:50:54 nit: "From" -> "For"
kaiwang 2012/08/24 04:17:58 I really don't think "For" is better than "From",
Ilya Sherman 2012/08/29 08:48:16 If you want to use "from", the name should be "Get
kaiwang 2012/08/30 03:13:21 What do you think of GetCountAtIndex? from Jim's s
Ilya Sherman 2012/08/30 07:57:39 Works for me :)
+
+ protected:
+ virtual bool AddSubtractHelper(SampleCountIterator* iter,
+ bool is_add) OVERRIDE;
+
+ static size_t BucketIndex(HistogramBase::Sample value,
Ilya Sherman 2012/08/23 07:50:54 nit: GetBucketIndex()
kaiwang 2012/08/24 04:17:58 Done.
+ const BucketRanges* bucket_ranges);
Ilya Sherman 2012/08/23 07:50:54 nit: Can this be passed by const-reference?
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(BucketHistogramSamples);
Ilya Sherman 2012/08/23 07:50:54 Optional nit: I think this is usually the very las
kaiwang 2012/08/24 04:17:58 Done.
+ FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptSampleCounts);
+
+ std::vector<HistogramBase::Count> counts_;
+
+ // Shares the same BucketRanges with Histogram object.
+ const BucketRanges* bucket_ranges_;
Ilya Sherman 2012/08/23 07:50:54 nit: Can this be a const reference or a const Buck
kaiwang 2012/08/24 04:17:58 Done.
+};
+
+class BASE_EXPORT_PRIVATE BucketHistogramSamplesIterator
+ : public SampleCountIterator {
+ public:
+ BucketHistogramSamplesIterator(
+ const std::vector<HistogramBase::Count>* counts,
Ilya Sherman 2012/08/23 07:50:54 nit: Can this be passed by const-reference?
+ const BucketRanges* bucket_ranges);
Ilya Sherman 2012/08/23 07:50:54 nit: Ditto
kaiwang 2012/08/24 04:17:58 For all the reference related comments: IMHO, I ra
+
+ virtual bool Done() OVERRIDE;
+ virtual void Next() OVERRIDE;
+ virtual void Get(HistogramBase::Sample* min,
+ HistogramBase::Sample* max,
+ HistogramBase::Count* count) OVERRIDE;
+ private:
+ void ForwardIndex(); // Find the next place with data.
Ilya Sherman 2012/08/23 07:50:54 nit: Please choose a more descriptive name rather
kaiwang 2012/08/24 04:17:58 Done.
+
+ const std::vector<HistogramBase::Count>* counts_;
+ const BucketRanges* bucket_ranges_;
+
+ int index_;
+ bool is_done_;
+};
Ilya Sherman 2012/08/23 07:50:54 Please declare & define these classes in separate
kaiwang 2012/08/24 04:17:58 This file currently contains all stuff related to
Ilya Sherman 2012/08/29 08:48:16 You are adding a new class, so moving the new clas
Ilya Sherman 2012/08/29 23:41:27 (bump)
kaiwang 2012/08/30 03:13:21 Done.
+
class BASE_EXPORT Histogram : public HistogramBase {
public:
// Initialize maximum number of buckets in histograms as 16,384.
@@ -473,7 +530,8 @@
Add(static_cast<int>(time.InMilliseconds()));
}
- void AddSampleSet(const SampleSet& sample);
+ void AddSamples(const HistogramSamples& samples);
+ bool AddSamples(PickleIterator* iter);
// This method is an interface, used only by LinearHistogram.
virtual void SetRangeDescriptions(const DescriptionPair descriptions[]);
@@ -491,19 +549,28 @@
// Serialize the given snapshot of a Histogram into a String. Uses
// Pickle class to flatten the object.
static std::string SerializeHistogramInfo(const Histogram& histogram,
- const SampleSet& snapshot);
+ const HistogramSamples& snapshot);
// The following method accepts a list of pickled histograms and
// builds a histogram and updates shadow copy of histogram data in the
// browser process.
static bool DeserializeHistogramInfo(const std::string& histogram_info);
+ // This constant if for FindCorruption. Since snapshots of histograms are
+ // taken asynchronously relative to sampling, and out counting code currently
jar (doing other things) 2012/08/30 22:54:38 nit: out --> our
kaiwang 2012/09/07 01:14:11 Done.
+ // does not prevent race conditions, it is pretty likely that we'll catch a
+ // redundant count that doesn't match the sample count. We allow for a
+ // certain amount of slop before flagging this as an inconsistency. Even with
+ // an inconsistency, we'll snapshot it again (for UMA in about a half hour),
+ // so we'll eventually get the data, if it was not the result of a corruption.
+ static const int kCommonRaceBasedCountMismatch;
+
// Check to see if bucket ranges, counts and tallies in the snapshot are
// consistent with the bucket ranges and checksums in our histogram. This can
// produce a false-alarm if a race occurred in the reading of the data during
// a SnapShot process, but should otherwise be false at all times (unless we
// have memory over-writes, or DRAM failures).
- virtual Inconsistencies FindCorruption(const SampleSet& snapshot) const;
+ virtual Inconsistencies FindCorruption(const HistogramSamples& samples) const;
//----------------------------------------------------------------------------
// Accessors for factory constuction, serialization and testing.
@@ -517,7 +584,7 @@
// Snapshot the current complete set of sample data.
// Override with atomic/locked snapshot if needed.
- virtual void SnapshotSample(SampleSet* sample) const;
+ virtual scoped_ptr<BucketHistogramSamples> SnapshotSamples() const;
virtual bool HasConstructionArguments(Sample minimum,
Sample maximum,
@@ -553,11 +620,6 @@
// Method to override to skip the display of the i'th bucket if it's empty.
virtual bool PrintEmptyBucket(size_t index) const;
- //----------------------------------------------------------------------------
- // Methods to override to create histogram with different bucket widths.
- //----------------------------------------------------------------------------
- // Find bucket to increment for sample value.
- virtual size_t BucketIndex(Sample value) const;
// Get normalized size, relative to the ranges(i).
virtual double GetBucketSize(Count current, size_t i) const;
@@ -566,12 +628,6 @@
// be a name (or string description) given to the bucket.
virtual const std::string GetAsciiBucketRange(size_t it) const;
- //----------------------------------------------------------------------------
- // Methods to override to create thread safe histogram.
- //----------------------------------------------------------------------------
- // Update all our internal data, including histogram
- virtual void Accumulate(Sample value, Count count, size_t index);
-
private:
// Allow tests to corrupt our innards for testing purposes.
FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptBucketBounds);
@@ -589,12 +645,13 @@
const std::string& newline,
std::string* output) const;
- // Find out how large the (graphically) the largest bucket will appear to be.
- double GetPeakBucketSize(const SampleSet& snapshot) const;
+ // Find out how large (graphically) the largest bucket will appear to be.
+ double GetPeakBucketSize(const BucketHistogramSamples& samples) const;
// Write a common header message describing this histogram.
- void WriteAsciiHeader(const SampleSet& snapshot,
- Count sample_count, std::string* output) const;
+ void WriteAsciiHeader(const BucketHistogramSamples& samples,
+ Count sample_count,
+ std::string* output) const;
// Write information about previous, current, and next buckets.
// Information such as cumulative percentage, etc.
@@ -620,7 +677,7 @@
// Finally, provide the state that changes with the addition of each new
// sample.
- SampleSet sample_;
+ scoped_ptr<BucketHistogramSamples> samples_;
DISALLOW_COPY_AND_ASSIGN(Histogram);
};

Powered by Google App Engine
This is Rietveld 408576698