diff options
author | vollick@chromium.org <vollick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-11 23:10:40 +0000 |
---|---|---|
committer | vollick@chromium.org <vollick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-11 23:10:40 +0000 |
commit | 2bf64a930e179a2bd11492e897df86869dd94bd0 (patch) | |
tree | fc983571c53936a2c7b27168b4184bae76538be7 /base | |
parent | e617613625f7a368c9f4c198affe473cfa4f2819 (diff) | |
download | chromium_src-2bf64a930e179a2bd11492e897df86869dd94bd0.zip chromium_src-2bf64a930e179a2bd11492e897df86869dd94bd0.tar.gz chromium_src-2bf64a930e179a2bd11492e897df86869dd94bd0.tar.bz2 |
Allow tracing to console everywhere.
This patch gets rid of the cc-only trace-to-vlog stuff and replaces it with a
general trace-to-console approach that can be used everywhere, even the
browser.
BUG=None
Review URL: https://chromiumcodereview.appspot.com/18174006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@211245 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/base_switches.cc | 3 | ||||
-rw-r--r-- | base/base_switches.h | 1 | ||||
-rw-r--r-- | base/command_line.cc | 5 | ||||
-rw-r--r-- | base/command_line.h | 3 | ||||
-rw-r--r-- | base/debug/trace_event_impl.cc | 63 | ||||
-rw-r--r-- | base/debug/trace_event_impl.h | 5 |
6 files changed, 66 insertions, 14 deletions
diff --git a/base/base_switches.cc b/base/base_switches.cc index 7c7b061..f0ac32b 100644 --- a/base/base_switches.cc +++ b/base/base_switches.cc @@ -46,4 +46,7 @@ const char kVModule[] = "vmodule"; // Will wait for 60 seconds for a debugger to come to attach to the process. const char kWaitForDebugger[] = "wait-for-debugger"; +// Sends a pretty-printed version of tracing info to the console. +const char kTraceToConsole[] = "trace-to-console"; + } // namespace switches diff --git a/base/base_switches.h b/base/base_switches.h index 558a5cf..464493a 100644 --- a/base/base_switches.h +++ b/base/base_switches.h @@ -18,6 +18,7 @@ extern const char kTestChildProcess[]; extern const char kV[]; extern const char kVModule[]; extern const char kWaitForDebugger[]; +extern const char kTraceToConsole[]; } // namespace switches diff --git a/base/command_line.cc b/base/command_line.cc index 7d137f26..36ac88f 100644 --- a/base/command_line.cc +++ b/base/command_line.cc @@ -201,6 +201,11 @@ CommandLine* CommandLine::ForCurrentProcess() { return current_process_commandline_; } +// static +bool CommandLine::InitializedForCurrentProcess() { + return !!current_process_commandline_; +} + #if defined(OS_WIN) // static CommandLine CommandLine::FromString(const std::wstring& command_line) { diff --git a/base/command_line.h b/base/command_line.h index aebda06..ed46c4f 100644 --- a/base/command_line.h +++ b/base/command_line.h @@ -72,6 +72,9 @@ class BASE_EXPORT CommandLine { // only mutate if you know what you're doing! static CommandLine* ForCurrentProcess(); + // Returns true if the CommandLine has been initialized for the given process. + static bool InitializedForCurrentProcess(); + #if defined(OS_WIN) static CommandLine FromString(const std::wstring& command_line); #endif diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc index af5591b..4d637cd 100644 --- a/base/debug/trace_event_impl.cc +++ b/base/debug/trace_event_impl.cc @@ -6,7 +6,9 @@ #include <algorithm> +#include "base/base_switches.h" #include "base/bind.h" +#include "base/command_line.h" #include "base/debug/leak_annotations.h" #include "base/debug/trace_event.h" #include "base/format_macros.h" @@ -535,6 +537,29 @@ void TraceEvent::AppendAsJSON(std::string* out) const { *out += "}"; } +void TraceEvent::AppendPrettyPrinted(std::ostringstream* out) const { + *out << name_ << "["; + *out << TraceLog::GetCategoryGroupName(category_group_enabled_); + *out << "]"; + if (arg_names_[0]) { + *out << ", {"; + for (int i = 0; i < kTraceMaxNumArgs && arg_names_[i]; ++i) { + if (i > 0) + *out << ", "; + *out << arg_names_[i] << ":"; + std::string value_as_text; + + if (arg_types_[i] == TRACE_VALUE_TYPE_CONVERTABLE) + convertable_values_[i]->AppendAsTraceFormat(&value_as_text); + else + AppendValueAsJSON(arg_types_[i], arg_values_[i], &value_as_text); + + *out << value_as_text; + } + *out << "}"; + } +} + //////////////////////////////////////////////////////////////////////////////// // // TraceResultBuffer @@ -798,6 +823,19 @@ TraceLog::TraceLog() SetProcessID(0); #else SetProcessID(static_cast<int>(GetCurrentProcId())); + + // NaCl also shouldn't access the command line. + if (CommandLine::InitializedForCurrentProcess() && + CommandLine::ForCurrentProcess()->HasSwitch(switches::kTraceToConsole)) { + std::string category_string = + CommandLine::ForCurrentProcess()->GetSwitchValueASCII( + switches::kTraceToConsole); + + if (category_string.empty()) + category_string = "*"; + + SetEnabled(CategoryFilter(category_string), ECHO_TO_CONSOLE); + } #endif logged_events_.reset(GetTraceBuffer()); @@ -1064,7 +1102,7 @@ void TraceLog::SetNotificationCallback( TraceBuffer* TraceLog::GetTraceBuffer() { if (trace_options_ & RECORD_CONTINUOUSLY) return new TraceBufferRingBuffer(); - else if (trace_options_ & ECHO_TO_VLOG) + else if (trace_options_ & ECHO_TO_CONSOLE) return new TraceBufferDiscardsEvents(); return new TraceBufferVector(); } @@ -1136,7 +1174,7 @@ void TraceLog::AddTraceEventWithThreadIdAndTimestamp( DCHECK(name); TimeDelta duration; - if (phase == TRACE_EVENT_PHASE_END && trace_options_ & ECHO_TO_VLOG) { + if (phase == TRACE_EVENT_PHASE_END && trace_options_ & ECHO_TO_CONSOLE) { duration = timestamp - thread_event_start_times_[thread_id].top(); thread_event_start_times_[thread_id].pop(); } @@ -1194,7 +1232,14 @@ void TraceLog::AddTraceEventWithThreadIdAndTimestamp( } } - if (trace_options_ & ECHO_TO_VLOG) { + TraceEvent trace_event(thread_id, + now, phase, category_group_enabled, name, id, + num_args, arg_names, arg_types, arg_values, + convertable_values, flags); + + logged_events_->AddEvent(trace_event); + + if (trace_options_ & ECHO_TO_CONSOLE) { 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; @@ -1212,19 +1257,13 @@ void TraceLog::AddTraceEventWithThreadIdAndTimestamp( for (size_t i = 0; i < depth; ++i) log << "| "; - log << base::StringPrintf("'%c', %s", phase, name); - + trace_event.AppendPrettyPrinted(&log); if (phase == TRACE_EVENT_PHASE_END) log << base::StringPrintf(" (%.3f ms)", duration.InMillisecondsF()); - VLOG(0) << log.str() << "\x1b[0;m"; + LOG(ERROR) << log.str() << "\x1b[0;m"; } - logged_events_->AddEvent(TraceEvent(thread_id, - now, phase, category_group_enabled, name, id, - num_args, arg_names, arg_types, arg_values, - convertable_values, flags)); - if (logged_events_->IsFull()) notifier.AddNotificationWhileLocked(TRACE_BUFFER_FULL); @@ -1232,7 +1271,7 @@ void TraceLog::AddTraceEventWithThreadIdAndTimestamp( notifier.AddNotificationWhileLocked(EVENT_WATCH_NOTIFICATION); } while (0); // release lock - if (phase == TRACE_EVENT_PHASE_BEGIN && trace_options_ & ECHO_TO_VLOG) + if (phase == TRACE_EVENT_PHASE_BEGIN && trace_options_ & ECHO_TO_CONSOLE) thread_event_start_times_[thread_id].push(timestamp); notifier.SendNotificationIfAny(); diff --git a/base/debug/trace_event_impl.h b/base/debug/trace_event_impl.h index c189b37..0449090b 100644 --- a/base/debug/trace_event_impl.h +++ b/base/debug/trace_event_impl.h @@ -101,6 +101,7 @@ class BASE_EXPORT TraceEvent { size_t count, std::string* out); void AppendAsJSON(std::string* out) const; + void AppendPrettyPrinted(std::ostringstream* out) const; static void AppendValueAsJSON(unsigned char type, TraceValue value, @@ -290,8 +291,8 @@ class BASE_EXPORT TraceLog { // Enable the sampling profiler. ENABLE_SAMPLING = 1 << 2, - // Echo to VLOG. Events are discared. - ECHO_TO_VLOG = 1 << 3 + // Echo to console. Events are discared. + ECHO_TO_CONSOLE = 1 << 3 }; static TraceLog* GetInstance(); |