Index: base/trace_event/heap_profiler_event_filter.cc |
diff --git a/base/trace_event/heap_profiler_event_filter.cc b/base/trace_event/heap_profiler_event_filter.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b666f19581275efe2497afb4e9b5d97adaed218d |
--- /dev/null |
+++ b/base/trace_event/heap_profiler_event_filter.cc |
@@ -0,0 +1,60 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/trace_event/heap_profiler_event_filter.h" |
+ |
+#include "base/trace_event/category_registry.h" |
+#include "base/trace_event/heap_profiler_allocation_context_tracker.h" |
+#include "base/trace_event/trace_category.h" |
+#include "base/trace_event/trace_event.h" |
+#include "base/trace_event/trace_event_impl.h" |
+ |
+namespace base { |
+namespace trace_event { |
+ |
+// static |
+const char HeapProfilerEventFilter::kName[] = "heap_profiler_predicate"; |
+ |
+HeapProfilerEventFilter::HeapProfilerEventFilter() {} |
+HeapProfilerEventFilter::~HeapProfilerEventFilter() {} |
+ |
+bool HeapProfilerEventFilter::FilterTraceEvent( |
+ const TraceEvent& trace_event) const { |
+ if (AllocationContextTracker::capture_mode() != |
+ AllocationContextTracker::CaptureMode::PSEUDO_STACK) { |
+ return true; |
+ } |
+ |
+ // TODO(primiano): Add support for events with copied name crbug.com/581079. |
+ if (trace_event.flags() & TRACE_EVENT_FLAG_COPY) |
+ return true; |
+ |
+ const char* category_name = CategoryRegistry::GetCategoryByStatePtr( |
+ trace_event.category_group_enabled()) |
kraynov
2016/12/06 18:24:23
hard readable
Primiano Tucci (use gerrit)
2016/12/07 11:17:47
unfortunately this is what our style imposes and w
|
+ ->name(); |
+ if (trace_event.phase() == TRACE_EVENT_PHASE_BEGIN || |
+ trace_event.phase() == TRACE_EVENT_PHASE_COMPLETE) { |
+ AllocationContextTracker::GetInstanceForCurrentThread() |
+ ->PushPseudoStackFrame({category_name, trace_event.name()}); |
+ } else if (trace_event.phase() == TRACE_EVENT_PHASE_END) { |
+ // The pop for |TRACE_EVENT_PHASE_COMPLETE| events is in |EndEvent|. |
+ AllocationContextTracker::GetInstanceForCurrentThread() |
+ ->PopPseudoStackFrame({category_name, trace_event.name()}); |
+ } |
+ // Do not filter-out any events and always return true. TraceLog adds the |
+ // event only if it is enabled for recording. |
+ return true; |
+} |
+ |
+void HeapProfilerEventFilter::EndEvent(const char* category_name, |
+ const char* event_name) const { |
+ if (AllocationContextTracker::capture_mode() == |
+ AllocationContextTracker::CaptureMode::PSEUDO_STACK) { |
+ AllocationContextTracker::GetInstanceForCurrentThread() |
kraynov
2016/12/06 18:24:23
Should you check that it's TRACE_EVENT_PHASE_COMPL
Primiano Tucci (use gerrit)
2016/12/07 11:17:47
No, in an "EndEvent" there cannot be any BEGIN pha
|
+ ->PopPseudoStackFrame({category_name, event_name}); |
+ } |
+} |
+ |
+} // namespace trace_event |
+} // namespace base |