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

Side by Side Diff: base/metrics/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: Refactoring to use string instead of char buffers 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 <stdio.h>
6
7 #include <string>
8
9 #include "base/logging.h"
10 #include "base/metrics/chromeos_metrics.h"
11 #include "base/metrics/linearhistogram_sample.h"
12 #include "base/metrics/metric_sample.h"
13 #include "base/strings/stringprintf.h"
14
15 using std::string;
16
17 namespace base {
18 LinearHistogramSample::LinearHistogramSample(const std::string& histname,
19 int sample,
20 int max)
21 : MetricSample(MetricSample::LINEAR_HISTOGRAM) {
22 name_ = histname;
23 sample_ = sample;
24 max_ = max;
25 }
26
27 int LinearHistogramSample::sample() { return sample_; }
28
29 int LinearHistogramSample::max() { return max_; }
30
31 LinearHistogramSample* LinearHistogramSample::ReadLinearHistogram(
32 const std::string& hist_repr) {
33 int sample, max;
34 char name[128];
35 int result = sscanf(hist_repr.c_str(), "%127s %d %d", name, &sample, &max);
36 if (result != 3) {
37 return NULL;
38 }
39 return new LinearHistogramSample(name, sample, max);
40 }
41
42 LinearHistogramSample::~LinearHistogramSample() {}
43
44 string LinearHistogramSample::toString() const {
45 return StringPrintf(
46 "linearhistogram%c%s %d %d%c", '\0', name_.c_str(), sample_, max_, '\0');
47 }
48 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698