Bug 1758643 - Preemptively discard child profiles that would add too much data - r=florian

Instead of throwing away the whole profile at the end if it's too big, we try
to keep as much data as possible, by only throwing away incoming child profiles
that would make the resulting combined full profile too big.

Differential Revision: https://phabricator.services.mozilla.com/D152026
This commit is contained in:
Gerald Squelart 2022-07-20 12:52:59 +00:00
Родитель 871abc7243
Коммит 06cccd124c
1 изменённых файлов: 31 добавлений и 3 удалений

Просмотреть файл

@ -47,6 +47,9 @@ using dom::Promise;
using std::string;
static constexpr size_t scLengthMax = size_t(JS::MaxStringLength);
// Used when trying to add more JSON data, to account for the extra space needed
// for the log and to close the profile.
static constexpr size_t scLengthAccumulationThreshold = scLengthMax - 16 * 1024;
NS_IMPL_ISUPPORTS(nsProfiler, nsIProfiler)
@ -1042,8 +1045,19 @@ void nsProfiler::GatheredOOPProfile(base::ProcessId aChildPid,
"Should always have a writer if mGathering is true");
if (!aProfile.IsEmpty()) {
// TODO: Remove PromiseFlatCString, see bug 1657033.
mWriter->Splice(PromiseFlatCString(aProfile));
if (mWriter->ChunkedWriteFunc().Length() + aProfile.Length() <
scLengthAccumulationThreshold) {
// TODO: Remove PromiseFlatCString, see bug 1657033.
mWriter->Splice(PromiseFlatCString(aProfile));
} else {
LogEvent([&](Json::Value& aEvent) {
aEvent.append(
Json::StaticString{"Discarded child profile that would make the "
"full profile too big, pid and size:"});
aEvent.append(Json::Value::UInt64(aChildPid));
aEvent.append(Json::Value::UInt64{aProfile.Length()});
});
}
}
if (PendingProfile* pendingProfile = GetPendingProfile(aChildPid);
@ -1154,7 +1168,21 @@ RefPtr<nsProfiler::GatheringPromise> nsProfiler::StartGathering(
!exitProfiles.empty()) {
for (auto& exitProfile : exitProfiles) {
if (!exitProfile.IsEmpty()) {
mWriter->Splice(exitProfile);
if (mWriter->ChunkedWriteFunc().Length() + exitProfile.Length() <
scLengthAccumulationThreshold) {
mWriter->Splice(exitProfile);
LogEvent([&](Json::Value& aEvent) {
aEvent.append(Json::StaticString{"Added exit profile with size:"});
aEvent.append(Json::Value::UInt64{exitProfile.Length()});
});
} else {
LogEvent([&](Json::Value& aEvent) {
aEvent.append(
Json::StaticString{"Discarded an exit profile that would make "
"the full profile too big, size:"});
aEvent.append(Json::Value::UInt64{exitProfile.Length()});
});
}
}
}