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

Unified Diff: base/metrics/sparsehistogram_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 side-by-side diff with in-line comments
Download patch
Index: base/metrics/sparsehistogram_sample.cc
diff --git a/base/metrics/sparsehistogram_sample.cc b/base/metrics/sparsehistogram_sample.cc
new file mode 100644
index 0000000000000000000000000000000000000000..47294e2f1fc0f85a0c78f1b139556c5468e49104
--- /dev/null
+++ b/base/metrics/sparsehistogram_sample.cc
@@ -0,0 +1,45 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <stdio.h>
+
+#include <string>
+
+#include "base/logging.h"
gauravsh 2014/04/11 23:50:51 Is this being used?
+#include "base/metrics/chromeos_metrics.h"
+#include "base/metrics/metric_sample.h"
+#include "base/metrics/sparsehistogram_sample.h"
gauravsh 2014/04/11 23:50:51 this needs to be after this #include block.
+#include "base/strings/stringprintf.h"
+
+using std::string;
+
+namespace base {
+
+SparseHistogramSample::SparseHistogramSample(const std::string& histname,
+ int sample)
+ : MetricSample(MetricSample::SPARSE_HISTOGRAM) {
+ name_ = histname;
gauravsh 2014/04/11 23:50:51 Use constructor initializer lists wherever possibl
+ sample_ = sample;
+}
+
+int SparseHistogramSample::sample() { return sample_; }
+
+SparseHistogramSample* SparseHistogramSample::ReadSparseHistogram(
+ const std::string& hist_repr) {
+ int sample;
+ char name[128];
+ int result = sscanf(hist_repr.c_str(), "%127s %d", name, &sample);
gauravsh 2014/04/11 23:50:51 There's probably a better way of doing this than u
+ if (result != 2) {
+ return NULL;
+ }
+ return new SparseHistogramSample(name, sample);
+}
+
+SparseHistogramSample::~SparseHistogramSample() {}
+
+string SparseHistogramSample::toString() const {
+ return StringPrintf(
+ "sparsehistogram%c%s %d%c", '\0', name_.c_str(), sample_, '\0');
gauravsh 2014/04/11 23:50:51 This is returning a string with embedded NULL byte
bsimonnet 2014/04/14 23:03:05 This is used for the serialization. The message fo
+}
+} // namespace base

Powered by Google App Engine
This is Rietveld 408576698