local root=assert(arg[1]) local P={release='test',Localized=function(a)return a end} local cvars={maxFPS='60',maxFPSBk='15'} RuenUIDB={optimizer={enabled=true,profiles={world={tier=2,calibrated=true}}}} C_CVar={GetCVar=function(k)return cvars[k]end,SetCVar=function()error('benchmark must not change graphics')end} function GetPhysicalScreenSize()return 1920,1080 end -- No frame creation, timer, expensive script profiler or idle work is allowed. local made={} function CreateFrame() local f={scripts={},events={}} function f:SetScript(k,v)self.scripts[k]=v end function f:RegisterEvent(e)self.events[e]=true end made[#made+1]=f;return f end local opaque={};function issecretvalue(v)return v==opaque end Enum={};APIDocumentation={AddDocumentationTable=function(_,d) for _,t in ipairs(d.Tables or {})do if t.Type=='Enumeration'then Enum[t.Name]={};for _,f in ipairs(t.Fields)do Enum[t.Name][f.Name]=f.EnumValue end end end end} dofile(assert(os.getenv('RUEN_NATIVE_UI'))..'/AddOnProfilerConstantsDocumentation.lua') local E=Enum.AddOnProfilerMetric local readings={[E.RecentAverageTime]=.1,[E.CountTimeOver1Ms]=70,[E.CountTimeOver5Ms]=50,[E.CountTimeOver10Ms]=20,[E.CountTimeOver50Ms]=10} local calls,topCalls=0,0 C_AddOnProfiler={IsEnabled=function()return true end, GetAddOnMetric=function(name,k)assert(name=='RuenUI');calls=calls+1;return readings[k]end, GetOverallMetric=function(k)assert(k==E.RecentAverageTime);return .4 end, GetTopKAddOnsForMetric=function(k,n)assert(k==E.RecentAverageTime and n==3);topCalls=topCalls+1;return {{addOnName='Other',metricValue=.3}}end} assert(loadfile(root..'FrameTiming.lua'))('RuenUI',P) assert(loadfile(root..'Benchmark.lua'))('RuenUI',P) assert(calls==0,'loading diagnostics started profiler work') local d=P.StartBenchmarkDiagnostics() for i=1,180 do readings[E.RecentAverageTime]=i<=90 and .1 or .3 P.SampleBenchmarkDiagnostics(d,i<=167 and 60 or 25) end local before=calls;P.SampleBenchmarkDiagnostics(d,25) assert(calls==before and #d.samples==180 and topCalls==13,'unbounded capture or top-addon scans') readings[E.CountTimeOver5Ms]=53 local message=P.FinishBenchmarkDiagnostics(d) assert(math.abs(d.sampledMeanMS-.2)<.0001 and d.maxSampledRecentMS==.3) assert(d.ticksOver.CountTimeOver5Ms==3 and not d.settingsChanged,'used whole-session slow count') assert(message:find('ticks over 5 ms: 3',1,true)) assert(d.samples[180].fps==25 and d.samples[180].allAddonsRecentMS==.4 and d.samples[180].topAddons) assert(d.release=='test' and d.settingsStart.width==1920) local changed=P.StartBenchmarkDiagnostics();cvars.maxFPS='72' P.FinishBenchmarkDiagnostics(changed);assert(changed.settingsChanged and changed.settingsStart.maxFPS=='60') -- Disabled/missing/restricted profiler never turns an FPS run into a Lua error -- or invents a zero-cost report. Reset counters do not become negative counts. for _,mode in ipairs({'disabled','missing','throws','opaque','nan'})do local api=C_AddOnProfiler if mode=='disabled'then C_AddOnProfiler={IsEnabled=function()return false end} elseif mode=='missing'then C_AddOnProfiler=nil elseif mode=='throws'then C_AddOnProfiler={GetAddOnMetric=function()error('unavailable')end} elseif mode=='opaque'then C_AddOnProfiler={GetAddOnMetric=function()return opaque end} else C_AddOnProfiler={GetAddOnMetric=function()return 0/0 end}end local no=P.StartBenchmarkDiagnostics();P.SampleBenchmarkDiagnostics(no,25) assert(P.FinishBenchmarkDiagnostics(no):find('unavailable') and not no.sampledMeanMS) C_AddOnProfiler=api end local reset=P.StartBenchmarkDiagnostics();readings[E.CountTimeOver5Ms]=1 P.FinishBenchmarkDiagnostics(reset);assert(reset.ticksOver.CountTimeOver5Ms==nil) print('PASS: bounded native profiler snapshots, per-benchmark slow-tick deltas, low-FPS attribution, graphics-change detection, unavailable/opaque data and no idle or graphics writes') -- Fast smoothed FPS with sparse visible freezes: the old once/second FPS -- sampling would pass, while frame recording must show their true duration. function time()return 123456 end function GetFramerate()return 60 end P.BenchmarkCommand('');local f=made[#made] assert(P.IsBenchmarkRunning()) local function frames(n,dt)for _=1,n do if f.scripts.OnUpdate then f.scripts.OnUpdate(f,dt)end end end frames(60,1/60) -- initial settling for i=1,11000 do frames(1,i%600==0 and .2 or 1/60)end assert(not P.IsBenchmarkRunning() and not f.scripts.OnUpdate) local report=RuenUIDB.reports[#RuenUIDB.reports] assert(report.over100>=17 and report.worstMS==200 and report.p99MS<18,'sub-second hitches disappeared') assert(report.low1FPS=50) assert(report.seconds<8 and not f.scripts.OnUpdate) P.IsOptimizerCalibrating=function()return true end P.BenchmarkCommand('');assert(not P.IsBenchmarkRunning()) P.IsOptimizerCalibrating=nil for i=1,7 do P.BenchmarkCommand('');frames(120,1/60);P.BenchmarkCommand('stop')end assert(#RuenUIDB.reports==5,'reports unbounded') -- Histogram tail definition and invalid frame guard. local sample=P.NewFrameSample() for i=1,99 do P.AddFrameSample(sample,.01)end P.AddFrameSample(sample,.2);P.AddFrameSample(sample,0);P.AddFrameSample(sample,math.huge) local summary=P.FrameSampleSummary(sample) assert(summary.frames==100 and summary.p99MS==10 and summary.low1FPS==5 and summary.over100==1) print('PASS: every-frame stutter capture despite smooth FPS, actual slowest-1% average, loading/pause exclusion, long stalls, bounded reports, benchmark/optimizer mutual exclusion and no idle frames')