| 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 // See header file for details and examples. | 8 // See header file for details and examples. |
| 9 | 9 |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 double Histogram::GetBucketSize(Count current, size_t i) const { | 333 double Histogram::GetBucketSize(Count current, size_t i) const { |
| 334 DCHECK_GT(ranges(i + 1), ranges(i)); | 334 DCHECK_GT(ranges(i + 1), ranges(i)); |
| 335 static const double kTransitionWidth = 5; | 335 static const double kTransitionWidth = 5; |
| 336 double denominator = ranges(i + 1) - ranges(i); | 336 double denominator = ranges(i + 1) - ranges(i); |
| 337 if (denominator > kTransitionWidth) | 337 if (denominator > kTransitionWidth) |
| 338 denominator = kTransitionWidth; // Stop trying to normalize. | 338 denominator = kTransitionWidth; // Stop trying to normalize. |
| 339 return current/denominator; | 339 return current/denominator; |
| 340 } | 340 } |
| 341 | 341 |
| 342 const string Histogram::GetAsciiBucketRange(size_t i) const { | 342 const string Histogram::GetAsciiBucketRange(size_t i) const { |
| 343 string result; | 343 return GetSimpleAsciiBucketRange(ranges(i)); |
| 344 if (kHexRangePrintingFlag & flags()) | |
| 345 StringAppendF(&result, "%#x", ranges(i)); | |
| 346 else | |
| 347 StringAppendF(&result, "%d", ranges(i)); | |
| 348 return result; | |
| 349 } | 344 } |
| 350 | 345 |
| 351 //------------------------------------------------------------------------------ | 346 //------------------------------------------------------------------------------ |
| 352 // Private methods | 347 // Private methods |
| 353 | 348 |
| 354 // static | 349 // static |
| 355 HistogramBase* Histogram::DeserializeInfoImpl(PickleIterator* iter) { | 350 HistogramBase* Histogram::DeserializeInfoImpl(PickleIterator* iter) { |
| 356 string histogram_name; | 351 string histogram_name; |
| 357 int flags; | 352 int flags; |
| 358 int declared_min; | 353 int declared_min; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 const size_t i, | 478 const size_t i, |
| 484 string* output) const { | 479 string* output) const { |
| 485 double scaled_sum = (past + current + remaining) / 100.0; | 480 double scaled_sum = (past + current + remaining) / 100.0; |
| 486 WriteAsciiBucketValue(current, scaled_sum, output); | 481 WriteAsciiBucketValue(current, scaled_sum, output); |
| 487 if (0 < i) { | 482 if (0 < i) { |
| 488 double percentage = past / scaled_sum; | 483 double percentage = past / scaled_sum; |
| 489 StringAppendF(output, " {%3.1f%%}", percentage); | 484 StringAppendF(output, " {%3.1f%%}", percentage); |
| 490 } | 485 } |
| 491 } | 486 } |
| 492 | 487 |
| 493 void Histogram::WriteAsciiBucketValue(Count current, | |
| 494 double scaled_sum, | |
| 495 string* output) const { | |
| 496 StringAppendF(output, " (%d = %3.1f%%)", current, current/scaled_sum); | |
| 497 } | |
| 498 | |
| 499 void Histogram::WriteAsciiBucketGraph(double current_size, | |
| 500 double max_size, | |
| 501 string* output) const { | |
| 502 const int k_line_length = 72; // Maximal horizontal width of graph. | |
| 503 int x_count = static_cast<int>(k_line_length * (current_size / max_size) | |
| 504 + 0.5); | |
| 505 int x_remainder = k_line_length - x_count; | |
| 506 | |
| 507 while (0 < x_count--) | |
| 508 output->append("-"); | |
| 509 output->append("O"); | |
| 510 while (0 < x_remainder--) | |
| 511 output->append(" "); | |
| 512 } | |
| 513 | |
| 514 void Histogram::GetParameters(DictionaryValue* params) const { | 488 void Histogram::GetParameters(DictionaryValue* params) const { |
| 515 params->SetString("type", HistogramTypeToString(GetHistogramType())); | 489 params->SetString("type", HistogramTypeToString(GetHistogramType())); |
| 516 params->SetInteger("min", declared_min()); | 490 params->SetInteger("min", declared_min()); |
| 517 params->SetInteger("max", declared_max()); | 491 params->SetInteger("max", declared_max()); |
| 518 params->SetInteger("bucket_count", static_cast<int>(bucket_count())); | 492 params->SetInteger("bucket_count", static_cast<int>(bucket_count())); |
| 519 } | 493 } |
| 520 | 494 |
| 521 void Histogram::GetCountAndBucketData(Count* count, ListValue* buckets) const { | 495 void Histogram::GetCountAndBucketData(Count* count, ListValue* buckets) const { |
| 522 scoped_ptr<SampleVector> snapshot = SnapshotSampleVector(); | 496 scoped_ptr<SampleVector> snapshot = SnapshotSampleVector(); |
| 523 *count = snapshot->TotalCount(); | 497 *count = snapshot->TotalCount(); |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 | 834 |
| 861 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); | 835 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); |
| 862 for (size_t i = 0; i < ranges.size(); i++) { | 836 for (size_t i = 0; i < ranges.size(); i++) { |
| 863 bucket_ranges->set_range(i, ranges[i]); | 837 bucket_ranges->set_range(i, ranges[i]); |
| 864 } | 838 } |
| 865 bucket_ranges->ResetChecksum(); | 839 bucket_ranges->ResetChecksum(); |
| 866 return bucket_ranges; | 840 return bucket_ranges; |
| 867 } | 841 } |
| 868 | 842 |
| 869 } // namespace base | 843 } // namespace base |
| OLD | NEW |