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

Side by Side Diff: base/metrics/histogram.h

Issue 1485763002: Merge multiple histogram snapshots into single one for reporting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shared-histograms
Patch Set: rebased Created 4 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/metrics/histogram.cc » ('j') | base/metrics/histogram.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Histogram is an object that aggregates statistics, and can summarize them in 5 // Histogram is an object that aggregates statistics, and can summarize them in
6 // various forms, including ASCII graphical, HTML, and numerically (as a 6 // various forms, including ASCII graphical, HTML, and numerically (as a
7 // vector of numbers corresponding to each of the aggregating buckets). 7 // vector of numbers corresponding to each of the aggregating buckets).
8 8
9 // It supports calls to accumulate either time intervals (which are processed 9 // It supports calls to accumulate either time intervals (which are processed
10 // as integral number of milliseconds), or arbitrary integral units. 10 // as integral number of milliseconds), or arbitrary integral units.
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 base::TimeDelta maximum, 138 base::TimeDelta maximum,
139 uint32_t bucket_count, 139 uint32_t bucket_count,
140 int32_t flags); 140 int32_t flags);
141 141
142 // Get a histogram using data in persistent storage. 142 // Get a histogram using data in persistent storage.
143 static HistogramBase* PersistentGet(const std::string& name, 143 static HistogramBase* PersistentGet(const std::string& name,
144 Sample minimum, 144 Sample minimum,
145 Sample maximum, 145 Sample maximum,
146 const BucketRanges* ranges, 146 const BucketRanges* ranges,
147 HistogramBase::AtomicCount* counts, 147 HistogramBase::AtomicCount* counts,
148 HistogramBase::AtomicCount* logged,
148 uint32_t counts_size, 149 uint32_t counts_size,
149 HistogramSamples::Metadata* meta); 150 HistogramSamples::Metadata* meta);
150 151
151 static void InitializeBucketRanges(Sample minimum, 152 static void InitializeBucketRanges(Sample minimum,
152 Sample maximum, 153 Sample maximum,
153 BucketRanges* ranges); 154 BucketRanges* ranges);
154 155
155 // This constant if for FindCorruption. Since snapshots of histograms are 156 // This constant if for FindCorruption. Since snapshots of histograms are
156 // taken asynchronously relative to sampling, and our counting code currently 157 // taken asynchronously relative to sampling, and our counting code currently
157 // does not prevent race conditions, it is pretty likely that we'll catch a 158 // does not prevent race conditions, it is pretty likely that we'll catch a
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 191
191 // HistogramBase implementation: 192 // HistogramBase implementation:
192 uint64_t name_hash() const override; 193 uint64_t name_hash() const override;
193 HistogramType GetHistogramType() const override; 194 HistogramType GetHistogramType() const override;
194 bool HasConstructionArguments(Sample expected_minimum, 195 bool HasConstructionArguments(Sample expected_minimum,
195 Sample expected_maximum, 196 Sample expected_maximum,
196 uint32_t expected_bucket_count) const override; 197 uint32_t expected_bucket_count) const override;
197 void Add(Sample value) override; 198 void Add(Sample value) override;
198 void AddCount(Sample value, int count) override; 199 void AddCount(Sample value, int count) override;
199 scoped_ptr<HistogramSamples> SnapshotSamples() const override; 200 scoped_ptr<HistogramSamples> SnapshotSamples() const override;
201 scoped_ptr<HistogramSamples> SnapshotDelta() override;
200 void AddSamples(const HistogramSamples& samples) override; 202 void AddSamples(const HistogramSamples& samples) override;
201 bool AddSamplesFromPickle(base::PickleIterator* iter) override; 203 bool AddSamplesFromPickle(base::PickleIterator* iter) override;
202 void WriteHTMLGraph(std::string* output) const override; 204 void WriteHTMLGraph(std::string* output) const override;
203 void WriteAscii(std::string* output) const override; 205 void WriteAscii(std::string* output) const override;
204 206
205 protected: 207 protected:
206 // This class, defined entirely within the .cc file, contains all the 208 // This class, defined entirely within the .cc file, contains all the
207 // common logic for building a Histogram and can be overridden by more 209 // common logic for building a Histogram and can be overridden by more
208 // specific types to alter details of how the creation is done. It is 210 // specific types to alter details of how the creation is done. It is
209 // defined as an embedded class (rather than an anonymous one) so it 211 // defined as an embedded class (rather than an anonymous one) so it
(...skipping 11 matching lines...) Expand all
221 // vector but "shared" histograms use memory regions allocated from a 223 // vector but "shared" histograms use memory regions allocated from a
222 // special memory segment that is passed in here. It is assumed that 224 // special memory segment that is passed in here. It is assumed that
223 // the life of this memory is managed externally and exceeds the lifetime 225 // the life of this memory is managed externally and exceeds the lifetime
224 // of this object. Practically, this memory is never released until the 226 // of this object. Practically, this memory is never released until the
225 // process exits and the OS cleans it up. 227 // process exits and the OS cleans it up.
226 Histogram(const std::string& name, 228 Histogram(const std::string& name,
227 Sample minimum, 229 Sample minimum,
228 Sample maximum, 230 Sample maximum,
229 const BucketRanges* ranges, 231 const BucketRanges* ranges,
230 HistogramBase::AtomicCount* counts, 232 HistogramBase::AtomicCount* counts,
233 HistogramBase::AtomicCount* logged,
Alexei Svitkine (slow) 2016/02/09 19:46:51 Nit: logged_counts Change everywhere.
bcwhite 2016/02/11 16:42:38 Done.
231 uint32_t counts_size, 234 uint32_t counts_size,
232 HistogramSamples::Metadata* meta); 235 HistogramSamples::Metadata* meta);
233 236
234 ~Histogram() override; 237 ~Histogram() override;
235 238
236 // HistogramBase implementation: 239 // HistogramBase implementation:
237 bool SerializeInfoImpl(base::Pickle* pickle) const override; 240 bool SerializeInfoImpl(base::Pickle* pickle) const override;
238 241
239 // Method to override to skip the display of the i'th bucket if it's empty. 242 // Method to override to skip the display of the i'th bucket if it's empty.
240 virtual bool PrintEmptyBucket(uint32_t index) const; 243 virtual bool PrintEmptyBucket(uint32_t index) const;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 // Does not own this object. Should get from StatisticsRecorder. 299 // Does not own this object. Should get from StatisticsRecorder.
297 const BucketRanges* bucket_ranges_; 300 const BucketRanges* bucket_ranges_;
298 301
299 Sample declared_min_; // Less than this goes into the first bucket. 302 Sample declared_min_; // Less than this goes into the first bucket.
300 Sample declared_max_; // Over this goes into the last bucket. 303 Sample declared_max_; // Over this goes into the last bucket.
301 304
302 // Finally, provide the state that changes with the addition of each new 305 // Finally, provide the state that changes with the addition of each new
303 // sample. 306 // sample.
304 scoped_ptr<SampleVector> samples_; 307 scoped_ptr<SampleVector> samples_;
305 308
309 // Also keep a previous uploaded state for calculating deltas.
310 scoped_ptr<HistogramSamples> logged_;
311
306 DISALLOW_COPY_AND_ASSIGN(Histogram); 312 DISALLOW_COPY_AND_ASSIGN(Histogram);
307 }; 313 };
308 314
309 //------------------------------------------------------------------------------ 315 //------------------------------------------------------------------------------
310 316
311 // LinearHistogram is a more traditional histogram, with evenly spaced 317 // LinearHistogram is a more traditional histogram, with evenly spaced
312 // buckets. 318 // buckets.
313 class BASE_EXPORT LinearHistogram : public Histogram { 319 class BASE_EXPORT LinearHistogram : public Histogram {
314 public: 320 public:
315 ~LinearHistogram() override; 321 ~LinearHistogram() override;
(...skipping 24 matching lines...) Expand all
340 TimeDelta maximum, 346 TimeDelta maximum,
341 uint32_t bucket_count, 347 uint32_t bucket_count,
342 int32_t flags); 348 int32_t flags);
343 349
344 // Get a histogram using data in persistent storage. 350 // Get a histogram using data in persistent storage.
345 static HistogramBase* PersistentGet(const std::string& name, 351 static HistogramBase* PersistentGet(const std::string& name,
346 Sample minimum, 352 Sample minimum,
347 Sample maximum, 353 Sample maximum,
348 const BucketRanges* ranges, 354 const BucketRanges* ranges,
349 HistogramBase::AtomicCount* counts, 355 HistogramBase::AtomicCount* counts,
356 HistogramBase::AtomicCount* logged,
350 uint32_t counts_size, 357 uint32_t counts_size,
351 HistogramSamples::Metadata* meta); 358 HistogramSamples::Metadata* meta);
352 359
353 struct DescriptionPair { 360 struct DescriptionPair {
354 Sample sample; 361 Sample sample;
355 const char* description; // Null means end of a list of pairs. 362 const char* description; // Null means end of a list of pairs.
356 }; 363 };
357 364
358 // Create a LinearHistogram and store a list of number/text values for use in 365 // Create a LinearHistogram and store a list of number/text values for use in
359 // writing the histogram graph. 366 // writing the histogram graph.
(...skipping 21 matching lines...) Expand all
381 LinearHistogram(const std::string& name, 388 LinearHistogram(const std::string& name,
382 Sample minimum, 389 Sample minimum,
383 Sample maximum, 390 Sample maximum,
384 const BucketRanges* ranges); 391 const BucketRanges* ranges);
385 392
386 LinearHistogram(const std::string& name, 393 LinearHistogram(const std::string& name,
387 Sample minimum, 394 Sample minimum,
388 Sample maximum, 395 Sample maximum,
389 const BucketRanges* ranges, 396 const BucketRanges* ranges,
390 HistogramBase::AtomicCount* counts, 397 HistogramBase::AtomicCount* counts,
398 HistogramBase::AtomicCount* logged,
391 uint32_t counts_size, 399 uint32_t counts_size,
392 HistogramSamples::Metadata* meta); 400 HistogramSamples::Metadata* meta);
393 401
394 double GetBucketSize(Count current, uint32_t i) const override; 402 double GetBucketSize(Count current, uint32_t i) const override;
395 403
396 // If we have a description for a bucket, then return that. Otherwise 404 // If we have a description for a bucket, then return that. Otherwise
397 // let parent class provide a (numeric) description. 405 // let parent class provide a (numeric) description.
398 const std::string GetAsciiBucketRange(uint32_t i) const override; 406 const std::string GetAsciiBucketRange(uint32_t i) const override;
399 407
400 // Skip printing of name for numeric range if we have a name (and if this is 408 // Skip printing of name for numeric range if we have a name (and if this is
(...skipping 23 matching lines...) Expand all
424 432
425 // Overload of the above function that takes a const char* |name| param, 433 // Overload of the above function that takes a const char* |name| param,
426 // to avoid code bloat from the std::string constructor being inlined into 434 // to avoid code bloat from the std::string constructor being inlined into
427 // call sites. 435 // call sites.
428 static HistogramBase* FactoryGet(const char* name, int32_t flags); 436 static HistogramBase* FactoryGet(const char* name, int32_t flags);
429 437
430 // Get a histogram using data in persistent storage. 438 // Get a histogram using data in persistent storage.
431 static HistogramBase* PersistentGet(const std::string& name, 439 static HistogramBase* PersistentGet(const std::string& name,
432 const BucketRanges* ranges, 440 const BucketRanges* ranges,
433 HistogramBase::AtomicCount* counts, 441 HistogramBase::AtomicCount* counts,
442 HistogramBase::AtomicCount* logged,
434 HistogramSamples::Metadata* meta); 443 HistogramSamples::Metadata* meta);
435 444
436 HistogramType GetHistogramType() const override; 445 HistogramType GetHistogramType() const override;
437 446
438 protected: 447 protected:
439 class Factory; 448 class Factory;
440 449
441 private: 450 private:
442 BooleanHistogram(const std::string& name, const BucketRanges* ranges); 451 BooleanHistogram(const std::string& name, const BucketRanges* ranges);
443 BooleanHistogram(const std::string& name, 452 BooleanHistogram(const std::string& name,
444 const BucketRanges* ranges, 453 const BucketRanges* ranges,
445 HistogramBase::AtomicCount* counts, 454 HistogramBase::AtomicCount* counts,
455 HistogramBase::AtomicCount* logged,
446 HistogramSamples::Metadata* meta); 456 HistogramSamples::Metadata* meta);
447 457
448 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( 458 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo(
449 base::PickleIterator* iter); 459 base::PickleIterator* iter);
450 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); 460 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter);
451 461
452 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); 462 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram);
453 }; 463 };
454 464
455 //------------------------------------------------------------------------------ 465 //------------------------------------------------------------------------------
(...skipping 13 matching lines...) Expand all
469 // to avoid code bloat from the std::string constructor being inlined into 479 // to avoid code bloat from the std::string constructor being inlined into
470 // call sites. 480 // call sites.
471 static HistogramBase* FactoryGet(const char* name, 481 static HistogramBase* FactoryGet(const char* name,
472 const std::vector<Sample>& custom_ranges, 482 const std::vector<Sample>& custom_ranges,
473 int32_t flags); 483 int32_t flags);
474 484
475 // Get a histogram using data in persistent storage. 485 // Get a histogram using data in persistent storage.
476 static HistogramBase* PersistentGet(const std::string& name, 486 static HistogramBase* PersistentGet(const std::string& name,
477 const BucketRanges* ranges, 487 const BucketRanges* ranges,
478 HistogramBase::AtomicCount* counts, 488 HistogramBase::AtomicCount* counts,
489 HistogramBase::AtomicCount* logged,
479 uint32_t counts_size, 490 uint32_t counts_size,
480 HistogramSamples::Metadata* meta); 491 HistogramSamples::Metadata* meta);
481 492
482 // Overridden from Histogram: 493 // Overridden from Histogram:
483 HistogramType GetHistogramType() const override; 494 HistogramType GetHistogramType() const override;
484 495
485 // Helper method for transforming an array of valid enumeration values 496 // Helper method for transforming an array of valid enumeration values
486 // to the std::vector<int> expected by UMA_HISTOGRAM_CUSTOM_ENUMERATION. 497 // to the std::vector<int> expected by UMA_HISTOGRAM_CUSTOM_ENUMERATION.
487 // This function ensures that a guard bucket exists right after any 498 // This function ensures that a guard bucket exists right after any
488 // valid sample value (unless the next higher sample is also a valid value), 499 // valid sample value (unless the next higher sample is also a valid value),
489 // so that invalid samples never fall into the same bucket as valid samples. 500 // so that invalid samples never fall into the same bucket as valid samples.
490 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges. 501 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges.
491 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, 502 static std::vector<Sample> ArrayToCustomRanges(const Sample* values,
492 uint32_t num_values); 503 uint32_t num_values);
493 protected: 504 protected:
494 class Factory; 505 class Factory;
495 506
496 CustomHistogram(const std::string& name, 507 CustomHistogram(const std::string& name,
497 const BucketRanges* ranges); 508 const BucketRanges* ranges);
498 509
499 CustomHistogram(const std::string& name, 510 CustomHistogram(const std::string& name,
500 const BucketRanges* ranges, 511 const BucketRanges* ranges,
501 HistogramBase::AtomicCount* counts, 512 HistogramBase::AtomicCount* counts,
513 HistogramBase::AtomicCount* logged,
502 uint32_t counts_size, 514 uint32_t counts_size,
503 HistogramSamples::Metadata* meta); 515 HistogramSamples::Metadata* meta);
504 516
505 // HistogramBase implementation: 517 // HistogramBase implementation:
506 bool SerializeInfoImpl(base::Pickle* pickle) const override; 518 bool SerializeInfoImpl(base::Pickle* pickle) const override;
507 519
508 double GetBucketSize(Count current, uint32_t i) const override; 520 double GetBucketSize(Count current, uint32_t i) const override;
509 521
510 private: 522 private:
511 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( 523 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo(
512 base::PickleIterator* iter); 524 base::PickleIterator* iter);
513 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); 525 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter);
514 526
515 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); 527 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges);
516 528
517 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); 529 DISALLOW_COPY_AND_ASSIGN(CustomHistogram);
518 }; 530 };
519 531
520 } // namespace base 532 } // namespace base
521 533
522 #endif // BASE_METRICS_HISTOGRAM_H_ 534 #endif // BASE_METRICS_HISTOGRAM_H_
OLDNEW
« no previous file with comments | « no previous file | base/metrics/histogram.cc » ('j') | base/metrics/histogram.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698