Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1515214 - Add markers with cause stacks and the name of the calle…
Browse files Browse the repository at this point in the history
…d function for setTimeout callback execution. r=jesup

These duplicate the existing setTimeout markers a bit.

Differential Revision: https://phabricator.services.mozilla.com/D19194
  • Loading branch information
mstange committed Jul 10, 2019
1 parent 984e4fd commit 21217d8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
7 changes: 7 additions & 0 deletions dom/base/Timeout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ void Timeout::SetWhenOrTimeRemaining(const TimeStamp& aBaseTime,
MOZ_DIAGNOSTIC_ASSERT(mWindow);
mSubmitTime = aBaseTime;

mSubmitTime = aBaseTime;
#ifdef MOZ_GECKO_PROFILER
if (profiler_is_active()) {
mCause = profiler_get_backtrace();
}
#endif

// If we are frozen simply set mTimeRemaining to be the "time remaining" in
// the timeout (i.e., the interval itself). This will be used to create a
// new mWhen time when the window is thawed. The end effect is that time does
Expand Down
9 changes: 9 additions & 0 deletions dom/base/Timeout.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "mozilla/TimeStamp.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "GeckoProfiler.h"

class nsIEventTarget;
class nsIPrincipal;
Expand Down Expand Up @@ -50,6 +51,10 @@ class Timeout final : public LinkedListElement<RefPtr<Timeout>> {
// Can only be called when frozen.
const TimeDuration& TimeRemaining() const;

#ifdef MOZ_GECKO_PROFILER
UniqueProfilerBacktrace TakeProfilerBacktrace() { return std::move(mCause); }
#endif

private:
// mWhen and mTimeRemaining can't be in a union, sadly, because they
// have constructors.
Expand Down Expand Up @@ -82,6 +87,10 @@ class Timeout final : public LinkedListElement<RefPtr<Timeout>> {
// Interval
TimeDuration mInterval;

#ifdef MOZ_GECKO_PROFILER
UniqueProfilerBacktrace mCause;
#endif

// Returned as value of setTimeout()
uint32_t mTimeoutId;

Expand Down
40 changes: 34 additions & 6 deletions dom/base/nsGlobalWindowInner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5854,6 +5854,21 @@ int32_t nsGlobalWindowInner::SetTimeoutOrInterval(JSContext* aCx,
return result;
}

static const char* GetTimeoutReasonString(Timeout* aTimeout) {
switch (aTimeout->mReason) {
case Timeout::Reason::eTimeoutOrInterval:
if (aTimeout->mIsInterval) {
return "setInterval handler";
}
return "setTimeout handler";
case Timeout::Reason::eIdleCallbackTimeout:
return "setIdleCallback handler (timed out)";
default:
MOZ_CRASH("Unexpected enum value");
return "";
}
}

bool nsGlobalWindowInner::RunTimeoutHandler(Timeout* aTimeout,
nsIScriptContext* aScx) {
// Hold on to the timeout in case mExpr or mFunObj releases its
Expand Down Expand Up @@ -5881,12 +5896,25 @@ bool nsGlobalWindowInner::RunTimeoutHandler(Timeout* aTimeout,
TimeoutManager::SetNestingLevel(timeout->mNestingLevel);
}

const char* reason;
if (timeout->mIsInterval) {
reason = "setInterval handler";
} else {
reason = "setTimeout handler";
}
const char* reason = GetTimeoutReasonString(timeout);

#ifdef MOZ_GECKO_PROFILER
nsCOMPtr<nsIDocShell> docShell = GetDocShell();
nsCString str;
if (profiler_is_active()) {
TimeDuration originalInterval = timeout->When() - timeout->SubmitTime();
str.Append(reason);
str.Append(" with interval ");
str.AppendInt(int(originalInterval.ToMilliseconds()));
str.Append("ms: ");
nsCString handlerDescription;
timeout->mScriptHandler->GetDescription(handlerDescription);
str.Append(handlerDescription);
}
AUTO_PROFILER_TEXT_MARKER_DOCSHELL_CAUSE("setTimeout callback", str, JS,
docShell,
timeout->TakeProfilerBacktrace());
#endif

bool abortIntervalHandler;
{
Expand Down

0 comments on commit 21217d8

Please sign in to comment.