Index: base/trace_event/trace_event.h |
diff --git a/base/trace_event/trace_event.h b/base/trace_event/trace_event.h |
index 2321d7ad62bd66c38653ab49b5d28e664b8a861d..7d489aecc26d72700b62685bd0170372eb843122 100644 |
--- a/base/trace_event/trace_event.h |
+++ b/base/trace_event/trace_event.h |
@@ -18,6 +18,7 @@ |
#include "base/macros.h" |
#include "base/time/time.h" |
#include "base/trace_event/common/trace_event_common.h" |
+#include "base/trace_event/heap_profiler_allocation_context_tracker.h" |
#include "base/trace_event/trace_event_system_stats_monitor.h" |
#include "base/trace_event/trace_log.h" |
#include "build/build_config.h" |
@@ -71,11 +72,18 @@ |
#define TRACE_EVENT_API_CURRENT_THREAD_ID \ |
static_cast<int>(base::PlatformThread::CurrentId()) |
+#define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_TRACING() \ |
+ UNLIKELY(*INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \ |
+ (base::trace_event::TraceLog::ENABLED_FOR_HEAP_PROFILING | \ |
+ base::trace_event::TraceLog::ENABLED_FOR_NON_PROFILING_MODE)) |
+ |
#define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \ |
- UNLIKELY(*INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \ |
- (base::trace_event::TraceLog::ENABLED_FOR_RECORDING | \ |
- base::trace_event::TraceLog::ENABLED_FOR_EVENT_CALLBACK | \ |
- base::trace_event::TraceLog::ENABLED_FOR_ETW_EXPORT)) |
+ UNLIKELY(*INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \ |
+ (base::trace_event::TraceLog::ENABLED_FOR_NON_PROFILING_MODE)) |
+ |
+#define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_HEAP_PROFILING() \ |
+ UNLIKELY(*INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \ |
+ base::trace_event::TraceLog::ENABLED_FOR_HEAP_PROFILING) |
//////////////////////////////////////////////////////////////////////////////// |
// Implementation specific tracing API definitions. |
@@ -263,8 +271,9 @@ TRACE_EVENT_API_CLASS_EXPORT extern \ |
// event if the category is enabled. Also adds the end event when the scope |
// ends. |
#define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \ |
- INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
- trace_event_internal::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \ |
+ INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
+ trace_event_internal::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \ |
+ if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_TRACING()) { \ |
if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
base::trace_event::TraceEventHandle h = \ |
trace_event_internal::AddTraceEvent( \ |
@@ -273,26 +282,39 @@ TRACE_EVENT_API_CLASS_EXPORT extern \ |
trace_event_internal::kGlobalScope, trace_event_internal::kNoId, \ |
TRACE_EVENT_FLAG_NONE, trace_event_internal::kNoId, \ |
##__VA_ARGS__); \ |
- INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \ |
- INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \ |
- } |
+ INTERNAL_TRACE_EVENT_UID(tracer) \ |
+ .Initialize(INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ |
+ h); \ |
+ } \ |
+ if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_HEAP_PROFILING()) { \ |
+ INTERNAL_TRACE_EVENT_UID(tracer) \ |
+ .InitializeForHeapProfiling(name, TRACE_EVENT_FLAG_NONE); \ |
+ } \ |
+ } |
-#define INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW( \ |
- category_group, name, bind_id, flow_flags, ...) \ |
+#define INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, \ |
+ bind_id, flow_flags, ...) \ |
INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ |
trace_event_internal::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \ |
- if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
- unsigned int trace_event_flags = flow_flags; \ |
- trace_event_internal::TraceID trace_event_bind_id(bind_id, \ |
- &trace_event_flags); \ |
- base::trace_event::TraceEventHandle h = \ |
- trace_event_internal::AddTraceEvent( \ |
- TRACE_EVENT_PHASE_COMPLETE, \ |
- INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ |
- trace_event_internal::kGlobalScope, trace_event_internal::kNoId, \ |
- trace_event_flags, trace_event_bind_id.raw_id(), ##__VA_ARGS__); \ |
- INTERNAL_TRACE_EVENT_UID(tracer).Initialize( \ |
- INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, h); \ |
+ if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_TRACING()) { \ |
+ if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ |
+ unsigned int trace_event_flags = flow_flags; \ |
+ trace_event_internal::TraceID trace_event_bind_id(bind_id, \ |
+ &trace_event_flags); \ |
+ base::trace_event::TraceEventHandle h = \ |
+ trace_event_internal::AddTraceEvent( \ |
+ TRACE_EVENT_PHASE_COMPLETE, \ |
+ INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ |
+ trace_event_internal::kGlobalScope, trace_event_internal::kNoId, \ |
+ trace_event_flags, trace_event_bind_id.raw_id(), ##__VA_ARGS__); \ |
+ INTERNAL_TRACE_EVENT_UID(tracer) \ |
+ .Initialize(INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ |
+ h); \ |
+ } \ |
+ if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_HEAP_PROFILING()) { \ |
+ INTERNAL_TRACE_EVENT_UID(tracer) \ |
+ .InitializeForHeapProfiling(name, flow_flags); \ |
+ } \ |
} |
// Implementation detail: internal macro to create static category and add |
@@ -964,9 +986,13 @@ class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer { |
ScopedTracer() : p_data_(NULL) {} |
~ScopedTracer() { |
- if (p_data_ && *data_.category_group_enabled) |
+ if (p_data_ && *data_.category_group_enabled) { |
TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( |
data_.category_group_enabled, data_.name, data_.event_handle); |
+ } |
+ // TODO(ssid): Pop the frame from the pseudo stack if initialized for |
+ // profiling is true, after adding profiling mode in skia and Blink |
+ // crbug.com/598426. |
} |
void Initialize(const unsigned char* category_group_enabled, |
@@ -978,6 +1004,15 @@ class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer { |
p_data_ = &data_; |
} |
+ void InitializeForHeapProfiling(const char* name, unsigned int flags) { |
+ if (!(flags & TRACE_EVENT_FLAG_COPY)) { |
+ data_.initialized_for_profiling = true; |
+ data_.name = name; |
+ // TODO(ssid): Add the frame to the pseudo stack after adding profiling |
+ // mode in skia and Blink crbug.com/598426. |
+ } |
+ } |
+ |
private: |
// This Data struct workaround is to avoid initializing all the members |
// in Data during construction of this object, since this object is always |
@@ -988,6 +1023,7 @@ class TRACE_EVENT_API_CLASS_EXPORT ScopedTracer { |
const unsigned char* category_group_enabled; |
const char* name; |
base::trace_event::TraceEventHandle event_handle; |
+ bool initialized_for_profiling; |
}; |
Data* p_data_; |
Data data_; |