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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/trace_event/trace_log.h" 5 #include "base/trace_event/trace_log.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } 126 }
127 127
128 private: 128 private:
129 std::unordered_set<std::string> whitelist_; 129 std::unordered_set<std::string> whitelist_;
130 }; 130 };
131 131
132 base::LazyInstance< 132 base::LazyInstance<
133 std::list<std::unique_ptr<TraceLog::TraceEventFilter>>>::Leaky 133 std::list<std::unique_ptr<TraceLog::TraceEventFilter>>>::Leaky
134 g_category_group_filter[MAX_CATEGORY_GROUPS] = {LAZY_INSTANCE_INITIALIZER}; 134 g_category_group_filter[MAX_CATEGORY_GROUPS] = {LAZY_INSTANCE_INITIALIZER};
135 135
136 class HeapProfilerFilter : public TraceLog::TraceEventFilter {
137 public:
138 HeapProfilerFilter() {}
139
140 bool FilterTraceEvent(const TraceEvent& trace_event) const override {
141 // TODO(primiano): Add support for events with copied name crbug.com/581078
142 if (!(trace_event.flags() & TRACE_EVENT_FLAG_COPY)) {
143 if (AllocationContextTracker::capture_mode() ==
144 AllocationContextTracker::CaptureMode::PSEUDO_STACK) {
145 if (trace_event.phase() == TRACE_EVENT_PHASE_BEGIN ||
146 trace_event.phase() == TRACE_EVENT_PHASE_COMPLETE) {
147 AllocationContextTracker::GetInstanceForCurrentThread()
148 ->PushPseudoStackFrame(trace_event.name());
149 } else if (trace_event.phase() == TRACE_EVENT_PHASE_END)
150 // The pop for |TRACE_EVENT_PHASE_COMPLETE| events is in |EndEvent|.
151 AllocationContextTracker::GetInstanceForCurrentThread()
152 ->PopPseudoStackFrame(trace_event.name());
153 }
154 }
155 // This predicate does not filter any events, but only records the events.
156 // So, it should return true iff the category is enabled for recoding.
157 return (*trace_event.category_group_enabled() &
158 TraceLog::ENABLED_FOR_RECORDING);
159 }
160 void EndEvent(const char* name, const char* category_group) override {
161 AllocationContextTracker::GetInstanceForCurrentThread()
162 ->PopPseudoStackFrame(name);
163 }
164 };
165
136 TraceLog::TraceEventFilterConstructorForTesting 166 TraceLog::TraceEventFilterConstructorForTesting
137 g_trace_event_filter_constructor_for_testing = nullptr; 167 g_trace_event_filter_constructor_for_testing = nullptr;
138 168
139 // Indexes here have to match the g_category_groups array indexes above. 169 // Indexes here have to match the g_category_groups array indexes above.
140 const int kCategoryAlreadyShutdown = 1; 170 const int kCategoryAlreadyShutdown = 1;
141 const int kCategoryCategoriesExhausted = 2; 171 const int kCategoryCategoriesExhausted = 2;
142 const int kCategoryMetadata = 3; 172 const int kCategoryMetadata = 3;
143 const int kNumBuiltinCategories = 4; 173 const int kNumBuiltinCategories = 4;
144 // Skip default categories. 174 // Skip default categories.
145 base::subtle::AtomicWord g_category_index = kNumBuiltinCategories; 175 base::subtle::AtomicWord g_category_index = kNumBuiltinCategories;
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 if (!(g_category_group_filter[category_index] == nullptr)) 565 if (!(g_category_group_filter[category_index] == nullptr))
536 g_category_group_filter[category_index].Get().clear(); 566 g_category_group_filter[category_index].Get().clear();
537 567
538 for (const auto& event_filter : trace_config_.event_filters()) { 568 for (const auto& event_filter : trace_config_.event_filters()) {
539 if (event_filter.IsCategoryGroupEnabled(category_group)) { 569 if (event_filter.IsCategoryGroupEnabled(category_group)) {
540 std::unique_ptr<TraceEventFilter> new_filter; 570 std::unique_ptr<TraceEventFilter> new_filter;
541 571
542 if (event_filter.predicate_name() == "event_whitelist_predicate") { 572 if (event_filter.predicate_name() == "event_whitelist_predicate") {
543 new_filter = 573 new_filter =
544 WrapUnique(new EventNameFilter(event_filter.filter_args())); 574 WrapUnique(new EventNameFilter(event_filter.filter_args()));
575 } else if (event_filter.predicate_name() == "heap_profiler_predicate") {
576 new_filter = WrapUnique(new HeapProfilerFilter());
545 } else if (event_filter.predicate_name() == "testing_predicate") { 577 } else if (event_filter.predicate_name() == "testing_predicate") {
546 CHECK(g_trace_event_filter_constructor_for_testing); 578 CHECK(g_trace_event_filter_constructor_for_testing);
547 new_filter = g_trace_event_filter_constructor_for_testing(); 579 new_filter = g_trace_event_filter_constructor_for_testing();
548 } 580 }
549 581
550 if (new_filter) { 582 if (new_filter) {
551 g_category_group_filter[category_index].Get().push_back( 583 g_category_group_filter[category_index].Get().push_back(
552 std::move(new_filter)); 584 std::move(new_filter));
553 enabled_flag |= ENABLED_FOR_FILTERING; 585 enabled_flag |= ENABLED_FOR_FILTERING;
554 } 586 }
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 subtle::NoBarrier_Load(&event_callback_)); 1454 subtle::NoBarrier_Load(&event_callback_));
1423 if (event_callback) { 1455 if (event_callback) {
1424 event_callback( 1456 event_callback(
1425 offset_event_timestamp, 1457 offset_event_timestamp,
1426 phase == TRACE_EVENT_PHASE_COMPLETE ? TRACE_EVENT_PHASE_BEGIN : phase, 1458 phase == TRACE_EVENT_PHASE_COMPLETE ? TRACE_EVENT_PHASE_BEGIN : phase,
1427 category_group_enabled, name, scope, id, num_args, arg_names, 1459 category_group_enabled, name, scope, id, num_args, arg_names,
1428 arg_types, arg_values, flags); 1460 arg_types, arg_values, flags);
1429 } 1461 }
1430 } 1462 }
1431 1463
1432 // TODO(primiano): Add support for events with copied name crbug.com/581078
1433 if (!(flags & TRACE_EVENT_FLAG_COPY)) {
1434 if (AllocationContextTracker::capture_mode() ==
1435 AllocationContextTracker::CaptureMode::PSEUDO_STACK) {
1436 if (phase == TRACE_EVENT_PHASE_BEGIN ||
1437 phase == TRACE_EVENT_PHASE_COMPLETE) {
1438 AllocationContextTracker::GetInstanceForCurrentThread()
1439 ->PushPseudoStackFrame(name);
1440 } else if (phase == TRACE_EVENT_PHASE_END) {
1441 // The pop for |TRACE_EVENT_PHASE_COMPLETE| events
1442 // is in |TraceLog::UpdateTraceEventDuration|.
1443 AllocationContextTracker::GetInstanceForCurrentThread()
1444 ->PopPseudoStackFrame(name);
1445 }
1446 }
1447 }
1448
1449 return handle; 1464 return handle;
1450 } 1465 }
1451 1466
1452 void TraceLog::AddMetadataEvent( 1467 void TraceLog::AddMetadataEvent(
1453 const unsigned char* category_group_enabled, 1468 const unsigned char* category_group_enabled,
1454 const char* name, 1469 const char* name,
1455 int num_args, 1470 int num_args,
1456 const char** arg_names, 1471 const char** arg_names,
1457 const unsigned char* arg_types, 1472 const unsigned char* arg_types,
1458 const unsigned long long* arg_values, 1473 const unsigned long long* arg_values,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 trace_event->UpdateDuration(now, thread_now); 1585 trace_event->UpdateDuration(now, thread_now);
1571 #if defined(OS_ANDROID) 1586 #if defined(OS_ANDROID)
1572 trace_event->SendToATrace(); 1587 trace_event->SendToATrace();
1573 #endif 1588 #endif
1574 } 1589 }
1575 1590
1576 if (trace_options() & kInternalEchoToConsole) { 1591 if (trace_options() & kInternalEchoToConsole) {
1577 console_message = 1592 console_message =
1578 EventToConsoleMessage(TRACE_EVENT_PHASE_END, now, trace_event); 1593 EventToConsoleMessage(TRACE_EVENT_PHASE_END, now, trace_event);
1579 } 1594 }
1580
1581 if (AllocationContextTracker::capture_mode() ==
1582 AllocationContextTracker::CaptureMode::PSEUDO_STACK) {
1583 // The corresponding push is in |AddTraceEventWithThreadIdAndTimestamp|.
1584 AllocationContextTracker::GetInstanceForCurrentThread()
1585 ->PopPseudoStackFrame(name);
1586 }
1587 } 1595 }
1588 1596
1589 if (!console_message.empty()) 1597 if (!console_message.empty())
1590 LOG(ERROR) << console_message; 1598 LOG(ERROR) << console_message;
1591 1599
1592 if (category_group_enabled_local & ENABLED_FOR_EVENT_CALLBACK) { 1600 if (category_group_enabled_local & ENABLED_FOR_EVENT_CALLBACK) {
1593 EventCallback event_callback = reinterpret_cast<EventCallback>( 1601 EventCallback event_callback = reinterpret_cast<EventCallback>(
1594 subtle::NoBarrier_Load(&event_callback_)); 1602 subtle::NoBarrier_Load(&event_callback_));
1595 if (event_callback) { 1603 if (event_callback) {
1596 event_callback( 1604 event_callback(
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1884 } 1892 }
1885 1893
1886 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { 1894 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() {
1887 if (*category_group_enabled_) { 1895 if (*category_group_enabled_) {
1888 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_, 1896 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_,
1889 event_handle_); 1897 event_handle_);
1890 } 1898 }
1891 } 1899 }
1892 1900
1893 } // namespace trace_event_internal 1901 } // namespace trace_event_internal
OLDNEW
« 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