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

Side by Side Diff: components/metrics/sparsehistogram_sample_chromeos.cc

Issue 227873002: Create a histogram serialization mechanism in components/metrics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moving to components instead of base. Adding sanity checks. Fixing lint 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/sparsehistogram_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 SparseHistogramSample::SparseHistogramSample(const std::string& histogram_name,
23 int sample)
24 : MetricSample(MetricSample::SPARSE_HISTOGRAM, histogram_name),
25 sample_(sample) {}
26
27 SparseHistogramSample::~SparseHistogramSample() {}
28
29 string SparseHistogramSample::ToString() const {
30 return StringPrintf(
31 "sparsehistogram%c%s %d%c", '\0', name().c_str(), sample_, '\0');
32 }
33
34 // static
35 SparseHistogramSample* SparseHistogramSample::ReadSparseHistogram(
36 const std::string& histogram_serialized) {
37 vector<string> parts;
38 SplitString(histogram_serialized, ' ', &parts);
39 if (parts.size() != 2) return NULL;
40 int sample;
41 if (!StringToInt(parts[1], &sample)) return NULL;
42
43 return new SparseHistogramSample(parts[0], sample);
44 }
45
46 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698