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

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: Remove WriteStackFrames, DISALLOW_COPY_AND_ASSIGN 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
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..44b1367a7154df3b28cb449845d9de5cb5a1fc62 100644
--- a/base/trace_event/memory_profiler_allocation_context.h
+++ b/base/trace_event/memory_profiler_allocation_context.h
@@ -69,23 +69,22 @@ 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;
+struct BASE_EXPORT Backtrace {
Primiano Tucci (use gerrit) 2015/10/26 11:52:06 not really sure this is more readable than before.
Ruud van Asseldonk 2015/10/26 14:51:26 Going to leave it outside for now to avoid rightwa
+ // 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];
+};
- // 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];
+bool BASE_EXPORT operator==(const Backtrace& lhs, const Backtrace& rhs);
+
+// A hasher for |Backtrace| that allows using it as a key for |base::hash_map|.
+class BASE_EXPORT BacktraceHash {
Primiano Tucci (use gerrit) 2015/10/26 11:52:06 A search in the codebase suggests that the way we
Primiano Tucci (use gerrit) 2015/10/26 11:52:06 +er (Hasher)?
Ruud van Asseldonk 2015/10/26 14:51:26 Done.
Ruud van Asseldonk 2015/10/26 14:51:26 Would be called |hash<Backtrace>| then.
+ public:
+ using result_type = uint32_t;
+ using argument_type = Backtrace;
+ uint32_t operator()(const Backtrace& backtrace) const;
};
// A data structure that allows grouping a set of backtraces in a space-
@@ -117,10 +116,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 +131,19 @@ class BASE_EXPORT StackFrameDeduplicator {
DISALLOW_COPY_AND_ASSIGN(StackFrameDeduplicator);
};
+// 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 {
+ 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

Powered by Google App Engine
This is Rietveld 408576698