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

Side by Side Diff: base/metrics/histogram_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: 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 <string>
6
7 #include "base/logging.h"
8
9 #include "base/metrics/chromeos_metrics.h"
10 #include "base/metrics/histogram_sample.h"
11 #include "base/metrics/metric_sample.h"
12
13 using std::string;
14
15 namespace base {
16
17 HistogramSample::HistogramSample(const std::string& histname,
18 int sample, int min, int max, int nbucket):
19 MetricSample(MetricSample::HISTOGRAM) {
20 name_ = histname;
21 sample_ = sample;
22 min_ = min;
23 max_ = max;
24 nbucket_ = nbucket;
25 }
26
27 std::string HistogramSample::name() {
28 return name_;
29 }
30
31 int HistogramSample::sample() {
32 return sample_;
33 }
34
35 int HistogramSample::min() {
36 return min_;
37 }
38
39 int HistogramSample::max() {
40 return max_;
41 }
42
43 int HistogramSample::nbucket() {
44 return nbucket_;
45 }
46
47 HistogramSample* HistogramSample::ReadHistogram(const std::string& hist_repr) {
48 int sample, min, max, nbucket;
49 char name[128];
50 sscanf(hist_repr.c_str(), "%127s %d %d %d %d", name, &sample, &min, &max,
51 &nbucket);
52 return new HistogramSample(name, sample, min, max, nbucket);
53 }
54
55 HistogramSample::~HistogramSample() {}
56
57 int HistogramSample::Write(int buffer_size, char* buffer) {
58 return ChromeOSMetrics::FormatSample(buffer_size, buffer,
59 "histogram%c%s %d %d %d %d", '\0', name_.c_str(),
60 sample_, min_, max_, nbucket_);
61 }
62 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698