Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <stdio.h> | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/logging.h" | |
|
gauravsh
2014/04/11 23:50:51
Is this being used?
| |
| 10 #include "base/metrics/chromeos_metrics.h" | |
| 11 #include "base/metrics/metric_sample.h" | |
| 12 #include "base/metrics/sparsehistogram_sample.h" | |
|
gauravsh
2014/04/11 23:50:51
this needs to be after this #include block.
| |
| 13 #include "base/strings/stringprintf.h" | |
| 14 | |
| 15 using std::string; | |
| 16 | |
| 17 namespace base { | |
| 18 | |
| 19 SparseHistogramSample::SparseHistogramSample(const std::string& histname, | |
| 20 int sample) | |
| 21 : MetricSample(MetricSample::SPARSE_HISTOGRAM) { | |
| 22 name_ = histname; | |
|
gauravsh
2014/04/11 23:50:51
Use constructor initializer lists wherever possibl
| |
| 23 sample_ = sample; | |
| 24 } | |
| 25 | |
| 26 int SparseHistogramSample::sample() { return sample_; } | |
| 27 | |
| 28 SparseHistogramSample* SparseHistogramSample::ReadSparseHistogram( | |
| 29 const std::string& hist_repr) { | |
| 30 int sample; | |
| 31 char name[128]; | |
| 32 int result = sscanf(hist_repr.c_str(), "%127s %d", name, &sample); | |
|
gauravsh
2014/04/11 23:50:51
There's probably a better way of doing this than u
| |
| 33 if (result != 2) { | |
| 34 return NULL; | |
| 35 } | |
| 36 return new SparseHistogramSample(name, sample); | |
| 37 } | |
| 38 | |
| 39 SparseHistogramSample::~SparseHistogramSample() {} | |
| 40 | |
| 41 string SparseHistogramSample::toString() const { | |
| 42 return StringPrintf( | |
| 43 "sparsehistogram%c%s %d%c", '\0', name_.c_str(), sample_, '\0'); | |
|
gauravsh
2014/04/11 23:50:51
This is returning a string with embedded NULL byte
bsimonnet
2014/04/14 23:03:05
This is used for the serialization. The message fo
| |
| 44 } | |
| 45 } // namespace base | |
| OLD | NEW |