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

Unified Diff: base/trace_event/memory_profiler_allocation_context.h

Issue 1419633004: [Tracing] Introduce HeapDumpWriter helper class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nits Created 5 years, 2 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/trace_event/BUILD.gn ('k') | base/trace_event/memory_profiler_allocation_context.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/memory_profiler_allocation_context.h
diff --git a/base/trace_event/memory_profiler_allocation_context.h b/base/trace_event/memory_profiler_allocation_context.h
index c9b8f737f095f61c33a5928aa45cbd1ce4e5d313..222d8d4c1fa1cdb7243d1c86605b2212a19cf012 100644
--- a/base/trace_event/memory_profiler_allocation_context.h
+++ b/base/trace_event/memory_profiler_allocation_context.h
@@ -69,25 +69,16 @@ class BASE_EXPORT AllocationStack {
//
// See the design doc (https://goo.gl/4s7v7b) for more details.
-// The allocation context is context metadata that is kept for every allocation
-// when heap profiling is enabled. To simplify memory management for
-// bookkeeping, this struct has a fixed size. All |const char*|s here
-// must have static lifetime.
-struct BASE_EXPORT AllocationContext {
- struct Backtrace {
- // Unused backtrace frames are filled with nullptr frames. If the stack is
- // higher than what can be stored here, the bottom frames are stored. Based
- // on the data above, a depth of 12 captures the full stack in the vast
- // majority of the cases.
- StackFrame frames[12];
- } backtrace;
-
- // There is room for two arbitrary context fields, which can be set by the
- // |TRACE_ALLOCATION_CONTEXT| macro. A nullptr key indicates that the field is
- // unused.
- std::pair<const char*, const char*> fields[2];
+struct BASE_EXPORT Backtrace {
+ // Unused backtrace frames are filled with nullptr frames. If the stack is
+ // higher than what can be stored here, the bottom frames are stored. Based
+ // on the data above, a depth of 12 captures the full stack in the vast
+ // majority of the cases.
+ StackFrame frames[12];
};
+bool BASE_EXPORT operator==(const Backtrace& lhs, const Backtrace& rhs);
+
// A data structure that allows grouping a set of backtraces in a space-
// efficient manner by creating a call tree and writing it as a set of (node,
// parent) pairs. The tree nodes reference both parent and children. The parent
@@ -117,10 +108,9 @@ class BASE_EXPORT StackFrameDeduplicator {
StackFrameDeduplicator();
~StackFrameDeduplicator();
- // Inserts a backtrace and returns the index of its leaf node in the range
- // defined by |begin| and |end|. I.e. if this returns |n|, the node is
- // |begin() + n|. Returns -1 if the backtrace is empty.
- int Insert(const AllocationContext::Backtrace& bt);
+ // Inserts a backtrace and returns the index of its leaf node in |frames_|.
+ // Returns -1 if the backtrace is empty.
+ int Insert(const Backtrace& bt);
// Iterators over the frame nodes in the call tree.
ConstIterator begin() const { return frames_.begin(); }
@@ -133,6 +123,19 @@ class BASE_EXPORT StackFrameDeduplicator {
DISALLOW_COPY_AND_ASSIGN(StackFrameDeduplicator);
};
+// The |AllocationContext| is context metadata that is kept for every allocation
+// when heap profiling is enabled. To simplify memory management for
+// bookkeeping, this struct has a fixed size. All |const char*|s here
+// must have static lifetime.
+struct BASE_EXPORT AllocationContext {
+ Backtrace backtrace;
+
+ // There is room for two arbitrary context fields, which can be set by the
+ // |TRACE_ALLOCATION_CONTEXT| macro. A nullptr key indicates that the field is
+ // unused.
+ std::pair<const char*, const char*> fields[2];
+};
+
// The allocation context tracker keeps track of thread-local context for heap
// profiling. It includes a pseudo stack of trace events, and it might contain
// arbitrary (key, value) context. On every allocation the tracker provides a
@@ -197,4 +200,13 @@ class BASE_EXPORT AllocationContextTracker {
} // namespace trace_event
} // namespace base
+namespace BASE_HASH_NAMESPACE {
+
+template <>
+struct hash<base::trace_event::Backtrace> {
+ size_t operator()(const base::trace_event::Backtrace& backtrace) const;
+};
+
+} // BASE_HASH_NAMESPACE
+
#endif // BASE_TRACE_EVENT_MEMORY_PROFILER_ALLOCATION_CONTEXT_H_
« no previous file with comments | « base/trace_event/BUILD.gn ('k') | base/trace_event/memory_profiler_allocation_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698