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

Unified Diff: base/trace_event/trace_log.cc

Issue 1923533004: Tracing pre-filtering (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « base/trace_event/trace_log.h ('k') | content/app/content_main_runner.cc » ('j') | 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 1a375d146a9eb20582e7948677029c93c6a1842f..6cfa5effef98864378e197804cd586fb69181f7b 100644
--- a/base/trace_event/trace_log.cc
+++ b/base/trace_event/trace_log.cc
@@ -16,6 +16,7 @@
#include "base/lazy_instance.h"
#include "base/location.h"
#include "base/macros.h"
+#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/singleton.h"
#include "base/process/process_metrics.h"
@@ -102,6 +103,48 @@ const char* g_category_groups[MAX_CATEGORY_GROUPS] = {
// The enabled flag is char instead of bool so that the API can be used from C.
unsigned char g_category_group_enabled[MAX_CATEGORY_GROUPS] = {0};
+
+class TraceEventFilter {
+ public:
+ TraceEventFilter(const base::DictionaryValue* filter_args) {}
+ virtual bool FilterTraceEvent(const TraceEvent& trace_event) const = 0;
shatch 2016/05/04 19:57:38 Did we come to a decision on whether to allow the
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TraceEventFilter);
+};
+
+class EventNameFilter : public TraceEventFilter {
+ public:
+ EventNameFilter(const base::DictionaryValue* filter_args)
+ : TraceEventFilter(filter_args) {
+ const base::ListValue* whitelist = nullptr;
+ if (filter_args->GetList("event_name_whitelist", &whitelist)) {
+ for (size_t i = 0; i < whitelist->GetSize(); ++i) {
+ std::string event_name;
+ if (!whitelist->GetString(i, &event_name))
+ continue;
+
+ whitelist_.push_back(event_name);
+ }
+ }
+ }
+
+ bool FilterTraceEvent(const TraceEvent& trace_event) const override {
+ for (const auto& entry : whitelist_) {
+ if (trace_event.name() == entry)
+ return true;
+ }
+
+ return false;
+ }
+
+ private:
+ std::vector<std::string> whitelist_;
+};
+
+base::LazyInstance<std::list<std::unique_ptr<TraceEventFilter>>>::Leaky
+ g_category_group_filter[MAX_CATEGORY_GROUPS] = {LAZY_INSTANCE_INITIALIZER};
+
// Indexes here have to match the g_category_groups array indexes above.
const int g_category_already_shutdown = 1;
const int g_category_categories_exhausted = 2;
@@ -434,8 +477,8 @@ const unsigned char* TraceLog::GetCategoryGroupEnabled(
return tracelog->GetCategoryGroupEnabledInternal(category_group);
}
-const char* TraceLog::GetCategoryGroupName(
- const unsigned char* category_group_enabled) {
+namespace {
+uintptr_t GetCategoryIndex(const unsigned char* category_group_enabled) {
// Calculate the index of the category group by finding
// category_group_enabled in g_category_group_enabled array.
uintptr_t category_begin =
@@ -447,7 +490,20 @@ const char* TraceLog::GetCategoryGroupName(
<< "out of bounds category pointer";
uintptr_t category_index =
(category_ptr - category_begin) / sizeof(g_category_group_enabled[0]);
- return g_category_groups[category_index];
+
+ return category_index;
+}
+}
+
+const char* TraceLog::GetCategoryGroupName(
+ const unsigned char* category_group_enabled) {
+ return g_category_groups[GetCategoryIndex(category_group_enabled)];
+}
+
+std::list<std::unique_ptr<TraceEventFilter>>* GetCategoryGroupFilter(
+ const unsigned char* category_group_enabled) {
+ return g_category_group_filter[GetCategoryIndex(category_group_enabled)]
+ .Pointer();
}
void TraceLog::UpdateCategoryGroupEnabledFlag(size_t category_index) {
@@ -470,6 +526,27 @@ void TraceLog::UpdateCategoryGroupEnabledFlag(size_t category_index) {
}
#endif
+ if (!(g_category_group_filter[category_index] == nullptr))
+ g_category_group_filter[category_index].Get().clear();
+
+ for (const auto& category_event_filter :
+ trace_config_.GetCategoryEventFilters()) {
+ if (category_event_filter.IsCategoryGroupEnabled(category_group)) {
+ std::unique_ptr<TraceEventFilter> new_filter;
+
+ if (category_event_filter.predicate_name == "event_whitelist_predicate") {
+ new_filter =
+ WrapUnique(new EventNameFilter(category_event_filter.args.get()));
+ }
+
+ if (new_filter) {
+ g_category_group_filter[category_index].Get().push_back(
+ std::move(new_filter));
+ enabled_flag |= ENABLED_FOR_FILTERING;
+ }
+ }
+ }
+
g_category_group_enabled[category_index] = enabled_flag;
}
@@ -1247,7 +1324,39 @@ TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp(
#endif // OS_WIN
std::string console_message;
- if (*category_group_enabled & ENABLED_FOR_RECORDING) {
+ if (*category_group_enabled & ENABLED_FOR_FILTERING) {
+ std::unique_ptr<TraceEvent> new_trace_event(new TraceEvent);
+ new_trace_event->Initialize(thread_id, offset_event_timestamp, thread_now,
+ phase, category_group_enabled, name, scope, id,
+ bind_id, num_args, arg_names, arg_types,
+ arg_values, convertable_values, flags);
+
+ std::list<std::unique_ptr<TraceEventFilter>>* filter_list =
+ GetCategoryGroupFilter(category_group_enabled);
+ DCHECK(filter_list);
+ DCHECK(!filter_list->empty());
+
+ bool should_add_event = false;
+ for (const auto& trace_event_filter : *filter_list) {
+ DCHECK(trace_event_filter);
+ if (trace_event_filter.get()->FilterTraceEvent(*new_trace_event))
+ should_add_event = true;
+ }
+
+ if (should_add_event) {
+ OptionalAutoLock lock(&lock_);
+
+ TraceEvent* trace_event = NULL;
+ if (thread_local_event_buffer) {
+ trace_event = thread_local_event_buffer->AddTraceEvent(&handle);
+ } else {
+ lock.EnsureAcquired();
+ trace_event = AddEventToThreadSharedChunkWhileLocked(&handle, true);
+ }
+
+ trace_event->MoveFrom(std::move(new_trace_event));
+ }
+ } else if (*category_group_enabled & ENABLED_FOR_RECORDING) {
OptionalAutoLock lock(&lock_);
TraceEvent* trace_event = NULL;
« no previous file with comments | « base/trace_event/trace_log.h ('k') | content/app/content_main_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698