diff options
author | jbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-04 23:08:09 +0000 |
---|---|---|
committer | jbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-04 23:08:09 +0000 |
commit | 2a2e3d67d14de8e39d97273b57b1a079f25f83fd (patch) | |
tree | f48671ba4129e290a70484421e4dce96823dbdf1 /ipc/ipc_message.cc | |
parent | fa2f1155fc8ba28621ca6a1ace002e30543f67e8 (diff) | |
download | chromium_src-2a2e3d67d14de8e39d97273b57b1a079f25f83fd.zip chromium_src-2a2e3d67d14de8e39d97273b57b1a079f25f83fd.tar.gz chromium_src-2a2e3d67d14de8e39d97273b57b1a079f25f83fd.tar.bz2 |
Add async trace events to trace progress of IPC messages
BUG=79942
Review URL: https://chromiumcodereview.appspot.com/10919023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154840 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc/ipc_message.cc')
-rw-r--r-- | ipc/ipc_message.cc | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/ipc/ipc_message.cc b/ipc/ipc_message.cc index 9908bc7..cf3a65e 100644 --- a/ipc/ipc_message.cc +++ b/ipc/ipc_message.cc @@ -4,6 +4,7 @@ #include "ipc/ipc_message.h" +#include "base/atomicops.h" #include "base/logging.h" #include "build/build_config.h" @@ -11,6 +12,26 @@ #include "ipc/file_descriptor_set_posix.h" #endif +namespace { + +base::subtle::Atomic32 g_ref_num = 0; + +// Create a reference number for identifying IPC messages in traces. The return +// values has the reference number stored in the upper 24 bits, leaving the low +// 8 bits set to 0 for use as flags. +inline uint32 GetRefNumUpper24() { + base::debug::TraceLog* trace_log = base::debug::TraceLog::GetInstance(); + int32 pid = trace_log ? trace_log->process_id() : 0; + int32 count = base::subtle::NoBarrier_AtomicIncrement(&g_ref_num, 1); + // The 24 bit hash is composed of 14 bits of the count and 10 bits of the + // Process ID. With the current trace event buffer cap, the 14-bit count did + // not appear to wrap during a trace. Note that it is not a big deal if + // collisions occur, as this is only used for debugging and trace analysis. + return ((pid << 14) | (count & 0x3fff)) << 8; +} + +} // namespace + namespace IPC { //------------------------------------------------------------------------------ @@ -20,7 +41,8 @@ Message::~Message() { Message::Message() : Pickle(sizeof(Header)) { - header()->routing = header()->type = header()->flags = 0; + header()->routing = header()->type = 0; + header()->flags = GetRefNumUpper24(); #if defined(OS_POSIX) header()->num_fds = 0; header()->pad = 0; @@ -32,7 +54,8 @@ Message::Message(int32 routing_id, uint32 type, PriorityValue priority) : Pickle(sizeof(Header)) { header()->routing = routing_id; header()->type = type; - header()->flags = priority; + DCHECK((priority & 0xffffff00) == 0); + header()->flags = priority | GetRefNumUpper24(); #if defined(OS_POSIX) header()->num_fds = 0; header()->pad = 0; |