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

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

Issue 1425533011: Support "shared" histograms between processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shmem-alloc
Patch Set: added a couple tests (and fixed related issues) Created 5 years 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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 void WriteAscii(std::string* output) const override; 190 void WriteAscii(std::string* output) const override;
191 191
192 protected: 192 protected:
193 // |ranges| should contain the underflow and overflow buckets. See top 193 // |ranges| should contain the underflow and overflow buckets. See top
194 // comments for example. 194 // comments for example.
195 Histogram(const std::string& name, 195 Histogram(const std::string& name,
196 Sample minimum, 196 Sample minimum,
197 Sample maximum, 197 Sample maximum,
198 const BucketRanges* ranges); 198 const BucketRanges* ranges);
199 199
200 // Traditionally, histograms allocate their own memory for the bucket
201 // vector but "shared" histograms use memory regions allocated from a
202 // special memory segment that is passed in here. It is assumed that
203 // the life of this memory is managed externally and exceeds the lifetime
204 // of this object. Practically, this memory is never released until the
205 // process exits and the OS cleans it up.
206 Histogram(const std::string& name,
207 Sample minimum,
208 Sample maximum,
209 const BucketRanges* ranges,
210 HistogramBase::AtomicCount* counts,
211 size_t counts_size,
212 HistogramSamples::Metadata* meta);
213
200 ~Histogram() override; 214 ~Histogram() override;
201 215
202 // HistogramBase implementation: 216 // HistogramBase implementation:
203 bool SerializeInfoImpl(base::Pickle* pickle) const override; 217 bool SerializeInfoImpl(base::Pickle* pickle) const override;
204 218
205 // Method to override to skip the display of the i'th bucket if it's empty. 219 // Method to override to skip the display of the i'th bucket if it's empty.
206 virtual bool PrintEmptyBucket(size_t index) const; 220 virtual bool PrintEmptyBucket(size_t index) const;
207 221
208 // Get normalized size, relative to the ranges(i). 222 // Get normalized size, relative to the ranges(i).
209 virtual double GetBucketSize(Count current, size_t i) const; 223 virtual double GetBucketSize(Count current, size_t i) const;
210 224
211 // Return a string description of what goes in a given bucket. 225 // Return a string description of what goes in a given bucket.
212 // Most commonly this is the numeric value, but in derived classes it may 226 // Most commonly this is the numeric value, but in derived classes it may
213 // be a name (or string description) given to the bucket. 227 // be a name (or string description) given to the bucket.
214 virtual const std::string GetAsciiBucketRange(size_t it) const; 228 virtual const std::string GetAsciiBucketRange(size_t it) const;
215 229
216 private: 230 private:
217 // Allow tests to corrupt our innards for testing purposes. 231 // Allow tests to corrupt our innards for testing purposes.
218 FRIEND_TEST_ALL_PREFIXES(HistogramTest, BoundsTest); 232 FRIEND_TEST_ALL_PREFIXES(HistogramTest, BoundsTest);
219 FRIEND_TEST_ALL_PREFIXES(HistogramTest, BucketPlacementTest); 233 FRIEND_TEST_ALL_PREFIXES(HistogramTest, BucketPlacementTest);
220 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptBucketBounds); 234 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptBucketBounds);
221 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptSampleCounts); 235 FRIEND_TEST_ALL_PREFIXES(HistogramTest, CorruptSampleCounts);
222 FRIEND_TEST_ALL_PREFIXES(HistogramTest, NameMatchTest); 236 FRIEND_TEST_ALL_PREFIXES(HistogramTest, NameMatchTest);
223 FRIEND_TEST_ALL_PREFIXES(HistogramTest, AddCountTest); 237 FRIEND_TEST_ALL_PREFIXES(HistogramTest, AddCountTest);
224 238
225 friend class StatisticsRecorder; // To allow it to delete duplicates. 239 friend class StatisticsRecorder; // To allow it to delete duplicates.
226 friend class StatisticsRecorderTest; 240 friend class StatisticsRecorderTest;
227 241
242 friend BASE_EXPORT HistogramBase* HistogramBase::CreatePersistentHistogram(
243 PersistentMemoryAllocator* allocator,
244 PersistentHistogramData* histogram_data);
228 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( 245 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo(
229 base::PickleIterator* iter); 246 base::PickleIterator* iter);
230 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); 247 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter);
231 248
232 // Implementation of SnapshotSamples function. 249 // Implementation of SnapshotSamples function.
233 scoped_ptr<SampleVector> SnapshotSampleVector() const; 250 scoped_ptr<SampleVector> SnapshotSampleVector() const;
234 251
235 //---------------------------------------------------------------------------- 252 //----------------------------------------------------------------------------
236 // Helpers for emitting Ascii graphic. Each method appends data to output. 253 // Helpers for emitting Ascii graphic. Each method appends data to output.
237 254
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 349
333 // Overridden from Histogram: 350 // Overridden from Histogram:
334 HistogramType GetHistogramType() const override; 351 HistogramType GetHistogramType() const override;
335 352
336 protected: 353 protected:
337 LinearHistogram(const std::string& name, 354 LinearHistogram(const std::string& name,
338 Sample minimum, 355 Sample minimum,
339 Sample maximum, 356 Sample maximum,
340 const BucketRanges* ranges); 357 const BucketRanges* ranges);
341 358
359 LinearHistogram(const std::string& name,
360 Sample minimum,
361 Sample maximum,
362 const BucketRanges* ranges,
363 HistogramBase::AtomicCount* counts,
364 size_t counts_size,
365 HistogramSamples::Metadata* meta);
366
342 double GetBucketSize(Count current, size_t i) const override; 367 double GetBucketSize(Count current, size_t i) const override;
343 368
344 // If we have a description for a bucket, then return that. Otherwise 369 // If we have a description for a bucket, then return that. Otherwise
345 // let parent class provide a (numeric) description. 370 // let parent class provide a (numeric) description.
346 const std::string GetAsciiBucketRange(size_t i) const override; 371 const std::string GetAsciiBucketRange(size_t i) const override;
347 372
348 // Skip printing of name for numeric range if we have a name (and if this is 373 // Skip printing of name for numeric range if we have a name (and if this is
349 // an empty bucket). 374 // an empty bucket).
350 bool PrintEmptyBucket(size_t index) const override; 375 bool PrintEmptyBucket(size_t index) const override;
351 376
352 private: 377 private:
378 friend BASE_EXPORT HistogramBase* HistogramBase::CreatePersistentHistogram(
379 PersistentMemoryAllocator* allocator,
380 PersistentHistogramData* histogram_data);
353 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( 381 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo(
354 base::PickleIterator* iter); 382 base::PickleIterator* iter);
355 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); 383 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter);
356 384
357 // For some ranges, we store a printable description of a bucket range. 385 // For some ranges, we store a printable description of a bucket range.
358 // If there is no description, then GetAsciiBucketRange() uses parent class 386 // If there is no description, then GetAsciiBucketRange() uses parent class
359 // to provide a description. 387 // to provide a description.
360 typedef std::map<Sample, std::string> BucketDescriptionMap; 388 typedef std::map<Sample, std::string> BucketDescriptionMap;
361 BucketDescriptionMap bucket_description_; 389 BucketDescriptionMap bucket_description_;
362 390
363 DISALLOW_COPY_AND_ASSIGN(LinearHistogram); 391 DISALLOW_COPY_AND_ASSIGN(LinearHistogram);
364 }; 392 };
365 393
366 //------------------------------------------------------------------------------ 394 //------------------------------------------------------------------------------
367 395
368 // BooleanHistogram is a histogram for booleans. 396 // BooleanHistogram is a histogram for booleans.
369 class BASE_EXPORT BooleanHistogram : public LinearHistogram { 397 class BASE_EXPORT BooleanHistogram : public LinearHistogram {
370 public: 398 public:
371 static HistogramBase* FactoryGet(const std::string& name, int32 flags); 399 static HistogramBase* FactoryGet(const std::string& name, int32 flags);
372 400
373 // Overload of the above function that takes a const char* |name| param, 401 // Overload of the above function that takes a const char* |name| param,
374 // to avoid code bloat from the std::string constructor being inlined into 402 // to avoid code bloat from the std::string constructor being inlined into
375 // call sites. 403 // call sites.
376 static HistogramBase* FactoryGet(const char* name, int32 flags); 404 static HistogramBase* FactoryGet(const char* name, int32 flags);
377 405
378 HistogramType GetHistogramType() const override; 406 HistogramType GetHistogramType() const override;
379 407
380 private: 408 private:
381 BooleanHistogram(const std::string& name, const BucketRanges* ranges); 409 BooleanHistogram(const std::string& name, const BucketRanges* ranges);
410 BooleanHistogram(const std::string& name,
411 const BucketRanges* ranges,
412 HistogramBase::AtomicCount* counts,
413 HistogramSamples::Metadata* meta);
382 414
415 friend BASE_EXPORT HistogramBase* HistogramBase::CreatePersistentHistogram(
416 PersistentMemoryAllocator* allocator,
417 PersistentHistogramData* histogram_data);
383 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( 418 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo(
384 base::PickleIterator* iter); 419 base::PickleIterator* iter);
385 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); 420 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter);
386 421
387 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); 422 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram);
388 }; 423 };
389 424
390 //------------------------------------------------------------------------------ 425 //------------------------------------------------------------------------------
391 426
392 // CustomHistogram is a histogram for a set of custom integers. 427 // CustomHistogram is a histogram for a set of custom integers.
(...skipping 22 matching lines...) Expand all
415 // This function ensures that a guard bucket exists right after any 450 // This function ensures that a guard bucket exists right after any
416 // valid sample value (unless the next higher sample is also a valid value), 451 // valid sample value (unless the next higher sample is also a valid value),
417 // so that invalid samples never fall into the same bucket as valid samples. 452 // so that invalid samples never fall into the same bucket as valid samples.
418 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges. 453 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges.
419 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, 454 static std::vector<Sample> ArrayToCustomRanges(const Sample* values,
420 size_t num_values); 455 size_t num_values);
421 protected: 456 protected:
422 CustomHistogram(const std::string& name, 457 CustomHistogram(const std::string& name,
423 const BucketRanges* ranges); 458 const BucketRanges* ranges);
424 459
460 CustomHistogram(const std::string& name,
461 const BucketRanges* ranges,
462 HistogramBase::AtomicCount* counts,
463 size_t counts_size,
464 HistogramSamples::Metadata* meta);
465
425 // HistogramBase implementation: 466 // HistogramBase implementation:
426 bool SerializeInfoImpl(base::Pickle* pickle) const override; 467 bool SerializeInfoImpl(base::Pickle* pickle) const override;
427 468
428 double GetBucketSize(Count current, size_t i) const override; 469 double GetBucketSize(Count current, size_t i) const override;
429 470
430 private: 471 private:
472 friend BASE_EXPORT HistogramBase* HistogramBase::CreatePersistentHistogram(
473 PersistentMemoryAllocator* allocator,
474 PersistentHistogramData* histogram_data);
431 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( 475 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo(
432 base::PickleIterator* iter); 476 base::PickleIterator* iter);
433 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); 477 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter);
434 478
435 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); 479 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges);
436 static BucketRanges* CreateBucketRangesFromCustomRanges( 480 static BucketRanges* CreateBucketRangesFromCustomRanges(
437 const std::vector<Sample>& custom_ranges); 481 const std::vector<Sample>& custom_ranges);
438 482
439 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); 483 DISALLOW_COPY_AND_ASSIGN(CustomHistogram);
440 }; 484 };
441 485
442 } // namespace base 486 } // namespace base
443 487
444 #endif // BASE_METRICS_HISTOGRAM_H_ 488 #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