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

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: 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 #include "base/metrics/chromeos_metrics.h"
9 #include "base/metrics/linearhistogram_sample.h"
10 #include "base/metrics/metric_sample.h"
11
12 using std::string;
13
14 namespace base {
15 LinearHistogramSample::LinearHistogramSample(const std::string& histname,
16 int sample, int max):
17 MetricSample(MetricSample::LINEAR_HISTOGRAM) {
18 name_ = histname;
19 sample_ = sample;
20 max_ = max;
21 }
22
23 std::string LinearHistogramSample::name() {
24 return name_;
25 }
26
27 int LinearHistogramSample::sample() {
28 return sample_;
29 }
30
31 int LinearHistogramSample::max() {
32 return max_;
33 }
34
35 LinearHistogramSample* LinearHistogramSample::ReadLinearHistogram(
36 const std::string& hist_repr) {
37 int sample, max;
38 char name[128];
39 sscanf(hist_repr.c_str(), "%127s %d %d", name, &sample, &max);
achaulk 2014/04/07 22:16:00 Need to check return. Might want to note that spac
40 return new LinearHistogramSample(name, sample, max);
41 }
42
43 LinearHistogramSample::~LinearHistogramSample() {}
44
45 int LinearHistogramSample::Write(int buffer_size, char* buffer) {
46 return ChromeOSMetrics::FormatSample(buffer_size, buffer,
47 "linearhistogram%c%s %d %d", '\0', name_.c_str(),
achaulk 2014/04/07 22:16:00 Why not inline \0? Also indentation
bsimonnet 2014/04/08 23:00:09 the compiler complains when I embed the \0 in a fo
48 sample_, max_);
49 }
50 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698