Temporarily make lastchange use only the git hash.
[chromium-blink-merge.git] / base / metrics / histogram_delta_serialization.h
blobccadb12894fc57ab57439b00e08560dc2cf02d63
1 // Copyright 2013 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.
5 #ifndef BASE_METRICS_HISTOGRAM_DELTA_SERIALIZATION_H_
6 #define BASE_METRICS_HISTOGRAM_DELTA_SERIALIZATION_H_
8 #include <string>
9 #include <vector>
11 #include "base/base_export.h"
12 #include "base/basictypes.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/metrics/histogram_flattener.h"
15 #include "base/metrics/histogram_snapshot_manager.h"
17 namespace base {
19 class HistogramBase;
21 // Serializes and restores histograms deltas.
22 class BASE_EXPORT HistogramDeltaSerialization : public HistogramFlattener {
23 public:
24 // |caller_name| is string used in histograms for counting inconsistencies.
25 explicit HistogramDeltaSerialization(const std::string& caller_name);
26 virtual ~HistogramDeltaSerialization();
28 // Computes deltas in histogram bucket counts relative to the previous call to
29 // this method. Stores the deltas in serialized form into |serialized_deltas|.
30 // If |serialized_deltas| is NULL, no data is serialized, though the next call
31 // will compute the deltas relative to this one.
32 void PrepareAndSerializeDeltas(std::vector<std::string>* serialized_deltas);
34 // Deserialize deltas and add samples to corresponding histograms, creating
35 // them if necessary. Silently ignores errors in |serialized_deltas|.
36 static void DeserializeAndAddSamples(
37 const std::vector<std::string>& serialized_deltas);
39 private:
40 // HistogramFlattener implementation.
41 virtual void RecordDelta(const HistogramBase& histogram,
42 const HistogramSamples& snapshot) OVERRIDE;
43 virtual void InconsistencyDetected(
44 HistogramBase::Inconsistency problem) OVERRIDE;
45 virtual void UniqueInconsistencyDetected(
46 HistogramBase::Inconsistency problem) OVERRIDE;
47 virtual void InconsistencyDetectedInLoggedCount(int amount) OVERRIDE;
49 // Calculates deltas in histogram counters.
50 HistogramSnapshotManager histogram_snapshot_manager_;
52 // Output buffer for serialized deltas.
53 std::vector<std::string>* serialized_deltas_;
55 // Histograms to count inconsistencies in snapshots.
56 HistogramBase* inconsistencies_histogram_;
57 HistogramBase* inconsistencies_unique_histogram_;
58 HistogramBase* inconsistent_snapshot_histogram_;
60 DISALLOW_COPY_AND_ASSIGN(HistogramDeltaSerialization);
63 } // namespace base
65 #endif // BASE_METRICS_HISTOGRAM_DELTA_SERIALIZATION_H_