Bug 1587332 - Encapsulate ActivePS::mProfileBuffer as a ProfileBuffer value - r=canaltinova

Having `mProfileBuffer` be a pointer is not really helpful:
- The pointer is never null (It's allocated on ActivePS construction, and
  implicitly deleted on ActivePS destruction); it's never moved-from.
- It requires an extra `new` and an extra `delete`.

Differential Revision: https://phabricator.services.mozilla.com/D48650

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Gerald Squelart 2019-10-10 10:52:09 +00:00
Родитель dff1750481
Коммит d24177fe2a
2 изменённых файлов: 26 добавлений и 30 удалений

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

@ -521,9 +521,8 @@ class ActivePS {
mInterval(aInterval),
mFeatures(AdjustFeatures(aFeatures, aFilterCount)),
// 8 bytes per entry.
mProfileBuffer(
MakeUnique<ProfileBuffer>(CorePS::CoreBlocksRingBuffer(),
PowerOfTwo32(aCapacity.Value() * 8))),
mProfileBuffer(CorePS::CoreBlocksRingBuffer(),
PowerOfTwo32(aCapacity.Value() * 8)),
// The new sampler thread doesn't start sampling immediately because the
// main loop within Run() is blocked until this function's caller
// unlocks gPSMutex.
@ -620,7 +619,7 @@ class ActivePS {
size_t n = aMallocSizeOf(sInstance);
n += sInstance->mProfileBuffer->SizeOfIncludingThis(aMallocSizeOf);
n += sInstance->mProfileBuffer.SizeOfIncludingThis(aMallocSizeOf);
// Measurement of the following members may be added later if DMD finds it
// is worthwhile:
@ -661,7 +660,7 @@ class ActivePS {
static ProfileBuffer& Buffer(PSLockRef) {
MOZ_ASSERT(sInstance);
return *sInstance->mProfileBuffer;
return sInstance->mProfileBuffer;
}
static const Vector<LiveProfiledThreadData>& LiveProfiledThreads(PSLockRef) {
@ -757,7 +756,7 @@ class ActivePS {
LiveProfiledThreadData& thread = sInstance->mLiveProfiledThreads[i];
if (thread.mRegisteredThread == aRegisteredThread) {
thread.mProfiledThreadData->NotifyUnregistered(
sInstance->mProfileBuffer->BufferRangeEnd());
sInstance->mProfileBuffer.BufferRangeEnd());
MOZ_RELEASE_ASSERT(sInstance->mDeadProfiledThreads.append(
std::move(thread.mProfiledThreadData)));
sInstance->mLiveProfiledThreads.erase(
@ -775,7 +774,7 @@ class ActivePS {
static void DiscardExpiredDeadProfiledThreads(PSLockRef) {
MOZ_ASSERT(sInstance);
uint64_t bufferRangeStart = sInstance->mProfileBuffer->BufferRangeStart();
uint64_t bufferRangeStart = sInstance->mProfileBuffer.BufferRangeStart();
// Discard any dead threads that were unregistered before bufferRangeStart.
sInstance->mDeadProfiledThreads.eraseIf(
[bufferRangeStart](
@ -795,7 +794,7 @@ class ActivePS {
for (size_t i = 0; i < registeredPages.length(); i++) {
RefPtr<PageInformation>& page = registeredPages[i];
if (page->InnerWindowID() == aRegisteredInnerWindowID) {
page->NotifyUnregistered(sInstance->mProfileBuffer->BufferRangeEnd());
page->NotifyUnregistered(sInstance->mProfileBuffer.BufferRangeEnd());
MOZ_RELEASE_ASSERT(
sInstance->mDeadProfiledPages.append(std::move(page)));
registeredPages.erase(&registeredPages[i--]);
@ -805,7 +804,7 @@ class ActivePS {
static void DiscardExpiredPages(PSLockRef) {
MOZ_ASSERT(sInstance);
uint64_t bufferRangeStart = sInstance->mProfileBuffer->BufferRangeStart();
uint64_t bufferRangeStart = sInstance->mProfileBuffer.BufferRangeStart();
// Discard any dead pages that were unregistered before
// bufferRangeStart.
sInstance->mDeadProfiledPages.eraseIf(
@ -825,7 +824,7 @@ class ActivePS {
static void ClearExpiredExitProfiles(PSLockRef) {
MOZ_ASSERT(sInstance);
uint64_t bufferRangeStart = sInstance->mProfileBuffer->BufferRangeStart();
uint64_t bufferRangeStart = sInstance->mProfileBuffer.BufferRangeStart();
// Discard exit profiles that were gathered before our buffer RangeStart.
sInstance->mExitProfiles.eraseIf(
[bufferRangeStart](const ExitProfile& aExitProfile) {
@ -838,8 +837,8 @@ class ActivePS {
ClearExpiredExitProfiles(aLock);
MOZ_RELEASE_ASSERT(sInstance->mExitProfiles.append(ExitProfile{
aExitProfile, sInstance->mProfileBuffer->BufferRangeEnd()}));
MOZ_RELEASE_ASSERT(sInstance->mExitProfiles.append(
ExitProfile{aExitProfile, sInstance->mProfileBuffer.BufferRangeEnd()}));
}
static Vector<std::string> MoveExitProfiles(PSLockRef aLock) {
@ -896,9 +895,8 @@ class ActivePS {
// Substrings of names of threads we want to profile.
Vector<std::string> mFilters;
// The buffer into which all samples are recorded. Always non-null. Always
// used in conjunction with CorePS::m{Live,Dead}Threads.
const UniquePtr<ProfileBuffer> mProfileBuffer;
// The buffer into which all samples are recorded.
ProfileBuffer mProfileBuffer;
// ProfiledThreadData objects for any threads that were profiled at any point
// during this run of the profiler:

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

@ -592,9 +592,8 @@ class ActivePS {
mInterval(aInterval),
mFeatures(AdjustFeatures(aFeatures, aFilterCount)),
// 8 bytes per entry.
mProfileBuffer(
MakeUnique<ProfileBuffer>(CorePS::CoreBlocksRingBuffer(),
PowerOfTwo32(aCapacity.Value() * 8))),
mProfileBuffer(CorePS::CoreBlocksRingBuffer(),
PowerOfTwo32(aCapacity.Value() * 8)),
// The new sampler thread doesn't start sampling immediately because the
// main loop within Run() is blocked until this function's caller
// unlocks gPSMutex.
@ -729,7 +728,7 @@ class ActivePS {
size_t n = aMallocSizeOf(sInstance);
n += sInstance->mProfileBuffer->SizeOfIncludingThis(aMallocSizeOf);
n += sInstance->mProfileBuffer.SizeOfIncludingThis(aMallocSizeOf);
// Measurement of the following members may be added later if DMD finds it
// is worthwhile:
@ -786,7 +785,7 @@ class ActivePS {
static ProfileBuffer& Buffer(PSLockRef) {
MOZ_ASSERT(sInstance);
return *sInstance->mProfileBuffer;
return sInstance->mProfileBuffer;
}
static const Vector<LiveProfiledThreadData>& LiveProfiledThreads(PSLockRef) {
@ -882,7 +881,7 @@ class ActivePS {
LiveProfiledThreadData& thread = sInstance->mLiveProfiledThreads[i];
if (thread.mRegisteredThread == aRegisteredThread) {
thread.mProfiledThreadData->NotifyUnregistered(
sInstance->mProfileBuffer->BufferRangeEnd());
sInstance->mProfileBuffer.BufferRangeEnd());
MOZ_RELEASE_ASSERT(sInstance->mDeadProfiledThreads.append(
std::move(thread.mProfiledThreadData)));
sInstance->mLiveProfiledThreads.erase(
@ -900,7 +899,7 @@ class ActivePS {
static void DiscardExpiredDeadProfiledThreads(PSLockRef) {
MOZ_ASSERT(sInstance);
uint64_t bufferRangeStart = sInstance->mProfileBuffer->BufferRangeStart();
uint64_t bufferRangeStart = sInstance->mProfileBuffer.BufferRangeStart();
// Discard any dead threads that were unregistered before bufferRangeStart.
sInstance->mDeadProfiledThreads.eraseIf(
[bufferRangeStart](
@ -920,7 +919,7 @@ class ActivePS {
for (size_t i = 0; i < registeredPages.length(); i++) {
RefPtr<PageInformation>& page = registeredPages[i];
if (page->InnerWindowID() == aRegisteredInnerWindowID) {
page->NotifyUnregistered(sInstance->mProfileBuffer->BufferRangeEnd());
page->NotifyUnregistered(sInstance->mProfileBuffer.BufferRangeEnd());
MOZ_RELEASE_ASSERT(
sInstance->mDeadProfiledPages.append(std::move(page)));
registeredPages.erase(&registeredPages[i--]);
@ -930,7 +929,7 @@ class ActivePS {
static void DiscardExpiredPages(PSLockRef) {
MOZ_ASSERT(sInstance);
uint64_t bufferRangeStart = sInstance->mProfileBuffer->BufferRangeStart();
uint64_t bufferRangeStart = sInstance->mProfileBuffer.BufferRangeStart();
// Discard any dead pages that were unregistered before
// bufferRangeStart.
sInstance->mDeadProfiledPages.eraseIf(
@ -984,7 +983,7 @@ class ActivePS {
static void ClearExpiredExitProfiles(PSLockRef) {
MOZ_ASSERT(sInstance);
uint64_t bufferRangeStart = sInstance->mProfileBuffer->BufferRangeStart();
uint64_t bufferRangeStart = sInstance->mProfileBuffer.BufferRangeStart();
// Discard exit profiles that were gathered before our buffer RangeStart.
#ifdef MOZ_BASE_PROFILER
if (bufferRangeStart != 0 && sInstance->mBaseProfileThreads) {
@ -1018,8 +1017,8 @@ class ActivePS {
ClearExpiredExitProfiles(aLock);
MOZ_RELEASE_ASSERT(sInstance->mExitProfiles.append(ExitProfile{
aExitProfile, sInstance->mProfileBuffer->BufferRangeEnd()}));
MOZ_RELEASE_ASSERT(sInstance->mExitProfiles.append(
ExitProfile{aExitProfile, sInstance->mProfileBuffer.BufferRangeEnd()}));
}
static Vector<nsCString> MoveExitProfiles(PSLockRef aLock) {
@ -1076,9 +1075,8 @@ class ActivePS {
// Substrings of names of threads we want to profile.
Vector<std::string> mFilters;
// The buffer into which all samples are recorded. Always non-null. Always
// used in conjunction with CorePS::m{Live,Dead}Threads.
const UniquePtr<ProfileBuffer> mProfileBuffer;
// The buffer into which all samples are recorded.
ProfileBuffer mProfileBuffer;
// ProfiledThreadData objects for any threads that were profiled at any point
// during this run of the profiler: