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

Side by Side Diff: base/trace_event/memory_usage_estimator.h

Issue 2977783002: [tracing] Optimize StackFrameDeduplicator. (Closed)
Patch Set: Don't use ASSERT_EQ on deque iterators (see goo.gl/9gkBf7) Created 3 years, 5 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
« no previous file with comments | « base/trace_event/heap_profiler_stack_frame_deduplicator_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 BASE_TRACE_EVENT_MEMORY_USAGE_ESTIMATOR_H_ 5 #ifndef BASE_TRACE_EVENT_MEMORY_USAGE_ESTIMATOR_H_
6 #define BASE_TRACE_EVENT_MEMORY_USAGE_ESTIMATOR_H_ 6 #define BASE_TRACE_EVENT_MEMORY_USAGE_ESTIMATOR_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <array> 10 #include <array>
11 #include <deque> 11 #include <deque>
12 #include <list> 12 #include <list>
13 #include <map> 13 #include <map>
14 #include <memory> 14 #include <memory>
15 #include <queue> 15 #include <queue>
16 #include <set> 16 #include <set>
17 #include <stack> 17 #include <stack>
18 #include <string> 18 #include <string>
19 #include <type_traits> 19 #include <type_traits>
20 #include <unordered_map> 20 #include <unordered_map>
21 #include <unordered_set> 21 #include <unordered_set>
22 #include <vector> 22 #include <vector>
23 23
24 #include "base/base_export.h" 24 #include "base/base_export.h"
25 #include "base/containers/flat_map.h"
26 #include "base/containers/flat_set.h"
25 #include "base/containers/linked_list.h" 27 #include "base/containers/linked_list.h"
26 #include "base/strings/string16.h" 28 #include "base/strings/string16.h"
27 29
28 // Composable memory usage estimators. 30 // Composable memory usage estimators.
29 // 31 //
30 // This file defines set of EstimateMemoryUsage(object) functions that return 32 // This file defines set of EstimateMemoryUsage(object) functions that return
31 // approximate memory usage of their argument. 33 // approximate memory usage of their argument.
32 // 34 //
33 // The ultimate goal is to make memory usage estimation for a class simply a 35 // The ultimate goal is to make memory usage estimation for a class simply a
34 // matter of aggregating EstimateMemoryUsage() results over all fields. 36 // matter of aggregating EstimateMemoryUsage() results over all fields.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 145
144 template <class T, class C> 146 template <class T, class C>
145 size_t EstimateMemoryUsage(const std::queue<T, C>& queue); 147 size_t EstimateMemoryUsage(const std::queue<T, C>& queue);
146 148
147 template <class T, class C> 149 template <class T, class C>
148 size_t EstimateMemoryUsage(const std::priority_queue<T, C>& queue); 150 size_t EstimateMemoryUsage(const std::priority_queue<T, C>& queue);
149 151
150 template <class T, class C> 152 template <class T, class C>
151 size_t EstimateMemoryUsage(const std::stack<T, C>& stack); 153 size_t EstimateMemoryUsage(const std::stack<T, C>& stack);
152 154
155 template <class T, class C>
156 size_t EstimateMemoryUsage(const base::flat_set<T, C>& set);
157
158 template <class K, class V, class C>
159 size_t EstimateMemoryUsage(const base::flat_map<K, V, C>& map);
160
153 // TODO(dskiba): 161 // TODO(dskiba):
154 // std::forward_list 162 // std::forward_list
155 163
156 // Definitions 164 // Definitions
157 165
158 namespace internal { 166 namespace internal {
159 167
160 // HasEMU<T>::value is true iff EstimateMemoryUsage(T) is available. 168 // HasEMU<T>::value is true iff EstimateMemoryUsage(T) is available.
161 // (This is the default version, which is false.) 169 // (This is the default version, which is false.)
162 template <class T, class X = void> 170 template <class T, class X = void>
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 template <class T, class C> 543 template <class T, class C>
536 size_t EstimateMemoryUsage(const std::priority_queue<T, C>& queue) { 544 size_t EstimateMemoryUsage(const std::priority_queue<T, C>& queue) {
537 return EstimateMemoryUsage(internal::GetUnderlyingContainer(queue)); 545 return EstimateMemoryUsage(internal::GetUnderlyingContainer(queue));
538 } 546 }
539 547
540 template <class T, class C> 548 template <class T, class C>
541 size_t EstimateMemoryUsage(const std::stack<T, C>& stack) { 549 size_t EstimateMemoryUsage(const std::stack<T, C>& stack) {
542 return EstimateMemoryUsage(internal::GetUnderlyingContainer(stack)); 550 return EstimateMemoryUsage(internal::GetUnderlyingContainer(stack));
543 } 551 }
544 552
553 // Flat containers
554
555 template <class T, class C>
556 size_t EstimateMemoryUsage(const base::flat_set<T, C>& set) {
557 using value_type = typename base::flat_set<T, C>::value_type;
558 return sizeof(value_type) * set.capacity() + EstimateIterableMemoryUsage(set);
559 }
560
561 template <class K, class V, class C>
562 size_t EstimateMemoryUsage(const base::flat_map<K, V, C>& map) {
563 using value_type = typename base::flat_map<K, V, C>::value_type;
564 return sizeof(value_type) * map.capacity() + EstimateIterableMemoryUsage(map);
565 }
566
545 } // namespace trace_event 567 } // namespace trace_event
546 } // namespace base 568 } // namespace base
547 569
548 #endif // BASE_TRACE_EVENT_MEMORY_USAGE_ESTIMATOR_H_ 570 #endif // BASE_TRACE_EVENT_MEMORY_USAGE_ESTIMATOR_H_
OLDNEW
« no previous file with comments | « base/trace_event/heap_profiler_stack_frame_deduplicator_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698