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/histogram_sample_chromeos.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/strings/string_number_conversions.h" | |
10 #include "base/strings/string_split.h" | |
11 #include "base/strings/stringprintf.h" | |
12 #include "components/metrics/metric_sample_chromeos.h" | |
13 | |
14 using base::SplitString; | |
15 using base::StringPrintf; | |
16 using base::StringToInt; | |
17 using std::string; | |
18 using std::vector; | |
19 | |
20 namespace metrics { | |
21 | |
22 HistogramSample::HistogramSample(const std::string& name, | |
23 int sample, | |
24 int min, | |
25 int max, | |
26 int nbucket) | |
27 : MetricSample(MetricSample::HISTOGRAM, name), | |
28 max_(max), | |
29 min_(min), | |
30 sample_(sample), | |
Ben Chan
2014/04/18 20:27:08
nit: when possible, order the member variables in
| |
31 nbucket_(nbucket) {} | |
32 | |
33 HistogramSample::~HistogramSample() {} | |
34 | |
35 string HistogramSample::ToString() const { | |
36 return StringPrintf("histogram%c%s %d %d %d %d%c", | |
37 '\0', | |
38 name().c_str(), | |
39 sample_, | |
40 min_, | |
41 max_, | |
42 nbucket_, | |
43 '\0'); | |
44 } | |
45 | |
46 // static | |
47 HistogramSample* HistogramSample::ReadHistogram( | |
48 const std::string& histogram_serialized) { | |
49 vector<string> parts; | |
50 SplitString(histogram_serialized, ' ', &parts); | |
51 if (parts.size() != 5) return NULL; | |
Ben Chan
2014/04/18 20:27:08
nit: add a comment to describe the serialized form
| |
52 int sample, min, max, nbucket; | |
53 if (!StringToInt(parts[1], &sample) || !StringToInt(parts[2], &min) || | |
54 !StringToInt(parts[3], &max) || !StringToInt(parts[4], &nbucket)) | |
55 return NULL; | |
56 | |
57 return new HistogramSample(parts[0], sample, min, max, nbucket); | |
Ben Chan
2014/04/18 20:27:08
I think SplitString still gives 5 components on a
| |
58 } | |
59 | |
60 } // namespace metrics | |
OLD | NEW |