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/export/linearhistogram_sample.h" |
| 6 |
| 7 #include <string> |
| 8 #include <vector> |
| 9 |
| 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/string_split.h" |
| 12 #include "base/strings/stringprintf.h" |
| 13 #include "components/metrics/export/metric_sample.h" |
| 14 |
| 15 using base::StringPrintf; |
| 16 using base::StringToInt; |
| 17 using base::SplitString; |
| 18 using std::string; |
| 19 using std::vector; |
| 20 |
| 21 namespace metrics { |
| 22 |
| 23 LinearHistogramSample::LinearHistogramSample(const std::string& histname, |
| 24 int sample, |
| 25 int max) |
| 26 : MetricSample(MetricSample::LINEAR_HISTOGRAM, histname), |
| 27 sample_(sample), |
| 28 max_(max) {} |
| 29 |
| 30 LinearHistogramSample::~LinearHistogramSample() {} |
| 31 |
| 32 string LinearHistogramSample::ToString() const { |
| 33 return StringPrintf( |
| 34 "linearhistogram%c%s %d %d%c", '\0', name().c_str(), sample_, max_, '\0'); |
| 35 } |
| 36 |
| 37 // static |
| 38 // Read a linear histogram from a string listing |name|, |sample|, |max| |
| 39 // separated by space. |
| 40 LinearHistogramSample* LinearHistogramSample::ReadLinearHistogram( |
| 41 const std::string& histogram_serialized) { |
| 42 vector<string> parts; |
| 43 int sample, max; |
| 44 SplitString(histogram_serialized, ' ', &parts); |
| 45 if (parts.size() != 3) return NULL; |
| 46 if (parts[0].length() == 0 || !StringToInt(parts[1], &sample) || |
| 47 !StringToInt(parts[2], &max)) |
| 48 return NULL; |
| 49 |
| 50 return new LinearHistogramSample(parts[0], sample, max); |
| 51 } |
| 52 |
| 53 } // namespace metrics |
OLD | NEW |