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

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, 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
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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 455
456 void Histogram::AddSamples(const HistogramSamples& samples) { 456 void Histogram::AddSamples(const HistogramSamples& samples) {
457 samples_->Add(samples); 457 samples_->Add(samples);
458 } 458 }
459 459
460 bool Histogram::AddSamplesFromPickle(PickleIterator* iter) { 460 bool Histogram::AddSamplesFromPickle(PickleIterator* iter) {
461 return samples_->AddFromPickle(iter); 461 return samples_->AddFromPickle(iter);
462 } 462 }
463 463
464 // The following methods provide a graphical histogram display. 464 // The following methods provide a graphical histogram display.
465 void Histogram::WriteHTMLGraph(std::string* output) const { 465 void Histogram::WriteHTMLGraph(const HistogramSamples* snapshot,
466 std::string* output) const {
466 // TBD(jar) Write a nice HTML bar chart, with divs an mouse-overs etc. 467 // TBD(jar) Write a nice HTML bar chart, with divs an mouse-overs etc.
467 output->append("<PRE>"); 468 output->append("<PRE>");
468 WriteAsciiImpl(true, "<br>", output); 469 WriteAsciiImpl(true, "<br>", static_cast<const SampleVector*>(snapshot),
Ilya Sherman 2016/04/13 00:29:32 Hmm, I'm not super happy about the static_cast her
bcwhite 2016/04/13 11:58:18 This is a virtual function off of HistogramBase so
470 output);
469 output->append("</PRE>"); 471 output->append("</PRE>");
470 } 472 }
471 473
472 void Histogram::WriteAscii(std::string* output) const { 474 void Histogram::WriteAscii(const HistogramSamples* snapshot,
473 WriteAsciiImpl(true, "\n", output); 475 std::string* output) const {
476 WriteAsciiImpl(true, "\n", static_cast<const SampleVector*>(snapshot),
477 output);
474 } 478 }
475 479
476 bool Histogram::SerializeInfoImpl(Pickle* pickle) const { 480 bool Histogram::SerializeInfoImpl(Pickle* pickle) const {
477 DCHECK(bucket_ranges()->HasValidChecksum()); 481 DCHECK(bucket_ranges()->HasValidChecksum());
478 return pickle->WriteString(histogram_name()) && 482 return pickle->WriteString(histogram_name()) &&
479 pickle->WriteInt(flags()) && 483 pickle->WriteInt(flags()) &&
480 pickle->WriteInt(declared_min()) && 484 pickle->WriteInt(declared_min()) &&
481 pickle->WriteInt(declared_max()) && 485 pickle->WriteInt(declared_max()) &&
482 pickle->WriteUInt32(bucket_count()) && 486 pickle->WriteUInt32(bucket_count()) &&
483 pickle->WriteUInt32(bucket_ranges()->checksum()); 487 pickle->WriteUInt32(bucket_ranges()->checksum());
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 575
572 std::unique_ptr<SampleVector> Histogram::SnapshotSampleVector() const { 576 std::unique_ptr<SampleVector> Histogram::SnapshotSampleVector() const {
573 std::unique_ptr<SampleVector> samples( 577 std::unique_ptr<SampleVector> samples(
574 new SampleVector(samples_->id(), bucket_ranges())); 578 new SampleVector(samples_->id(), bucket_ranges()));
575 samples->Add(*samples_); 579 samples->Add(*samples_);
576 return samples; 580 return samples;
577 } 581 }
578 582
579 void Histogram::WriteAsciiImpl(bool graph_it, 583 void Histogram::WriteAsciiImpl(bool graph_it,
580 const std::string& newline, 584 const std::string& newline,
585 const SampleVector* snapshot,
581 std::string* output) const { 586 std::string* output) const {
582 // Get local (stack) copies of all effectively volatile class data so that we 587 // Get local (stack) copies of all effectively volatile class data so that we
583 // are consistent across our output activities. 588 // are consistent across our output activities.
Ilya Sherman 2016/04/13 00:29:32 nit: Mebbe move this comment into the if-stmt?
bcwhite 2016/04/13 11:58:18 Done.
584 std::unique_ptr<SampleVector> snapshot = SnapshotSampleVector(); 589 std::unique_ptr<SampleVector> local_snapshot;
590 if (!snapshot) {
591 local_snapshot = SnapshotSampleVector();
592 snapshot = local_snapshot.get();
593 }
585 Count sample_count = snapshot->TotalCount(); 594 Count sample_count = snapshot->TotalCount();
586 595
587 WriteAsciiHeader(*snapshot, sample_count, output); 596 WriteAsciiHeader(*snapshot, sample_count, output);
588 output->append(newline); 597 output->append(newline);
589 598
590 // Prepare to normalize graphical rendering of bucket contents. 599 // Prepare to normalize graphical rendering of bucket contents.
591 double max_size = 0; 600 double max_size = 0;
592 if (graph_it) 601 if (graph_it)
593 max_size = GetPeakBucketSize(*snapshot); 602 max_size = GetPeakBucketSize(*snapshot);
594 603
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 Sample sample = custom_ranges[i]; 1174 Sample sample = custom_ranges[i];
1166 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1) 1175 if (sample < 0 || sample > HistogramBase::kSampleType_MAX - 1)
1167 return false; 1176 return false;
1168 if (sample != 0) 1177 if (sample != 0)
1169 has_valid_range = true; 1178 has_valid_range = true;
1170 } 1179 }
1171 return has_valid_range; 1180 return has_valid_range;
1172 } 1181 }
1173 1182
1174 } // namespace base 1183 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698