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 // Represents (pseudo) stack frame. Used in Backtrace class below. |
| 39 // | |
| 40 // Conceptually stack frame is identified by its value, and type is used | |
| 41 // mostly to properly format the value. Value is expected to be a valid | |
| 42 // pointer from process' address space. | |
| 43 struct BASE_EXPORT StackFrame { | |
| 44 enum class Type { | |
| 45 TRACE_EVENT_NAME, // const char* string | |
| 46 THREAD_NAME, // const char* thread name | |
| 47 }; | |
| 48 | |
| 49 static StackFrame FromTraceEventName(const char* name) { | |
| 50 return {Type::TRACE_EVENT_NAME, name}; | |
| 51 } | |
| 52 static StackFrame FromThreadName(const char* name) { | |
| 53 return {Type::THREAD_NAME, name}; | |
| 54 } | |
| 55 | |
| 56 Type type; | |
| 57 const void* value; | |
|
Primiano Tucci (use gerrit)
2016/04/19 19:45:06
since both of these are const char* should this al
Dmitry Skiba
2016/04/19 22:14:14
Yeah, but my next CL adds PROGRAM_COUNTER which is
Primiano Tucci (use gerrit)
2016/04/20 13:17:59
yeah I realized this too late. ignore my comment.
| |
| 58 }; | |
| 59 | |
| 60 bool BASE_EXPORT operator < (const StackFrame& lhs, const StackFrame& rhs); | |
| 61 bool BASE_EXPORT operator == (const StackFrame& lhs, const StackFrame& rhs); | |
| 62 bool BASE_EXPORT operator != (const StackFrame& lhs, const StackFrame& rhs); | |
| 39 | 63 |
| 40 struct BASE_EXPORT Backtrace { | 64 struct BASE_EXPORT Backtrace { |
| 41 // Unused backtrace frames are filled with nullptr frames. If the stack is | 65 // If the stack is higher than what can be stored here, the bottom frames |
|
Primiano Tucci (use gerrit)
2016/04/19 19:45:06
small req, not really related with your change: ca
Dmitry Skiba
2016/04/19 22:14:14
Actually, that is not true when it comes to native
Primiano Tucci (use gerrit)
2016/04/20 13:17:59
should we keep it consistent and just bump the dep
| |
| 42 // higher than what can be stored here, the bottom frames are stored. Based | 66 // are stored. Based on the data above, a depth of 12 captures the full |
| 43 // on the data above, a depth of 12 captures the full stack in the vast | 67 // stack in the vast majority of the cases. |
| 44 // majority of the cases. | 68 enum { kMaxFrameCount = 12 }; |
| 45 StackFrame frames[12]; | 69 StackFrame frames[kMaxFrameCount]; |
| 70 size_t frame_count; | |
| 46 }; | 71 }; |
| 47 | 72 |
| 48 // Struct to store the size and count of the allocations. | 73 // Struct to store the size and count of the allocations. |
| 49 struct AllocationMetrics { | 74 struct AllocationMetrics { |
| 50 size_t size; | 75 size_t size; |
| 51 size_t count; | 76 size_t count; |
| 52 }; | 77 }; |
| 53 | 78 |
| 54 bool BASE_EXPORT operator==(const Backtrace& lhs, const Backtrace& rhs); | 79 bool BASE_EXPORT operator==(const Backtrace& lhs, const Backtrace& rhs); |
| 55 | 80 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 82 | 107 |
| 83 bool BASE_EXPORT operator==(const AllocationContext& lhs, | 108 bool BASE_EXPORT operator==(const AllocationContext& lhs, |
| 84 const AllocationContext& rhs); | 109 const AllocationContext& rhs); |
| 85 | 110 |
| 86 } // namespace trace_event | 111 } // namespace trace_event |
| 87 } // namespace base | 112 } // namespace base |
| 88 | 113 |
| 89 namespace BASE_HASH_NAMESPACE { | 114 namespace BASE_HASH_NAMESPACE { |
| 90 | 115 |
| 91 template <> | 116 template <> |
| 117 struct BASE_EXPORT hash<base::trace_event::StackFrame> { | |
| 118 size_t operator()(const base::trace_event::StackFrame& frame) const; | |
| 119 }; | |
| 120 | |
| 121 template <> | |
| 92 struct BASE_EXPORT hash<base::trace_event::Backtrace> { | 122 struct BASE_EXPORT hash<base::trace_event::Backtrace> { |
| 93 size_t operator()(const base::trace_event::Backtrace& backtrace) const; | 123 size_t operator()(const base::trace_event::Backtrace& backtrace) const; |
| 94 }; | 124 }; |
| 95 | 125 |
| 96 template <> | 126 template <> |
| 97 struct BASE_EXPORT hash<base::trace_event::AllocationContext> { | 127 struct BASE_EXPORT hash<base::trace_event::AllocationContext> { |
| 98 size_t operator()(const base::trace_event::AllocationContext& context) const; | 128 size_t operator()(const base::trace_event::AllocationContext& context) const; |
| 99 }; | 129 }; |
| 100 | 130 |
| 101 } // BASE_HASH_NAMESPACE | 131 } // BASE_HASH_NAMESPACE |
| 102 | 132 |
| 103 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_H_ | 133 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_H_ |
| OLD | NEW |