diff options
author | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-12 04:00:08 +0000 |
---|---|---|
committer | agl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-12 04:00:08 +0000 |
commit | e707d5e60b2191d3ffde90edcbafc01d8d7f7590 (patch) | |
tree | b9d29f7a0667325481e68b00900812ec4c9f68fd /chrome/common/ipc_logging.cc | |
parent | 84dd17ec3f2b4ccd2bec330596bb1aa912ae78d7 (diff) | |
download | chromium_src-e707d5e60b2191d3ffde90edcbafc01d8d7f7590.zip chromium_src-e707d5e60b2191d3ffde90edcbafc01d8d7f7590.tar.gz chromium_src-e707d5e60b2191d3ffde90edcbafc01d8d7f7590.tar.bz2 |
POSIX: basic IPC logging
For the moment, we enable IPC logging with an environment variable
(CHROME_IPC_LOGGING) and log everything to stderr.
Review URL: http://codereview.chromium.org/20156
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9643 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/ipc_logging.cc')
-rw-r--r-- | chrome/common/ipc_logging.cc | 82 |
1 files changed, 60 insertions, 22 deletions
diff --git a/chrome/common/ipc_logging.cc b/chrome/common/ipc_logging.cc index c9874b7..6cb401f 100644 --- a/chrome/common/ipc_logging.cc +++ b/chrome/common/ipc_logging.cc @@ -4,17 +4,34 @@ #include "chrome/common/ipc_logging.h" +#if defined(OS_POSIX) +#ifdef IPC_MESSAGE_LOG_ENABLED +// This will cause render_messages.h etc to define ViewMsgLog and friends. +#define IPC_MESSAGE_MACROS_LOG_ENABLED +#endif +#endif + #include "base/command_line.h" #include "base/logging.h" #include "base/message_loop.h" #include "base/string_util.h" #include "base/thread.h" #include "base/time.h" +#include "base/waitable_event.h" +#include "base/waitable_event_watcher.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/ipc_sync_message.h" #include "chrome/common/ipc_message_utils.h" #include "chrome/common/render_messages.h" +#if defined(OS_WIN) +// TODO(port): These messages will need to be ported at some point #include "chrome/common/plugin_messages.h" +#endif + +#if defined(OS_POSIX) +#include "base/string_util.h" +#include <unistd.h> +#endif #ifdef IPC_MESSAGE_LOG_ENABLED @@ -41,14 +58,17 @@ Logging::Logging() : logging_event_on_(NULL), logging_event_off_(NULL), enabled_(false), - sender_(NULL), - consumer_(NULL), queue_invoke_later_pending_(false), - main_thread_(MessageLoop::current()) { + sender_(NULL), + main_thread_(MessageLoop::current()), + consumer_(NULL) { // Create an event for this browser instance that's set when logging is // enabled, so child processes can know when logging is enabled. - int browser_pid; +#if defined(OS_WIN) + // On Windows we have a couple of named events which switch logging on and + // off. + int browser_pid; const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); std::wstring process_type = parsed_command_line.GetSwitchValue(switches::kProcessType); @@ -63,18 +83,23 @@ Logging::Logging() } std::wstring event_name = GetEventName(browser_pid, true); - logging_event_on_ = CreateEvent(NULL, TRUE, FALSE, event_name.c_str()); + logging_event_on_.reset(new base::WaitableEvent( + CreateEvent(NULL, TRUE, FALSE, event_name.c_str()))); event_name = GetEventName(browser_pid, false); - logging_event_off_ = CreateEvent(NULL, TRUE, FALSE, event_name.c_str()); + logging_event_off_.reset(new base::WaitableEvent( + CreateEvent(NULL, TRUE, FALSE, event_name.c_str()))); RegisterWaitForEvent(true); +#elif defined(OS_POSIX) + if (getenv("CHROME_IPC_LOGGING")) + enabled_ = true; + SetLoggerFunctions(g_log_function_mapping); +#endif } Logging::~Logging() { watcher_.StopWatching(); - CloseHandle(logging_event_on_); - CloseHandle(logging_event_off_); } Logging* Logging::current() { @@ -84,11 +109,11 @@ Logging* Logging::current() { void Logging::RegisterWaitForEvent(bool enabled) { watcher_.StopWatching(); watcher_.StartWatching( - enabled ? logging_event_on_ : logging_event_off_, this); + enabled ? logging_event_on_.get() : logging_event_off_.get(), this); } -void Logging::OnObjectSignaled(HANDLE object) { - enabled_ = object == logging_event_on_; +void Logging::OnWaitableEventSignaled(base::WaitableEvent* event) { + enabled_ = event == logging_event_on_.get(); RegisterWaitForEvent(!enabled_); } @@ -96,9 +121,11 @@ void Logging::SetLoggerFunctions(LogFunction *functions) { log_function_mapping_ = functions; } +#if defined(OS_WIN) std::wstring Logging::GetEventName(bool enabled) { return current()->GetEventName(GetCurrentProcessId(), enabled); } +#endif std::wstring Logging::GetEventName(int browser_pid, bool enabled) { std::wstring result = StringPrintf(kLoggingEventName, browser_pid); @@ -111,17 +138,13 @@ void Logging::SetConsumer(Consumer* consumer) { } void Logging::Enable() { - ResetEvent(logging_event_off_); - SetEvent(logging_event_on_); + logging_event_off_->Reset(); + logging_event_on_->Signal(); } void Logging::Disable() { - ResetEvent(logging_event_on_); - SetEvent(logging_event_off_); -} - -inline bool Logging::Enabled() const { - return enabled_; + logging_event_on_->Reset(); + logging_event_off_->Signal(); } void Logging::OnSendLogs() { @@ -182,7 +205,11 @@ void Logging::OnPreDispatchMessage(const Message& message) { void Logging::OnPostDispatchMessage(const Message& message, const std::wstring& channel_id) { - if (!Enabled() || !message.sent_time() || message.dont_log()) + if (!Enabled() || +#if defined(OS_WIN) + !message.sent_time() || +#endif + message.dont_log()) return; LogData data; @@ -212,6 +239,7 @@ void Logging::GetMessageText(uint16 type, std::wstring* name, } void Logging::Log(const LogData& data) { +#if defined(OS_WIN) if (consumer_) { // We're in the browser process. consumer_->Log(data); @@ -226,6 +254,15 @@ void Logging::Log(const LogData& data) { } } } +#elif defined(OS_POSIX) + // On POSIX, for now, we just dump the log to stderr + fprintf(stderr, "ipc %s %d %s %s %s\n", + WideToUTF8(data.channel).c_str(), + data.type, + WideToUTF8(data.flags).c_str(), + WideToUTF8(data.message_name).c_str(), + WideToUTF8(data.params).c_str()); +#endif } void GenerateLogData(const std::wstring& channel, const Message& message, @@ -252,8 +289,8 @@ void GenerateLogData(const std::wstring& channel, const Message& message, if (message.is_reply_error()) flags += L"E"; - std::wstring params; - Logging::GetMessageText(message.type(), NULL, &message, ¶ms); + std::wstring params, message_name; + Logging::GetMessageText(message.type(), &message_name, &message, ¶ms); data->channel = channel; data->type = message.type(); @@ -262,6 +299,7 @@ void GenerateLogData(const std::wstring& channel, const Message& message, data->receive = message.received_time(); data->dispatch = Time::Now().ToInternalValue(); data->params = params; + data->message_name = message_name; } } |