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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 }; | 45 }; |
46 | 46 |
47 bool BASE_EXPORT operator==(const Backtrace& lhs, const Backtrace& rhs); | 47 bool BASE_EXPORT operator==(const Backtrace& lhs, const Backtrace& rhs); |
48 | 48 |
49 // The |AllocationContext| is context metadata that is kept for every allocation | 49 // The |AllocationContext| is context metadata that is kept for every allocation |
50 // when heap profiling is enabled. To simplify memory management for book- | 50 // when heap profiling is enabled. To simplify memory management for book- |
51 // keeping, this struct has a fixed size. All |const char*|s here must have | 51 // keeping, this struct has a fixed size. All |const char*|s here must have |
52 // static lifetime. | 52 // static lifetime. |
53 struct BASE_EXPORT AllocationContext { | 53 struct BASE_EXPORT AllocationContext { |
54 public: | 54 public: |
55 // A type ID is a number that is unique for every C++ type. A type ID is | 55 // An allocation context with empty backtrace and unknown type. |
56 // stored instead of the type name to avoid inflating the binary with type | |
57 // name strings. There is an out of band lookup table mapping IDs to the type | |
58 // names. A value of 0 means that the type is not known. | |
59 using TypeId = uint16_t; | |
60 | |
61 // An allocation context with empty backtrace and type ID 0 (unknown type). | |
62 static AllocationContext Empty(); | 56 static AllocationContext Empty(); |
63 | 57 |
64 Backtrace backtrace; | 58 Backtrace backtrace; |
65 TypeId type_id; | 59 |
| 60 // Type name of the type stored in the allocated memory. A null pointer |
| 61 // indicates "unknown type". Grouping is done by comparing pointers, not by |
| 62 // deep string comparison. In a component build, where a type name can have a |
| 63 // string literal in several dynamic libraries, this may distort grouping. |
| 64 const char* type_name; |
66 | 65 |
67 private: | 66 private: |
68 friend class AllocationContextTracker; | 67 friend class AllocationContextTracker; |
69 | 68 |
70 // Don't allow uninitialized instances except inside the allocation context | 69 // Don't allow uninitialized instances except inside the allocation context |
71 // tracker. Except in tests, an |AllocationContext| should only be obtained | 70 // tracker. Except in tests, an |AllocationContext| should only be obtained |
72 // from the tracker. In tests, paying the overhead of initializing the struct | 71 // from the tracker. In tests, paying the overhead of initializing the struct |
73 // to |Empty| and then overwriting the members is not such a big deal. | 72 // to |Empty| and then overwriting the members is not such a big deal. |
74 AllocationContext(); | 73 AllocationContext(); |
75 }; | 74 }; |
(...skipping 12 matching lines...) Expand all Loading... |
88 }; | 87 }; |
89 | 88 |
90 template <> | 89 template <> |
91 struct hash<base::trace_event::AllocationContext> { | 90 struct hash<base::trace_event::AllocationContext> { |
92 size_t operator()(const base::trace_event::AllocationContext& context) const; | 91 size_t operator()(const base::trace_event::AllocationContext& context) const; |
93 }; | 92 }; |
94 | 93 |
95 } // BASE_HASH_NAMESPACE | 94 } // BASE_HASH_NAMESPACE |
96 | 95 |
97 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_H_ | 96 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_H_ |
OLD | NEW |