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

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

Issue 2811713003: Embed a single sample in histogram metadata. (Closed)
Patch Set: fixed build problems Created 3 years, 8 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_samples.h » ('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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 #include "base/macros.h" 79 #include "base/macros.h"
80 #include "base/metrics/bucket_ranges.h" 80 #include "base/metrics/bucket_ranges.h"
81 #include "base/metrics/histogram_base.h" 81 #include "base/metrics/histogram_base.h"
82 #include "base/metrics/histogram_samples.h" 82 #include "base/metrics/histogram_samples.h"
83 #include "base/time/time.h" 83 #include "base/time/time.h"
84 84
85 namespace base { 85 namespace base {
86 86
87 class BooleanHistogram; 87 class BooleanHistogram;
88 class CustomHistogram; 88 class CustomHistogram;
89 class DelayedPersistentAllocation;
89 class Histogram; 90 class Histogram;
90 class LinearHistogram; 91 class LinearHistogram;
91 class Pickle; 92 class Pickle;
92 class PickleIterator; 93 class PickleIterator;
93 class SampleVector; 94 class SampleVector;
95 class SampleVectorBase;
94 96
95 class BASE_EXPORT Histogram : public HistogramBase { 97 class BASE_EXPORT Histogram : public HistogramBase {
96 public: 98 public:
97 // Initialize maximum number of buckets in histograms as 16,384. 99 // Initialize maximum number of buckets in histograms as 16,384.
98 static const uint32_t kBucketCount_MAX; 100 static const uint32_t kBucketCount_MAX;
99 101
100 typedef std::vector<Count> Counts; 102 typedef std::vector<Count> Counts;
101 103
102 ~Histogram() override; 104 ~Histogram() override;
103 105
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 base::TimeDelta maximum, 137 base::TimeDelta maximum,
136 uint32_t bucket_count, 138 uint32_t bucket_count,
137 int32_t flags); 139 int32_t flags);
138 140
139 // Create a histogram using data in persistent storage. 141 // Create a histogram using data in persistent storage.
140 static std::unique_ptr<HistogramBase> PersistentCreate( 142 static std::unique_ptr<HistogramBase> PersistentCreate(
141 const std::string& name, 143 const std::string& name,
142 Sample minimum, 144 Sample minimum,
143 Sample maximum, 145 Sample maximum,
144 const BucketRanges* ranges, 146 const BucketRanges* ranges,
145 HistogramBase::AtomicCount* counts,
146 HistogramBase::AtomicCount* logged_counts,
147 uint32_t counts_size,
148 HistogramSamples::Metadata* meta, 147 HistogramSamples::Metadata* meta,
149 HistogramSamples::Metadata* logged_meta); 148 const DelayedPersistentAllocation& counts,
149 HistogramSamples::Metadata* logged_meta,
Alexei Svitkine (slow) 2017/04/12 17:38:06 Non-const params should be last - so add the new p
bcwhite 2017/04/13 00:06:00 <sigh> There were arranged like that but I figure
150 const DelayedPersistentAllocation& logged_counts);
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
158 // redundant count that doesn't match the sample count. We allow for a 159 // redundant count that doesn't match the sample count. We allow for a
159 // certain amount of slop before flagging this as an inconsistency. Even with 160 // certain amount of slop before flagging this as an inconsistency. Even with
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 // Traditionally, histograms allocate their own memory for the bucket 224 // Traditionally, histograms allocate their own memory for the bucket
224 // vector but "shared" histograms use memory regions allocated from a 225 // vector but "shared" histograms use memory regions allocated from a
225 // special memory segment that is passed in here. It is assumed that 226 // special memory segment that is passed in here. It is assumed that
226 // the life of this memory is managed externally and exceeds the lifetime 227 // the life of this memory is managed externally and exceeds the lifetime
227 // of this object. Practically, this memory is never released until the 228 // of this object. Practically, this memory is never released until the
228 // process exits and the OS cleans it up. 229 // process exits and the OS cleans it up.
229 Histogram(const std::string& name, 230 Histogram(const std::string& name,
230 Sample minimum, 231 Sample minimum,
231 Sample maximum, 232 Sample maximum,
232 const BucketRanges* ranges, 233 const BucketRanges* ranges,
233 HistogramBase::AtomicCount* counts,
234 HistogramBase::AtomicCount* logged_counts,
235 uint32_t counts_size,
236 HistogramSamples::Metadata* meta, 234 HistogramSamples::Metadata* meta,
237 HistogramSamples::Metadata* logged_meta); 235 const DelayedPersistentAllocation& counts,
236 HistogramSamples::Metadata* logged_meta,
237 const DelayedPersistentAllocation& logged_counts);
238 238
239 // HistogramBase implementation: 239 // HistogramBase implementation:
240 bool SerializeInfoImpl(base::Pickle* pickle) const override; 240 bool SerializeInfoImpl(base::Pickle* pickle) const override;
241 241
242 // 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.
243 virtual bool PrintEmptyBucket(uint32_t index) const; 243 virtual bool PrintEmptyBucket(uint32_t index) const;
244 244
245 // Get normalized size, relative to the ranges(i). 245 // Get normalized size, relative to the ranges(i).
246 virtual double GetBucketSize(Count current, uint32_t i) const; 246 virtual double GetBucketSize(Count current, uint32_t i) const;
247 247
(...skipping 19 matching lines...) Expand all
267 std::unique_ptr<SampleVector> SnapshotSampleVector() const; 267 std::unique_ptr<SampleVector> SnapshotSampleVector() const;
268 268
269 //---------------------------------------------------------------------------- 269 //----------------------------------------------------------------------------
270 // Helpers for emitting Ascii graphic. Each method appends data to output. 270 // Helpers for emitting Ascii graphic. Each method appends data to output.
271 271
272 void WriteAsciiImpl(bool graph_it, 272 void WriteAsciiImpl(bool graph_it,
273 const std::string& newline, 273 const std::string& newline,
274 std::string* output) const; 274 std::string* output) const;
275 275
276 // Find out how large (graphically) the largest bucket will appear to be. 276 // Find out how large (graphically) the largest bucket will appear to be.
277 double GetPeakBucketSize(const SampleVector& samples) const; 277 double GetPeakBucketSize(const SampleVectorBase& samples) const;
278 278
279 // Write a common header message describing this histogram. 279 // Write a common header message describing this histogram.
280 void WriteAsciiHeader(const SampleVector& samples, 280 void WriteAsciiHeader(const SampleVectorBase& samples,
281 Count sample_count, 281 Count sample_count,
282 std::string* output) const; 282 std::string* output) const;
283 283
284 // Write information about previous, current, and next buckets. 284 // Write information about previous, current, and next buckets.
285 // Information such as cumulative percentage, etc. 285 // Information such as cumulative percentage, etc.
286 void WriteAsciiBucketContext(const int64_t past, 286 void WriteAsciiBucketContext(const int64_t past,
287 const Count current, 287 const Count current,
288 const int64_t remaining, 288 const int64_t remaining,
289 const uint32_t i, 289 const uint32_t i,
290 std::string* output) const; 290 std::string* output) const;
291 291
292 // WriteJSON calls these. 292 // WriteJSON calls these.
293 void GetParameters(DictionaryValue* params) const override; 293 void GetParameters(DictionaryValue* params) const override;
294 294
295 void GetCountAndBucketData(Count* count, 295 void GetCountAndBucketData(Count* count,
296 int64_t* sum, 296 int64_t* sum,
297 ListValue* buckets) const override; 297 ListValue* buckets) const override;
298 298
299 // Does not own this object. Should get from StatisticsRecorder. 299 // Does not own this object. Should get from StatisticsRecorder.
300 const BucketRanges* bucket_ranges_; 300 const BucketRanges* bucket_ranges_;
301 301
302 Sample declared_min_; // Less than this goes into the first bucket. 302 Sample declared_min_; // Less than this goes into the first bucket.
303 Sample declared_max_; // Over this goes into the last bucket. 303 Sample declared_max_; // Over this goes into the last bucket.
304 304
305 // 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
306 // sample. 306 // sample.
307 std::unique_ptr<SampleVector> samples_; 307 std::unique_ptr<SampleVectorBase> samples_;
308 308
309 // Also keep a previous uploaded state for calculating deltas. 309 // Also keep a previous uploaded state for calculating deltas.
310 std::unique_ptr<HistogramSamples> logged_samples_; 310 std::unique_ptr<HistogramSamples> logged_samples_;
311 311
312 // Flag to indicate if PrepareFinalDelta has been previously called. It is 312 // Flag to indicate if PrepareFinalDelta has been previously called. It is
313 // used to DCHECK that a final delta is not created multiple times. 313 // used to DCHECK that a final delta is not created multiple times.
314 mutable bool final_delta_created_ = false; 314 mutable bool final_delta_created_ = false;
315 315
316 DISALLOW_COPY_AND_ASSIGN(Histogram); 316 DISALLOW_COPY_AND_ASSIGN(Histogram);
317 }; 317 };
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 TimeDelta maximum, 350 TimeDelta maximum,
351 uint32_t bucket_count, 351 uint32_t bucket_count,
352 int32_t flags); 352 int32_t flags);
353 353
354 // Create a histogram using data in persistent storage. 354 // Create a histogram using data in persistent storage.
355 static std::unique_ptr<HistogramBase> PersistentCreate( 355 static std::unique_ptr<HistogramBase> PersistentCreate(
356 const std::string& name, 356 const std::string& name,
357 Sample minimum, 357 Sample minimum,
358 Sample maximum, 358 Sample maximum,
359 const BucketRanges* ranges, 359 const BucketRanges* ranges,
360 HistogramBase::AtomicCount* counts,
361 HistogramBase::AtomicCount* logged_counts,
362 uint32_t counts_size,
363 HistogramSamples::Metadata* meta, 360 HistogramSamples::Metadata* meta,
364 HistogramSamples::Metadata* logged_meta); 361 const DelayedPersistentAllocation& counts,
362 HistogramSamples::Metadata* logged_meta,
363 const DelayedPersistentAllocation& logged_counts);
365 364
366 struct DescriptionPair { 365 struct DescriptionPair {
367 Sample sample; 366 Sample sample;
368 const char* description; // Null means end of a list of pairs. 367 const char* description; // Null means end of a list of pairs.
369 }; 368 };
370 369
371 // Create a LinearHistogram and store a list of number/text values for use in 370 // Create a LinearHistogram and store a list of number/text values for use in
372 // writing the histogram graph. 371 // writing the histogram graph.
373 // |descriptions| can be NULL, which means no special descriptions to set. If 372 // |descriptions| can be NULL, which means no special descriptions to set. If
374 // it's not NULL, the last element in the array must has a NULL in its 373 // it's not NULL, the last element in the array must has a NULL in its
(...skipping 18 matching lines...) Expand all
393 392
394 LinearHistogram(const std::string& name, 393 LinearHistogram(const std::string& name,
395 Sample minimum, 394 Sample minimum,
396 Sample maximum, 395 Sample maximum,
397 const BucketRanges* ranges); 396 const BucketRanges* ranges);
398 397
399 LinearHistogram(const std::string& name, 398 LinearHistogram(const std::string& name,
400 Sample minimum, 399 Sample minimum,
401 Sample maximum, 400 Sample maximum,
402 const BucketRanges* ranges, 401 const BucketRanges* ranges,
403 HistogramBase::AtomicCount* counts,
404 HistogramBase::AtomicCount* logged_counts,
405 uint32_t counts_size,
406 HistogramSamples::Metadata* meta, 402 HistogramSamples::Metadata* meta,
407 HistogramSamples::Metadata* logged_meta); 403 const DelayedPersistentAllocation& counts,
404 HistogramSamples::Metadata* logged_meta,
405 const DelayedPersistentAllocation& logged_counts);
408 406
409 double GetBucketSize(Count current, uint32_t i) const override; 407 double GetBucketSize(Count current, uint32_t i) const override;
410 408
411 // If we have a description for a bucket, then return that. Otherwise 409 // If we have a description for a bucket, then return that. Otherwise
412 // let parent class provide a (numeric) description. 410 // let parent class provide a (numeric) description.
413 const std::string GetAsciiBucketRange(uint32_t i) const override; 411 const std::string GetAsciiBucketRange(uint32_t i) const override;
414 412
415 // Skip printing of name for numeric range if we have a name (and if this is 413 // Skip printing of name for numeric range if we have a name (and if this is
416 // an empty bucket). 414 // an empty bucket).
417 bool PrintEmptyBucket(uint32_t index) const override; 415 bool PrintEmptyBucket(uint32_t index) const override;
(...skipping 21 matching lines...) Expand all
439 437
440 // Overload of the above function that takes a const char* |name| param, 438 // Overload of the above function that takes a const char* |name| param,
441 // to avoid code bloat from the std::string constructor being inlined into 439 // to avoid code bloat from the std::string constructor being inlined into
442 // call sites. 440 // call sites.
443 static HistogramBase* FactoryGet(const char* name, int32_t flags); 441 static HistogramBase* FactoryGet(const char* name, int32_t flags);
444 442
445 // Create a histogram using data in persistent storage. 443 // Create a histogram using data in persistent storage.
446 static std::unique_ptr<HistogramBase> PersistentCreate( 444 static std::unique_ptr<HistogramBase> PersistentCreate(
447 const std::string& name, 445 const std::string& name,
448 const BucketRanges* ranges, 446 const BucketRanges* ranges,
449 HistogramBase::AtomicCount* counts,
450 HistogramBase::AtomicCount* logged_counts,
451 HistogramSamples::Metadata* meta, 447 HistogramSamples::Metadata* meta,
452 HistogramSamples::Metadata* logged_meta); 448 const DelayedPersistentAllocation& counts,
449 HistogramSamples::Metadata* logged_meta,
450 const DelayedPersistentAllocation& logged_counts);
453 451
454 HistogramType GetHistogramType() const override; 452 HistogramType GetHistogramType() const override;
455 453
456 protected: 454 protected:
457 class Factory; 455 class Factory;
458 456
459 private: 457 private:
460 BooleanHistogram(const std::string& name, const BucketRanges* ranges); 458 BooleanHistogram(const std::string& name, const BucketRanges* ranges);
461 BooleanHistogram(const std::string& name, 459 BooleanHistogram(const std::string& name,
462 const BucketRanges* ranges, 460 const BucketRanges* ranges,
463 HistogramBase::AtomicCount* counts,
464 HistogramBase::AtomicCount* logged_counts,
465 HistogramSamples::Metadata* meta, 461 HistogramSamples::Metadata* meta,
466 HistogramSamples::Metadata* logged_meta); 462 const DelayedPersistentAllocation& counts,
463 HistogramSamples::Metadata* logged_meta,
464 const DelayedPersistentAllocation& logged_counts);
467 465
468 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( 466 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo(
469 base::PickleIterator* iter); 467 base::PickleIterator* iter);
470 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); 468 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter);
471 469
472 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); 470 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram);
473 }; 471 };
474 472
475 //------------------------------------------------------------------------------ 473 //------------------------------------------------------------------------------
476 474
(...skipping 12 matching lines...) Expand all
489 // to avoid code bloat from the std::string constructor being inlined into 487 // to avoid code bloat from the std::string constructor being inlined into
490 // call sites. 488 // call sites.
491 static HistogramBase* FactoryGet(const char* name, 489 static HistogramBase* FactoryGet(const char* name,
492 const std::vector<Sample>& custom_ranges, 490 const std::vector<Sample>& custom_ranges,
493 int32_t flags); 491 int32_t flags);
494 492
495 // Create a histogram using data in persistent storage. 493 // Create a histogram using data in persistent storage.
496 static std::unique_ptr<HistogramBase> PersistentCreate( 494 static std::unique_ptr<HistogramBase> PersistentCreate(
497 const std::string& name, 495 const std::string& name,
498 const BucketRanges* ranges, 496 const BucketRanges* ranges,
499 HistogramBase::AtomicCount* counts,
500 HistogramBase::AtomicCount* logged_counts,
501 uint32_t counts_size,
502 HistogramSamples::Metadata* meta, 497 HistogramSamples::Metadata* meta,
503 HistogramSamples::Metadata* logged_meta); 498 const DelayedPersistentAllocation& counts,
499 HistogramSamples::Metadata* logged_meta,
500 const DelayedPersistentAllocation& logged_counts);
504 501
505 // Overridden from Histogram: 502 // Overridden from Histogram:
506 HistogramType GetHistogramType() const override; 503 HistogramType GetHistogramType() const override;
507 504
508 // Helper method for transforming an array of valid enumeration values 505 // Helper method for transforming an array of valid enumeration values
509 // to the std::vector<int> expected by UMA_HISTOGRAM_CUSTOM_ENUMERATION. 506 // to the std::vector<int> expected by UMA_HISTOGRAM_CUSTOM_ENUMERATION.
510 // This function ensures that a guard bucket exists right after any 507 // This function ensures that a guard bucket exists right after any
511 // valid sample value (unless the next higher sample is also a valid value), 508 // valid sample value (unless the next higher sample is also a valid value),
512 // so that invalid samples never fall into the same bucket as valid samples. 509 // so that invalid samples never fall into the same bucket as valid samples.
513 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges. 510 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges.
514 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, 511 static std::vector<Sample> ArrayToCustomRanges(const Sample* values,
515 uint32_t num_values); 512 uint32_t num_values);
516 protected: 513 protected:
517 class Factory; 514 class Factory;
518 515
519 CustomHistogram(const std::string& name, 516 CustomHistogram(const std::string& name,
520 const BucketRanges* ranges); 517 const BucketRanges* ranges);
521 518
522 CustomHistogram(const std::string& name, 519 CustomHistogram(const std::string& name,
523 const BucketRanges* ranges, 520 const BucketRanges* ranges,
524 HistogramBase::AtomicCount* counts,
525 HistogramBase::AtomicCount* logged_counts,
526 uint32_t counts_size,
527 HistogramSamples::Metadata* meta, 521 HistogramSamples::Metadata* meta,
528 HistogramSamples::Metadata* logged_meta); 522 const DelayedPersistentAllocation& counts,
523 HistogramSamples::Metadata* logged_meta,
524 const DelayedPersistentAllocation& logged_counts);
529 525
530 // HistogramBase implementation: 526 // HistogramBase implementation:
531 bool SerializeInfoImpl(base::Pickle* pickle) const override; 527 bool SerializeInfoImpl(base::Pickle* pickle) const override;
532 528
533 double GetBucketSize(Count current, uint32_t i) const override; 529 double GetBucketSize(Count current, uint32_t i) const override;
534 530
535 private: 531 private:
536 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( 532 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo(
537 base::PickleIterator* iter); 533 base::PickleIterator* iter);
538 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); 534 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter);
539 535
540 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); 536 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges);
541 537
542 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); 538 DISALLOW_COPY_AND_ASSIGN(CustomHistogram);
543 }; 539 };
544 540
545 } // namespace base 541 } // namespace base
546 542
547 #endif // BASE_METRICS_HISTOGRAM_H_ 543 #endif // BASE_METRICS_HISTOGRAM_H_
OLDNEW
« no previous file with comments | « no previous file | base/metrics/histogram.cc » ('j') | base/metrics/histogram_samples.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698