Bug 1812368 - Truncate the URLs we are passing into profiler markers r=julienw

Differential Revision: https://phabricator.services.mozilla.com/D169053
This commit is contained in:
Nazım Can Altınova 2023-02-09 10:16:51 +00:00
parent 7abf0b4fd8
commit 3c14a0bff0
9 changed files with 35 additions and 36 deletions

View File

@ -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();

View File

@ -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()) {

View File

@ -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,

View File

@ -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);
}
}

View File

@ -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.

View File

@ -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;
@ -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
@ -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);

View File

@ -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.

View File

@ -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;

View File

@ -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));
}
}
@ -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));
}
}
@ -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,