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/sparsehistogram_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/export/metric_sample.h" | |
15 | |
16 namespace metrics { | |
17 | |
18 SparseHistogramSample::SparseHistogramSample(const std::string& histogram_name, | |
19 int sample) | |
20 : MetricSample(MetricSample::SPARSE_HISTOGRAM, histogram_name), | |
21 sample_(sample) {} | |
22 | |
23 SparseHistogramSample::~SparseHistogramSample() {} | |
24 | |
25 std::string SparseHistogramSample::ToString() const { | |
26 return base::StringPrintf( | |
27 "sparsehistogram%c%s %d%c", '\0', name().c_str(), sample_, '\0'); | |
28 } | |
29 | |
30 // static | |
31 // Read a sparse histogram from a string listing |name| and |sample| separated | |
32 // by a space. | |
33 scoped_ptr<SparseHistogramSample> SparseHistogramSample::ReadSparseHistogram( | |
34 const std::string& histogram_serialized) { | |
Alexei Svitkine (slow)
2014/05/01 15:57:09
Nit: serialized_histogram which also makes it cons
| |
35 std::vector<std::string> parts; | |
36 base::SplitString(histogram_serialized, ' ', &parts); | |
37 if (parts.size() != 2) | |
38 return scoped_ptr<SparseHistogramSample>(); | |
39 int sample; | |
40 if (parts[0].length() == 0 || !base::StringToInt(parts[1], &sample)) | |
41 return scoped_ptr<SparseHistogramSample>(); | |
42 | |
43 return scoped_ptr<SparseHistogramSample>( | |
44 new SparseHistogramSample(parts[0], sample)); | |
45 } | |
46 | |
47 } // namespace metrics | |
OLD | NEW |