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 // StatisticsRecorder holds all Histograms and BucketRanges that are used by | 5 // StatisticsRecorder holds all Histograms and BucketRanges that are used by |
6 // Histograms in the system. It provides a general place for | 6 // Histograms in the system. It provides a general place for |
7 // Histograms/BucketRanges to register, and supports a global API for accessing | 7 // Histograms/BucketRanges to register, and supports a global API for accessing |
8 // (i.e., dumping, or graphing) the data. | 8 // (i.e., dumping, or graphing) the data. |
9 | 9 |
10 #ifndef BASE_METRICS_STATISTICS_RECORDER_H_ | 10 #ifndef BASE_METRICS_STATISTICS_RECORDER_H_ |
(...skipping 13 matching lines...) Expand all Loading... | |
24 #include "base/macros.h" | 24 #include "base/macros.h" |
25 #include "base/metrics/histogram_base.h" | 25 #include "base/metrics/histogram_base.h" |
26 #include "base/strings/string_piece.h" | 26 #include "base/strings/string_piece.h" |
27 | 27 |
28 namespace base { | 28 namespace base { |
29 | 29 |
30 class BucketRanges; | 30 class BucketRanges; |
31 class Lock; | 31 class Lock; |
32 | 32 |
33 class BASE_EXPORT StatisticsRecorder { | 33 class BASE_EXPORT StatisticsRecorder { |
34 // A class used as a key for the histogram map below. It always references | |
Alexei Svitkine (slow)
2016/04/07 20:21:10
Nit: Move this within the public section below.
bcwhite
2016/04/07 20:24:33
Oh? It's not something that should be accessed ou
Alexei Svitkine (slow)
2016/04/07 20:49:08
From the style guide:
"Use the specified order of
bcwhite
2016/04/07 21:09:16
It does say "should". I think that would allow fo
| |
35 // a string owned outside of this class, likely in the value of the map. | |
36 class StringKey : public StringPiece { | |
37 public: | |
38 // Constructs the StringKey using various sources. The source must live | |
39 // at least as long as the created object. | |
40 StringKey(const std::string& str) : StringPiece(str) {} | |
41 StringKey(StringPiece str) : StringPiece(str) {} | |
42 | |
43 // Though StringPiece is better passed by value than by reference, in | |
44 // this case it's being passed many times and likely already been stored | |
45 // in memory (not just registers) so the benefit of pass-by-value is | |
46 // negated. | |
47 bool operator<(const StringKey& rhs) const { | |
48 // Since order is unimportant in the map and string comparisons can be | |
49 // slow, use the length as the primary sort value. | |
50 if (length() < rhs.length()) | |
51 return true; | |
52 if (length() > rhs.length()) | |
53 return false; | |
54 | |
55 // Fall back to an actual string comparison. The lengths are the same | |
56 // so a simple memory-compare is sufficient. | |
57 return wordmemcmp(data(), rhs.data(), length()) < 0; | |
Alexei Svitkine (slow)
2016/04/07 20:21:10
Nit: How about "return StringPiece::operator<(rhs)
bcwhite
2016/04/07 20:24:33
I had something like that previously but removed i
Alexei Svitkine (slow)
2016/04/07 20:49:08
I see - I guess since we don't if the compiler wil
bcwhite
2016/04/07 21:09:16
Done.
| |
58 } | |
59 }; | |
60 | |
34 public: | 61 public: |
35 typedef std::map<uint64_t, HistogramBase*> HistogramMap; // Key is name-hash. | 62 typedef std::map<StringKey, HistogramBase*> HistogramMap; |
36 typedef std::vector<HistogramBase*> Histograms; | 63 typedef std::vector<HistogramBase*> Histograms; |
37 | 64 |
38 // A class for iterating over the histograms held within this global resource. | 65 // A class for iterating over the histograms held within this global resource. |
39 class BASE_EXPORT HistogramIterator { | 66 class BASE_EXPORT HistogramIterator { |
40 public: | 67 public: |
41 HistogramIterator(const HistogramMap::iterator& iter, | 68 HistogramIterator(const HistogramMap::iterator& iter, |
42 bool include_persistent); | 69 bool include_persistent); |
43 HistogramIterator(const HistogramIterator& rhs); // Must be copyable. | 70 HistogramIterator(const HistogramIterator& rhs); // Must be copyable. |
44 ~HistogramIterator(); | 71 ~HistogramIterator(); |
45 | 72 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 | 206 |
180 // Lock protects access to above maps. | 207 // Lock protects access to above maps. |
181 static base::Lock* lock_; | 208 static base::Lock* lock_; |
182 | 209 |
183 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); | 210 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); |
184 }; | 211 }; |
185 | 212 |
186 } // namespace base | 213 } // namespace base |
187 | 214 |
188 #endif // BASE_METRICS_STATISTICS_RECORDER_H_ | 215 #endif // BASE_METRICS_STATISTICS_RECORDER_H_ |
OLD | NEW |