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

Unified Diff: base/debug/trace_event_impl.cc

Issue 14474006: Add a command line flag for dumping trace events to VLOG (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: "Now beautiful" Created 7 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
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..edda26895fb8b34b8713cf23a7d03a43b09425b5 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].back();
+ thread_event_start_times_[thread_id].pop_back();
+ }
+
if (flags & TRACE_EVENT_FLAG_MANGLE_ID)
id ^= process_id_hash_;
@@ -1111,6 +1117,36 @@ void TraceLog::AddTraceEventWithThreadIdAndTimestamp(
}
}
+ if (trace_options_ & ECHO_TO_STDERR) {
+ 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())
+ 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_back(timestamp);
+
notifier.SendNotificationIfAny();
if (event_callback_copy != NULL) {
event_callback_copy(phase, category_group_enabled, name, id,

Powered by Google App Engine
This is Rietveld 408576698