Files
Diabolo/Demon_v0.19/performance_soak_tests.gd
T

71 lines
4.0 KiB
GDScript

extends RefCounted
var failures=0
func check(ok,label):
if not ok:failures+=1;push_error("PERFORMANCE SOAK: "+label)
func contact_probe(g):
g.set_process(false)
await g.get_tree().physics_frame;await g.get_tree().physics_frame
var subject=Node3D.new();g.add_child(subject)
for point in [Vector3(41.30359,0,-20.25188),Vector3(5.30359,0,-2.25188)]:
var samples=[]
for i in range(40):
subject.position=point
var start=Time.get_ticks_usec()
g.workshop.mesh_walking.move_actor(subject,Vector3(-.03,0,.02),.34,1.18)
samples.append(float(Time.get_ticks_usec()-start)/1000.0)
samples.sort()
print("SOAK_CONTACT ",point," median_ms=",samples[20]," p95_ms=",samples[38])
check(samples[38]<8.0,"known dense-maiden collision hotspot stays below 8 ms")
subject.queue_free();g.set_process(true)
func run(g):
await g.get_tree().create_timer(.3).timeout
g.start_game();g.reset_shift();g.game_started=true;g.paused=false;g.menu.show_page("")
DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_DISABLED);Engine.max_fps=0
var w=g.workshop;w.unlock=5;g.coins=50000;g.essence=5000
w.add_station(0,Vector3(0,0,-2));w.add_station(3,Vector3(4,0,-2));w.rebuild_nav()
var mode="queue"
for arg in OS.get_cmdline_user_args():
if arg.begins_with("--soak-mode="):mode=arg.get_slice("=",1)
if mode=="auto":
w.add_station(1,Vector3(8,0,-2));w.add_station(2,Vector3(0,0,3))
w.add_station(4,Vector3(4,0,3));w.add_station(5,Vector3(8,0,3));w.rebuild_nav()
for i in range(3):w.add_helper()
w.automation=true;g.development.xp=370
g.player.position=Vector3(-3,0,2.5);g.avatar.reset_gait();g.camera.size=20
await contact_probe(g)
g.set_meta("profile_life",true)
var start=Time.get_ticks_msec();var last=start;var times=[];var records=[]
var life=Vector3.ZERO;var soul_us=0.0;var workshop_us=0.0
var worst={"total_us":0}
while Time.get_ticks_msec()-start<65000:
g.set_meta("soul_cpu_us",0)
var tick=Time.get_ticks_usec()
await g.get_tree().process_frame;await RenderingServer.frame_post_draw
times.append(float(Time.get_ticks_usec()-tick)/1000)
life+=g.get_meta("life_profile",Vector3.ZERO)
var imp=g.get_meta("life_worst",{})
if imp.get("total_us",0)>worst.total_us:worst=imp
soul_us+=g.get_meta("soul_cpu_us",0);workshop_us+=g.get_meta("workshop_cpu_us",0)
if Time.get_ticks_msec()-last>=5000:
var count=times.size();times.sort()
var record={"seconds":(Time.get_ticks_msec()-start)/1000.0,"sim_time":g.time,"mode":mode,
"median_ms":times[count/2],"p95_ms":times[int(count*.95)],"max_ms":times.back(),
"soul_ms":soul_us/count/1000,"workshop_ms":workshop_us/count/1000,
"imp_activity_ms":life.x/count/1000,"imp_movement_ms":life.y/count/1000,"imp_gait_ms":life.z/count/1000,
"souls":g.souls.size(),"departures":w.losses.departures.size(),"burns":g.life.burns.size(),"done":g.done,
"nodes":Performance.get_monitor(Performance.OBJECT_NODE_COUNT),"objects":Performance.get_monitor(Performance.OBJECT_COUNT),
"video_mb":Performance.get_monitor(Performance.RENDER_VIDEO_MEM_USED)/1048576.0,
"draws":Performance.get_monitor(Performance.RENDER_TOTAL_DRAW_CALLS_IN_FRAME),"worst_imp":worst}
records.append(record);print("SOAK_PROFILE ",JSON.stringify(record))
last=Time.get_ticks_msec();times.clear();life=Vector3.ZERO;soul_us=0.0;workshop_us=0.0
worst={"total_us":0}
check(w.queue_load()<=7 and w.losses.departures.size()<=2,"queue/departures remain bounded")
for record in records:
if record.seconds>=30:check(record.median_ms<records[0].median_ms*2.5+8,"no sustained late frame-time collapse")
var capture_root="res://captures/performance-soak" if OS.has_feature("editor") else OS.get_executable_path().get_base_dir()+"/captures/performance-soak"
DirAccess.make_dir_recursive_absolute(capture_root)
var file=FileAccess.open(capture_root+"/"+mode+".json",FileAccess.WRITE)
file.store_string(JSON.stringify(records,"\t"));file.close()
print("PERFORMANCE SOAK ","PASSED" if failures==0 else "FAILED",": 65s of normal spawns, queue losses and real game frames; timings recorded")
g.get_tree().quit(1 if failures else 0)