Chromium Code Reviews| 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/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::SplitString; | |
| 16 using base::StringPrintf; | |
| 17 using base::StringToInt; | |
| 18 using std::string; | |
| 19 using std::vector; | |
|
Alexei Svitkine (slow)
2014/04/30 15:25:24
Using declarations are generally discouraged. It d
bsimonnet
2014/04/30 20:28:40
Done.
| |
| 20 | |
| 21 namespace metrics { | |
| 22 | |
| 23 SparseHistogramSample::SparseHistogramSample(const std::string& histogram_name, | |
| 24 int sample) | |
| 25 : MetricSample(MetricSample::SPARSE_HISTOGRAM, histogram_name), | |
| 26 sample_(sample) {} | |
| 27 | |
| 28 SparseHistogramSample::~SparseHistogramSample() {} | |
| 29 | |
| 30 string SparseHistogramSample::ToString() const { | |
| 31 return StringPrintf( | |
| 32 "sparsehistogram%c%s %d%c", '\0', name().c_str(), sample_, '\0'); | |
| 33 } | |
| 34 | |
| 35 // static | |
| 36 // Read a sparse histogram from a string listing |name| and |sample| separated | |
| 37 // by a space. | |
| 38 SparseHistogramSample* SparseHistogramSample::ReadSparseHistogram( | |
| 39 const std::string& histogram_serialized) { | |
| 40 vector<string> parts; | |
| 41 SplitString(histogram_serialized, ' ', &parts); | |
| 42 if (parts.size() != 2) return NULL; | |
| 43 int sample; | |
| 44 if (parts[0].length() == 0 || !StringToInt(parts[1], &sample)) | |
| 45 return NULL; | |
| 46 | |
| 47 return new SparseHistogramSample(parts[0], sample); | |
| 48 } | |
| 49 | |
| 50 } // namespace metrics | |
| OLD | NEW |