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

Unified Diff: base/trace_event/trace_event_impl.cc

Issue 1067233002: Added a trace option for whitewashing trace args against a known-PII-less list. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed enable_args_whitelist Created 5 years, 8 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_event_impl.h ('k') | base/trace_event/trace_event_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/trace_event_impl.cc
diff --git a/base/trace_event/trace_event_impl.cc b/base/trace_event/trace_event_impl.cc
index 12f9598a2c8a099ccd62700a8a98a0d0a9983d41..734b10692390bc9e702c13c0ea4d46a94ea5cfaa 100644
--- a/base/trace_event/trace_event_impl.cc
+++ b/base/trace_event/trace_event_impl.cc
@@ -694,34 +694,45 @@ void TraceEvent::AppendValueAsJSON(unsigned char type,
}
}
-void TraceEvent::AppendAsJSON(std::string* out) const {
+void TraceEvent::AppendAsJSON(
+ std::string* out,
+ const EventFilterPredicate& event_filter_predicate) const {
int64 time_int64 = timestamp_.ToInternalValue();
int process_id = TraceLog::GetInstance()->process_id();
+ const char* category_group_name =
+ TraceLog::GetCategoryGroupName(category_group_enabled_);
+
// Category group checked at category creation time.
DCHECK(!strchr(name_, '"'));
- StringAppendF(out,
- "{\"pid\":%i,\"tid\":%i,\"ts\":%" PRId64 ","
- "\"ph\":\"%c\",\"cat\":\"%s\",\"name\":\"%s\",\"args\":{",
- process_id,
- thread_id_,
- time_int64,
- phase_,
- TraceLog::GetCategoryGroupName(category_group_enabled_),
- name_);
+ StringAppendF(out, "{\"pid\":%i,\"tid\":%i,\"ts\":%" PRId64
+ ","
+ "\"ph\":\"%c\",\"cat\":\"%s\",\"name\":\"%s\",\"args\":{",
+ process_id, thread_id_, time_int64, phase_, category_group_name,
+ name_);
// Output argument names and values, stop at first NULL argument name.
- for (int i = 0; i < kTraceMaxNumArgs && arg_names_[i]; ++i) {
- if (i > 0)
- *out += ",";
- *out += "\"";
- *out += arg_names_[i];
- *out += "\":";
-
- if (arg_types_[i] == TRACE_VALUE_TYPE_CONVERTABLE)
- convertable_values_[i]->AppendAsTraceFormat(out);
- else
- AppendValueAsJSON(arg_types_[i], arg_values_[i], out);
+ if (arg_names_[0]) {
+ bool allow_args = event_filter_predicate.is_null() ||
+ event_filter_predicate.Run(category_group_name, name_);
+
+ if (allow_args) {
+ for (int i = 0; i < kTraceMaxNumArgs && arg_names_[i]; ++i) {
+ if (i > 0)
+ *out += ",";
+ *out += "\"";
+ *out += arg_names_[i];
+ *out += "\":";
+
+ if (arg_types_[i] == TRACE_VALUE_TYPE_CONVERTABLE)
+ convertable_values_[i]->AppendAsTraceFormat(out);
+ else
+ AppendValueAsJSON(arg_types_[i], arg_values_[i], out);
+ }
+ } else {
+ *out += "\"stripped\":1";
+ }
}
+
*out += "}";
if (phase_ == TRACE_EVENT_PHASE_COMPLETE) {
@@ -1480,6 +1491,12 @@ void TraceLog::SetEnabled(const CategoryFilter& category_filter,
}
}
+void TraceLog::SetEventFilterPredicate(
+ const TraceEvent::EventFilterPredicate& event_filter_predicate) {
+ AutoLock lock(lock_);
+ event_filter_predicate_ = event_filter_predicate;
+}
+
TraceLog::InternalTraceOptions TraceLog::GetInternalOptionsFromTraceOptions(
const TraceOptions& options) {
InternalTraceOptions ret =
@@ -1748,8 +1765,8 @@ void TraceLog::Flush(const TraceLog::OutputCallback& cb,
// Usually it runs on a different thread.
void TraceLog::ConvertTraceEventsToTraceFormat(
scoped_ptr<TraceBuffer> logged_events,
- const TraceLog::OutputCallback& flush_output_callback) {
-
+ const OutputCallback& flush_output_callback,
+ const TraceEvent::EventFilterPredicate& event_filter_predicate) {
if (flush_output_callback.is_null())
return;
@@ -1768,7 +1785,8 @@ void TraceLog::ConvertTraceEventsToTraceFormat(
for (size_t j = 0; j < chunk->size(); ++j) {
if (json_events_str_ptr->size())
json_events_str_ptr->data().append(",\n");
- chunk->GetEventAt(j)->AppendAsJSON(&(json_events_str_ptr->data()));
+ chunk->GetEventAt(j)->AppendAsJSON(&(json_events_str_ptr->data()),
+ event_filter_predicate);
}
}
flush_output_callback.Run(json_events_str_ptr, has_more_events);
@@ -1778,6 +1796,7 @@ void TraceLog::ConvertTraceEventsToTraceFormat(
void TraceLog::FinishFlush(int generation) {
scoped_ptr<TraceBuffer> previous_logged_events;
OutputCallback flush_output_callback;
+ TraceEvent::EventFilterPredicate event_filter_predicate;
if (!CheckGeneration(generation))
return;
@@ -1792,20 +1811,23 @@ void TraceLog::FinishFlush(int generation) {
flush_message_loop_proxy_ = NULL;
flush_output_callback = flush_output_callback_;
flush_output_callback_.Reset();
+
+ event_filter_predicate = event_filter_predicate_;
+ event_filter_predicate_.Reset();
}
if (use_worker_thread_ &&
WorkerPool::PostTask(
- FROM_HERE,
- Bind(&TraceLog::ConvertTraceEventsToTraceFormat,
- Passed(&previous_logged_events),
- flush_output_callback),
+ FROM_HERE, Bind(&TraceLog::ConvertTraceEventsToTraceFormat,
+ Unretained(this), Passed(&previous_logged_events),
+ flush_output_callback, event_filter_predicate),
true)) {
return;
}
ConvertTraceEventsToTraceFormat(previous_logged_events.Pass(),
- flush_output_callback);
+ flush_output_callback,
+ event_filter_predicate);
}
// Run in each thread holding a local event buffer.
@@ -1856,6 +1878,7 @@ void TraceLog::OnFlushTimeout(int generation) {
void TraceLog::FlushButLeaveBufferIntact(
const TraceLog::OutputCallback& flush_output_callback) {
scoped_ptr<TraceBuffer> previous_logged_events;
+ TraceEvent::EventFilterPredicate event_filter_predicate;
{
AutoLock lock(lock_);
AddMetadataEventsWhileLocked();
@@ -1865,10 +1888,12 @@ void TraceLog::FlushButLeaveBufferIntact(
thread_shared_chunk_.Pass());
}
previous_logged_events = logged_events_->CloneForIteration().Pass();
+ event_filter_predicate = event_filter_predicate_;
} // release lock
ConvertTraceEventsToTraceFormat(previous_logged_events.Pass(),
- flush_output_callback);
+ flush_output_callback,
+ event_filter_predicate);
}
void TraceLog::UseNextTraceBuffer() {
« no previous file with comments | « base/trace_event/trace_event_impl.h ('k') | base/trace_event/trace_event_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698