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/strings/stringprintf.h" | |
12 #include "base/values.h" | |
13 | |
14 namespace base { | |
15 | |
16 namespace { | |
17 | |
18 void DeserializeHistogramAndAddSamples(PickleIterator* iter) { | |
Ilya Sherman
2013/10/17 04:37:42
nit: Please add documentation for this function.
Vitaly Buka (NO REVIEWS)
2013/10/17 10:15:47
Done. Recovered old doc string.
| |
19 HistogramBase* histogram = DeserializeHistogramInfo(iter); | |
20 if (!histogram) | |
21 return; | |
22 | |
23 if (histogram->flags() & HistogramBase::kIPCSerializationSourceFlag) { | |
24 DVLOG(1) << "Single process mode, histogram observed and not copied: " | |
25 << histogram->histogram_name(); | |
26 return; | |
27 } | |
28 histogram->AddSamplesFromPickle(iter); | |
29 } | |
30 | |
31 } | |
32 | |
33 HistogramDeltasSerializer::HistogramDeltasSerializer( | |
34 const std::string& caller_name) | |
35 : caller_name_(caller_name), | |
36 histogram_snapshot_manager_(new HistogramSnapshotManager(this)) { | |
Ilya Sherman
2013/10/17 04:37:42
nit: Why heap-allocate this, rather than including
Vitaly Buka (NO REVIEWS)
2013/10/17 10:15:47
Recently I was asked often to do so. I had impress
| |
37 } | |
38 | |
39 HistogramDeltasSerializer::~HistogramDeltasSerializer() { | |
40 } | |
41 | |
42 const HistogramDeltasSerializer::SerializedDeltas& | |
43 HistogramDeltasSerializer::GetNewDeltas() { | |
44 histograms_.clear(); | |
45 // Note: Before serializing, we set the kIPCSerializationSourceFlag for all | |
46 // the histograms, so that the receiving process can distinguish them from the | |
47 // local histograms. | |
48 histogram_snapshot_manager_->PrepareDeltas( | |
49 Histogram::kIPCSerializationSourceFlag, false); | |
50 return histograms_; | |
51 } | |
52 | |
53 // static | |
54 void HistogramDeltasSerializer::DeserializeAndAddSamples( | |
55 const SerializedDeltas& deltas) { | |
56 for (SerializedDeltas::const_iterator it = deltas.begin(); | |
57 it != deltas.end(); ++it) { | |
58 Pickle pickle(it->data(), it->size()); | |
59 PickleIterator iter(pickle); | |
60 DeserializeHistogramAndAddSamples(&iter); | |
61 } | |
62 } | |
63 | |
64 void HistogramDeltasSerializer::RecordDelta(const HistogramBase& histogram, | |
65 const HistogramSamples& snapshot) { | |
66 DCHECK_NE(0, snapshot.TotalCount()); | |
67 | |
68 Pickle pickle; | |
69 histogram.SerializeInfo(&pickle); | |
70 snapshot.Serialize(&pickle); | |
71 | |
72 histograms_.push_back( | |
73 std::string(static_cast<const char*>(pickle.data()), pickle.size())); | |
74 } | |
75 | |
76 void HistogramDeltasSerializer::InconsistencyDetected( | |
77 HistogramBase::Inconsistency problem) { | |
78 UMA_HISTOGRAM_ENUMERATION(StringPrintf("Histogram.Inconsistencies%s", | |
79 caller_name_.c_str()), | |
Ilya Sherman
2013/10/17 04:37:42
Why StringPrintf rather than just using the concat
Ilya Sherman
2013/10/17 04:37:42
UMA_HISTOGRAM_ENUMERATION requires the histogram n
Vitaly Buka (NO REVIEWS)
2013/10/17 10:15:47
Done.
Vitaly Buka (NO REVIEWS)
2013/10/17 10:15:47
Done.
| |
80 problem, HistogramBase::NEVER_EXCEEDED_VALUE); | |
81 } | |
82 | |
83 void HistogramDeltasSerializer::UniqueInconsistencyDetected( | |
84 HistogramBase::Inconsistency problem) { | |
85 UMA_HISTOGRAM_ENUMERATION(StringPrintf("Histogram.Inconsistencies%sUnique", | |
86 caller_name_.c_str()), | |
87 problem, HistogramBase::NEVER_EXCEEDED_VALUE); | |
88 } | |
89 | |
90 void HistogramDeltasSerializer::InconsistencyDetectedInLoggedCount(int amount) { | |
91 UMA_HISTOGRAM_COUNTS(StringPrintf("Histogram.InconsistentSnapshot%s", | |
92 caller_name_.c_str()), | |
93 std::abs(amount)); | |
94 } | |
95 | |
96 } // namespace base | |
OLD | NEW |