blob: 211606a9898b7bad263643bb092878fe8eb4c93e [file] [log] [blame]
[email protected]c884117b2012-07-19 05:31:491// Copyright (c) 2012 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#ifndef BASE_METRICS_HISTOGRAM_BASE_H_
6#define BASE_METRICS_HISTOGRAM_BASE_H_
7
[email protected]c884117b2012-07-19 05:31:498#include <string>
9
10#include "base/base_export.h"
[email protected]7c7a42752012-08-09 05:14:1511#include "base/basictypes.h"
[email protected]877ef562012-10-20 02:56:1812#include "base/memory/scoped_ptr.h"
[email protected]c884117b2012-07-19 05:31:4913
14namespace base {
15
[email protected]24a7ec5e2012-10-08 10:31:5016class DictionaryValue;
17class ListValue;
18
[email protected]877ef562012-10-20 02:56:1819class HistogramSamples;
20
[email protected]c884117b2012-07-19 05:31:4921class BASE_EXPORT HistogramBase {
22 public:
23 typedef int Sample; // Used for samples.
24 typedef int Count; // Used to count samples.
25
[email protected]34d062322012-08-01 21:34:0826 static const Sample kSampleType_MAX; // INT_MAX
[email protected]c884117b2012-07-19 05:31:4927
[email protected]7c7a42752012-08-09 05:14:1528 enum Flags {
29 kNoFlags = 0,
30 kUmaTargetedHistogramFlag = 0x1, // Histogram should be UMA uploaded.
31
32 // Indicate that the histogram was pickled to be sent across an IPC Channel.
33 // If we observe this flag on a histogram being aggregated into after IPC,
34 // then we are running in a single process mode, and the aggregation should
35 // not take place (as we would be aggregating back into the source
36 // histogram!).
37 kIPCSerializationSourceFlag = 0x10,
38
39 // Only for Histogram and its sub classes: fancy bucket-naming support.
40 kHexRangePrintingFlag = 0x8000,
41 };
42
43
[email protected]c884117b2012-07-19 05:31:4944 HistogramBase(const std::string& name);
45 virtual ~HistogramBase();
46
47 std::string histogram_name() const { return histogram_name_; }
48
[email protected]7c7a42752012-08-09 05:14:1549 // Operations with Flags enum.
50 int32 flags() const { return flags_; }
51 void SetFlags(int32 flags);
52 void ClearFlags(int32 flags);
53
[email protected]c884117b2012-07-19 05:31:4954 virtual void Add(Sample value) = 0;
55
[email protected]877ef562012-10-20 02:56:1856 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const = 0;
57
[email protected]c884117b2012-07-19 05:31:4958 // The following methods provide graphical histogram displays.
59 virtual void WriteHTMLGraph(std::string* output) const = 0;
60 virtual void WriteAscii(std::string* output) const = 0;
61
[email protected]24a7ec5e2012-10-08 10:31:5062 // Produce a JSON representation of the histogram. This is implemented with
63 // the help of GetParameters and GetCountAndBucketData; overwrite them to
64 // customize the output.
65 void WriteJSON(std::string* output) const;
66
67protected:
68 // Writes information about the construction parameters in |params|.
69 virtual void GetParameters(DictionaryValue* params) const = 0;
70
71 // Writes information about the current (non-empty) buckets and their sample
72 // counts to |buckets| and the total sample count to |count|.
73 virtual void GetCountAndBucketData(Count* count,
74 ListValue* buckets) const = 0;
[email protected]c884117b2012-07-19 05:31:4975 private:
76 const std::string histogram_name_;
[email protected]7c7a42752012-08-09 05:14:1577 int32 flags_;
78
79 DISALLOW_COPY_AND_ASSIGN(HistogramBase);
[email protected]c884117b2012-07-19 05:31:4980};
81
82} // namespace base
83
84#endif // BASE_METRICS_HISTOGRAM_BASE_H_