mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-28 05:10:49 +00:00
Bug 1141283 - Compensate for stackwalk duration and sleep overhead when determining sampler sleep time. r=BenWa
This commit is contained in:
parent
4ec89acaaf
commit
9e20b57aab
@ -68,6 +68,7 @@
|
||||
#include "mozilla/Mutex.h"
|
||||
#include "mozilla/Atomics.h"
|
||||
#include "mozilla/LinuxSignal.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
#include "ProfileEntry.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "TableTicker.h"
|
||||
@ -101,6 +102,8 @@ pid_t gettid()
|
||||
}
|
||||
#endif
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
/* static */ Thread::tid_t
|
||||
Thread::GetCurrentId()
|
||||
{
|
||||
@ -292,7 +295,10 @@ static void* SignalSender(void* arg) {
|
||||
|
||||
int vm_tgid_ = getpid();
|
||||
|
||||
TimeDuration lastSleepOverhead = 0;
|
||||
TimeStamp sampleStart = TimeStamp::Now();
|
||||
while (SamplerRegistry::sampler->IsActive()) {
|
||||
|
||||
SamplerRegistry::sampler->HandleSaveRequest();
|
||||
SamplerRegistry::sampler->DeleteExpiredMarkers();
|
||||
|
||||
@ -345,14 +351,13 @@ static void* SignalSender(void* arg) {
|
||||
}
|
||||
}
|
||||
|
||||
// Convert ms to us and subtract 100 us to compensate delays
|
||||
// occuring during signal delivery.
|
||||
// TODO measure and confirm this.
|
||||
int interval = floor(SamplerRegistry::sampler->interval() * 1000 + 0.5) - 100;
|
||||
if (interval <= 0) {
|
||||
interval = 1;
|
||||
}
|
||||
OS::SleepMicro(interval);
|
||||
TimeStamp targetSleepEndTime = sampleStart + TimeDuration::FromMicroseconds(SamplerRegistry::sampler->interval() * 1000);
|
||||
TimeStamp beforeSleep = TimeStamp::Now();
|
||||
TimeDuration targetSleepDuration = targetSleepEndTime - beforeSleep;
|
||||
double sleepTime = std::max(0.0, (targetSleepDuration - lastSleepOverhead).ToMicroseconds());
|
||||
OS::SleepMicro(sleepTime);
|
||||
sampleStart = TimeStamp::Now();
|
||||
lastSleepOverhead = sampleStart - (beforeSleep + TimeDuration::FromMicroseconds(sleepTime));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "platform.h"
|
||||
#include "TableTicker.h"
|
||||
#include "UnwinderThread2.h" /* uwt__register_thread_for_profiling */
|
||||
#include "mozilla/TimeStamp.h"
|
||||
|
||||
// Memory profile
|
||||
#include "nsMemoryReporterManager.h"
|
||||
@ -202,6 +203,8 @@ class SamplerThread : public Thread {
|
||||
|
||||
// Implement Thread::Run().
|
||||
virtual void Run() {
|
||||
TimeDuration lastSleepOverhead = 0;
|
||||
TimeStamp sampleStart = TimeStamp::Now();
|
||||
while (SamplerRegistry::sampler->IsActive()) {
|
||||
SamplerRegistry::sampler->DeleteExpiredMarkers();
|
||||
if (!SamplerRegistry::sampler->IsPaused()) {
|
||||
@ -231,7 +234,14 @@ class SamplerThread : public Thread {
|
||||
isFirstProfiledThread = false;
|
||||
}
|
||||
}
|
||||
OS::SleepMicro(intervalMicro_);
|
||||
|
||||
TimeStamp targetSleepEndTime = sampleStart + TimeDuration::FromMicroseconds(intervalMicro_);
|
||||
TimeStamp beforeSleep = TimeStamp::Now();
|
||||
TimeDuration targetSleepDuration = targetSleepEndTime - beforeSleep;
|
||||
double sleepTime = std::max(0.0, (targetSleepDuration - lastSleepOverhead).ToMicroseconds());
|
||||
OS::SleepMicro(sleepTime);
|
||||
sampleStart = TimeStamp::Now();
|
||||
lastSleepOverhead = sampleStart - (beforeSleep + TimeDuration::FromMicroseconds(sleepTime));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user