Chromium Code Reviews| 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..1ee1fb4346244f814733e73c52c3f712554db8f3 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" |
| @@ -382,6 +383,15 @@ TRACE_EVENT_API_CLASS_EXPORT extern \ |
| INTERNAL_TRACE_EVENT_UID(ScopedContext) \ |
| INTERNAL_TRACE_EVENT_UID(scoped_context)(context.raw_id()); |
| +// Special trace event macro to trace task execution with the location where it |
| +// was posted from. |
| +#define TRACE_TASK_EXECUTION(run_function, task) \ |
|
oystein (OOO til 10th of July)
2016/03/29 21:28:35
I don't think this belongs in trace_event.h; typic
ssid
2016/03/29 23:04:19
Thanks I was really confused about trace_event.h a
oystein (OOO til 10th of July)
2016/03/29 23:44:52
Almost! I mainly don't think trace_event.h should
|
| + TRACE_EVENT2("toplevel", (run_function), "src_file", \ |
|
oystein (OOO til 10th of July)
2016/03/29 21:28:35
Why are the parameter usages all wrapped by ()? We
ssid
2016/03/29 23:04:19
Ah, it existed in the other file and I had copied
|
| + (task).posted_from.file_name(), "src_func", \ |
| + (task).posted_from.function_name()); \ |
| + trace_event_internal::ScopedTaskExecutionEvent event( \ |
|
oystein (OOO til 10th of July)
2016/03/29 21:28:35
INTERNAL_TRACE_EVENT_UID(event) to avoid conflicts
ssid
2016/03/29 23:04:19
Done.
|
| + (task).posted_from.file_name()); |
| + |
| namespace trace_event_internal { |
| // Specify these values when the corresponding argument of AddTraceEvent is not |
| @@ -1045,6 +1055,30 @@ class TraceEventSamplingStateScope { |
| const char* previous_state_; |
| }; |
| +// ScopedTaskExecutionEvent records the current task's context in the heap |
| +// profiler. |
| +class ScopedTaskExecutionEvent { |
| + public: |
| + ScopedTaskExecutionEvent(const char* task_context) : context_(task_context) { |
| + if (UNLIKELY( |
| + base::trace_event::AllocationContextTracker::capture_enabled())) { |
| + base::trace_event::AllocationContextTracker::GetInstanceForCurrentThread() |
| + ->PushCurrentTaskContext(context_); |
| + } |
| + } |
| + |
| + ~ScopedTaskExecutionEvent() { |
| + if (UNLIKELY( |
| + base::trace_event::AllocationContextTracker::capture_enabled())) { |
| + base::trace_event::AllocationContextTracker::GetInstanceForCurrentThread() |
| + ->PopCurrentTaskContext(context_); |
| + } |
| + } |
| + |
| + private: |
| + const char* context_; |
| +}; |
| + |
| } // namespace trace_event_internal |
| namespace base { |