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

Unified Diff: components/metrics/export/metric_sample.h

Issue 227873002: Create a histogram serialization mechanism in components/metrics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Running tests only for chromeos. 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: components/metrics/export/metric_sample.h
diff --git a/components/metrics/export/metric_sample.h b/components/metrics/export/metric_sample.h
new file mode 100644
index 0000000000000000000000000000000000000000..0d12bfda6c6fa6691bb70fdf43b976ca11c73c3a
--- /dev/null
+++ b/components/metrics/export/metric_sample.h
@@ -0,0 +1,60 @@
+// Copyright 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.
+
+#ifndef COMPONENTS_METRICS_EXPORT_METRIC_SAMPLE_H_
+#define COMPONENTS_METRICS_EXPORT_METRIC_SAMPLE_H_
+
+#include <string>
+
+#include "base/base_export.h"
+#include "base/macros.h"
+
+namespace metrics {
+
+// Abstract class representing a metric sample (single measures).
+// This class and its subclasses are used by libmetrics (ChromeOS) to serialize
+// and deserialize measurements to send them to a metrics sending service.
+// It is meant to be a simple container with serialization functions.
+class BASE_EXPORT MetricSample {
+ public:
+ // Types of metric sample used.
+ enum SampleType {
+ CRASH,
+ HISTOGRAM,
+ LINEAR_HISTOGRAM,
+ SPARSE_HISTOGRAM,
+ USER_ACTION
+ };
Alexei Svitkine (slow) 2014/04/30 15:25:24 Nit: Add a blank line after this.
bsimonnet 2014/04/30 20:28:40 Done.
+ MetricSample(SampleType sample_type, const std::string& metric_name);
+ virtual ~MetricSample();
+
+ // Return true if the sample is valid (can be serialized without ambiguity).
+ //
+ // This function should be used to filter bad samples before serializing them
+ // to disk.
+ virtual bool IsValid() const;
Alexei Svitkine (slow) 2014/04/30 15:25:24 Add a blank line after this.
bsimonnet 2014/04/30 20:28:40 Done.
+ SampleType type() const { return type_; }
+ const std::string& name() const { return name_; }
+
+ // Return a serialized version of the sample.
+ //
+ // This function should be overriden by subclasses to define their own
+ // serialization format.
+ // The general serialized message is:
+ // |sampletype|,\0,<sample type specific serialized data>,\0
+ //
+ // The format is akward but it is implemented independently in both chrome os
+ // and chrome. We will keep it for now.
+ virtual std::string ToString() const;
+
+ private:
+ const SampleType type_;
+ const std::string name_;
+
+ DISALLOW_COPY_AND_ASSIGN(MetricSample);
+};
+
+} // namespace metrics
+
+#endif // COMPONENTS_METRICS_EXPORT_METRIC_SAMPLE_H_

Powered by Google App Engine
This is Rietveld 408576698