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

Side by Side Diff: base/metrics/histogram_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/histogram_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
19 HistogramSample::HistogramSample(const std::string& histname,
20 int sample,
21 int min,
22 int max,
23 int nbucket)
24 : MetricSample(MetricSample::HISTOGRAM, histname),
25 max_(max),
26 min_(min),
27 sample_(sample),
28 nbucket_(nbucket) {}
29
30 HistogramSample::~HistogramSample() {}
31
32 int HistogramSample::sample() const { return sample_; }
33
34 int HistogramSample::min() const { return min_; }
35
36 int HistogramSample::max() const { return max_; }
37
38 int HistogramSample::nbucket() const { return nbucket_; }
39
40 string HistogramSample::ToString() const {
41 return StringPrintf("histogram%c%s %d %d %d %d%c",
42 '\0',
43 name_.c_str(),
44 sample_,
45 min_,
46 max_,
47 nbucket_,
48 '\0');
49 }
50
51 HistogramSample* HistogramSample::ReadHistogram(
52 const std::string& histogram_serialized) {
53 vector<string> parts;
54 SplitString(histogram_serialized, ' ', &parts);
55 if (parts.size() != 5) {
56 return NULL;
57 }
58 int sample, min, max, nbucket;
59 if (!StringToInt(parts[1], &sample) || !StringToInt(parts[2], &min) ||
60 !StringToInt(parts[3], &max) || !StringToInt(parts[4], &nbucket)) {
61 return NULL;
62 }
63
64 return new HistogramSample(parts[0], sample, min, max, nbucket);
65 }
66 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698