Skip to content

Commit

Permalink
Enclose IPC::Listener::OnMessageReceived with TRACE_EVENT_WITH_FLOW
Browse files Browse the repository at this point in the history
The trace-viewer recursively connects flow events when a previous event
contains the next event. That is useful when we want to track a series
of asynchronous events on chrome://tracing.
However, the trace event in IPC::ChannelReader::DispatchInputData did
not contain IPC::Listener::OnMessageReceived, which is the IPC handler,
and the tracing flow was disconnected here.

This CL extends the region of the IPC::ChannelReader::DispatchInputData
to enclose IPC::Listener::OnMessageReceived.

BUG=580902

Review URL: https://codereview.chromium.org/1840673002

Cr-Commit-Position: refs/heads/master@{#383667}
  • Loading branch information
tzik authored and Commit bot committed Mar 29, 2016
1 parent 95d170a commit 467662c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
45 changes: 27 additions & 18 deletions ipc/ipc_channel_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@
namespace IPC {
namespace internal {

#ifdef IPC_MESSAGE_LOG_ENABLED

namespace {
std::string GetMessageText(const Message& message) {
std::string name;
Logging::GetInstance()->GetMessageText(
message.type(), &name, &message, nullptr);
return name;
}
} // namespace

#define EMIT_TRACE_EVENT(message) \
TRACE_EVENT_WITH_FLOW1( \
"ipc,toplevel", "ChannelReader::DispatchInputData", \
(message).flags(), TRACE_EVENT_FLAG_FLOW_IN, "name", \
GetMessageText(message));
#else
#define EMIT_TRACE_EVENT(message) \
TRACE_EVENT_WITH_FLOW2("ipc,toplevel", "ChannelReader::DispatchInputData", \
(message).flags(), TRACE_EVENT_FLAG_FLOW_IN, "class", \
IPC_MESSAGE_ID_CLASS((message).type()), "line", \
IPC_MESSAGE_ID_LINE((message).type()));
#endif // IPC_MESSAGE_LOG_ENABLED

ChannelReader::ChannelReader(Listener* listener)
: listener_(listener),
max_input_buffer_size_(Channel::kMaximumReadBufferSize) {
Expand Down Expand Up @@ -74,7 +98,7 @@ void ChannelReader::CleanUp() {
}

void ChannelReader::DispatchMessage(Message* m) {
EmitLogBeforeDispatch(*m);
EMIT_TRACE_EVENT(*m);
listener_->OnMessageReceived(*m);
HandleDispatchError(*m);
}
Expand Down Expand Up @@ -167,7 +191,7 @@ bool ChannelReader::HandleTranslatedMessage(
const AttachmentIdVector& attachment_ids) {
// Immediately handle internal messages.
if (IsInternalMessage(*translated_message)) {
EmitLogBeforeDispatch(*translated_message);
EMIT_TRACE_EVENT(*translated_message);
HandleInternalMessage(*translated_message);
HandleDispatchError(*translated_message);
return true;
Expand All @@ -180,7 +204,7 @@ bool ChannelReader::HandleTranslatedMessage(
// Ideally, the log would have been emitted prior to dispatching the
// message, but that would require this class to know more about the
// internals of attachment brokering, which should be avoided.
EmitLogBeforeDispatch(*translated_message);
EMIT_TRACE_EVENT(*translated_message);
HandleDispatchError(*translated_message);
return true;
}
Expand Down Expand Up @@ -223,21 +247,6 @@ void ChannelReader::HandleDispatchError(const Message& message) {
listener_->OnBadMessageReceived(message);
}

void ChannelReader::EmitLogBeforeDispatch(const Message& message) {
#ifdef IPC_MESSAGE_LOG_ENABLED
std::string name;
Logging::GetInstance()->GetMessageText(message.type(), &name, &message, NULL);
TRACE_EVENT_WITH_FLOW1("ipc,toplevel", "ChannelReader::DispatchInputData",
message.flags(), TRACE_EVENT_FLAG_FLOW_IN, "name",
name);
#else
TRACE_EVENT_WITH_FLOW2("ipc,toplevel", "ChannelReader::DispatchInputData",
message.flags(), TRACE_EVENT_FLAG_FLOW_IN, "class",
IPC_MESSAGE_ID_CLASS(message.type()), "line",
IPC_MESSAGE_ID_LINE(message.type()));
#endif
}

bool ChannelReader::DispatchAttachmentBrokerMessage(const Message& message) {
#if USE_ATTACHMENT_BROKER
if (IsAttachmentBrokerEndpoint() && GetAttachmentBroker()) {
Expand Down
3 changes: 0 additions & 3 deletions ipc/ipc_channel_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ class IPC_EXPORT ChannelReader : public SupportsAttachmentBrokering,
// If there was a dispatch error, informs |listener_|.
void HandleDispatchError(const Message& message);

// Emits logging associated with a Message that is about to be dispatched.
void EmitLogBeforeDispatch(const Message& message);

// Attachment broker messages should be dispatched out of band, since there
// are no ordering restrictions on them, and they may be required to dispatch
// the messages waiting in |queued_messages_|.
Expand Down

0 comments on commit 467662c

Please sign in to comment.