Commit 7471bb63 authored by Nazım Can Altınova's avatar Nazım Can Altınova
Browse files

Bug 1758099 - Add the origin tid of the IPC markers if the thread is not being profiled r=gerald

parent 024c07a7
Loading
Loading
Loading
Loading
+21 −15
Original line number Diff line number Diff line
@@ -30,7 +30,10 @@ void AddIPCProfilerMarker(const Message& aMessage, int32_t aOtherPid,

    // The current timestamp must be given to the `IPCMarker` payload.
    [[maybe_unused]] const mozilla::TimeStamp now = mozilla::TimeStamp::Now();
    PROFILER_MARKER("IPC", IPC,
    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
@@ -39,12 +42,15 @@ void AddIPCProfilerMarker(const Message& aMessage, int32_t aOtherPid,
            // appear in the main thread's IPC track. Profiler
            // analysis UI correlates all the IPC markers from
            // different threads and generates processed markers.
                        profiler_thread_is_being_profiled_for_markers()
                            ? mozilla::MarkerThreadId::CurrentThread()
            isThreadBeingProfiled ? mozilla::MarkerThreadId::CurrentThread()
                                  : mozilla::MarkerThreadId::MainThread()),
                    IPCMarker, now, now, aOtherPid, aMessage.seqno(),
                    aMessage.type(), mozilla::ipc::UnknownSide, aDirection,
                    aPhase, aMessage.is_sync());
        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());
  }
}

+10 −4
Original line number Diff line number Diff line
@@ -2113,6 +2113,8 @@ void MessageChannel::AddProfilerMarker(const IPC::Message& aMessage,
        !profiler_is_locked_on_current_thread()) {
      // The current timestamp must be given to the `IPCMarker` payload.
      [[maybe_unused]] const TimeStamp now = TimeStamp::Now();
      bool isThreadBeingProfiled =
          profiler_thread_is_being_profiled_for_markers();
      PROFILER_MARKER(
          "IPC", IPC,
          mozilla::MarkerOptions(
@@ -2123,11 +2125,15 @@ void MessageChannel::AddProfilerMarker(const IPC::Message& aMessage,
              // will appear in the main thread's IPC track. Profiler analysis
              // UI correlates all the IPC markers from different threads and
              // generates processed markers.
              profiler_thread_is_being_profiled_for_markers()
                  ? mozilla::MarkerThreadId::CurrentThread()
              isThreadBeingProfiled ? mozilla::MarkerThreadId::CurrentThread()
                                    : mozilla::MarkerThreadId::MainThread()),
          IPCMarker, now, now, pid, aMessage.seqno(), aMessage.type(), mSide,
          aDirection, MessagePhase::Endpoint, aMessage.is_sync());
          aDirection, MessagePhase::Endpoint, 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());
    }
  }
}
+11 −1
Original line number Diff line number Diff line
@@ -718,7 +718,8 @@ struct IPCMarker {
      mozilla::TimeStamp aStart, mozilla::TimeStamp aEnd, int32_t aOtherPid,
      int32_t aMessageSeqno, IPC::Message::msgid_t aMessageType,
      mozilla::ipc::Side aSide, mozilla::ipc::MessageDirection aDirection,
      mozilla::ipc::MessagePhase aPhase, bool aSync) {
      mozilla::ipc::MessagePhase aPhase, bool aSync,
      mozilla::MarkerThreadId aOriginThreadId) {
    using namespace mozilla::ipc;
    // This payload still streams a startTime and endTime property because it
    // made the migration to MarkerTiming on the front-end easier.
@@ -737,6 +738,15 @@ struct IPCMarker {
                               : mozilla::MakeStringSpan("receiving"));
    aWriter.StringProperty("phase", IPCPhaseToString(aPhase));
    aWriter.BoolProperty("sync", aSync);
    if (!aOriginThreadId.IsUnspecified()) {
      // Tech note: If `ToNumber()` returns a uint64_t, the conversion to
      // int64_t is "implementation-defined" before C++20. This is acceptable
      // here, because this is a one-way conversion to a unique identifier
      // that's used to visually separate data by thread on the front-end.
      aWriter.IntProperty(
          "threadId",
          static_cast<int64_t>(aOriginThreadId.ThreadId().ToNumber()));
    }
  }
  static mozilla::MarkerSchema MarkerTypeDisplay() {
    return mozilla::MarkerSchema::SpecialFrontendLocation{};