Bug 1734867 - Allocate ProfilerBuffer's worker ChunkManager only when first needed - r=florian

Some ProfileBuffers are temporary and don't actually need this allocation.

Differential Revision: https://phabricator.services.mozilla.com/D133723
This commit is contained in:
Gerald Squelart 2021-12-16 11:06:28 +00:00
parent 4ea4986b93
commit 2b3ce6d818
4 changed files with 29 additions and 14 deletions

View File

@ -135,10 +135,17 @@ class ProfileBuffer final {
// - Adding JIT info.
// - Streaming stacks to JSON.
// Mutable because it's accessed from non-multithreaded const methods.
mutable ProfileBufferChunkManagerSingle mWorkerChunkManager{
ProfileBufferChunk::Create(
mutable Maybe<ProfileBufferChunkManagerSingle> mMaybeWorkerChunkManager;
ProfileBufferChunkManagerSingle& WorkerChunkManager() const {
if (mMaybeWorkerChunkManager.isNothing()) {
// Only actually allocate it on first use. (Some ProfileBuffers are
// temporary and don't actually need this.)
mMaybeWorkerChunkManager.emplace(
ProfileBufferChunk::SizeofChunkMetadata() +
ProfileBufferChunkManager::scExpectedMaximumStackSize)};
ProfileBufferChunkManager::scExpectedMaximumStackSize);
}
return *mMaybeWorkerChunkManager;
}
// Time from launch (us) when first sampling was recorded.
double mFirstSamplingTimeUs = 0.0;

View File

@ -1210,10 +1210,10 @@ bool ProfileBuffer::DuplicateLastSample(BaseProfilerThreadId aThreadId,
}
ProfileChunkedBuffer tempBuffer(
ProfileChunkedBuffer::ThreadSafety::WithoutMutex, mWorkerChunkManager);
ProfileChunkedBuffer::ThreadSafety::WithoutMutex, WorkerChunkManager());
auto retrieveWorkerChunk = MakeScopeExit(
[&]() { mWorkerChunkManager.Reset(tempBuffer.GetAllChunks()); });
[&]() { WorkerChunkManager().Reset(tempBuffer.GetAllChunks()); });
const bool ok = mEntries.Read([&](ProfileChunkedBuffer::Reader* aReader) {
MOZ_ASSERT(aReader,

View File

@ -178,10 +178,18 @@ class ProfileBuffer final {
// - Adding JIT info.
// - Streaming stacks to JSON.
// Mutable because it's accessed from non-multithreaded const methods.
mutable mozilla::ProfileBufferChunkManagerSingle mWorkerChunkManager{
mozilla::ProfileBufferChunk::Create(
mutable mozilla::Maybe<mozilla::ProfileBufferChunkManagerSingle>
mMaybeWorkerChunkManager;
mozilla::ProfileBufferChunkManagerSingle& WorkerChunkManager() const {
if (mMaybeWorkerChunkManager.isNothing()) {
// Only actually allocate it on first use. (Some ProfileBuffers are
// temporary and don't actually need this.)
mMaybeWorkerChunkManager.emplace(
mozilla::ProfileBufferChunk::SizeofChunkMetadata() +
mozilla::ProfileBufferChunkManager::scExpectedMaximumStackSize)};
mozilla::ProfileBufferChunkManager::scExpectedMaximumStackSize);
}
return *mMaybeWorkerChunkManager;
}
// GetStreamingParametersForThreadCallback:
// (ProfilerThreadId) -> Maybe<StreamingParametersForThread>

View File

@ -1184,7 +1184,7 @@ ProfilerThreadId ProfileBuffer::DoStreamSamplesAndMarkersToJSON(
if (kind == ProfileBufferEntry::Kind::CompactStack) {
ProfileChunkedBuffer tempBuffer(
ProfileChunkedBuffer::ThreadSafety::WithoutMutex,
mWorkerChunkManager);
WorkerChunkManager());
er.ReadIntoObject(tempBuffer);
tempBuffer.Read([&](ProfileChunkedBuffer::Reader* aReader) {
MOZ_ASSERT(aReader,
@ -1195,7 +1195,7 @@ ProfilerThreadId ProfileBuffer::DoStreamSamplesAndMarkersToJSON(
it.CurrentBlockIndex().ConvertToProfileBufferIndex(),
unresponsiveDuration, runningTimes);
});
mWorkerChunkManager.Reset(tempBuffer.GetAllChunks());
WorkerChunkManager().Reset(tempBuffer.GetAllChunks());
break;
}
@ -1394,7 +1394,7 @@ void ProfileBuffer::AddJITInfoForRange(uint64_t aRangeStart,
if (kind == ProfileBufferEntry::Kind::CompactStack) {
ProfileChunkedBuffer tempBuffer(
ProfileChunkedBuffer::ThreadSafety::WithoutMutex,
mWorkerChunkManager);
WorkerChunkManager());
er.ReadIntoObject(tempBuffer);
tempBuffer.Read([&](ProfileChunkedBuffer::Reader* aReader) {
MOZ_ASSERT(
@ -1408,7 +1408,7 @@ void ProfileBuffer::AddJITInfoForRange(uint64_t aRangeStart,
stackEntryGetter.Next();
}
});
mWorkerChunkManager.Reset(tempBuffer.GetAllChunks());
WorkerChunkManager().Reset(tempBuffer.GetAllChunks());
break;
}
@ -1939,10 +1939,10 @@ bool ProfileBuffer::DuplicateLastSample(ProfilerThreadId aThreadId,
AUTO_PROFILER_STATS(DuplicateLastSample_copy);
ProfileChunkedBuffer tempBuffer(
ProfileChunkedBuffer::ThreadSafety::WithoutMutex, mWorkerChunkManager);
ProfileChunkedBuffer::ThreadSafety::WithoutMutex, WorkerChunkManager());
auto retrieveWorkerChunk = MakeScopeExit(
[&]() { mWorkerChunkManager.Reset(tempBuffer.GetAllChunks()); });
[&]() { WorkerChunkManager().Reset(tempBuffer.GetAllChunks()); });
const bool ok = mEntries.Read([&](ProfileChunkedBuffer::Reader* aReader) {
MOZ_ASSERT(aReader,