| 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 834f826e04078dae5b992276b986a1581f6a1037..15068ef9983d5615287e04fedf08a7f7e61a50b5 100644
|
| --- a/base/trace_event/trace_event_impl.cc
|
| +++ b/base/trace_event/trace_event_impl.cc
|
| @@ -66,6 +66,7 @@ const char kRecordAsMuchAsPossible[] = "record-as-much-as-possible";
|
| const char kTraceToConsole[] = "trace-to-console";
|
| const char kEnableSampling[] = "enable-sampling";
|
| const char kEnableSystrace[] = "enable-systrace";
|
| +const char kEnableArgsWhitelist[] = "enable-args-whitelist";
|
|
|
| // Controls the number of trace events we will buffer in-memory
|
| // before throwing them away.
|
| @@ -693,7 +694,30 @@ void TraceEvent::AppendValueAsJSON(unsigned char type,
|
| }
|
| }
|
|
|
| -void TraceEvent::AppendAsJSON(std::string* out) const {
|
| +bool TraceEvent::IsPIIWhitelisted() const {
|
| + const char* category_group_name =
|
| + TraceLog::GetCategoryGroupName(category_group_enabled_);
|
| + CStringTokenizer category_group_tokens(
|
| + category_group_name, category_group_name + strlen(category_group_name),
|
| + ",");
|
| + while (category_group_tokens.GetNext()) {
|
| + const std::string& category_group_token = category_group_tokens.token();
|
| + for (int i = 0; kEventArgsWhitelist[i][0] != NULL; ++i) {
|
| + DCHECK(kEventArgsWhitelist[i][1]);
|
| +
|
| + if (MatchPattern(category_group_token.c_str(),
|
| + kEventArgsWhitelist[i][0]) &&
|
| + MatchPattern(name_, kEventArgsWhitelist[i][1])) {
|
| + return true;
|
| + }
|
| + }
|
| + }
|
| +
|
| + return false;
|
| +}
|
| +
|
| +void TraceEvent::AppendAsJSON(std::string* out,
|
| + bool enable_args_whitelist) const {
|
| int64 time_int64 = timestamp_.ToInternalValue();
|
| int process_id = TraceLog::GetInstance()->process_id();
|
| // Category group checked at category creation time.
|
| @@ -709,18 +733,27 @@ void TraceEvent::AppendAsJSON(std::string* out) const {
|
| 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 = !enable_args_whitelist || IsPIIWhitelisted();
|
| +
|
| + 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) {
|
| @@ -996,6 +1029,8 @@ bool TraceOptions::SetFromString(const std::string& options_string) {
|
| enable_sampling = true;
|
| } else if (*iter == kEnableSystrace) {
|
| enable_systrace = true;
|
| + } else if (*iter == kEnableArgsWhitelist) {
|
| + enable_args_whitelist = true;
|
| } else {
|
| return false;
|
| }
|
| @@ -1025,6 +1060,8 @@ std::string TraceOptions::ToString() const {
|
| ret = ret + "," + kEnableSampling;
|
| if (enable_systrace)
|
| ret = ret + "," + kEnableSystrace;
|
| + if (enable_args_whitelist)
|
| + ret = ret + "," + kEnableArgsWhitelist;
|
| return ret;
|
| }
|
|
|
| @@ -1478,6 +1515,8 @@ TraceLog::InternalTraceOptions TraceLog::GetInternalOptionsFromTraceOptions(
|
| const TraceOptions& options) {
|
| InternalTraceOptions ret =
|
| options.enable_sampling ? kInternalEnableSampling : kInternalNone;
|
| + if (options.enable_args_whitelist)
|
| + ret |= kInternalEnableArgsWhitelist;
|
| switch (options.record_mode) {
|
| case RECORD_UNTIL_FULL:
|
| return ret | kInternalRecordUntilFull;
|
| @@ -1501,6 +1540,7 @@ TraceOptions TraceLog::GetCurrentTraceOptions() const {
|
| TraceOptions ret;
|
| InternalTraceOptions option = trace_options();
|
| ret.enable_sampling = (option & kInternalEnableSampling) != 0;
|
| + ret.enable_args_whitelist = (option & kInternalEnableArgsWhitelist) != 0;
|
| if (option & kInternalRecordUntilFull)
|
| ret.record_mode = RECORD_UNTIL_FULL;
|
| else if (option & kInternalRecordContinuously)
|
| @@ -1747,6 +1787,8 @@ void TraceLog::ConvertTraceEventsToTraceFormat(
|
| if (flush_output_callback.is_null())
|
| return;
|
|
|
| + InternalTraceOptions options = trace_options();
|
| + bool enable_args_whitelist = (options & kInternalEnableArgsWhitelist) != 0;
|
| // The callback need to be called at least once even if there is no events
|
| // to let the caller know the completion of flush.
|
| bool has_more_events = true;
|
| @@ -1762,7 +1804,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()),
|
| + enable_args_whitelist);
|
| }
|
| }
|
| flush_output_callback.Run(json_events_str_ptr, has_more_events);
|
| @@ -1791,9 +1834,8 @@ void TraceLog::FinishFlush(int generation) {
|
| if (use_worker_thread_ &&
|
| WorkerPool::PostTask(
|
| FROM_HERE,
|
| - Bind(&TraceLog::ConvertTraceEventsToTraceFormat,
|
| - Passed(&previous_logged_events),
|
| - flush_output_callback),
|
| + Bind(&TraceLog::ConvertTraceEventsToTraceFormat, Unretained(this),
|
| + Passed(&previous_logged_events), flush_output_callback),
|
| true)) {
|
| return;
|
| }
|
|
|