Bug 1569506 - SamplerThread can own a Sampler instead of being one - r=canaltinova

`SamplerThread` inheriting from `Sampler` was a bit confusing, and scary with no
virtual destructor&functions.
`SamplerThread` only uses `Sampler`'s `Disable()` and
`SuspendAndSampleAndResumeThread()` functions, and `SamplerThread` is never
accessed through a `Sampler` reference/pointer.
So `SamplerThread` can just own a `Sampler` to make that relationship clearer.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Gerald Squelart 2019-07-31 01:28:49 +00:00
Родитель d1b58951a1
Коммит 68db1b82de
8 изменённых файлов: 26 добавлений и 20 удалений

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

@ -387,7 +387,7 @@ static void* ThreadEntry(void* aArg) {
SamplerThread::SamplerThread(PSLockRef aLock, uint32_t aActivityGeneration,
double aIntervalMilliseconds)
: Sampler(aLock),
: mSampler(aLock),
mActivityGeneration(aActivityGeneration),
mIntervalMicroseconds(
std::max(1, int(floor(aIntervalMilliseconds * 1000 + 0.5)))) {
@ -451,7 +451,7 @@ void SamplerThread::Stop(PSLockRef aLock) {
// though this SamplerThread is still alive, because the next time the main
// loop of Run() iterates it won't get past the mActivityGeneration check,
// and so won't send any signals.
Sampler::Disable(aLock);
mSampler.Disable(aLock);
}
// END SamplerThread target specifics

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

@ -153,7 +153,7 @@ static void* ThreadEntry(void* aArg) {
SamplerThread::SamplerThread(PSLockRef aLock, uint32_t aActivityGeneration,
double aIntervalMilliseconds)
: Sampler(aLock),
: mSampler(aLock),
mActivityGeneration(aActivityGeneration),
mIntervalMicroseconds(
std::max(1, int(floor(aIntervalMilliseconds * 1000 + 0.5)))),
@ -174,7 +174,7 @@ void SamplerThread::SleepMicro(uint32_t aMicroseconds) {
// case where the usleep call is interrupted by a signal.
}
void SamplerThread::Stop(PSLockRef aLock) { Sampler::Disable(aLock); }
void SamplerThread::Stop(PSLockRef aLock) { mSampler.Disable(aLock); }
// END SamplerThread target specifics
////////////////////////////////////////////////////////////////////////

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

@ -200,7 +200,7 @@ static unsigned int __stdcall ThreadEntry(void* aArg) {
SamplerThread::SamplerThread(PSLockRef aLock, uint32_t aActivityGeneration,
double aIntervalMilliseconds)
: Sampler(aLock),
: mSampler(aLock),
mActivityGeneration(aActivityGeneration),
mIntervalMicroseconds(
std::max(1, int(floor(aIntervalMilliseconds * 1000 + 0.5)))) {
@ -267,7 +267,7 @@ void SamplerThread::Stop(PSLockRef aLock) {
::timeEndPeriod(mIntervalMicroseconds / 1000);
}
Sampler::Disable(aLock);
mSampler.Disable(aLock);
}
// END SamplerThread target specifics

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

@ -983,8 +983,8 @@ class Registers {
void Clear() { memset(this, 0, sizeof(*this)); }
// These fields are filled in by
// SamplerThread::SuspendAndSampleAndResumeThread() for periodic and
// backtrace samples, and by SyncPopulate() for synchronous samples.
// Sampler::SuspendAndSampleAndResumeThread() for periodic and backtrace
// samples, and by SyncPopulate() for synchronous samples.
Address mPC; // Instruction pointer.
Address mSP; // Stack pointer.
Address mFP; // Frame pointer.
@ -1885,7 +1885,7 @@ class Sampler {
// active. It periodically runs through all registered threads, finds those
// that should be sampled, then pauses and samples them.
class SamplerThread : public Sampler {
class SamplerThread {
public:
// Creates a sampler thread, but doesn't start it.
SamplerThread(PSLockRef aLock, uint32_t aActivityGeneration,
@ -1903,6 +1903,9 @@ class SamplerThread : public Sampler {
// Best effort timing.
void SleepMicro(uint32_t aMicroseconds);
// The sampler used to suspend and sample threads.
Sampler mSampler;
// The activity generation, for detecting when the sampler thread must stop.
const uint32_t mActivityGeneration;
@ -2010,7 +2013,7 @@ void SamplerThread::Run() {
}
now = TimeStamp::NowUnfuzzed();
SuspendAndSampleAndResumeThread(
mSampler.SuspendAndSampleAndResumeThread(
lock, *registeredThread, [&](const Registers& aRegs) {
DoPeriodicSample(lock, *registeredThread, *profiledThreadData,
now, aRegs);

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

@ -378,7 +378,7 @@ static void* ThreadEntry(void* aArg) {
SamplerThread::SamplerThread(PSLockRef aLock, uint32_t aActivityGeneration,
double aIntervalMilliseconds)
: Sampler(aLock),
: mSampler(aLock),
mActivityGeneration(aActivityGeneration),
mIntervalMicroseconds(
std::max(1, int(floor(aIntervalMilliseconds * 1000 + 0.5)))) {
@ -442,7 +442,7 @@ void SamplerThread::Stop(PSLockRef aLock) {
// though this SamplerThread is still alive, because the next time the main
// loop of Run() iterates it won't get past the mActivityGeneration check,
// and so won't send any signals.
Sampler::Disable(aLock);
mSampler.Disable(aLock);
}
// END SamplerThread target specifics

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

@ -148,7 +148,7 @@ static void* ThreadEntry(void* aArg) {
SamplerThread::SamplerThread(PSLockRef aLock, uint32_t aActivityGeneration,
double aIntervalMilliseconds)
: Sampler(aLock),
: mSampler(aLock),
mActivityGeneration(aActivityGeneration),
mIntervalMicroseconds(
std::max(1, int(floor(aIntervalMilliseconds * 1000 + 0.5)))),
@ -169,7 +169,7 @@ void SamplerThread::SleepMicro(uint32_t aMicroseconds) {
// case where the usleep call is interrupted by a signal.
}
void SamplerThread::Stop(PSLockRef aLock) { Sampler::Disable(aLock); }
void SamplerThread::Stop(PSLockRef aLock) { mSampler.Disable(aLock); }
// END SamplerThread target specifics
////////////////////////////////////////////////////////////////////////

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

@ -185,7 +185,7 @@ static unsigned int __stdcall ThreadEntry(void* aArg) {
SamplerThread::SamplerThread(PSLockRef aLock, uint32_t aActivityGeneration,
double aIntervalMilliseconds)
: Sampler(aLock),
: mSampler(aLock),
mActivityGeneration(aActivityGeneration),
mIntervalMicroseconds(
std::max(1, int(floor(aIntervalMilliseconds * 1000 + 0.5)))) {
@ -252,7 +252,7 @@ void SamplerThread::Stop(PSLockRef aLock) {
::timeEndPeriod(mIntervalMicroseconds / 1000);
}
Sampler::Disable(aLock);
mSampler.Disable(aLock);
}
// END SamplerThread target specifics

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

@ -1083,8 +1083,8 @@ class Registers {
void Clear() { memset(this, 0, sizeof(*this)); }
// These fields are filled in by
// SamplerThread::SuspendAndSampleAndResumeThread() for periodic and
// backtrace samples, and by SyncPopulate() for synchronous samples.
// Sampler::SuspendAndSampleAndResumeThread() for periodic and backtrace
// samples, and by SyncPopulate() for synchronous samples.
Address mPC; // Instruction pointer.
Address mSP; // Stack pointer.
Address mFP; // Frame pointer.
@ -2431,7 +2431,7 @@ class Sampler {
// active. It periodically runs through all registered threads, finds those
// that should be sampled, then pauses and samples them.
class SamplerThread : public Sampler {
class SamplerThread {
public:
// Creates a sampler thread, but doesn't start it.
SamplerThread(PSLockRef aLock, uint32_t aActivityGeneration,
@ -2449,6 +2449,9 @@ class SamplerThread : public Sampler {
// Best effort timing.
void SleepMicro(uint32_t aMicroseconds);
// The sampler used to suspend and sample threads.
Sampler mSampler;
// The activity generation, for detecting when the sampler thread must stop.
const uint32_t mActivityGeneration;
@ -2578,7 +2581,7 @@ void SamplerThread::Run() {
}
now = TimeStamp::NowUnfuzzed();
SuspendAndSampleAndResumeThread(
mSampler.SuspendAndSampleAndResumeThread(
lock, *registeredThread, [&](const Registers& aRegs) {
DoPeriodicSample(lock, *registeredThread, *profiledThreadData,
now, aRegs);