[email protected] | 6afa90f | 2013-10-23 01:16:04 | [diff] [blame] | 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. |
| 4 | |
| 5 | #ifndef BASE_METRICS_HISTOGRAM_DELTA_SERIALIZATION_H_ |
| 6 | #define BASE_METRICS_HISTOGRAM_DELTA_SERIALIZATION_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include "base/base_export.h" |
avi | 9b6f4293 | 2015-12-26 22:15:14 | [diff] [blame] | 12 | #include "base/macros.h" |
[email protected] | 6afa90f | 2013-10-23 01:16:04 | [diff] [blame] | 13 | #include "base/memory/scoped_ptr.h" |
| 14 | #include "base/metrics/histogram_flattener.h" |
| 15 | #include "base/metrics/histogram_snapshot_manager.h" |
asvitkine | 0b6761f | 2015-11-19 23:49:49 | [diff] [blame] | 16 | #include "base/threading/thread_checker.h" |
[email protected] | 6afa90f | 2013-10-23 01:16:04 | [diff] [blame] | 17 | |
| 18 | namespace base { |
| 19 | |
| 20 | class HistogramBase; |
| 21 | |
| 22 | // Serializes and restores histograms deltas. |
| 23 | class BASE_EXPORT HistogramDeltaSerialization : public HistogramFlattener { |
| 24 | public: |
| 25 | // |caller_name| is string used in histograms for counting inconsistencies. |
| 26 | explicit HistogramDeltaSerialization(const std::string& caller_name); |
dcheng | 5648818 | 2014-10-21 10:54:51 | [diff] [blame] | 27 | ~HistogramDeltaSerialization() override; |
[email protected] | 6afa90f | 2013-10-23 01:16:04 | [diff] [blame] | 28 | |
| 29 | // Computes deltas in histogram bucket counts relative to the previous call to |
| 30 | // this method. Stores the deltas in serialized form into |serialized_deltas|. |
bcwhite | 5cb99eb | 2016-02-01 21:07:56 | [diff] [blame] | 31 | // If |serialized_deltas| is null, no data is serialized, though the next call |
| 32 | // will compute the deltas relative to this one. Setting |include_persistent| |
| 33 | // will include histograms held in persistent memory (and thus may be reported |
| 34 | // elsewhere); otherwise only histograms local to this process are serialized. |
| 35 | void PrepareAndSerializeDeltas(std::vector<std::string>* serialized_deltas, |
| 36 | bool include_persistent); |
[email protected] | 6afa90f | 2013-10-23 01:16:04 | [diff] [blame] | 37 | |
| 38 | // Deserialize deltas and add samples to corresponding histograms, creating |
| 39 | // them if necessary. Silently ignores errors in |serialized_deltas|. |
| 40 | static void DeserializeAndAddSamples( |
| 41 | const std::vector<std::string>& serialized_deltas); |
| 42 | |
| 43 | private: |
| 44 | // HistogramFlattener implementation. |
dcheng | 5648818 | 2014-10-21 10:54:51 | [diff] [blame] | 45 | void RecordDelta(const HistogramBase& histogram, |
| 46 | const HistogramSamples& snapshot) override; |
| 47 | void InconsistencyDetected(HistogramBase::Inconsistency problem) override; |
| 48 | void UniqueInconsistencyDetected( |
mostynb | 9e096de | 2014-10-07 17:59:11 | [diff] [blame] | 49 | HistogramBase::Inconsistency problem) override; |
dcheng | 5648818 | 2014-10-21 10:54:51 | [diff] [blame] | 50 | void InconsistencyDetectedInLoggedCount(int amount) override; |
[email protected] | 6afa90f | 2013-10-23 01:16:04 | [diff] [blame] | 51 | |
asvitkine | 0b6761f | 2015-11-19 23:49:49 | [diff] [blame] | 52 | ThreadChecker thread_checker_; |
| 53 | |
[email protected] | 6afa90f | 2013-10-23 01:16:04 | [diff] [blame] | 54 | // Calculates deltas in histogram counters. |
| 55 | HistogramSnapshotManager histogram_snapshot_manager_; |
| 56 | |
| 57 | // Output buffer for serialized deltas. |
| 58 | std::vector<std::string>* serialized_deltas_; |
| 59 | |
| 60 | // Histograms to count inconsistencies in snapshots. |
| 61 | HistogramBase* inconsistencies_histogram_; |
| 62 | HistogramBase* inconsistencies_unique_histogram_; |
| 63 | HistogramBase* inconsistent_snapshot_histogram_; |
| 64 | |
| 65 | DISALLOW_COPY_AND_ASSIGN(HistogramDeltaSerialization); |
| 66 | }; |
| 67 | |
| 68 | } // namespace base |
| 69 | |
| 70 | #endif // BASE_METRICS_HISTOGRAM_DELTA_SERIALIZATION_H_ |