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 <string> |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/metrics/chromeos_metrics.h" |
| 9 #include "base/metrics/metric_sample.h" |
| 10 #include "base/metrics/sparsehistogram_sample.h" |
| 11 |
| 12 using std::string; |
| 13 |
| 14 namespace base { |
| 15 |
| 16 SparseHistogramSample::SparseHistogramSample(const std::string& histname, |
| 17 int sample): |
| 18 MetricSample(MetricSample::SPARSE_HISTOGRAM) { |
| 19 name_ = histname; |
| 20 sample_ = sample; |
| 21 } |
| 22 |
| 23 std::string SparseHistogramSample::name() { |
| 24 return name_; |
| 25 } |
| 26 |
| 27 int SparseHistogramSample::sample() { |
| 28 return sample_; |
| 29 } |
| 30 |
| 31 SparseHistogramSample* SparseHistogramSample::ReadSparseHistogram( |
| 32 const std::string& hist_repr) { |
| 33 int sample; |
| 34 char name[128]; |
| 35 sscanf(hist_repr.c_str(), "%127s %d", name, &sample); |
| 36 return new SparseHistogramSample(name, sample); |
| 37 } |
| 38 |
| 39 SparseHistogramSample::~SparseHistogramSample() {} |
| 40 |
| 41 int SparseHistogramSample::Write(int buffer_size, char* buffer) { |
| 42 return ChromeOSMetrics::FormatSample(buffer_size, buffer, |
| 43 "sparsehistogram%c%s %d", '\0', name_.c_str(), |
| 44 sample_); |
| 45 } |
| 46 } // namespace base |
OLD | NEW |