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

Side by Side Diff: base/trace_event/heap_profiler_event_filter.cc

Issue 2549103003: tracing: split trace event filter classes out of TraceLog (Closed)
Patch Set: Add BASE_EXPORT Created 4 years 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 unified diff | Download patch
« no previous file with comments | « base/trace_event/heap_profiler_event_filter.h ('k') | base/trace_event/memory_dump_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/trace_event/heap_profiler_event_filter.h"
6
7 #include "base/trace_event/category_registry.h"
8 #include "base/trace_event/heap_profiler_allocation_context_tracker.h"
9 #include "base/trace_event/trace_category.h"
10 #include "base/trace_event/trace_event.h"
11 #include "base/trace_event/trace_event_impl.h"
12
13 namespace base {
14 namespace trace_event {
15
16 namespace {
17
18 inline bool IsPseudoStackEnabled() {
19 return AllocationContextTracker::capture_mode() ==
20 AllocationContextTracker::CaptureMode::PSEUDO_STACK;
21 }
22
23 inline AllocationContextTracker* GetThreadLocalTracker() {
24 return AllocationContextTracker::GetInstanceForCurrentThread();
25 }
26
27 } // namespace
28
29 // static
30 const char HeapProfilerEventFilter::kName[] = "heap_profiler_predicate";
31
32 HeapProfilerEventFilter::HeapProfilerEventFilter() {}
33 HeapProfilerEventFilter::~HeapProfilerEventFilter() {}
34
35 bool HeapProfilerEventFilter::FilterTraceEvent(
36 const TraceEvent& trace_event) const {
37 if (!IsPseudoStackEnabled())
38 return true;
39
40 // TODO(primiano): Add support for events with copied name crbug.com/581079.
41 if (trace_event.flags() & TRACE_EVENT_FLAG_COPY)
42 return true;
43
44 const auto* category = CategoryRegistry::GetCategoryByStatePtr(
45 trace_event.category_group_enabled());
46 AllocationContextTracker::PseudoStackFrame frame = {category->name(),
47 trace_event.name()};
48 if (trace_event.phase() == TRACE_EVENT_PHASE_BEGIN ||
49 trace_event.phase() == TRACE_EVENT_PHASE_COMPLETE) {
50 GetThreadLocalTracker()->PushPseudoStackFrame(frame);
51 } else if (trace_event.phase() == TRACE_EVENT_PHASE_END) {
52 // The pop for |TRACE_EVENT_PHASE_COMPLETE| events is in |EndEvent|.
53 GetThreadLocalTracker()->PopPseudoStackFrame(frame);
54 }
55 // Do not filter-out any events and always return true. TraceLog adds the
56 // event only if it is enabled for recording.
57 return true;
58 }
59
60 void HeapProfilerEventFilter::EndEvent(const char* category_name,
61 const char* event_name) const {
62 if (IsPseudoStackEnabled())
63 GetThreadLocalTracker()->PopPseudoStackFrame({category_name, event_name});
64 }
65
66 } // namespace trace_event
67 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/heap_profiler_event_filter.h ('k') | base/trace_event/memory_dump_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698