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

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

Issue 1467453003: [Tracing] Make heap profiler type info a string (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
OLDNEW
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
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, as returned by
Primiano Tucci (use gerrit) 2015/11/23 15:46:48 I'd remove the "as returned by typeid(T)" as it is
Ruud van Asseldonk 2015/11/23 18:23:26 Done.
61 // |typeid(T).name()|. A null pointer indicates "unknown type". Grouping is
62 // done by comparing pointers, not by deep string comparison. In a component
63 // build, where a type name can have a string literal in several dynamic
64 // libraries, this may distort grouping.
65 const char* type_name;
Primiano Tucci (use gerrit) 2015/11/23 15:46:47 in a follow up CL we might just hash this as well
Ruud van Asseldonk 2015/11/23 18:23:26 We could if it turns out to be an issue, but my ex
66 66
67 private: 67 private:
68 friend class AllocationContextTracker; 68 friend class AllocationContextTracker;
69 69
70 // Don't allow uninitialized instances except inside the allocation context 70 // Don't allow uninitialized instances except inside the allocation context
71 // tracker. Except in tests, an |AllocationContext| should only be obtained 71 // tracker. Except in tests, an |AllocationContext| should only be obtained
72 // from the tracker. In tests, paying the overhead of initializing the struct 72 // 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. 73 // to |Empty| and then overwriting the members is not such a big deal.
74 AllocationContext(); 74 AllocationContext();
75 }; 75 };
(...skipping 12 matching lines...) Expand all
88 }; 88 };
89 89
90 template <> 90 template <>
91 struct hash<base::trace_event::AllocationContext> { 91 struct hash<base::trace_event::AllocationContext> {
92 size_t operator()(const base::trace_event::AllocationContext& context) const; 92 size_t operator()(const base::trace_event::AllocationContext& context) const;
93 }; 93 };
94 94
95 } // BASE_HASH_NAMESPACE 95 } // BASE_HASH_NAMESPACE
96 96
97 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_H_ 97 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698