Closed Bug 2065408 Opened 2 months ago Closed 2 months ago

Add profiler markers for shutdown phases in AdvanceShutdownPhaseInternal

Categories

(Core :: XPCOM, task)

task

Tracking

()

RESOLVED FIXED
156 Branch
Tracking Status
firefox156 --- fixed

People

(Reporter: jstutte, Assigned: jstutte)

References

Details

Attachments

(2 external files, 1 obsolete file)

AppShutdown::AdvanceShutdownPhaseInternal emits no profiler markers, so shutdown phases are only indirectly visible through the NotifyObservers marker of the topic each phase fires. That leaves two gaps:

  • XPCOMShutdownFinal and CCPostLastCycleCollection have no observer topic (nullptr in sPhaseObserverKeys), so they are entirely invisible in a profile.
  • The notification is only one part of the phase advance. The two NS_ProcessPendingEvents drains, MaybeFastShutdown and KillClearOnShutdown all run outside it, so runnables processed there show up in a profile with no enclosing context.

Add markers for:

  • AdvanceShutdownPhase - interval over the whole advance, text is the phase name
  • ShutdownDrainBeforePhase - the drain before the phase flips
  • KillClearOnShutdown - the ClearOnShutdown kill
  • ShutdownDrainAfterKillClearOnShutdown - the drain after it, with a captured stack
  • ShutdownDrainAfterNotification - the drain after the observer notification

Only the post-kill drain captures a stack, since that is where late runnables have caused crashes and where the cost is worth paying.

This is not just bookkeeping: in a local run KillClearOnShutdown accounts for 16.4ms of the 17.2ms XPCOMShutdown phase advance, which is currently invisible in profiles.

AdvanceShutdownPhaseInternal emits no profiler markers, so shutdown phases are
only indirectly visible through the NotifyObservers marker of the topic each
phase fires. XPCOMShutdownFinal and CCPostLastCycleCollection have no observer
topic at all, and the notification covers only a part of the phase advance: the
two NS_ProcessPendingEvents drains and KillClearOnShutdown run outside it, so
runnables processed there show up with no enclosing context.

Add an interval marker over the whole advance, plus one for each drain and for
KillClearOnShutdown, all carrying the phase name. Only the drain that follows
KillClearOnShutdown captures a stack, since that is where late runnables have
caused crashes.

Assignee: nobody → jstutte
Status: NEW → ASSIGNED

The existing "AsyncShutdown blocker" marker spans from the moment a blocker is
registered, which for most blockers is startup, so a profile shows a wall of
multi second intervals that say nothing about shutdown itself.

Stamp the time at which the barrier starts waiting for a blocker and emit a
second marker covering only that wait, so it is visible which blockers actually
delayed which phase.

KillClearOnShutdown walks a list of type erased observers, so a profile shows
the aggregate cost of a phase's clearing with no way to tell which entry is
responsible, and nothing at all about which entries are registered for a phase.

Record the calling function and line in ShutdownObserver and emit a marker
around each entry. std::source_location would be the natural fit but the build
sysroot still ships libstdc++ 10, so use the same builtins it is implemented
with, as dom/quota/CheckedUnsafePtr.h already does.

See Also: → 2065729
See Also: → 2065730

Comment on attachment 9629410 [details]
Bug 2065408 - Add a profiler marker per ClearOnShutdown entry. r?#xpcom-reviewers

Revision D320448 was moved to bug 2065730. Setting attachment 9629410 [details] to obsolete.

Attachment #9629410 - Attachment is obsolete: true

Bug 2055234 comment 16 is a case where the existing AsyncShutdown marker is misleading. I wonder if anybody actually needs this one.

See Also: → 2055234
Pushed by jstutte@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/15522dafef37 https://hg.mozilla.org/integration/autoland/rev/419a2e88ba65 Add profiler markers for shutdown phases. r=xpcom-reviewers,profiler-reviewers,nika,canova https://github.com/mozilla-firefox/firefox/commit/b14c9be11381 https://hg.mozilla.org/integration/autoland/rev/8d923a80f4e5 Add a profiler marker for the actual AsyncShutdown blocker wait. r=xpcom-reviewers,mccr8
Status: ASSIGNED → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 156 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: