Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_H_ | 5 #ifndef BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_H_ |
| 6 #define BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_H_ | 6 #define BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 // The number of stack frames stored in the backtrace is a trade off between | 28 // The number of stack frames stored in the backtrace is a trade off between |
| 29 // memory used for tracing and accuracy. Measurements done on a prototype | 29 // memory used for tracing and accuracy. Measurements done on a prototype |
| 30 // revealed that: | 30 // revealed that: |
| 31 // | 31 // |
| 32 // - In 60 percent of the cases, stack depth <= 7. | 32 // - In 60 percent of the cases, stack depth <= 7. |
| 33 // - In 87 percent of the cases, stack depth <= 9. | 33 // - In 87 percent of the cases, stack depth <= 9. |
| 34 // - In 95 percent of the cases, stack depth <= 11. | 34 // - In 95 percent of the cases, stack depth <= 11. |
| 35 // | 35 // |
| 36 // See the design doc (https://goo.gl/4s7v7b) for more details. | 36 // See the design doc (https://goo.gl/4s7v7b) for more details. |
| 37 | 37 |
| 38 using StackFrame = const char*; | 38 // TODO: description |
|
Primiano Tucci (use gerrit)
2016/04/07 15:51:56
:)
| |
| 39 struct BASE_EXPORT StackFrame { | |
| 40 enum Type { | |
|
Primiano Tucci (use gerrit)
2016/04/07 15:51:56
enum class (thanks c++11), so we can get the right
| |
| 41 TYPE_SYMBOL, // const char* string | |
|
Primiano Tucci (use gerrit)
2016/04/07 15:51:56
Is this for the pseudo stack?
In this case I think
| |
| 42 TYPE_THREAD_NAME, // const char* thread name | |
| 43 TYPE_PC, // as returned by stack tracing (e.g. by StackTrace) | |
|
Primiano Tucci (use gerrit)
2016/04/07 15:51:56
Let's call it explicitly PROGRAM_COUNTER (or NATIV
| |
| 44 }; | |
| 45 | |
| 46 bool empty() const { return value == nullptr; } | |
| 47 | |
| 48 static StackFrame Empty() { | |
| 49 return {TYPE_SYMBOL, nullptr}; | |
| 50 } | |
| 51 | |
| 52 static StackFrame FromSymbol(const void* symbol) { | |
| 53 return {TYPE_SYMBOL, symbol}; | |
| 54 } | |
| 55 static StackFrame FromPC(const void* pc) { | |
| 56 return {TYPE_PC, pc}; | |
| 57 } | |
| 58 static StackFrame FromThreadName(const char* name) { | |
| 59 return {TYPE_THREAD_NAME, name}; | |
| 60 } | |
| 61 | |
| 62 Type type; | |
| 63 const void* value; | |
| 64 }; | |
| 65 | |
| 66 bool BASE_EXPORT operator < (const StackFrame& lhs, const StackFrame& rhs); | |
|
Primiano Tucci (use gerrit)
2016/04/07 15:51:56
what do we need these operators for?
Dmitry Skiba
2016/04/12 18:22:10
For inserting StackFrame in a map, deduplicator do
| |
| 67 bool BASE_EXPORT operator == (const StackFrame& lhs, const StackFrame& rhs); | |
| 68 bool BASE_EXPORT operator != (const StackFrame& lhs, const StackFrame& rhs); | |
| 39 | 69 |
| 40 struct BASE_EXPORT Backtrace { | 70 struct BASE_EXPORT Backtrace { |
| 41 // Unused backtrace frames are filled with nullptr frames. If the stack is | 71 // Unused backtrace frames are filled with empty frames. If the stack is |
| 42 // higher than what can be stored here, the bottom frames are stored. Based | 72 // higher than what can be stored here, the bottom frames are stored. Based |
| 43 // on the data above, a depth of 12 captures the full stack in the vast | 73 // on the data above, a depth of 12 captures the full stack in the vast |
| 44 // majority of the cases. | 74 // majority of the cases. |
| 45 StackFrame frames[12]; | 75 StackFrame frames[12]; |
| 46 }; | 76 }; |
| 47 | 77 |
| 48 bool BASE_EXPORT operator==(const Backtrace& lhs, const Backtrace& rhs); | 78 bool BASE_EXPORT operator==(const Backtrace& lhs, const Backtrace& rhs); |
| 49 | 79 |
| 50 // The |AllocationContext| is context metadata that is kept for every allocation | 80 // The |AllocationContext| is context metadata that is kept for every allocation |
| 51 // when heap profiling is enabled. To simplify memory management for book- | 81 // when heap profiling is enabled. To simplify memory management for book- |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 76 | 106 |
| 77 bool BASE_EXPORT operator==(const AllocationContext& lhs, | 107 bool BASE_EXPORT operator==(const AllocationContext& lhs, |
| 78 const AllocationContext& rhs); | 108 const AllocationContext& rhs); |
| 79 | 109 |
| 80 } // namespace trace_event | 110 } // namespace trace_event |
| 81 } // namespace base | 111 } // namespace base |
| 82 | 112 |
| 83 namespace BASE_HASH_NAMESPACE { | 113 namespace BASE_HASH_NAMESPACE { |
| 84 | 114 |
| 85 template <> | 115 template <> |
| 116 struct BASE_EXPORT hash<base::trace_event::StackFrame>: hash<const void*> { | |
|
Primiano Tucci (use gerrit)
2016/04/07 15:51:56
where do we hash StackFrame objects? Don't we keep
Dmitry Skiba
2016/04/12 18:22:10
Just in case someone decides to put it into a hash
| |
| 117 size_t operator()(const base::trace_event::StackFrame& frame) const; | |
| 118 }; | |
| 119 | |
| 120 template <> | |
| 86 struct BASE_EXPORT hash<base::trace_event::Backtrace> { | 121 struct BASE_EXPORT hash<base::trace_event::Backtrace> { |
| 87 size_t operator()(const base::trace_event::Backtrace& backtrace) const; | 122 size_t operator()(const base::trace_event::Backtrace& backtrace) const; |
| 88 }; | 123 }; |
| 89 | 124 |
| 90 template <> | 125 template <> |
| 91 struct BASE_EXPORT hash<base::trace_event::AllocationContext> { | 126 struct BASE_EXPORT hash<base::trace_event::AllocationContext> { |
| 92 size_t operator()(const base::trace_event::AllocationContext& context) const; | 127 size_t operator()(const base::trace_event::AllocationContext& context) const; |
| 93 }; | 128 }; |
| 94 | 129 |
| 95 } // BASE_HASH_NAMESPACE | 130 } // BASE_HASH_NAMESPACE |
| 96 | 131 |
| 97 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_H_ | 132 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_H_ |
| OLD | NEW |