| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/metrics/histogram_delta_serialization.h" | 5 #include "base/metrics/histogram_delta_serialization.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram_base.h" | 8 #include "base/metrics/histogram_base.h" |
| 9 #include "base/metrics/histogram_snapshot_manager.h" | 9 #include "base/metrics/histogram_snapshot_manager.h" |
| 10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 Histogram::FactoryGet( | 54 Histogram::FactoryGet( |
| 55 "Histogram.InconsistentSnapshot" + caller_name, 1, 1000000, 50, | 55 "Histogram.InconsistentSnapshot" + caller_name, 1, 1000000, 50, |
| 56 HistogramBase::kUmaTargetedHistogramFlag); | 56 HistogramBase::kUmaTargetedHistogramFlag); |
| 57 } | 57 } |
| 58 | 58 |
| 59 HistogramDeltaSerialization::~HistogramDeltaSerialization() { | 59 HistogramDeltaSerialization::~HistogramDeltaSerialization() { |
| 60 } | 60 } |
| 61 | 61 |
| 62 void HistogramDeltaSerialization::PrepareAndSerializeDeltas( | 62 void HistogramDeltaSerialization::PrepareAndSerializeDeltas( |
| 63 std::vector<std::string>* serialized_deltas) { | 63 std::vector<std::string>* serialized_deltas) { |
| 64 DCHECK(thread_checker_.CalledOnValidThread()); |
| 65 |
| 64 serialized_deltas_ = serialized_deltas; | 66 serialized_deltas_ = serialized_deltas; |
| 65 // Note: Before serializing, we set the kIPCSerializationSourceFlag for all | 67 // Note: Before serializing, we set the kIPCSerializationSourceFlag for all |
| 66 // the histograms, so that the receiving process can distinguish them from the | 68 // the histograms, so that the receiving process can distinguish them from the |
| 67 // local histograms. | 69 // local histograms. |
| 68 histogram_snapshot_manager_.PrepareDeltas( | 70 histogram_snapshot_manager_.PrepareDeltas( |
| 69 Histogram::kIPCSerializationSourceFlag, Histogram::kNoFlags); | 71 Histogram::kIPCSerializationSourceFlag, Histogram::kNoFlags); |
| 70 serialized_deltas_ = NULL; | 72 serialized_deltas_ = NULL; |
| 71 } | 73 } |
| 72 | 74 |
| 73 // static | 75 // static |
| 74 void HistogramDeltaSerialization::DeserializeAndAddSamples( | 76 void HistogramDeltaSerialization::DeserializeAndAddSamples( |
| 75 const std::vector<std::string>& serialized_deltas) { | 77 const std::vector<std::string>& serialized_deltas) { |
| 76 for (std::vector<std::string>::const_iterator it = serialized_deltas.begin(); | 78 for (std::vector<std::string>::const_iterator it = serialized_deltas.begin(); |
| 77 it != serialized_deltas.end(); ++it) { | 79 it != serialized_deltas.end(); ++it) { |
| 78 Pickle pickle(it->data(), checked_cast<int>(it->size())); | 80 Pickle pickle(it->data(), checked_cast<int>(it->size())); |
| 79 PickleIterator iter(pickle); | 81 PickleIterator iter(pickle); |
| 80 DeserializeHistogramAndAddSamples(&iter); | 82 DeserializeHistogramAndAddSamples(&iter); |
| 81 } | 83 } |
| 82 } | 84 } |
| 83 | 85 |
| 84 void HistogramDeltaSerialization::RecordDelta( | 86 void HistogramDeltaSerialization::RecordDelta( |
| 85 const HistogramBase& histogram, | 87 const HistogramBase& histogram, |
| 86 const HistogramSamples& snapshot) { | 88 const HistogramSamples& snapshot) { |
| 89 DCHECK(thread_checker_.CalledOnValidThread()); |
| 87 DCHECK_NE(0, snapshot.TotalCount()); | 90 DCHECK_NE(0, snapshot.TotalCount()); |
| 88 | 91 |
| 89 Pickle pickle; | 92 Pickle pickle; |
| 90 histogram.SerializeInfo(&pickle); | 93 histogram.SerializeInfo(&pickle); |
| 91 snapshot.Serialize(&pickle); | 94 snapshot.Serialize(&pickle); |
| 92 serialized_deltas_->push_back( | 95 serialized_deltas_->push_back( |
| 93 std::string(static_cast<const char*>(pickle.data()), pickle.size())); | 96 std::string(static_cast<const char*>(pickle.data()), pickle.size())); |
| 94 } | 97 } |
| 95 | 98 |
| 96 void HistogramDeltaSerialization::InconsistencyDetected( | 99 void HistogramDeltaSerialization::InconsistencyDetected( |
| 97 HistogramBase::Inconsistency problem) { | 100 HistogramBase::Inconsistency problem) { |
| 101 DCHECK(thread_checker_.CalledOnValidThread()); |
| 102 |
| 98 inconsistencies_histogram_->Add(problem); | 103 inconsistencies_histogram_->Add(problem); |
| 99 } | 104 } |
| 100 | 105 |
| 101 void HistogramDeltaSerialization::UniqueInconsistencyDetected( | 106 void HistogramDeltaSerialization::UniqueInconsistencyDetected( |
| 102 HistogramBase::Inconsistency problem) { | 107 HistogramBase::Inconsistency problem) { |
| 108 DCHECK(thread_checker_.CalledOnValidThread()); |
| 109 |
| 103 inconsistencies_unique_histogram_->Add(problem); | 110 inconsistencies_unique_histogram_->Add(problem); |
| 104 } | 111 } |
| 105 | 112 |
| 106 void HistogramDeltaSerialization::InconsistencyDetectedInLoggedCount( | 113 void HistogramDeltaSerialization::InconsistencyDetectedInLoggedCount( |
| 107 int amount) { | 114 int amount) { |
| 115 DCHECK(thread_checker_.CalledOnValidThread()); |
| 116 |
| 108 inconsistent_snapshot_histogram_->Add(std::abs(amount)); | 117 inconsistent_snapshot_histogram_->Add(std::abs(amount)); |
| 109 } | 118 } |
| 110 | 119 |
| 111 } // namespace base | 120 } // namespace base |
| OLD | NEW |