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

Side by Side Diff: components/metrics/leak_detector/ranked_set.h

Issue 1878863004: Revert of Record call site history in LeakDetectorImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #ifndef COMPONENTS_METRICS_LEAK_DETECTOR_RANKED_SET_H_ 5 #ifndef COMPONENTS_METRICS_LEAK_DETECTOR_RANKED_SET_H_
6 #define COMPONENTS_METRICS_LEAK_DETECTOR_RANKED_SET_H_ 6 #define COMPONENTS_METRICS_LEAK_DETECTOR_RANKED_SET_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <functional> // for std::less 10 #include <functional> // for std::less
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 // 65 //
66 // Time complexity is O(log n). 66 // Time complexity is O(log n).
67 void Add(const ValueType& value, int count); 67 void Add(const ValueType& value, int count);
68 68
69 // Helper functions to directly add a size or call stack to the RankedSet. 69 // Helper functions to directly add a size or call stack to the RankedSet.
70 void AddSize(size_t size, int count) { Add(ValueType(size), count); } 70 void AddSize(size_t size, int count) { Add(ValueType(size), count); }
71 void AddCallStack(const CallStack* call_stack, int count) { 71 void AddCallStack(const CallStack* call_stack, int count) {
72 Add(ValueType(call_stack), count); 72 Add(ValueType(call_stack), count);
73 } 73 }
74 74
75 // Helper functions to directly search for an element with |value| equal to a
76 // particular size or call stack. The time complexity is O(n) rather than the
77 // O(log n) typical of std::set. These should be called sparingly in
78 // performance-critical code.
79 const_iterator FindSize(size_t size) const { return Find(ValueType(size)); }
80 const_iterator FindCallStack(const CallStack* call_stack) const {
81 return Find(ValueType(call_stack));
82 }
83
84 private: 75 private:
85 // Returns an iterator to the element in |entries_| with value=|value|, or to
86 // entries_.end() if it was not found.
87 const_iterator Find(const ValueType& value) const;
88
89 // Max and min counts. Returns 0 if the list is empty. 76 // Max and min counts. Returns 0 if the list is empty.
90 int max_count() const { 77 int max_count() const {
91 return entries_.empty() ? 0 : entries_.begin()->count; 78 return entries_.empty() ? 0 : entries_.begin()->count;
92 } 79 }
93 int min_count() const { 80 int min_count() const {
94 return entries_.empty() ? 0 : entries_.rbegin()->count; 81 return entries_.empty() ? 0 : entries_.rbegin()->count;
95 } 82 }
96 83
97 // Max number of items that can be stored in the list. 84 // Max number of items that can be stored in the list.
98 size_t max_size_; 85 size_t max_size_;
99 86
100 // Actual storage container for entries. 87 // Actual storage container for entries.
101 EntrySet entries_; 88 EntrySet entries_;
102 89
103 DISALLOW_COPY_AND_ASSIGN(RankedSet); 90 DISALLOW_COPY_AND_ASSIGN(RankedSet);
104 }; 91 };
105 92
106 } // namespace leak_detector 93 } // namespace leak_detector
107 } // namespace metrics 94 } // namespace metrics
108 95
109 #endif // COMPONENTS_METRICS_LEAK_DETECTOR_RANKED_SET_H_ 96 #endif // COMPONENTS_METRICS_LEAK_DETECTOR_RANKED_SET_H_
OLDNEW
« no previous file with comments | « components/metrics/leak_detector/leak_detector_impl_unittest.cc ('k') | components/metrics/leak_detector/ranked_set.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698