Chromium Code Reviews| Index: base/debug/trace_event_impl.cc |
| diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc |
| index 9e7c981e0e7572f3d01c1efa35e60dd6da35fe92..dcf0ddfe2c0ee339c51a50780b99046eb83e0e2a 100644 |
| --- a/base/debug/trace_event_impl.cc |
| +++ b/base/debug/trace_event_impl.cc |
| @@ -1061,6 +1061,12 @@ void TraceLog::AddTraceEventWithThreadIdAndTimestamp( |
| unsigned char flags) { |
| DCHECK(name); |
| + TimeDelta duration; |
| + if (phase == TRACE_EVENT_PHASE_END && trace_options_ & ECHO_TO_STDERR) { |
| + duration = timestamp - thread_event_start_times_[thread_id].top(); |
| + thread_event_start_times_[thread_id].pop(); |
| + } |
| + |
| if (flags & TRACE_EVENT_FLAG_MANGLE_ID) |
| id ^= process_id_hash_; |
| @@ -1111,6 +1117,36 @@ void TraceLog::AddTraceEventWithThreadIdAndTimestamp( |
| } |
| } |
| + if (trace_options_ & ECHO_TO_STDERR) { |
|
nduca
2013/04/25 02:32:35
if you just used a echoing trace log, you might be
|
| + std::string thread_name = thread_names_[thread_id]; |
| + if (thread_colors_.find(thread_name) == thread_colors_.end()) |
| + thread_colors_[thread_name] = (thread_colors_.size() % 6) + 1; |
| + |
| + fprintf(stderr, |
| + "TraceLog (%lu) %s:", |
| + timestamp.ToInternalValue(), |
| + thread_name.c_str()); |
| + |
| + // Set the text color. With magic. |
| + fprintf(stderr, "\e[0;3%dm", thread_colors_[thread_name]); |
| + |
| + size_t depth = 0; |
| + if (thread_event_start_times_.find(thread_id) != |
| + thread_event_start_times_.end()) |
|
jar (doing other things)
2013/04/25 02:14:06
nit: undent-2 spaces.
You only need to indent 4 f
|
| + depth = thread_event_start_times_[thread_id].size(); |
| + |
| + for (size_t i = 0; i < depth; ++i) |
| + fprintf(stderr, "| "); |
| + |
| + fprintf(stderr, "'%c', %s", phase, name); |
| + |
| + if (phase == TRACE_EVENT_PHASE_END) |
| + fprintf(stderr, " (%.3f ms)", duration.InMillisecondsF()); |
| + |
| + // Resets the text color. |
| + fprintf(stderr, "\n\e[0;m"); |
| + } |
| + |
| logged_events_->AddEvent(TraceEvent(thread_id, |
| now, phase, category_group_enabled, name, id, |
| num_args, arg_names, arg_types, arg_values, |
| @@ -1125,6 +1161,9 @@ void TraceLog::AddTraceEventWithThreadIdAndTimestamp( |
| event_callback_copy = event_callback_; |
| } // release lock |
| + if (phase == TRACE_EVENT_PHASE_BEGIN && trace_options_ & ECHO_TO_STDERR) |
| + thread_event_start_times_[thread_id].push(timestamp); |
| + |
| notifier.SendNotificationIfAny(); |
| if (event_callback_copy != NULL) { |
| event_callback_copy(phase, category_group_enabled, name, id, |