Chromium Code Reviews| Index: base/metrics/sparsehistogram_sample.cc |
| diff --git a/base/metrics/sparsehistogram_sample.cc b/base/metrics/sparsehistogram_sample.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..47294e2f1fc0f85a0c78f1b139556c5468e49104 |
| --- /dev/null |
| +++ b/base/metrics/sparsehistogram_sample.cc |
| @@ -0,0 +1,45 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <stdio.h> |
| + |
| +#include <string> |
| + |
| +#include "base/logging.h" |
|
gauravsh
2014/04/11 23:50:51
Is this being used?
|
| +#include "base/metrics/chromeos_metrics.h" |
| +#include "base/metrics/metric_sample.h" |
| +#include "base/metrics/sparsehistogram_sample.h" |
|
gauravsh
2014/04/11 23:50:51
this needs to be after this #include block.
|
| +#include "base/strings/stringprintf.h" |
| + |
| +using std::string; |
| + |
| +namespace base { |
| + |
| +SparseHistogramSample::SparseHistogramSample(const std::string& histname, |
| + int sample) |
| + : MetricSample(MetricSample::SPARSE_HISTOGRAM) { |
| + name_ = histname; |
|
gauravsh
2014/04/11 23:50:51
Use constructor initializer lists wherever possibl
|
| + sample_ = sample; |
| +} |
| + |
| +int SparseHistogramSample::sample() { return sample_; } |
| + |
| +SparseHistogramSample* SparseHistogramSample::ReadSparseHistogram( |
| + const std::string& hist_repr) { |
| + int sample; |
| + char name[128]; |
| + 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
|
| + if (result != 2) { |
| + return NULL; |
| + } |
| + return new SparseHistogramSample(name, sample); |
| +} |
| + |
| +SparseHistogramSample::~SparseHistogramSample() {} |
| + |
| +string SparseHistogramSample::toString() const { |
| + return StringPrintf( |
| + "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
|
| +} |
| +} // namespace base |