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

Side by Side Diff: base/metrics/histogram_base.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 unified diff | Download patch
« no previous file with comments | « base/metrics/histogram_base.h ('k') | base/metrics/sparse_histogram.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 #include "base/metrics/histogram_base.h" 5 #include "base/metrics/histogram_base.h"
6 6
7 #include <climits> 7 #include <climits>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/json/json_string_value_serializer.h" 10 #include "base/json/json_string_value_serializer.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/metrics/histogram_samples.h" 13 #include "base/metrics/histogram_samples.h"
14 #include "base/metrics/sparse_histogram.h" 14 #include "base/metrics/sparse_histogram.h"
15 #include "base/pickle.h" 15 #include "base/pickle.h"
16 #include "base/process_util.h" 16 #include "base/process_util.h"
17 #include "base/stringprintf.h"
17 #include "base/values.h" 18 #include "base/values.h"
18 19
19 namespace base { 20 namespace base {
20 21
21 std::string HistogramTypeToString(HistogramType type) { 22 std::string HistogramTypeToString(HistogramType type) {
22 switch(type) { 23 switch(type) {
23 case HISTOGRAM: 24 case HISTOGRAM:
24 return "HISTOGRAM"; 25 return "HISTOGRAM";
25 case LINEAR_HISTOGRAM: 26 case LINEAR_HISTOGRAM:
26 return "LINEAR_HISTOGRAM"; 27 return "LINEAR_HISTOGRAM";
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 DictionaryValue root; 118 DictionaryValue root;
118 root.SetString("name", histogram_name()); 119 root.SetString("name", histogram_name());
119 root.SetInteger("count", count); 120 root.SetInteger("count", count);
120 root.SetInteger("flags", flags()); 121 root.SetInteger("flags", flags());
121 root.Set("params", parameters.release()); 122 root.Set("params", parameters.release());
122 root.Set("buckets", buckets.release()); 123 root.Set("buckets", buckets.release());
123 root.SetInteger("pid", GetCurrentProcId()); 124 root.SetInteger("pid", GetCurrentProcId());
124 serializer.Serialize(root); 125 serializer.Serialize(root);
125 } 126 }
126 127
128 void HistogramBase::WriteAsciiBucketGraph(double current_size,
129 double max_size,
130 std::string* output) const {
131 const int k_line_length = 72; // Maximal horizontal width of graph.
132 int x_count = static_cast<int>(k_line_length * (current_size / max_size)
133 + 0.5);
134 int x_remainder = k_line_length - x_count;
135
136 while (0 < x_count--)
137 output->append("-");
138 output->append("O");
139 while (0 < x_remainder--)
140 output->append(" ");
141 }
142
143 const std::string HistogramBase::GetSimpleAsciiBucketRange(
144 Sample sample) const {
145 std::string result;
146 if (kHexRangePrintingFlag & flags())
147 StringAppendF(&result, "%#x", sample);
148 else
149 StringAppendF(&result, "%d", sample);
150 return result;
151 }
152
153 void HistogramBase::WriteAsciiBucketValue(Count current,
154 double scaled_sum,
155 std::string* output) const {
156 StringAppendF(output, " (%d = %3.1f%%)", current, current/scaled_sum);
157 }
158
127 } // namespace base 159 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/histogram_base.h ('k') | base/metrics/sparse_histogram.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698