OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
11 | 11 |
12 #include <math.h> | 12 #include <math.h> |
13 | 13 |
14 #include <algorithm> | 14 #include <algorithm> |
15 #include <string> | 15 #include <string> |
16 | 16 |
| 17 #include "base/debug/leak_annotations.h" |
17 #include "base/logging.h" | 18 #include "base/logging.h" |
18 #include "base/pickle.h" | 19 #include "base/pickle.h" |
19 #include "base/stringprintf.h" | 20 #include "base/stringprintf.h" |
20 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
21 | 22 |
22 namespace base { | 23 namespace base { |
23 | 24 |
24 // Static table of checksums for all possible 8 bit bytes. | 25 // Static table of checksums for all possible 8 bit bytes. |
25 const uint32 Histogram::kCrcTable[256] = {0x0, 0x77073096L, 0xee0e612cL, | 26 const uint32 Histogram::kCrcTable[256] = {0x0, 0x77073096L, 0xee0e612cL, |
26 0x990951baL, 0x76dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0xedb8832L, | 27 0x990951baL, 0x76dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0xedb8832L, |
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1023 | 1024 |
1024 // static | 1025 // static |
1025 bool StatisticsRecorder::IsActive() { | 1026 bool StatisticsRecorder::IsActive() { |
1026 if (lock_ == NULL) | 1027 if (lock_ == NULL) |
1027 return false; | 1028 return false; |
1028 base::AutoLock auto_lock(*lock_); | 1029 base::AutoLock auto_lock(*lock_); |
1029 return NULL != histograms_; | 1030 return NULL != histograms_; |
1030 } | 1031 } |
1031 | 1032 |
1032 Histogram* StatisticsRecorder::RegisterOrDeleteDuplicate(Histogram* histogram) { | 1033 Histogram* StatisticsRecorder::RegisterOrDeleteDuplicate(Histogram* histogram) { |
| 1034 // As per crbug.com/79322 the histograms are intentionally leaked, so we need |
| 1035 // to annotate them. Because ANNOTATE_LEAKING_OBJECT_PTR may be used only once |
| 1036 // for an object, the duplicates should not be annotated. |
| 1037 // Callers are responsible for not calling RegisterOrDeleteDuplicate(ptr) |
| 1038 // twice if (lock_ == NULL) || (!histograms_). |
1033 DCHECK(histogram->HasValidRangeChecksum()); | 1039 DCHECK(histogram->HasValidRangeChecksum()); |
1034 if (lock_ == NULL) | 1040 if (lock_ == NULL) { |
| 1041 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322 |
1035 return histogram; | 1042 return histogram; |
| 1043 } |
1036 base::AutoLock auto_lock(*lock_); | 1044 base::AutoLock auto_lock(*lock_); |
1037 if (!histograms_) | 1045 if (!histograms_) { |
| 1046 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322 |
1038 return histogram; | 1047 return histogram; |
| 1048 } |
1039 const std::string name = histogram->histogram_name(); | 1049 const std::string name = histogram->histogram_name(); |
1040 HistogramMap::iterator it = histograms_->find(name); | 1050 HistogramMap::iterator it = histograms_->find(name); |
1041 // Avoid overwriting a previous registration. | 1051 // Avoid overwriting a previous registration. |
1042 if (histograms_->end() == it) { | 1052 if (histograms_->end() == it) { |
1043 (*histograms_)[name] = histogram; | 1053 (*histograms_)[name] = histogram; |
| 1054 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322 |
1044 } else { | 1055 } else { |
1045 delete histogram; // We already have one by this name. | 1056 delete histogram; // We already have one by this name. |
1046 histogram = it->second; | 1057 histogram = it->second; |
1047 } | 1058 } |
1048 return histogram; | 1059 return histogram; |
1049 } | 1060 } |
1050 | 1061 |
1051 // static | 1062 // static |
1052 void StatisticsRecorder::WriteHTMLGraph(const std::string& query, | 1063 void StatisticsRecorder::WriteHTMLGraph(const std::string& query, |
1053 std::string* output) { | 1064 std::string* output) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 } | 1149 } |
1139 | 1150 |
1140 // static | 1151 // static |
1141 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; | 1152 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; |
1142 // static | 1153 // static |
1143 base::Lock* StatisticsRecorder::lock_ = NULL; | 1154 base::Lock* StatisticsRecorder::lock_ = NULL; |
1144 // static | 1155 // static |
1145 bool StatisticsRecorder::dump_on_exit_ = false; | 1156 bool StatisticsRecorder::dump_on_exit_ = false; |
1146 | 1157 |
1147 } // namespace base | 1158 } // namespace base |
OLD | NEW |