OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Histogram is an object that aggregates statistics, and can summarize them in | 5 // Histogram is an object that aggregates statistics, and can summarize them in |
6 // various forms, including ASCII graphical, HTML, and numerically (as a | 6 // various forms, including ASCII graphical, HTML, and numerically (as a |
7 // vector of numbers corresponding to each of the aggregating buckets). | 7 // vector of numbers corresponding to each of the aggregating buckets). |
8 // See header file for details and examples. | 8 // See header file for details and examples. |
9 | 9 |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 230 |
231 // static | 231 // static |
232 std::string Histogram::SerializeHistogramInfo(const Histogram& histogram, | 232 std::string Histogram::SerializeHistogramInfo(const Histogram& histogram, |
233 const SampleSet& snapshot) { | 233 const SampleSet& snapshot) { |
234 DCHECK_NE(NOT_VALID_IN_RENDERER, histogram.histogram_type()); | 234 DCHECK_NE(NOT_VALID_IN_RENDERER, histogram.histogram_type()); |
235 | 235 |
236 Pickle pickle; | 236 Pickle pickle; |
237 pickle.WriteString(histogram.histogram_name()); | 237 pickle.WriteString(histogram.histogram_name()); |
238 pickle.WriteInt(histogram.declared_min()); | 238 pickle.WriteInt(histogram.declared_min()); |
239 pickle.WriteInt(histogram.declared_max()); | 239 pickle.WriteInt(histogram.declared_max()); |
240 pickle.WriteSize(histogram.bucket_count()); | 240 pickle.WriteUInt64(histogram.bucket_count()); |
241 pickle.WriteUInt32(histogram.range_checksum()); | 241 pickle.WriteUInt32(histogram.range_checksum()); |
242 pickle.WriteInt(histogram.histogram_type()); | 242 pickle.WriteInt(histogram.histogram_type()); |
243 pickle.WriteInt(histogram.flags()); | 243 pickle.WriteInt(histogram.flags()); |
244 | 244 |
245 snapshot.Serialize(&pickle); | 245 snapshot.Serialize(&pickle); |
246 | 246 |
247 histogram.SerializeRanges(&pickle); | 247 histogram.SerializeRanges(&pickle); |
248 | 248 |
249 return std::string(static_cast<const char*>(pickle.data()), pickle.size()); | 249 return std::string(static_cast<const char*>(pickle.data()), pickle.size()); |
250 } | 250 } |
251 | 251 |
252 // static | 252 // static |
253 bool Histogram::DeserializeHistogramInfo(const std::string& histogram_info) { | 253 bool Histogram::DeserializeHistogramInfo(const std::string& histogram_info) { |
254 if (histogram_info.empty()) { | 254 if (histogram_info.empty()) { |
255 return false; | 255 return false; |
256 } | 256 } |
257 | 257 |
258 Pickle pickle(histogram_info.data(), | 258 Pickle pickle(histogram_info.data(), |
259 static_cast<int>(histogram_info.size())); | 259 static_cast<int>(histogram_info.size())); |
260 std::string histogram_name; | 260 std::string histogram_name; |
261 int declared_min; | 261 int declared_min; |
262 int declared_max; | 262 int declared_max; |
263 size_t bucket_count; | 263 uint64 bucket_count; |
264 uint32 range_checksum; | 264 uint32 range_checksum; |
265 int histogram_type; | 265 int histogram_type; |
266 int pickle_flags; | 266 int pickle_flags; |
267 SampleSet sample; | 267 SampleSet sample; |
268 | 268 |
269 PickleIterator iter(pickle); | 269 PickleIterator iter(pickle); |
270 if (!iter.ReadString(&histogram_name) || | 270 if (!iter.ReadString(&histogram_name) || |
271 !iter.ReadInt(&declared_min) || | 271 !iter.ReadInt(&declared_min) || |
272 !iter.ReadInt(&declared_max) || | 272 !iter.ReadInt(&declared_max) || |
273 !iter.ReadSize(&bucket_count) || | 273 !iter.ReadUInt64(&bucket_count) || |
274 !iter.ReadUInt32(&range_checksum) || | 274 !iter.ReadUInt32(&range_checksum) || |
275 !iter.ReadInt(&histogram_type) || | 275 !iter.ReadInt(&histogram_type) || |
276 !iter.ReadInt(&pickle_flags) || | 276 !iter.ReadInt(&pickle_flags) || |
277 !sample.Histogram::SampleSet::Deserialize(&iter)) { | 277 !sample.Histogram::SampleSet::Deserialize(&iter)) { |
278 DLOG(ERROR) << "Pickle error decoding Histogram: " << histogram_name; | 278 DLOG(ERROR) << "Pickle error decoding Histogram: " << histogram_name; |
279 return false; | 279 return false; |
280 } | 280 } |
281 | 281 |
282 DCHECK(pickle_flags & kIPCSerializationSourceFlag); | 282 DCHECK(pickle_flags & kIPCSerializationSourceFlag); |
283 // Since these fields may have come from an untrusted renderer, do additional | 283 // Since these fields may have come from an untrusted renderer, do additional |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 redundant_count_ -= other.redundant_count_; | 756 redundant_count_ -= other.redundant_count_; |
757 for (size_t index = 0; index < counts_.size(); ++index) { | 757 for (size_t index = 0; index < counts_.size(); ++index) { |
758 counts_[index] -= other.counts_[index]; | 758 counts_[index] -= other.counts_[index]; |
759 DCHECK_GE(counts_[index], 0); | 759 DCHECK_GE(counts_[index], 0); |
760 } | 760 } |
761 } | 761 } |
762 | 762 |
763 bool Histogram::SampleSet::Serialize(Pickle* pickle) const { | 763 bool Histogram::SampleSet::Serialize(Pickle* pickle) const { |
764 pickle->WriteInt64(sum_); | 764 pickle->WriteInt64(sum_); |
765 pickle->WriteInt64(redundant_count_); | 765 pickle->WriteInt64(redundant_count_); |
766 pickle->WriteSize(counts_.size()); | 766 pickle->WriteUInt64(counts_.size()); |
767 | 767 |
768 for (size_t index = 0; index < counts_.size(); ++index) { | 768 for (size_t index = 0; index < counts_.size(); ++index) { |
769 pickle->WriteInt(counts_[index]); | 769 pickle->WriteInt(counts_[index]); |
770 } | 770 } |
771 | 771 |
772 return true; | 772 return true; |
773 } | 773 } |
774 | 774 |
775 bool Histogram::SampleSet::Deserialize(PickleIterator* iter) { | 775 bool Histogram::SampleSet::Deserialize(PickleIterator* iter) { |
776 DCHECK_EQ(counts_.size(), 0u); | 776 DCHECK_EQ(counts_.size(), 0u); |
777 DCHECK_EQ(sum_, 0); | 777 DCHECK_EQ(sum_, 0); |
778 DCHECK_EQ(redundant_count_, 0); | 778 DCHECK_EQ(redundant_count_, 0); |
779 | 779 |
780 size_t counts_size; | 780 uint64 counts_size; |
781 | 781 |
782 if (!iter->ReadInt64(&sum_) || | 782 if (!iter->ReadInt64(&sum_) || |
783 !iter->ReadInt64(&redundant_count_) || | 783 !iter->ReadInt64(&redundant_count_) || |
784 !iter->ReadSize(&counts_size)) { | 784 !iter->ReadUInt64(&counts_size)) { |
785 return false; | 785 return false; |
786 } | 786 } |
787 | 787 |
788 if (counts_size == 0) | 788 if (counts_size == 0) |
789 return false; | 789 return false; |
790 | 790 |
791 int count = 0; | 791 int count = 0; |
792 for (size_t index = 0; index < counts_size; ++index) { | 792 for (uint64 index = 0; index < counts_size; ++index) { |
793 int i; | 793 int i; |
794 if (!iter->ReadInt(&i)) | 794 if (!iter->ReadInt(&i)) |
795 return false; | 795 return false; |
796 counts_.push_back(i); | 796 counts_.push_back(i); |
797 count += i; | 797 count += i; |
798 } | 798 } |
799 DCHECK_EQ(count, redundant_count_); | 799 DCHECK_EQ(count, redundant_count_); |
800 return count == redundant_count_; | 800 return count == redundant_count_; |
801 } | 801 } |
802 | 802 |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1324 | 1324 |
1325 // static | 1325 // static |
1326 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; | 1326 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; |
1327 // static | 1327 // static |
1328 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; | 1328 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; |
1329 // static | 1329 // static |
1330 base::Lock* StatisticsRecorder::lock_ = NULL; | 1330 base::Lock* StatisticsRecorder::lock_ = NULL; |
1331 // static | 1331 // static |
1332 bool StatisticsRecorder::dump_on_exit_ = false; | 1332 bool StatisticsRecorder::dump_on_exit_ = false; |
1333 } // namespace base | 1333 } // namespace base |
OLD | NEW |