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

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

Issue 1870233003: Record call site history in LeakDetectorImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clarify comments in RankedSet 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
75 private: 84 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
76 // Max and min counts. Returns 0 if the list is empty. 89 // Max and min counts. Returns 0 if the list is empty.
77 int max_count() const { 90 int max_count() const {
78 return entries_.empty() ? 0 : entries_.begin()->count; 91 return entries_.empty() ? 0 : entries_.begin()->count;
79 } 92 }
80 int min_count() const { 93 int min_count() const {
81 return entries_.empty() ? 0 : entries_.rbegin()->count; 94 return entries_.empty() ? 0 : entries_.rbegin()->count;
82 } 95 }
83 96
84 // Max number of items that can be stored in the list. 97 // Max number of items that can be stored in the list.
85 size_t max_size_; 98 size_t max_size_;
86 99
87 // Actual storage container for entries. 100 // Actual storage container for entries.
88 EntrySet entries_; 101 EntrySet entries_;
89 102
90 DISALLOW_COPY_AND_ASSIGN(RankedSet); 103 DISALLOW_COPY_AND_ASSIGN(RankedSet);
91 }; 104 };
92 105
93 } // namespace leak_detector 106 } // namespace leak_detector
94 } // namespace metrics 107 } // namespace metrics
95 108
96 #endif // COMPONENTS_METRICS_LEAK_DETECTOR_RANKED_SET_H_ 109 #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