Skip to content

Commit

Permalink
Bug 1812368 - Truncate the URLs we are passing into profiler markers …
Browse files Browse the repository at this point in the history
…r=julienw

Differential Revision: https://phabricator.services.mozilla.com/D169053
  • Loading branch information
canova committed Feb 9, 2023
1 parent 276ec9b commit 0d4c7d4
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 36 deletions.
5 changes: 3 additions & 2 deletions docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8035,8 +8035,9 @@ nsresult nsDocShell::CreateContentViewer(const nsACString& aContentType,
if (profiler_thread_is_being_profiled_for_markers()) {
nsCOMPtr<nsIURI> prinURI;
BasePrincipal::Cast(thisPrincipal)->GetURI(getter_AddRefs(prinURI));
nsPrintfCString marker("Iframe loaded in background: %s",
prinURI->GetSpecOrDefault().get());
nsPrintfCString marker(
"Iframe loaded in background: %s",
nsContentUtils::TruncatedURLForDisplay(prinURI).get());
PROFILER_MARKER_TEXT("Background Iframe", DOM, {}, marker);
}
SetBackgroundLoadIframe();
Expand Down
11 changes: 8 additions & 3 deletions dom/workers/Worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,14 @@ void Worker::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
return;
}

NS_ConvertUTF16toUTF8 nameOrScriptURL(mWorkerPrivate->WorkerName().IsEmpty()
? mWorkerPrivate->ScriptURL()
: mWorkerPrivate->WorkerName());
NS_ConvertUTF16toUTF8 nameOrScriptURL(
mWorkerPrivate->WorkerName().IsEmpty()
? Substring(
mWorkerPrivate->ScriptURL(), 0,
std::min(size_t(1024), mWorkerPrivate->ScriptURL().Length()))
: Substring(
mWorkerPrivate->WorkerName(), 0,
std::min(size_t(1024), mWorkerPrivate->WorkerName().Length())));
AUTO_PROFILER_MARKER_TEXT("Worker.postMessage", DOM, {}, nameOrScriptURL);
uint32_t flags = uint32_t(js::ProfilingStackFrame::Flags::RELEVANT_FOR_JS);
if (mWorkerPrivate->IsChromeWorker()) {
Expand Down
6 changes: 5 additions & 1 deletion dom/workers/WorkerScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,11 @@ void WorkerGlobalScope::ImportScripts(JSContext* aCx,
profiler_thread_is_being_profiled_for_markers()
? StringJoin(","_ns, aScriptURLs,
[](nsACString& dest, const auto& scriptUrl) {
AppendUTF16toUTF8(scriptUrl, dest);
AppendUTF16toUTF8(
Substring(
scriptUrl, 0,
std::min(size_t(128), scriptUrl.Length())),
dest);
})
: nsAutoCString{});
workerinternals::Load(mWorkerPrivate, std::move(stack), aScriptURLs,
Expand Down
6 changes: 2 additions & 4 deletions image/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,8 @@ class ImageResource : public Image {
if (self->mURI && profiler_thread_is_being_profiled_for_markers()) {
mStartTime = TimeStamp::Now();
static const size_t sMaxTruncatedLength = 1024;
self->mURI->GetSpec(mSpec);
if (mSpec.Length() >= sMaxTruncatedLength) {
mSpec.Truncate(sMaxTruncatedLength);
}
mSpec = nsContentUtils::TruncatedURLForDisplay(self->mURI,
sMaxTruncatedLength);
}
}

Expand Down
10 changes: 3 additions & 7 deletions image/ImageFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,9 @@ already_AddRefed<Image> ImageFactory::CreateImage(

if (profiler_thread_is_being_profiled_for_markers()) {
static const size_t sMaxTruncatedLength = 1024;
nsAutoCString spec;
aURI->GetSpec(spec);
if (spec.Length() >= sMaxTruncatedLength) {
spec.Truncate(sMaxTruncatedLength);
}
PROFILER_MARKER_TEXT("Image Load", GRAPHICS,
MarkerInnerWindowId(aInnerWindowId), spec);
PROFILER_MARKER_TEXT(
"Image Load", GRAPHICS, MarkerInnerWindowId(aInnerWindowId),
nsContentUtils::TruncatedURLForDisplay(aURI, sMaxTruncatedLength));
}

// Select the type of image to create based on MIME type.
Expand Down
12 changes: 4 additions & 8 deletions js/xpconnect/loader/mozJSModuleLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,18 +669,14 @@ JSObject* mozJSModuleLoader::GetSharedGlobal(JSContext* aCx) {
nsresult mozJSModuleLoader::LoadSingleModuleScript(
ComponentModuleLoader* aModuleLoader, JSContext* aCx,
JS::loader::ModuleLoadRequest* aRequest, MutableHandleScript aScriptOut) {
nsAutoCString spec;
nsresult rv = aRequest->mURI->GetSpec(spec);
NS_ENSURE_SUCCESS(rv, rv);

AUTO_PROFILER_MARKER_TEXT(
"ChromeUtils.importESModule static import", JS,
MarkerOptions(MarkerStack::Capture(),
MarkerInnerWindowIdFromJSContext(aCx)),
spec);
nsContentUtils::TruncatedURLForDisplay(aRequest->mURI));

ModuleLoaderInfo info(aRequest);
rv = info.EnsureResolvedURI();
nsresult rv = info.EnsureResolvedURI();
NS_ENSURE_SUCCESS(rv, rv);

nsCOMPtr<nsIFile> sourceFile;
Expand Down Expand Up @@ -1501,7 +1497,7 @@ nsresult mozJSModuleLoader::Import(JSContext* aCx, const nsACString& aLocation,
"ChromeUtils.import", JS,
MarkerOptions(MarkerStack::Capture(),
MarkerInnerWindowIdFromJSContext(aCx)),
aLocation);
Substring(aLocation, 0, std::min(size_t(128), aLocation.Length())));

// The JSM may already be ESM-ified, and in that case the load is expected
// to fail. Suppress the error message, the crash, and also the telemetry
Expand Down Expand Up @@ -1789,7 +1785,7 @@ nsresult mozJSModuleLoader::ImportESModule(
"ChromeUtils.importESModule", JS,
MarkerOptions(MarkerStack::Capture(),
MarkerInnerWindowIdFromJSContext(aCx)),
aLocation);
Substring(aLocation, 0, std::min(size_t(128), aLocation.Length())));

RootedObject globalObj(aCx, GetSharedGlobal(aCx));
NS_ENSURE_TRUE(globalObj, NS_ERROR_FAILURE);
Expand Down
6 changes: 4 additions & 2 deletions js/xpconnect/loader/mozJSSubScriptLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,14 @@ nsresult mozJSSubScriptLoader::DoLoadSubScriptWithOptions(
}

NS_LossyConvertUTF16toASCII asciiUrl(url);
const nsDependentCSubstring profilerUrl =
Substring(asciiUrl, 0, std::min(size_t(128), asciiUrl.Length()));
AUTO_PROFILER_LABEL_DYNAMIC_NSCSTRING_NONSENSITIVE(
"mozJSSubScriptLoader::DoLoadSubScriptWithOptions", OTHER, asciiUrl);
"mozJSSubScriptLoader::DoLoadSubScriptWithOptions", OTHER, profilerUrl);
AUTO_PROFILER_MARKER_TEXT("SubScript", JS,
MarkerOptions(MarkerStack::Capture(),
MarkerInnerWindowIdFromJSContext(cx)),
asciiUrl);
profilerUrl);

// Make sure to explicitly create the URI, since we'll need the
// canonicalized spec.
Expand Down
3 changes: 2 additions & 1 deletion layout/base/PresShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6361,7 +6361,8 @@ void PresShell::PaintInternal(nsView* aViewToPaint, PaintInternalFlags aFlags) {
uri = contentRoot->GetDocumentURI();
}
url = uri ? uri->GetSpecOrDefault() : "N/A"_ns;
AUTO_PROFILER_LABEL_DYNAMIC_NSCSTRING_RELEVANT_FOR_JS("Paint", GRAPHICS, url);
AUTO_PROFILER_LABEL_DYNAMIC_NSCSTRING_RELEVANT_FOR_JS(
"Paint", GRAPHICS, Substring(url, std::min(size_t(128), url.Length())));

Maybe<js::AutoAssertNoContentJS> nojs;

Expand Down
12 changes: 4 additions & 8 deletions layout/base/nsRefreshDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1544,14 +1544,12 @@ void nsRefreshDriver::AddImageRequest(imgIRequest* aRequest) {

if (profiler_thread_is_being_profiled_for_markers()) {
nsCOMPtr<nsIURI> uri = aRequest->GetURI();
nsAutoCString uristr;
uri->GetAsciiSpec(uristr);

PROFILER_MARKER_TEXT("Image Animation", GRAPHICS,
MarkerOptions(MarkerTiming::IntervalStart(),
MarkerInnerWindowIdFromDocShell(
GetDocShell(mPresContext))),
uristr);
nsContentUtils::TruncatedURLForDisplay(uri));
}
}

Expand All @@ -1568,14 +1566,12 @@ void nsRefreshDriver::RemoveImageRequest(imgIRequest* aRequest) {

if (removed && profiler_thread_is_being_profiled_for_markers()) {
nsCOMPtr<nsIURI> uri = aRequest->GetURI();
nsAutoCString uristr;
uri->GetAsciiSpec(uristr);

PROFILER_MARKER_TEXT("Image Animation", GRAPHICS,
MarkerOptions(MarkerTiming::IntervalEnd(),
MarkerInnerWindowIdFromDocShell(
GetDocShell(mPresContext))),
uristr);
nsContentUtils::TruncatedURLForDisplay(uri));
}
}

Expand Down Expand Up @@ -1758,8 +1754,8 @@ void nsRefreshDriver::EnsureTimerStarted(EnsureTimerStartedFlags aFlags) {
if (profiler_thread_is_being_profiled_for_markers()) {
nsCString text = "initial timer start "_ns;
if (mPresContext->Document()->GetDocumentURI()) {
text.Append(
mPresContext->Document()->GetDocumentURI()->GetSpecOrDefault());
text.Append(nsContentUtils::TruncatedURLForDisplay(
mPresContext->Document()->GetDocumentURI()));
}

PROFILER_MARKER_TEXT("nsRefreshDriver", LAYOUT,
Expand Down

0 comments on commit 0d4c7d4

Please sign in to comment.