Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: components/metrics/export/sparsehistogram_sample.cc

Issue 227873002: Create a histogram serialization mechanism in components/metrics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Running tests only for chromeos. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698