Bug 1141283 - Compensate for stackwalk duration and sleep overhead when determining sampler sleep time. r=BenWa

This commit is contained in:
Markus Stange 2015-03-08 20:47:31 -04:00
parent 4ec89acaaf
commit 9e20b57aab
2 changed files with 24 additions and 9 deletions

View File

@ -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;
}

View File

@ -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));
}
}