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

Side by Side Diff: components/metrics/export/linearhistogram_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/linearhistogram_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::StringPrintf;
16 using base::StringToInt;
17 using base::SplitString;
18 using std::string;
19 using std::vector;
20
21 namespace metrics {
22
23 LinearHistogramSample::LinearHistogramSample(const std::string& histname,
24 int sample,
25 int max)
26 : MetricSample(MetricSample::LINEAR_HISTOGRAM, histname),
27 sample_(sample),
28 max_(max) {}
29
30 LinearHistogramSample::~LinearHistogramSample() {}
31
32 string LinearHistogramSample::ToString() const {
33 return StringPrintf(
34 "linearhistogram%c%s %d %d%c", '\0', name().c_str(), sample_, max_, '\0');
35 }
36
37 // static
38 // Read a linear histogram from a string listing |name|, |sample|, |max|
39 // separated by space.
40 LinearHistogramSample* LinearHistogramSample::ReadLinearHistogram(
41 const std::string& histogram_serialized) {
42 vector<string> parts;
43 int sample, max;
44 SplitString(histogram_serialized, ' ', &parts);
45 if (parts.size() != 3) return NULL;
46 if (parts[0].length() == 0 || !StringToInt(parts[1], &sample) ||
47 !StringToInt(parts[2], &max))
48 return NULL;
49
50 return new LinearHistogramSample(parts[0], sample, max);
51 }
52
53 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698