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

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

Issue 2853853002: Fix overflow when logging MaxInt32 to a sparse histogram. (Closed)
Patch Set: Address comments. Created 3 years, 7 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/sample_vector_unittest.cc ('k') | base/metrics/sparse_histogram_unittest.cc » ('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/sparse_histogram.h" 5 #include "base/metrics/sparse_histogram.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/metrics/metrics_hashes.h" 10 #include "base/metrics/metrics_hashes.h"
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 236
237 // Determine how wide the largest bucket range is (how many digits to print), 237 // Determine how wide the largest bucket range is (how many digits to print),
238 // so that we'll be able to right-align starts for the graphical bars. 238 // so that we'll be able to right-align starts for the graphical bars.
239 // Determine which bucket has the largest sample count so that we can 239 // Determine which bucket has the largest sample count so that we can
240 // normalize the graphical bar-width relative to that sample count. 240 // normalize the graphical bar-width relative to that sample count.
241 Count largest_count = 0; 241 Count largest_count = 0;
242 Sample largest_sample = 0; 242 Sample largest_sample = 0;
243 std::unique_ptr<SampleCountIterator> it = snapshot->Iterator(); 243 std::unique_ptr<SampleCountIterator> it = snapshot->Iterator();
244 while (!it->Done()) { 244 while (!it->Done()) {
245 Sample min; 245 Sample min;
246 Sample max; 246 int64_t max;
247 Count count; 247 Count count;
248 it->Get(&min, &max, &count); 248 it->Get(&min, &max, &count);
249 if (min > largest_sample) 249 if (min > largest_sample)
250 largest_sample = min; 250 largest_sample = min;
251 if (count > largest_count) 251 if (count > largest_count)
252 largest_count = count; 252 largest_count = count;
253 it->Next(); 253 it->Next();
254 } 254 }
255 size_t print_width = GetSimpleAsciiBucketRange(largest_sample).size() + 1; 255 size_t print_width = GetSimpleAsciiBucketRange(largest_sample).size() + 1;
256 256
257 // iterate over each item and display them 257 // iterate over each item and display them
258 it = snapshot->Iterator(); 258 it = snapshot->Iterator();
259 while (!it->Done()) { 259 while (!it->Done()) {
260 Sample min; 260 Sample min;
261 Sample max; 261 int64_t max;
262 Count count; 262 Count count;
263 it->Get(&min, &max, &count); 263 it->Get(&min, &max, &count);
264 264
265 // value is min, so display it 265 // value is min, so display it
266 std::string range = GetSimpleAsciiBucketRange(min); 266 std::string range = GetSimpleAsciiBucketRange(min);
267 output->append(range); 267 output->append(range);
268 for (size_t j = 0; range.size() + j < print_width + 1; ++j) 268 for (size_t j = 0; range.size() + j < print_width + 1; ++j)
269 output->push_back(' '); 269 output->push_back(' ');
270 270
271 if (graph_it) 271 if (graph_it)
272 WriteAsciiBucketGraph(count, largest_count, output); 272 WriteAsciiBucketGraph(count, largest_count, output);
273 WriteAsciiBucketValue(count, scaled_total_count, output); 273 WriteAsciiBucketValue(count, scaled_total_count, output);
274 output->append(newline); 274 output->append(newline);
275 it->Next(); 275 it->Next();
276 } 276 }
277 } 277 }
278 278
279 void SparseHistogram::WriteAsciiHeader(const Count total_count, 279 void SparseHistogram::WriteAsciiHeader(const Count total_count,
280 std::string* output) const { 280 std::string* output) const {
281 StringAppendF(output, 281 StringAppendF(output,
282 "Histogram: %s recorded %d samples", 282 "Histogram: %s recorded %d samples",
283 histogram_name().c_str(), 283 histogram_name().c_str(),
284 total_count); 284 total_count);
285 if (flags()) 285 if (flags())
286 StringAppendF(output, " (flags = 0x%x)", flags()); 286 StringAppendF(output, " (flags = 0x%x)", flags());
287 } 287 }
288 288
289 } // namespace base 289 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/sample_vector_unittest.cc ('k') | base/metrics/sparse_histogram_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698