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

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

Issue 1880803003: Display histograms from subprocesses in chrome://histograms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 6 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 | « base/metrics/histogram.h ('k') | base/metrics/histogram_base.h » ('j') | no next file with comments »
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 // 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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 469
470 void Histogram::AddSamples(const HistogramSamples& samples) { 470 void Histogram::AddSamples(const HistogramSamples& samples) {
471 samples_->Add(samples); 471 samples_->Add(samples);
472 } 472 }
473 473
474 bool Histogram::AddSamplesFromPickle(PickleIterator* iter) { 474 bool Histogram::AddSamplesFromPickle(PickleIterator* iter) {
475 return samples_->AddFromPickle(iter); 475 return samples_->AddFromPickle(iter);
476 } 476 }
477 477
478 // The following methods provide a graphical histogram display. 478 // The following methods provide a graphical histogram display.
479 void Histogram::WriteHTMLGraph(std::string* output) const { 479 void Histogram::WriteHTMLGraph(const HistogramSamples* snapshot,
480 std::string* output) const {
480 // TBD(jar) Write a nice HTML bar chart, with divs an mouse-overs etc. 481 // TBD(jar) Write a nice HTML bar chart, with divs an mouse-overs etc.
481 output->append("<PRE>"); 482 output->append("<PRE>");
482 WriteAsciiImpl(true, "<br>", output); 483 WriteAsciiImpl(true, "<br>", static_cast<const SampleVector*>(snapshot),
484 output);
483 output->append("</PRE>"); 485 output->append("</PRE>");
484 } 486 }
485 487
486 void Histogram::WriteAscii(std::string* output) const { 488 void Histogram::WriteAscii(const HistogramSamples* snapshot,
487 WriteAsciiImpl(true, "\n", output); 489 std::string* output) const {
490 WriteAsciiImpl(true, "\n", static_cast<const SampleVector*>(snapshot),
491 output);
488 } 492 }
489 493
490 bool Histogram::SerializeInfoImpl(Pickle* pickle) const { 494 bool Histogram::SerializeInfoImpl(Pickle* pickle) const {
491 DCHECK(bucket_ranges()->HasValidChecksum()); 495 DCHECK(bucket_ranges()->HasValidChecksum());
492 return pickle->WriteString(histogram_name()) && 496 return pickle->WriteString(histogram_name()) &&
493 pickle->WriteInt(flags()) && 497 pickle->WriteInt(flags()) &&
494 pickle->WriteInt(declared_min()) && 498 pickle->WriteInt(declared_min()) &&
495 pickle->WriteInt(declared_max()) && 499 pickle->WriteInt(declared_max()) &&
496 pickle->WriteUInt32(bucket_count()) && 500 pickle->WriteUInt32(bucket_count()) &&
497 pickle->WriteUInt32(bucket_ranges()->checksum()); 501 pickle->WriteUInt32(bucket_ranges()->checksum());
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 589
586 std::unique_ptr<SampleVector> Histogram::SnapshotSampleVector() const { 590 std::unique_ptr<SampleVector> Histogram::SnapshotSampleVector() const {
587 std::unique_ptr<SampleVector> samples( 591 std::unique_ptr<SampleVector> samples(
588 new SampleVector(samples_->id(), bucket_ranges())); 592 new SampleVector(samples_->id(), bucket_ranges()));
589 samples->Add(*samples_); 593 samples->Add(*samples_);
590 return samples; 594 return samples;
591 } 595 }
592 596
593 void Histogram::WriteAsciiImpl(bool graph_it, 597 void Histogram::WriteAsciiImpl(bool graph_it,
594 const std::string& newline, 598 const std::string& newline,
599 const SampleVector* snapshot,
595 std::string* output) const { 600 std::string* output) const {
596 // Get local (stack) copies of all effectively volatile class data so that we 601 std::unique_ptr<SampleVector> local_snapshot;
597 // are consistent across our output activities. 602 if (!snapshot) {
598 std::unique_ptr<SampleVector> snapshot = SnapshotSampleVector(); 603 // Get local (stack) copies of all effectively volatile class data so
604 // that we are consistent across our output activities.
605 local_snapshot = SnapshotSampleVector();
606 snapshot = local_snapshot.get();
607 }
599 Count sample_count = snapshot->TotalCount(); 608 Count sample_count = snapshot->TotalCount();
600 609
601 WriteAsciiHeader(*snapshot, sample_count, output); 610 WriteAsciiHeader(*snapshot, sample_count, output);
602 output->append(newline); 611 output->append(newline);
603 612
604 // Prepare to normalize graphical rendering of bucket contents. 613 // Prepare to normalize graphical rendering of bucket contents.
605 double max_size = 0; 614 double max_size = 0;
606 if (graph_it) 615 if (graph_it)
607 max_size = GetPeakBucketSize(*snapshot); 616 max_size = GetPeakBucketSize(*snapshot);
608 617
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 Sample sample = custom_ranges[i]; 1188 Sample sample = custom_ranges[i];
1180 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1) 1189 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1)
1181 return false; 1190 return false;
1182 if (sample != 0) 1191 if (sample != 0)
1183 has_valid_range = true; 1192 has_valid_range = true;
1184 } 1193 }
1185 return has_valid_range; 1194 return has_valid_range;
1186 } 1195 }
1187 1196
1188 } // namespace base 1197 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/histogram.h ('k') | base/metrics/histogram_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698