Skip to content

Commit

Permalink
Add simple trace logging of received IPC messages
Browse files Browse the repository at this point in the history
Adds an entry to chrome://tracing for processing IPC messages that includes the IPC message type ID (which can be matched to a name with the ipclist tool), and in DEBUG builds (or other builds where IPC_MESSAGE_LOG_ENABLED has been set), the message name.

Also adds shell_messages.h to the message generator headers (per the rules in ipc_message_macros.h) to fix broken IPC message logging.

BUG=79942
TEST=

Review URL: http://codereview.chromium.org/9389020

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121889 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
rbyers@chromium.org committed Feb 14, 2012
1 parent f1d34fd commit e7ca8dd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
6 changes: 4 additions & 2 deletions chrome/common/all_messages.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Multiply-included file, hence no include guard.
// Inclusion of all message files present in the system. Keep this file
// Inclusion of all message files present in chrome. Keep this file
// up-to-date when adding a new value to enum IPCMessageStart in
// ipc/ipc_message_utils.h to include the corresponding message file.
// Messages classes used exclusively outside of chrome should instead get an
// exemption in chrome/tools/ipclist/ipclist.cc.
#include "chrome/browser/importer/profile_import_process_messages.h"
// We can't make common_message_generator.h include automation_messages, since
// otherwise the Chrome Frame binaries will link in a lot of unrelated chrome
Expand Down
15 changes: 11 additions & 4 deletions chrome/tools/ipclist/ipclist.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -38,10 +38,11 @@ static bool check_msgtable() {
int highest_class_id = 0;
std::vector<int> exemptions;

// Exclude test files from consideration. Do not include message
// files used inside the actual chrome browser in this list.
// Exclude test and other non-browser files from consideration. Do not
// include message files used inside the actual chrome browser in this list.
exemptions.push_back(TestMsgStart);
exemptions.push_back(FirefoxImporterUnittestMsgStart);
exemptions.push_back(ShellMsgStart);

for (size_t i = 0; i < MSGTABLE_SIZE; ++i) {
int class_id = IPC_MESSAGE_ID_CLASS(msgtable[i].id);
Expand All @@ -64,9 +65,15 @@ static bool check_msgtable() {
highest_class_id = class_id;
}

if (LastIPCMsgStart > highest_class_id + 1) {
while (LastIPCMsgStart > highest_class_id + 1) {
std::vector<int>::iterator iter;
iter = find(exemptions.begin(), exemptions.end(), highest_class_id+1);
if (iter == exemptions.end()) {
std::cout << "Missing message file: gap before LastIPCMsgStart\n";
result = false;
break;
}
++highest_class_id;
}

if (!result)
Expand Down
15 changes: 13 additions & 2 deletions ipc/ipc_channel_proxy.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/debug/trace_event.h"
#include "base/location.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
Expand Down Expand Up @@ -238,13 +239,23 @@ void ChannelProxy::Context::AddFilter(MessageFilter* filter) {

// Called on the listener's thread
void ChannelProxy::Context::OnDispatchMessage(const Message& message) {
#ifdef IPC_MESSAGE_LOG_ENABLED
Logging* logger = Logging::GetInstance();
std::string name;
logger->GetMessageText(message.type(), &name, &message, NULL);
TRACE_EVENT1("task", "ChannelProxy::Context::OnDispatchMessage",
"name", name);
#else
TRACE_EVENT1("task", "ChannelProxy::Context::OnDispatchMessage",
"type", message.type());
#endif

if (!listener_)
return;

OnDispatchConnected();

#ifdef IPC_MESSAGE_LOG_ENABLED
Logging* logger = Logging::GetInstance();
if (message.type() == IPC_LOGGING_ID) {
logger->OnReceivedLoggingMessage(message);
return;
Expand Down

0 comments on commit e7ca8dd

Please sign in to comment.