vm: more accurate sample timing on windows

db4
Joe Groff 2011-10-31 16:59:10 -07:00
parent d9afe92c97
commit 1a665f3eac
1 changed files with 4 additions and 4 deletions

View File

@ -306,19 +306,19 @@ void factor_vm::sampler_thread_loop()
LARGE_INTEGER counter, new_counter, units_per_second; LARGE_INTEGER counter, new_counter, units_per_second;
assert(QueryPerformanceFrequency(&units_per_second)); assert(QueryPerformanceFrequency(&units_per_second));
long long units_per_sample =
units_per_second.QuadPart / FACTOR_PROFILE_SAMPLES_PER_SECOND;
assert(QueryPerformanceCounter(&counter)); assert(QueryPerformanceCounter(&counter));
counter.QuadPart *= FACTOR_PROFILE_SAMPLES_PER_SECOND;
while (FACTOR_MEMORY_BARRIER(), sampling_profiler_p) while (FACTOR_MEMORY_BARRIER(), sampling_profiler_p)
{ {
SwitchToThread(); SwitchToThread();
assert(QueryPerformanceCounter(&new_counter)); assert(QueryPerformanceCounter(&new_counter));
new_counter.QuadPart *= FACTOR_PROFILE_SAMPLES_PER_SECOND;
cell samples = 0; cell samples = 0;
while (new_counter.QuadPart - counter.QuadPart > units_per_sample) { while (new_counter.QuadPart - counter.QuadPart > units_per_second.QuadPart) {
// We would have to suspend the thread to sample the PC // We would have to suspend the thread to sample the PC
++samples; ++samples;
counter.QuadPart += units_per_sample; counter.QuadPart += units_per_second.QuadPart;
} }
if (samples > 0) if (samples > 0)
enqueue_safepoint_sample(samples, 0, false); enqueue_safepoint_sample(samples, 0, false);