From 11bcce27a9f7f047709abcd0075c587dea9ccf90 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Sat, 14 Mar 2020 11:33:46 +0000 Subject: [PATCH] Bug 1611053 - Add profiler marker for XPCJSContext::InterruptScript; r=gerald Differential Revision: https://phabricator.services.mozilla.com/D60792 --HG-- extra : moz-landing-system : lando --- js/xpconnect/src/XPCJSContext.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/js/xpconnect/src/XPCJSContext.cpp b/js/xpconnect/src/XPCJSContext.cpp index 7e4a14072903..2701cd0ed9b3 100644 --- a/js/xpconnect/src/XPCJSContext.cpp +++ b/js/xpconnect/src/XPCJSContext.cpp @@ -61,6 +61,9 @@ #include "nsIXULRuntime.h" #include "nsJSPrincipals.h" #include "ExpandedPrincipal.h" +#ifdef MOZ_GECKO_PROFILER +# include "ProfilerMarkerPayload.h" +#endif #if defined(XP_LINUX) && !defined(ANDROID) // For getrlimit and min/max. @@ -582,6 +585,21 @@ bool XPCJSContext::InterruptCallback(JSContext* cx) { // Now is a good time to turn on profiling if it's pending. PROFILER_JS_INTERRUPT_CALLBACK(); +#ifdef MOZ_GECKO_PROFILER + nsDependentCString filename("unknown file"); + JS::AutoFilename scriptFilename; + // Computing the line number can be very expensive (see bug 1330231 for + // example), so don't request it here. + if (JS::DescribeScriptedCaller(cx, &scriptFilename)) { + if (const char* file = scriptFilename.get()) { + filename.Assign(file, strlen(file)); + } + PROFILER_ADD_MARKER_WITH_PAYLOAD("JS::InterruptCallback", JS, + TextMarkerPayload, + (filename, TimeStamp::Now())); + } +#endif + // Normally we record mSlowScriptCheckpoint when we start to process an // event. However, we can run JS outside of event handlers. This code takes // care of that case.