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" |
| 10 #include "base/metrics/chromeos_metrics.h" |
| 11 #include "base/metrics/histogram_sample.h" |
| 12 #include "base/metrics/metric_sample.h" |
| 13 #include "base/strings/stringprintf.h" |
| 14 |
| 15 using std::string; |
| 16 |
| 17 namespace base { |
| 18 |
| 19 HistogramSample::HistogramSample(const std::string& histname, |
| 20 int sample, |
| 21 int min, |
| 22 int max, |
| 23 int nbucket) |
| 24 : MetricSample(MetricSample::HISTOGRAM) { |
| 25 name_ = histname; |
| 26 sample_ = sample; |
| 27 min_ = min; |
| 28 max_ = max; |
| 29 nbucket_ = nbucket; |
| 30 } |
| 31 |
| 32 int HistogramSample::sample() { return sample_; } |
| 33 |
| 34 int HistogramSample::min() { return min_; } |
| 35 |
| 36 int HistogramSample::max() { return max_; } |
| 37 |
| 38 int HistogramSample::nbucket() { return nbucket_; } |
| 39 |
| 40 HistogramSample* HistogramSample::ReadHistogram(const std::string& hist_repr) { |
| 41 int sample, min, max, nbucket; |
| 42 char name[128]; |
| 43 int result = sscanf(hist_repr.c_str(), |
| 44 "%127s %d %d %d %d", |
| 45 name, |
| 46 &sample, |
| 47 &min, |
| 48 &max, |
| 49 &nbucket); |
| 50 if (result != 5) { |
| 51 return NULL; |
| 52 } |
| 53 return new HistogramSample(name, sample, min, max, nbucket); |
| 54 } |
| 55 |
| 56 HistogramSample::~HistogramSample() {} |
| 57 |
| 58 string HistogramSample::toString() const { |
| 59 return StringPrintf("histogram%c%s %d %d %d %d%c", |
| 60 '\0', |
| 61 name_.c_str(), |
| 62 sample_, |
| 63 min_, |
| 64 max_, |
| 65 nbucket_, |
| 66 '\0'); |
| 67 } |
| 68 } // namespace base |
OLD | NEW |