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

Side by Side Diff: base/metrics/linearhistogram_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: Fixing clang complains about override keyword. 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 (c) 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 "base/metrics/linearhistogram_sample_chromeos.h"
6
7 #include <string>
8
9 #include "base/metrics/metric_sample_chromeos.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_split.h"
12 #include "base/strings/stringprintf.h"
13
14 using std::string;
15 using std::vector;
16
17 namespace base {
18 LinearHistogramSample::LinearHistogramSample(const std::string& histname,
19 int sample,
20 int max)
21 : MetricSample(MetricSample::LINEAR_HISTOGRAM, histname),
22 sample_(sample),
23 max_(max) {}
24
25 LinearHistogramSample::~LinearHistogramSample() {}
26
27 int LinearHistogramSample::sample() const { return sample_; }
28
29 int LinearHistogramSample::max() const { return max_; }
30
31 string LinearHistogramSample::ToString() const {
32 return StringPrintf(
33 "linearhistogram%c%s %d %d%c", '\0', name_.c_str(), sample_, max_, '\0');
34 }
35
36 LinearHistogramSample* LinearHistogramSample::ReadLinearHistogram(
37 const std::string& histogram_serialized) {
38 vector<string> parts;
39 int sample, max;
40 SplitString(histogram_serialized, ' ', &parts);
41 if (parts.size() != 3) {
42 return NULL;
43 }
44
45 if (!StringToInt(parts[1], &sample) || !StringToInt(parts[2], &max)) {
46 return NULL;
47 }
48
49 return new LinearHistogramSample(parts[0], sample, max);
50 }
51 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698