57 lines
3.6 KiB
Lua
57 lines
3.6 KiB
Lua
|
|
local root=assert(arg[1])
|
||
|
|
local P={release='test'}
|
||
|
|
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.
|
||
|
|
function CreateFrame()error('benchmark must reuse the existing manual ticker')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..'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')
|