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

Unified Diff: base/trace_event/heap_profiler_allocation_context.h

Issue 1891543003: [tracing] Turn StackFrame into struct. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add "the ones closer to main()" Created 4 years, 8 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 | « no previous file | base/trace_event/heap_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/heap_profiler_allocation_context.h
diff --git a/base/trace_event/heap_profiler_allocation_context.h b/base/trace_event/heap_profiler_allocation_context.h
index 98d835181d014fa57a29e2b193fcd9457c17b026..764712f38aae352bd6f7eb3f246fcc48a78c07ec 100644
--- a/base/trace_event/heap_profiler_allocation_context.h
+++ b/base/trace_event/heap_profiler_allocation_context.h
@@ -35,32 +35,50 @@ namespace trace_event {
//
// See the design doc (https://goo.gl/4s7v7b) for more details.
-using StackFrame = const char*;
-
-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];
+// Represents (pseudo) stack frame. Used in Backtrace class below.
+//
+// Conceptually stack frame is identified by its value, and type is used
+// mostly to properly format the value. Value is expected to be a valid
+// pointer from process' address space.
+struct BASE_EXPORT StackFrame {
+ enum class Type {
+ TRACE_EVENT_NAME, // const char* string
+ THREAD_NAME, // const char* thread name
+ };
+
+ static StackFrame FromTraceEventName(const char* name) {
+ return {Type::TRACE_EVENT_NAME, name};
+ }
+ static StackFrame FromThreadName(const char* name) {
+ return {Type::THREAD_NAME, name};
+ }
+
+ Type type;
+ const void* value;
};
-// Struct to store the size and count of the allocations.
-struct AllocationMetrics {
- size_t size;
- size_t count;
+bool BASE_EXPORT operator < (const StackFrame& lhs, const StackFrame& rhs);
+bool BASE_EXPORT operator == (const StackFrame& lhs, const StackFrame& rhs);
+bool BASE_EXPORT operator != (const StackFrame& lhs, const StackFrame& rhs);
+
+struct BASE_EXPORT Backtrace {
+ Backtrace();
+
+ // If the stack is higher than what can be stored here, the bottom frames
+ // (the ones closer to main()) are stored. Based on the data above, a depth
+ // of 12 captures the full stack in the vast majority of the cases.
+ enum { kMaxFrameCount = 12 };
+ StackFrame frames[kMaxFrameCount];
+ size_t frame_count;
};
bool BASE_EXPORT operator==(const Backtrace& lhs, const Backtrace& rhs);
// The |AllocationContext| is context metadata that is kept for every allocation
// when heap profiling is enabled. To simplify memory management for book-
-// keeping, this struct has a fixed size. All |const char*|s here must have
-// static lifetime.
+// keeping, this struct has a fixed size.
struct BASE_EXPORT AllocationContext {
- public:
- // An allocation context with empty backtrace and unknown type.
- static AllocationContext Empty();
+ AllocationContext();
Backtrace backtrace;
@@ -69,26 +87,28 @@ struct BASE_EXPORT AllocationContext {
// deep string comparison. In a component build, where a type name can have a
// string literal in several dynamic libraries, this may distort grouping.
const char* type_name;
-
- private:
- friend class AllocationContextTracker;
-
- // Don't allow uninitialized instances except inside the allocation context
- // tracker. Except in tests, an |AllocationContext| should only be obtained
- // from the tracker. In tests, paying the overhead of initializing the struct
- // to |Empty| and then overwriting the members is not such a big deal.
- AllocationContext();
};
bool BASE_EXPORT operator==(const AllocationContext& lhs,
const AllocationContext& rhs);
+// Struct to store the size and count of the allocations.
+struct AllocationMetrics {
+ size_t size;
+ size_t count;
+};
+
} // namespace trace_event
} // namespace base
namespace BASE_HASH_NAMESPACE {
template <>
+struct BASE_EXPORT hash<base::trace_event::StackFrame> {
+ size_t operator()(const base::trace_event::StackFrame& frame) const;
+};
+
+template <>
struct BASE_EXPORT hash<base::trace_event::Backtrace> {
size_t operator()(const base::trace_event::Backtrace& backtrace) const;
};
« no previous file with comments | « no previous file | base/trace_event/heap_profiler_allocation_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698