ipc_channel_utils.cc (2701B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "chrome/common/ipc_channel_utils.h" 8 9 #include "mozilla/ProfilerMarkers.h" 10 #include "chrome/common/ipc_message.h" 11 #include "base/process.h" 12 13 namespace IPC { 14 15 void AddIPCProfilerMarker(const Message& aMessage, int32_t aOtherPid, 16 mozilla::ipc::MessageDirection aDirection, 17 mozilla::ipc::MessagePhase aPhase) { 18 if (aMessage.routing_id() != MSG_ROUTING_NONE && 19 profiler_feature_active(ProfilerFeature::IPCMessages)) { 20 if (static_cast<base::ProcessId>(aOtherPid) == base::kInvalidProcessId) { 21 DLOG(WARNING) << "Unable to record IPC profile marker, other PID not set"; 22 return; 23 } 24 25 if (profiler_is_locked_on_current_thread()) { 26 // One of the profiler mutexes is locked on this thread, don't record 27 // markers, because we don't want to expose profiler IPCs due to the 28 // profiler itself, and also to avoid possible re-entrancy issues. 29 return; 30 } 31 32 // The current timestamp must be given to the `IPCMarker` payload. 33 const mozilla::TimeStamp now = mozilla::TimeStamp::Now(); 34 bool isThreadBeingProfiled = 35 profiler_thread_is_being_profiled_for_markers(); 36 PROFILER_MARKER( 37 "IPC", IPC, 38 mozilla::MarkerOptions( 39 mozilla::MarkerTiming::InstantAt(now), 40 // If the thread is being profiled, add the marker to 41 // the current thread. If the thread is not being 42 // profiled, add the marker to the main thread. It will 43 // appear in the main thread's IPC track. Profiler 44 // analysis UI correlates all the IPC markers from 45 // different threads and generates processed markers. 46 isThreadBeingProfiled ? mozilla::MarkerThreadId::CurrentThread() 47 : mozilla::MarkerThreadId::MainThread()), 48 IPCMarker, now, now, aOtherPid, aMessage.seqno(), aMessage.type(), 49 mozilla::ipc::UnknownSide, aDirection, aPhase, aMessage.is_sync(), 50 // aOriginThreadId: If the thread is being profiled, do not include a 51 // thread ID, as it's the same as the markers. Only include this field 52 // when the marker is being sent from another thread. 53 isThreadBeingProfiled ? mozilla::MarkerThreadId{} 54 : mozilla::MarkerThreadId::CurrentThread()); 55 } 56 } 57 58 } // namespace IPC