Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: base/metrics/histogram_delta_serializer.cc

Issue 27460003: Consolidate serialization code in base::HistogramDeltasSerializer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/values.h"
12
13 namespace base {
14
15 namespace {
16
17 // Create or find existing histogram and add the samples from pickle.
18 // Silently returns when seeing any data problem in the pickle.
19 void DeserializeHistogramAndAddSamples(PickleIterator* iter) {
20 HistogramBase* histogram = DeserializeHistogramInfo(iter);
21 if (!histogram)
22 return;
23
24 if (histogram->flags() & HistogramBase::kIPCSerializationSourceFlag) {
25 DVLOG(1) << "Single process mode, histogram observed and not copied: "
26 << histogram->histogram_name();
27 return;
28 }
29 histogram->AddSamplesFromPickle(iter);
30 }
31
32 }
33
34 HistogramDeltasSerializer::HistogramDeltasSerializer(
35 const std::string& caller_name)
36 : histogram_snapshot_manager_(this),
37 inconsistencies_histogram_(NULL),
38 inconsistencies_unique_histogram_(NULL),
39 inconsistent_stapshot_histogram_(NULL) {
Ilya Sherman 2013/10/17 22:41:47 nit: No need to explicitly initialize these histog
Vitaly Buka (NO REVIEWS) 2013/10/18 05:33:35 Done.
40 inconsistencies_histogram_ =
41 LinearHistogram::FactoryGet(
42 "Histogram.Inconsistencies" + caller_name, 1,
43 HistogramBase::NEVER_EXCEEDED_VALUE,
44 HistogramBase::NEVER_EXCEEDED_VALUE + 1,
45 HistogramBase::kUmaTargetedHistogramFlag);
46
47 inconsistencies_unique_histogram_ =
48 LinearHistogram::FactoryGet(
49 "Histogram.Inconsistencies" + caller_name + "Unique", 1,
50 HistogramBase::NEVER_EXCEEDED_VALUE,
51 HistogramBase::NEVER_EXCEEDED_VALUE + 1,
52 HistogramBase::kUmaTargetedHistogramFlag);
53
54 inconsistent_stapshot_histogram_ =
55 Histogram::FactoryGet(
56 "Histogram.InconsistentSnapshot" + caller_name, 1, 1000000, 50,
57 HistogramBase::kUmaTargetedHistogramFlag);
58 }
59
60 HistogramDeltasSerializer::~HistogramDeltasSerializer() {
61 }
62
63 const std::vector<std::string>& HistogramDeltasSerializer::GetNewDeltas() {
64 serialized_deltas_.clear();
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 return serialized_deltas_;
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(), static_cast<int>(it->size()));
Ilya Sherman 2013/10/17 22:41:47 nit: Please use checked_numeric_cast here.
Vitaly Buka (NO REVIEWS) 2013/10/18 05:33:35 Done.
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
92 serialized_deltas_.push_back(
93 std::string(static_cast<const char*>(pickle.data()), pickle.size()));
94 }
95
96 void HistogramDeltasSerializer::InconsistencyDetected(
97 HistogramBase::Inconsistency problem) {
98 inconsistencies_histogram_->Add(problem);
99 }
100
101 void HistogramDeltasSerializer::UniqueInconsistencyDetected(
102 HistogramBase::Inconsistency problem) {
103 inconsistencies_unique_histogram_->Add(problem);
104 }
105
106 void HistogramDeltasSerializer::InconsistencyDetectedInLoggedCount(int amount) {
107 inconsistent_stapshot_histogram_->Add(std::abs(amount));
108 }
109
110 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698