diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /ipc/chromium/src/chrome/common/ipc_channel_utils.cc | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ipc/chromium/src/chrome/common/ipc_channel_utils.cc')
-rw-r--r-- | ipc/chromium/src/chrome/common/ipc_channel_utils.cc | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/ipc/chromium/src/chrome/common/ipc_channel_utils.cc b/ipc/chromium/src/chrome/common/ipc_channel_utils.cc new file mode 100644 index 0000000000..7e737762f3 --- /dev/null +++ b/ipc/chromium/src/chrome/common/ipc_channel_utils.cc @@ -0,0 +1,58 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "chrome/common/ipc_channel_utils.h" + +#include "mozilla/ProfilerMarkers.h" +#include "chrome/common/ipc_message.h" +#include "base/process.h" + +namespace IPC { + +void AddIPCProfilerMarker(const Message& aMessage, int32_t aOtherPid, + mozilla::ipc::MessageDirection aDirection, + mozilla::ipc::MessagePhase aPhase) { + if (aMessage.routing_id() != MSG_ROUTING_NONE && + profiler_feature_active(ProfilerFeature::IPCMessages)) { + if (static_cast<base::ProcessId>(aOtherPid) == base::kInvalidProcessId) { + DLOG(WARNING) << "Unable to record IPC profile marker, other PID not set"; + return; + } + + if (profiler_is_locked_on_current_thread()) { + // One of the profiler mutexes is locked on this thread, don't record + // markers, because we don't want to expose profiler IPCs due to the + // profiler itself, and also to avoid possible re-entrancy issues. + return; + } + + // The current timestamp must be given to the `IPCMarker` payload. + [[maybe_unused]] const mozilla::TimeStamp now = mozilla::TimeStamp::Now(); + bool isThreadBeingProfiled = + profiler_thread_is_being_profiled_for_markers(); + PROFILER_MARKER( + "IPC", IPC, + mozilla::MarkerOptions( + mozilla::MarkerTiming::InstantAt(now), + // If the thread is being profiled, add the marker to + // the current thread. If the thread is not being + // profiled, add the marker to the main thread. It will + // appear in the main thread's IPC track. Profiler + // analysis UI correlates all the IPC markers from + // different threads and generates processed markers. + isThreadBeingProfiled ? mozilla::MarkerThreadId::CurrentThread() + : mozilla::MarkerThreadId::MainThread()), + IPCMarker, now, now, aOtherPid, aMessage.seqno(), aMessage.type(), + mozilla::ipc::UnknownSide, aDirection, aPhase, aMessage.is_sync(), + // aOriginThreadId: If the thread is being profiled, do not include a + // thread ID, as it's the same as the markers. Only include this field + // when the marker is being sent from another thread. + isThreadBeingProfiled ? mozilla::MarkerThreadId{} + : mozilla::MarkerThreadId::CurrentThread()); + } +} + +} // namespace IPC |