Bug 1777890 - Re-enable the chunk manager logic to limit the global profile buffer memory usage - r=canaltinova

Fix for a regression in bug 1668867, which removed this important line.
Without it, the logic that handles chunk manager updates doesn't run, and the
overall buffer size limit across processes is not enforced anymore.

To catch future regressions, the ProfileBufferGlobalController now adds its
creation timestamp to the profiling log, which can be tested.

Differential Revision: https://phabricator.services.mozilla.com/D150995
This commit is contained in:
Gerald Squelart 2022-07-06 10:01:46 +00:00
Родитель e1f9c7090a
Коммит 7618d829e2
2 изменённых файлов: 36 добавлений и 5 удалений

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

@ -24,6 +24,7 @@
#include "mozilla/Unused.h"
#include "nsTArray.h"
#include "nsThreadUtils.h"
#include "platform.h"
#include <utility>
@ -77,6 +78,10 @@ class ProfileBufferGlobalController final {
static bool IsLockedOnCurrentThread();
private:
// Calls aF(Json::Value&).
template <typename F>
void Log(F&& aF);
void HandleChunkManagerNonFinalUpdate(
base::ProcessId aProcessId,
ProfileBufferControlledChunkManager::Update&& aUpdate,
@ -196,17 +201,41 @@ class ProfilerParentTracker final {
Maybe<ProfileBufferGlobalController> mMaybeController;
};
static const Json::StaticString logRoot{"bufferGlobalController"};
template <typename F>
void ProfileBufferGlobalController::Log(F&& aF) {
ProfilingLog::Access([&](Json::Value& aLog) {
Json::Value& root = aLog[logRoot];
if (!root.isObject()) {
root = Json::Value(Json::objectValue);
root[Json::StaticString{"logBegin" TIMESTAMP_JSON_SUFFIX}] =
ProfilingLog::Timestamp();
}
std::forward<F>(aF)(root);
});
}
ProfileBufferGlobalController::ProfileBufferGlobalController(
size_t aMaximumBytes)
: mMaximumBytes(aMaximumBytes) {
MOZ_RELEASE_ASSERT(NS_IsMainThread());
Log([](Json::Value& aRoot) {
aRoot[Json::StaticString{"controllerCreationTime" TIMESTAMP_JSON_SUFFIX}] =
ProfilingLog::Timestamp();
});
// This is the local chunk manager for this parent process, so updates can be
// handled here.
ProfileBufferControlledChunkManager* parentChunkManager =
profiler_get_controlled_chunk_manager();
if (NS_WARN_IF(!parentChunkManager)) {
Log([](Json::Value& aRoot) {
aRoot[Json::StaticString{"controllerCreationFailureReason"}] =
"No parent chunk manager";
});
return;
}
@ -830,6 +859,8 @@ RefPtr<GenericPromise> ProfilerParent::ProfilerStarted(
}
aParams->GetActiveTabID(&ipcParams.activeTabID());
ProfilerParentTracker::ProfilerStarted(ipcParams.entries());
return SendAndConvertPromise([&](ProfilerParent* profilerParent) {
if (profiler::detail::FiltersExcludePid(
filtersCStrings,

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

@ -91,12 +91,12 @@ add_task(async function test_profile_fission_no_private_browsing() {
info("Check that the profiling logs exist with the expected properties.");
Assert.equal(typeof profile.profilingLog, "object");
Assert.equal(typeof profile.profilingLog[parentPid], "object");
const parentLog = profile.profilingLog[parentPid];
Assert.equal(typeof parentLog.profilingLogBegin_TSms, "number");
Assert.equal(typeof parentLog.profilingLogEnd_TSms, "number");
Assert.equal(typeof parentLog.bufferGlobalController, "object");
Assert.equal(
typeof profile.profilingLog[parentPid].profilingLogBegin_TSms,
"number"
);
Assert.equal(
typeof profile.profilingLog[parentPid].profilingLogEnd_TSms,
typeof parentLog.bufferGlobalController.controllerCreationTime_TSms,
"number"
);