OLD | NEW |
---|---|
(Empty) | |
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 #include "base/metrics/histogram_delta_serializer.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/metrics/histogram_base.h" | |
9 #include "base/metrics/histogram_snapshot_manager.h" | |
10 #include "base/pickle.h" | |
11 #include "base/safe_numerics.h" | |
12 #include "base/values.h" | |
13 | |
14 namespace base { | |
15 | |
16 namespace { | |
17 | |
18 // Create or find existing histogram and add the samples from pickle. | |
19 // Silently returns when seeing any data problem in the pickle. | |
20 void DeserializeHistogramAndAddSamples(PickleIterator* iter) { | |
21 HistogramBase* histogram = DeserializeHistogramInfo(iter); | |
22 if (!histogram) | |
23 return; | |
24 | |
25 if (histogram->flags() & HistogramBase::kIPCSerializationSourceFlag) { | |
26 DVLOG(1) << "Single process mode, histogram observed and not copied: " | |
27 << histogram->histogram_name(); | |
28 return; | |
29 } | |
30 histogram->AddSamplesFromPickle(iter); | |
31 } | |
32 | |
33 } | |
darin (slow to review)
2013/10/21 21:59:58
nit: "} // namespace"
Vitaly Buka (NO REVIEWS)
2013/10/21 23:05:32
Done.
| |
34 | |
35 HistogramDeltasSerializer::HistogramDeltasSerializer( | |
36 const std::string& caller_name) | |
37 : histogram_snapshot_manager_(this), | |
38 serialized_deltas_(NULL) { | |
39 inconsistencies_histogram_ = | |
40 LinearHistogram::FactoryGet( | |
41 "Histogram.Inconsistencies" + caller_name, 1, | |
42 HistogramBase::NEVER_EXCEEDED_VALUE, | |
43 HistogramBase::NEVER_EXCEEDED_VALUE + 1, | |
44 HistogramBase::kUmaTargetedHistogramFlag); | |
45 | |
46 inconsistencies_unique_histogram_ = | |
47 LinearHistogram::FactoryGet( | |
48 "Histogram.Inconsistencies" + caller_name + "Unique", 1, | |
49 HistogramBase::NEVER_EXCEEDED_VALUE, | |
50 HistogramBase::NEVER_EXCEEDED_VALUE + 1, | |
51 HistogramBase::kUmaTargetedHistogramFlag); | |
52 | |
53 inconsistent_snapshot_histogram_ = | |
54 Histogram::FactoryGet( | |
55 "Histogram.InconsistentSnapshot" + caller_name, 1, 1000000, 50, | |
56 HistogramBase::kUmaTargetedHistogramFlag); | |
57 } | |
58 | |
59 HistogramDeltasSerializer::~HistogramDeltasSerializer() { | |
60 } | |
61 | |
62 void HistogramDeltasSerializer::PrepareAndSerializeDeltas( | |
63 std::vector<std::string>* serialized_deltas) { | |
64 serialized_deltas_ = serialized_deltas; | |
65 // Note: Before serializing, we set the kIPCSerializationSourceFlag for all | |
66 // the histograms, so that the receiving process can distinguish them from the | |
67 // local histograms. | |
68 histogram_snapshot_manager_.PrepareDeltas( | |
69 Histogram::kIPCSerializationSourceFlag, false); | |
70 serialized_deltas_ = NULL; | |
71 } | |
72 | |
73 // static | |
74 void HistogramDeltasSerializer::DeserializeAndAddSamples( | |
75 const std::vector<std::string>& deltas) { | |
76 for (std::vector<std::string>::const_iterator it = deltas.begin(); | |
77 it != deltas.end(); ++it) { | |
78 Pickle pickle(it->data(), checked_numeric_cast<int>(it->size())); | |
79 PickleIterator iter(pickle); | |
80 DeserializeHistogramAndAddSamples(&iter); | |
81 } | |
82 } | |
83 | |
84 void HistogramDeltasSerializer::RecordDelta(const HistogramBase& histogram, | |
85 const HistogramSamples& snapshot) { | |
86 DCHECK_NE(0, snapshot.TotalCount()); | |
87 | |
88 Pickle pickle; | |
89 histogram.SerializeInfo(&pickle); | |
90 snapshot.Serialize(&pickle); | |
91 serialized_deltas_->push_back( | |
92 std::string(static_cast<const char*>(pickle.data()), pickle.size())); | |
93 } | |
94 | |
95 void HistogramDeltasSerializer::InconsistencyDetected( | |
96 HistogramBase::Inconsistency problem) { | |
97 inconsistencies_histogram_->Add(problem); | |
98 } | |
99 | |
100 void HistogramDeltasSerializer::UniqueInconsistencyDetected( | |
101 HistogramBase::Inconsistency problem) { | |
102 inconsistencies_unique_histogram_->Add(problem); | |
103 } | |
104 | |
105 void HistogramDeltasSerializer::InconsistencyDetectedInLoggedCount(int amount) { | |
106 inconsistent_snapshot_histogram_->Add(std::abs(amount)); | |
107 } | |
108 | |
109 } // namespace base | |
OLD | NEW |