OLD | NEW |
(Empty) | |
| 1 // Copyright 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 "components/metrics/chromeos/histogram_sample.h" |
| 6 |
| 7 #include <string> |
| 8 #include <vector> |
| 9 |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_split.h" |
| 13 #include "base/strings/stringprintf.h" |
| 14 #include "components/metrics/chromeos/metric_sample.h" |
| 15 |
| 16 namespace metrics { |
| 17 |
| 18 HistogramSample::HistogramSample(const std::string& name, |
| 19 int sample, |
| 20 int min, |
| 21 int max, |
| 22 int nbucket) |
| 23 : MetricSample(MetricSample::HISTOGRAM, name), |
| 24 sample_(sample), |
| 25 min_(min), |
| 26 max_(max), |
| 27 nbucket_(nbucket) {} |
| 28 |
| 29 HistogramSample::~HistogramSample() {} |
| 30 |
| 31 std::string HistogramSample::ToString() const { |
| 32 return base::StringPrintf("histogram%c%s %d %d %d %d%c", |
| 33 '\0', |
| 34 name().c_str(), |
| 35 sample_, |
| 36 min_, |
| 37 max_, |
| 38 nbucket_, |
| 39 '\0'); |
| 40 } |
| 41 |
| 42 // static |
| 43 scoped_ptr<HistogramSample> HistogramSample::ReadHistogram( |
| 44 const std::string& histogram_serialized) { |
| 45 std::vector<std::string> parts; |
| 46 base::SplitString(histogram_serialized, ' ', &parts); |
| 47 if (parts.size() != 5) |
| 48 return scoped_ptr<HistogramSample>(); |
| 49 int sample, min, max, nbucket; |
| 50 if (parts[0].length() == 0 || !base::StringToInt(parts[1], &sample) || |
| 51 !base::StringToInt(parts[2], &min) || |
| 52 !base::StringToInt(parts[3], &max) || |
| 53 !base::StringToInt(parts[4], &nbucket)) { |
| 54 return scoped_ptr<HistogramSample>(); |
| 55 } |
| 56 |
| 57 return scoped_ptr<HistogramSample>( |
| 58 new HistogramSample(parts[0], sample, min, max, nbucket)); |
| 59 } |
| 60 |
| 61 } // namespace metrics |
OLD | NEW |