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 // For performance reasons this struct is treated as bytes when comparing | |
| 41 // and hashing, so all members must be pointer-sized to make sure they are | |
| 42 // not padded. | |
| 43 struct BASE_EXPORT StackFrame { | |
| 44 enum class Type: uintptr_t { | |
|
Primiano Tucci (use gerrit)
2016/04/14 10:15:33
out of curiosity why this needs to be a uintptr_t?
Dmitry Skiba
2016/04/15 07:01:39
Because else there will be padding on 64-bit platf
Primiano Tucci (use gerrit)
2016/04/15 13:47:47
Yeah but see my comment. You shouldn't rely on the
| |
| 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; | |
| 58 }; | |
| 59 | |
| 60 bool BASE_EXPORT operator < (const StackFrame& lhs, const StackFrame& rhs); | |
|
Primiano Tucci (use gerrit)
2016/04/14 10:15:33
should we turn that map in the deduplicator into a
Dmitry Skiba
2016/04/15 07:01:39
Why minimizing number of operators? Yes, we could
Primiano Tucci (use gerrit)
2016/04/15 13:47:47
Oh is not for minimizing operators, I just realize
| |
| 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 |
| 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; | |
|
Primiano Tucci (use gerrit)
2016/04/14 10:15:33
not sure I understand from the code below why do w
| |
| 46 }; | 71 }; |
| 47 | 72 |
| 48 bool BASE_EXPORT operator==(const Backtrace& lhs, const Backtrace& rhs); | 73 bool BASE_EXPORT operator==(const Backtrace& lhs, const Backtrace& rhs); |
| 49 | 74 |
| 50 // The |AllocationContext| is context metadata that is kept for every allocation | 75 // The |AllocationContext| is context metadata that is kept for every allocation |
| 51 // when heap profiling is enabled. To simplify memory management for book- | 76 // when heap profiling is enabled. To simplify memory management for book- |
| 52 // keeping, this struct has a fixed size. All |const char*|s here must have | 77 // keeping, this struct has a fixed size. All |const char*|s here must have |
| 53 // static lifetime. | 78 // static lifetime. |
| 54 struct BASE_EXPORT AllocationContext { | 79 struct BASE_EXPORT AllocationContext { |
| 55 public: | 80 public: |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 76 | 101 |
| 77 bool BASE_EXPORT operator==(const AllocationContext& lhs, | 102 bool BASE_EXPORT operator==(const AllocationContext& lhs, |
| 78 const AllocationContext& rhs); | 103 const AllocationContext& rhs); |
| 79 | 104 |
| 80 } // namespace trace_event | 105 } // namespace trace_event |
| 81 } // namespace base | 106 } // namespace base |
| 82 | 107 |
| 83 namespace BASE_HASH_NAMESPACE { | 108 namespace BASE_HASH_NAMESPACE { |
| 84 | 109 |
| 85 template <> | 110 template <> |
| 111 struct BASE_EXPORT hash<base::trace_event::StackFrame> { | |
| 112 size_t operator()(const base::trace_event::StackFrame& frame) const; | |
| 113 }; | |
| 114 | |
| 115 template <> | |
| 86 struct BASE_EXPORT hash<base::trace_event::Backtrace> { | 116 struct BASE_EXPORT hash<base::trace_event::Backtrace> { |
| 87 size_t operator()(const base::trace_event::Backtrace& backtrace) const; | 117 size_t operator()(const base::trace_event::Backtrace& backtrace) const; |
| 88 }; | 118 }; |
| 89 | 119 |
| 90 template <> | 120 template <> |
| 91 struct BASE_EXPORT hash<base::trace_event::AllocationContext> { | 121 struct BASE_EXPORT hash<base::trace_event::AllocationContext> { |
| 92 size_t operator()(const base::trace_event::AllocationContext& context) const; | 122 size_t operator()(const base::trace_event::AllocationContext& context) const; |
| 93 }; | 123 }; |
| 94 | 124 |
| 95 } // BASE_HASH_NAMESPACE | 125 } // BASE_HASH_NAMESPACE |
| 96 | 126 |
| 97 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_H_ | 127 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_H_ |
| OLD | NEW |