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;
assert(QueryPerformanceFrequency(&units_per_second));
long long units_per_sample =
units_per_second.QuadPart / FACTOR_PROFILE_SAMPLES_PER_SECOND;
assert(QueryPerformanceCounter(&counter));
counter.QuadPart *= FACTOR_PROFILE_SAMPLES_PER_SECOND;
while (FACTOR_MEMORY_BARRIER(), sampling_profiler_p)
{
SwitchToThread();
assert(QueryPerformanceCounter(&new_counter));
new_counter.QuadPart *= FACTOR_PROFILE_SAMPLES_PER_SECOND;
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
++samples;
counter.QuadPart += units_per_sample;
counter.QuadPart += units_per_second.QuadPart;
}
if (samples > 0)
enqueue_safepoint_sample(samples, 0, false);