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

Unified Diff: base/metrics/sparse_histogram.cc

Issue 13469020: Implement write methods for SparseHistogram (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase due to conflict in histogram_base.cc Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/metrics/sparse_histogram.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/sparse_histogram.cc
diff --git a/base/metrics/sparse_histogram.cc b/base/metrics/sparse_histogram.cc
index 295267335a4efd6fb595c895ffdc93706a06500f..df361f7983928f562889ae954c7dc76a750af100 100644
--- a/base/metrics/sparse_histogram.cc
+++ b/base/metrics/sparse_histogram.cc
@@ -7,6 +7,7 @@
#include "base/metrics/sample_map.h"
#include "base/metrics/statistics_recorder.h"
#include "base/pickle.h"
+#include "base/stringprintf.h"
#include "base/synchronization/lock.h"
using std::map;
@@ -69,11 +70,13 @@ bool SparseHistogram::AddSamplesFromPickle(PickleIterator* iter) {
}
void SparseHistogram::WriteHTMLGraph(string* output) const {
- // TODO(kaiwang): Implement.
+ output->append("<PRE>");
+ WriteAsciiImpl(true, "<br>", output);
+ output->append("</PRE>");
}
void SparseHistogram::WriteAscii(string* output) const {
- // TODO(kaiwang): Implement.
+ WriteAsciiImpl(true, "\n", output);
}
bool SparseHistogram::SerializeInfoImpl(Pickle* pickle) const {
@@ -106,4 +109,69 @@ void SparseHistogram::GetCountAndBucketData(Count* count,
// TODO(kaiwang): Implement. (See HistogramBase::WriteJSON.)
}
+void SparseHistogram::WriteAsciiImpl(bool graph_it,
+ const std::string& newline,
+ std::string* output) const {
+ // Get a local copy of the data so we are consistent.
+ scoped_ptr<HistogramSamples> snapshot = SnapshotSamples();
+ Count total_count = snapshot->TotalCount();
+ double scaled_total_count = total_count / 100.0;
+
+ WriteAsciiHeader(total_count, output);
+ output->append(newline);
+
+ // Determine how wide the largest bucket range is (how many digits to print),
+ // so that we'll be able to right-align starts for the graphical bars.
+ // Determine which bucket has the largest sample count so that we can
+ // normalize the graphical bar-width relative to that sample count.
+ Count largest_count = 0;
+ Sample largest_sample = 0;
+ scoped_ptr<SampleCountIterator> it = snapshot->Iterator();
+ while (!it->Done())
+ {
+ Sample min;
+ Sample max;
+ Count count;
+ it->Get(&min, &max, &count);
+ if (min > largest_sample)
+ largest_sample = min;
+ if (count > largest_count)
+ largest_count = count;
+ it->Next();
+ }
+ size_t print_width = GetSimpleAsciiBucketRange(largest_sample).size() + 1;
+
+ // iterate over each item and display them
+ it = snapshot->Iterator();
+ while (!it->Done())
+ {
+ Sample min;
+ Sample max;
+ Count count;
+ it->Get(&min, &max, &count);
+
+ // value is min, so display it
+ string range = GetSimpleAsciiBucketRange(min);
+ output->append(range);
+ for (size_t j = 0; range.size() + j < print_width + 1; ++j)
+ output->push_back(' ');
+
+ if (graph_it)
+ WriteAsciiBucketGraph(count, largest_count, output);
+ WriteAsciiBucketValue(count, scaled_total_count, output);
+ output->append(newline);
+ it->Next();
+ }
+}
+
+void SparseHistogram::WriteAsciiHeader(const Count total_count,
+ std::string* output) const {
+ StringAppendF(output,
+ "Histogram: %s recorded %d samples",
+ histogram_name().c_str(),
+ total_count);
+ if (flags() & ~kHexRangePrintingFlag)
+ StringAppendF(output, " (flags = 0x%x)", flags() & ~kHexRangePrintingFlag);
+}
+
} // namespace base
« no previous file with comments | « base/metrics/sparse_histogram.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698