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

Unified Diff: base/trace_event/heap_profiler_allocation_context_tracker.h

Issue 1839503002: [tracing] Add native allocation tracing mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert whitespace change in malloc_dump_provider 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
Index: base/trace_event/heap_profiler_allocation_context_tracker.h
diff --git a/base/trace_event/heap_profiler_allocation_context_tracker.h b/base/trace_event/heap_profiler_allocation_context_tracker.h
index e5c8c187739b99afaa0f75995b1a534dd14a2e4d..df604e54991807dbf40773e44c5aeb253fcbfe8d 100644
--- a/base/trace_event/heap_profiler_allocation_context_tracker.h
+++ b/base/trace_event/heap_profiler_allocation_context_tracker.h
@@ -9,10 +9,19 @@
#include "base/atomicops.h"
#include "base/base_export.h"
+#include "base/debug/debugging_flags.h"
+#include "base/debug/stack_trace.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/trace_event/heap_profiler_allocation_context.h"
+#if HAVE_TRACE_STACK_FRAME_POINTERS && !defined(OS_NACL) && \
+ (BUILDFLAG(ENABLE_PROFILING) || defined(DEBUG))
Primiano Tucci (use gerrit) 2016/04/19 20:15:19 Why do you need the (BUILDFLAG(ENABLE_PROFILING) |
Dmitry Skiba 2016/04/20 19:19:25 Actually, you suggested these defines earlier :) B
Primiano Tucci (use gerrit) 2016/04/21 20:08:21 oh right lolz :)
+#define ENABLE_NATIVE_ALLOCATION_TRACES 1
+#else
+#define ENABLE_NATIVE_ALLOCATION_TRACES 0
+#endif
+
namespace base {
namespace trace_event {
@@ -23,24 +32,33 @@ namespace trace_event {
// details.
class BASE_EXPORT AllocationContextTracker {
public:
- // Globally enables capturing allocation context.
- // TODO(ruuda): Should this be replaced by |EnableCapturing| in the future?
- // Or at least have something that guards agains enable -> disable -> enable?
- static void SetCaptureEnabled(bool enabled);
+ enum class CaptureMode: int {
Primiano Tucci (use gerrit) 2016/04/19 20:15:19 s/int/int32_t/
Dmitry Skiba 2016/04/20 19:19:24 Done.
+ DISABLED, // Don't capture anything
+ PSEUDO_STACK, // GetContextSnapshot() returns pseudo stack trace
+#if ENABLE_NATIVE_ALLOCATION_TRACES
+ NATIVE_STACK // GetContextSnapshot() returns native (real) stack trace
+#endif
+ };
+
+ // Globally sets capturing mode.
+ // TODO(primiano): How to guard against *_STACK -> DISABLED -> *_STACK?
+ static void SetCaptureMode(CaptureMode mode);
// Returns whether capturing allocation context is enabled globally.
inline static bool capture_enabled() {
Primiano Tucci (use gerrit) 2016/04/19 20:15:19 I think you want to return a CaptureMode here and
Dmitry Skiba 2016/04/20 19:19:24 Done.
// A little lag after heap profiling is enabled or disabled is fine, it is
// more important that the check is as cheap as possible when capturing is
// not enabled, so do not issue a memory barrier in the fast path.
- if (subtle::NoBarrier_Load(&capture_enabled_) == 0)
+ if (subtle::NoBarrier_Load(&capture_mode_) ==
+ static_cast<int>(CaptureMode::DISABLED))
return false;
// In the slow path, an acquire load is required to pair with the release
- // store in |SetCaptureEnabled|. This is to ensure that the TLS slot for
+ // store in |SetCaptureMode|. This is to ensure that the TLS slot for
// the thread-local allocation context tracker has been initialized if
// |capture_enabled| returns true.
- return subtle::Acquire_Load(&capture_enabled_) != 0;
+ return subtle::Acquire_Load(&capture_mode_) !=
+ static_cast<int>(CaptureMode::DISABLED);
}
// Returns the thread-local instance, creating one if necessary. Returns
@@ -71,7 +89,7 @@ class BASE_EXPORT AllocationContextTracker {
private:
AllocationContextTracker();
- static subtle::Atomic32 capture_enabled_;
+ static subtle::Atomic32 capture_mode_;
// The pseudo stack where frames are |TRACE_EVENT| names.
std::vector<const char*> pseudo_stack_;

Powered by Google App Engine
This is Rietveld 408576698