From e87b8d455eaaa9582dea042fe418e41688abad76 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 4 Aug 2019 01:37:04 +0200 Subject: [PATCH] Use Theil estimator randomized approximation. --- server/TracyView.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index c1b3c681..9a4fe24d 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -5294,31 +5295,34 @@ void View::DrawOptions() if( ImGui::Button( "Auto" ) ) #endif { - double gsum = 0; size_t lastidx = 0; - for( size_t j=0; j 0; j-- ) { if( timeline[j]->gpuEnd >= 0 ) { lastidx = j; - gsum += timeline[j]->gpuStart - timeline[j]->cpuStart; + break; } } - if( lastidx > 0 ) + + enum { NumSlopes = 10000 }; + std::random_device rd; + std::default_random_engine gen( rd() ); + std::uniform_int_distribution dist( 0, lastidx - 1 ); + float slopes[NumSlopes]; + size_t idx = 0; + do { - const double cavg = ( timeline[lastidx]->cpuStart + timeline.front()->cpuStart ) * 0.5; - const double gavg = gsum / double( lastidx ); - double cov = 0; - double var = 0; - for( size_t j=0; jcpuStart - cavg; - cov += csub * ( timeline[j]->gpuStart - timeline[j]->cpuStart - gavg ); - var += csub * csub; + slopes[idx++] = float( 1.0 - double( timeline[p1]->gpuStart - timeline[p0]->gpuStart ) / double( timeline[p1]->cpuStart - timeline[p0]->cpuStart ) ); } - const double beta = cov / var; - drift = int( 1000000000 * -beta ); } + while( idx < NumSlopes ); + std::sort( slopes, slopes+NumSlopes ); + drift = int( 1000000000 * -slopes[NumSlopes/2] ); } } ImGui::TreePop();