| OLD | NEW |
| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 Sample minimum, | 114 Sample minimum, |
| 115 Sample maximum, | 115 Sample maximum, |
| 116 size_t bucket_count, | 116 size_t bucket_count, |
| 117 int32 flags); | 117 int32 flags); |
| 118 static HistogramBase* FactoryTimeGet(const std::string& name, | 118 static HistogramBase* FactoryTimeGet(const std::string& name, |
| 119 base::TimeDelta minimum, | 119 base::TimeDelta minimum, |
| 120 base::TimeDelta maximum, | 120 base::TimeDelta maximum, |
| 121 size_t bucket_count, | 121 size_t bucket_count, |
| 122 int32 flags); | 122 int32 flags); |
| 123 | 123 |
| 124 // Overloads of the above two functions that take a const char* |name| param, |
| 125 // to avoid code bloat from the std::string constructor being inlined into |
| 126 // call sites. |
| 127 static HistogramBase* FactoryGet(const char* name, |
| 128 Sample minimum, |
| 129 Sample maximum, |
| 130 size_t bucket_count, |
| 131 int32 flags); |
| 132 static HistogramBase* FactoryTimeGet(const char* name, |
| 133 base::TimeDelta minimum, |
| 134 base::TimeDelta maximum, |
| 135 size_t bucket_count, |
| 136 int32 flags); |
| 137 |
| 124 static void InitializeBucketRanges(Sample minimum, | 138 static void InitializeBucketRanges(Sample minimum, |
| 125 Sample maximum, | 139 Sample maximum, |
| 126 BucketRanges* ranges); | 140 BucketRanges* ranges); |
| 127 | 141 |
| 128 // This constant if for FindCorruption. Since snapshots of histograms are | 142 // This constant if for FindCorruption. Since snapshots of histograms are |
| 129 // taken asynchronously relative to sampling, and our counting code currently | 143 // taken asynchronously relative to sampling, and our counting code currently |
| 130 // does not prevent race conditions, it is pretty likely that we'll catch a | 144 // does not prevent race conditions, it is pretty likely that we'll catch a |
| 131 // redundant count that doesn't match the sample count. We allow for a | 145 // redundant count that doesn't match the sample count. We allow for a |
| 132 // certain amount of slop before flagging this as an inconsistency. Even with | 146 // certain amount of slop before flagging this as an inconsistency. Even with |
| 133 // an inconsistency, we'll snapshot it again (for UMA in about a half hour), | 147 // an inconsistency, we'll snapshot it again (for UMA in about a half hour), |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 Sample minimum, | 284 Sample minimum, |
| 271 Sample maximum, | 285 Sample maximum, |
| 272 size_t bucket_count, | 286 size_t bucket_count, |
| 273 int32 flags); | 287 int32 flags); |
| 274 static HistogramBase* FactoryTimeGet(const std::string& name, | 288 static HistogramBase* FactoryTimeGet(const std::string& name, |
| 275 TimeDelta minimum, | 289 TimeDelta minimum, |
| 276 TimeDelta maximum, | 290 TimeDelta maximum, |
| 277 size_t bucket_count, | 291 size_t bucket_count, |
| 278 int32 flags); | 292 int32 flags); |
| 279 | 293 |
| 294 // Overloads of the above two functions that take a const char* |name| param, |
| 295 // to avoid code bloat from the std::string constructor being inlined into |
| 296 // call sites. |
| 297 static HistogramBase* FactoryGet(const char* name, |
| 298 Sample minimum, |
| 299 Sample maximum, |
| 300 size_t bucket_count, |
| 301 int32 flags); |
| 302 static HistogramBase* FactoryTimeGet(const char* name, |
| 303 TimeDelta minimum, |
| 304 TimeDelta maximum, |
| 305 size_t bucket_count, |
| 306 int32 flags); |
| 307 |
| 280 struct DescriptionPair { | 308 struct DescriptionPair { |
| 281 Sample sample; | 309 Sample sample; |
| 282 const char* description; // Null means end of a list of pairs. | 310 const char* description; // Null means end of a list of pairs. |
| 283 }; | 311 }; |
| 284 | 312 |
| 285 // Create a LinearHistogram and store a list of number/text values for use in | 313 // Create a LinearHistogram and store a list of number/text values for use in |
| 286 // writing the histogram graph. | 314 // writing the histogram graph. |
| 287 // |descriptions| can be NULL, which means no special descriptions to set. If | 315 // |descriptions| can be NULL, which means no special descriptions to set. If |
| 288 // it's not NULL, the last element in the array must has a NULL in its | 316 // it's not NULL, the last element in the array must has a NULL in its |
| 289 // "description" field. | 317 // "description" field. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 DISALLOW_COPY_AND_ASSIGN(LinearHistogram); | 360 DISALLOW_COPY_AND_ASSIGN(LinearHistogram); |
| 333 }; | 361 }; |
| 334 | 362 |
| 335 //------------------------------------------------------------------------------ | 363 //------------------------------------------------------------------------------ |
| 336 | 364 |
| 337 // BooleanHistogram is a histogram for booleans. | 365 // BooleanHistogram is a histogram for booleans. |
| 338 class BASE_EXPORT BooleanHistogram : public LinearHistogram { | 366 class BASE_EXPORT BooleanHistogram : public LinearHistogram { |
| 339 public: | 367 public: |
| 340 static HistogramBase* FactoryGet(const std::string& name, int32 flags); | 368 static HistogramBase* FactoryGet(const std::string& name, int32 flags); |
| 341 | 369 |
| 370 // Overload of the above function that takes a const char* |name| param, |
| 371 // to avoid code bloat from the std::string constructor being inlined into |
| 372 // call sites. |
| 373 static HistogramBase* FactoryGet(const char* name, int32 flags); |
| 374 |
| 342 HistogramType GetHistogramType() const override; | 375 HistogramType GetHistogramType() const override; |
| 343 | 376 |
| 344 private: | 377 private: |
| 345 BooleanHistogram(const std::string& name, const BucketRanges* ranges); | 378 BooleanHistogram(const std::string& name, const BucketRanges* ranges); |
| 346 | 379 |
| 347 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( | 380 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( |
| 348 base::PickleIterator* iter); | 381 base::PickleIterator* iter); |
| 349 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); | 382 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); |
| 350 | 383 |
| 351 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); | 384 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); |
| 352 }; | 385 }; |
| 353 | 386 |
| 354 //------------------------------------------------------------------------------ | 387 //------------------------------------------------------------------------------ |
| 355 | 388 |
| 356 // CustomHistogram is a histogram for a set of custom integers. | 389 // CustomHistogram is a histogram for a set of custom integers. |
| 357 class BASE_EXPORT CustomHistogram : public Histogram { | 390 class BASE_EXPORT CustomHistogram : public Histogram { |
| 358 public: | 391 public: |
| 359 // |custom_ranges| contains a vector of limits on ranges. Each limit should be | 392 // |custom_ranges| contains a vector of limits on ranges. Each limit should be |
| 360 // > 0 and < kSampleType_MAX. (Currently 0 is still accepted for backward | 393 // > 0 and < kSampleType_MAX. (Currently 0 is still accepted for backward |
| 361 // compatibility). The limits can be unordered or contain duplication, but | 394 // compatibility). The limits can be unordered or contain duplication, but |
| 362 // client should not depend on this. | 395 // client should not depend on this. |
| 363 static HistogramBase* FactoryGet(const std::string& name, | 396 static HistogramBase* FactoryGet(const std::string& name, |
| 364 const std::vector<Sample>& custom_ranges, | 397 const std::vector<Sample>& custom_ranges, |
| 365 int32 flags); | 398 int32 flags); |
| 366 | 399 |
| 400 // Overload of the above function that takes a const char* |name| param, |
| 401 // to avoid code bloat from the std::string constructor being inlined into |
| 402 // call sites. |
| 403 static HistogramBase* FactoryGet(const char* name, |
| 404 const std::vector<Sample>& custom_ranges, |
| 405 int32 flags); |
| 406 |
| 367 // Overridden from Histogram: | 407 // Overridden from Histogram: |
| 368 HistogramType GetHistogramType() const override; | 408 HistogramType GetHistogramType() const override; |
| 369 | 409 |
| 370 // Helper method for transforming an array of valid enumeration values | 410 // Helper method for transforming an array of valid enumeration values |
| 371 // to the std::vector<int> expected by UMA_HISTOGRAM_CUSTOM_ENUMERATION. | 411 // to the std::vector<int> expected by UMA_HISTOGRAM_CUSTOM_ENUMERATION. |
| 372 // This function ensures that a guard bucket exists right after any | 412 // This function ensures that a guard bucket exists right after any |
| 373 // valid sample value (unless the next higher sample is also a valid value), | 413 // valid sample value (unless the next higher sample is also a valid value), |
| 374 // so that invalid samples never fall into the same bucket as valid samples. | 414 // so that invalid samples never fall into the same bucket as valid samples. |
| 375 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges. | 415 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges. |
| 376 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, | 416 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 392 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); | 432 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); |
| 393 static BucketRanges* CreateBucketRangesFromCustomRanges( | 433 static BucketRanges* CreateBucketRangesFromCustomRanges( |
| 394 const std::vector<Sample>& custom_ranges); | 434 const std::vector<Sample>& custom_ranges); |
| 395 | 435 |
| 396 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); | 436 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); |
| 397 }; | 437 }; |
| 398 | 438 |
| 399 } // namespace base | 439 } // namespace base |
| 400 | 440 |
| 401 #endif // BASE_METRICS_HISTOGRAM_H_ | 441 #endif // BASE_METRICS_HISTOGRAM_H_ |
| OLD | NEW |