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

Unified Diff: base/trace_event/trace_log.cc

Issue 2259493003: [tracing] Add trace events filtering predicate for heap profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@heap_prof_filter
Patch Set: Created 4 years, 4 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
« base/trace_event/trace_event.h ('K') | « base/trace_event/trace_event_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/trace_log.cc
diff --git a/base/trace_event/trace_log.cc b/base/trace_event/trace_log.cc
index a9f99d41f0dc97b37a1cc7364c30231451047088..2828ca1a2ffbe185e75a9739600d29a5d29a6392 100644
--- a/base/trace_event/trace_log.cc
+++ b/base/trace_event/trace_log.cc
@@ -133,6 +133,36 @@ base::LazyInstance<
std::list<std::unique_ptr<TraceLog::TraceEventFilter>>>::Leaky
g_category_group_filter[MAX_CATEGORY_GROUPS] = {LAZY_INSTANCE_INITIALIZER};
+class HeapProfilerFilter : public TraceLog::TraceEventFilter {
+ public:
+ HeapProfilerFilter() {}
+
+ bool FilterTraceEvent(const TraceEvent& trace_event) const override {
+ // TODO(primiano): Add support for events with copied name crbug.com/581078
+ if (!(trace_event.flags() & TRACE_EVENT_FLAG_COPY)) {
+ if (AllocationContextTracker::capture_mode() ==
+ AllocationContextTracker::CaptureMode::PSEUDO_STACK) {
+ if (trace_event.phase() == TRACE_EVENT_PHASE_BEGIN ||
+ trace_event.phase() == TRACE_EVENT_PHASE_COMPLETE) {
+ AllocationContextTracker::GetInstanceForCurrentThread()
+ ->PushPseudoStackFrame(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(trace_event.name());
+ }
+ }
+ // This predicate does not filter any events, but only records the events.
+ // So, it should return true iff the category is enabled for recoding.
+ return (*trace_event.category_group_enabled() &
+ TraceLog::ENABLED_FOR_RECORDING);
+ }
+ void EndEvent(const char* name, const char* category_group) override {
+ AllocationContextTracker::GetInstanceForCurrentThread()
+ ->PopPseudoStackFrame(name);
+ }
+};
+
TraceLog::TraceEventFilterConstructorForTesting
g_trace_event_filter_constructor_for_testing = nullptr;
@@ -542,6 +572,8 @@ void TraceLog::UpdateCategoryGroupEnabledFlag(size_t category_index) {
if (event_filter.predicate_name() == "event_whitelist_predicate") {
new_filter =
WrapUnique(new EventNameFilter(event_filter.filter_args()));
+ } else if (event_filter.predicate_name() == "heap_profiler_predicate") {
+ new_filter = WrapUnique(new HeapProfilerFilter());
} else if (event_filter.predicate_name() == "testing_predicate") {
CHECK(g_trace_event_filter_constructor_for_testing);
new_filter = g_trace_event_filter_constructor_for_testing();
@@ -1429,23 +1461,6 @@ TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp(
}
}
- // TODO(primiano): Add support for events with copied name crbug.com/581078
- if (!(flags & TRACE_EVENT_FLAG_COPY)) {
- if (AllocationContextTracker::capture_mode() ==
- AllocationContextTracker::CaptureMode::PSEUDO_STACK) {
- if (phase == TRACE_EVENT_PHASE_BEGIN ||
- phase == TRACE_EVENT_PHASE_COMPLETE) {
- AllocationContextTracker::GetInstanceForCurrentThread()
- ->PushPseudoStackFrame(name);
- } else if (phase == TRACE_EVENT_PHASE_END) {
- // The pop for |TRACE_EVENT_PHASE_COMPLETE| events
- // is in |TraceLog::UpdateTraceEventDuration|.
- AllocationContextTracker::GetInstanceForCurrentThread()
- ->PopPseudoStackFrame(name);
- }
- }
- }
-
return handle;
}
@@ -1577,13 +1592,6 @@ void TraceLog::UpdateTraceEventDuration(
console_message =
EventToConsoleMessage(TRACE_EVENT_PHASE_END, now, trace_event);
}
-
- if (AllocationContextTracker::capture_mode() ==
- AllocationContextTracker::CaptureMode::PSEUDO_STACK) {
- // The corresponding push is in |AddTraceEventWithThreadIdAndTimestamp|.
- AllocationContextTracker::GetInstanceForCurrentThread()
- ->PopPseudoStackFrame(name);
- }
}
if (!console_message.empty())
« base/trace_event/trace_event.h ('K') | « base/trace_event/trace_event_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698