Skip to content

Commit 8251438

Browse files
Deep sendmaps profiling (tgstation#59581)
* Adds in support for basic send maps profiling, I'd still like to get something that tracks with the round a bit better, but we can worry about that later * Adds a debug verb that displays the sendmaps profiling page, as basic as it is * Define respect * Patches over an error where profiles would persist through rounds, somehow. Adds the maptick stuff to performance logging, so we can look at how things change over a short period of time
1 parent 27b7a93 commit 8251438

File tree

5 files changed

+121
-6
lines changed

5 files changed

+121
-6
lines changed

code/__DEFINES/_profile.dm

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#if DM_BUILD >= 1506
22
// We don't actually care about storing the output here, this is just an easy way to ensure the profile runs first.
3-
GLOBAL_REAL_VAR(world_init_profiler) = world.Profile(PROFILE_START)
3+
GLOBAL_REAL_VAR(world_init_profiler) = world.Profile(PROFILE_RESTART)
44
#endif

code/_compile_options.dm

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
#if DM_VERSION < 514 && DM_BUILD < 1540
6262
#define USE_EXTOOLS
6363
#endif
64+
//Log the full sendmaps profile on 514.1556+, any earlier and we get bugs or it not existing
65+
#if DM_VERSION >= 514 && DM_BUILD >= 1556
66+
#define SENDMAPS_PROFILE
67+
#endif
6468

6569
//Additional code for the above flags.
6670
#ifdef TESTING

code/controllers/subsystem/profiler.dm

+35-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#define PROFILER_FILENAME "profiler.json"
22

3+
#ifdef SENDMAPS_PROFILE
4+
#define SENDMAPS_FILENAME "sendmaps.json"
5+
GLOBAL_REAL_VAR(world_init_maptick_profiler) = world.Profile(PROFILE_RESTART, type = "sendmaps")
6+
#endif
7+
38
SUBSYSTEM_DEF(profiler)
49
name = "Profiler"
510
init_order = INIT_ORDER_PROFILER
@@ -27,6 +32,9 @@ SUBSYSTEM_DEF(profiler)
2732
/datum/controller/subsystem/profiler/Shutdown()
2833
if(CONFIG_GET(flag/auto_profile))
2934
DumpFile()
35+
#ifdef SENDMAPS_PROFILE
36+
world.Profile(PROFILE_CLEAR, type = "sendmaps")
37+
#endif
3038
return ..()
3139

3240
/datum/controller/subsystem/profiler/proc/StartProfiling()
@@ -35,11 +43,18 @@ SUBSYSTEM_DEF(profiler)
3543
CONFIG_SET(flag/auto_profile, FALSE)
3644
#else
3745
world.Profile(PROFILE_START)
46+
#ifdef SENDMAPS_PROFILE
47+
world.Profile(PROFILE_START, type = "sendmaps")
48+
#endif
49+
3850
#endif
3951

4052
/datum/controller/subsystem/profiler/proc/StopProfiling()
4153
#if DM_BUILD >= 1506
4254
world.Profile(PROFILE_STOP)
55+
#ifdef SENDMAPS_PROFILE
56+
world.Profile(PROFILE_STOP, type = "sendmaps")
57+
#endif
4358
#endif
4459

4560
/datum/controller/subsystem/profiler/proc/DumpFile()
@@ -48,15 +63,30 @@ SUBSYSTEM_DEF(profiler)
4863
CONFIG_SET(flag/auto_profile, FALSE)
4964
#else
5065
var/timer = TICK_USAGE_REAL
51-
var/current_profile_data = world.Profile(PROFILE_REFRESH,format="json")
66+
var/current_profile_data = world.Profile(PROFILE_REFRESH, format = "json")
67+
#ifdef SENDMAPS_PROFILE
68+
var/current_sendmaps_data = world.Profile(PROFILE_REFRESH, type = "sendmaps", format="json")
69+
#endif
5270
fetch_cost = MC_AVERAGE(fetch_cost, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer))
5371
CHECK_TICK
72+
5473
if(!length(current_profile_data)) //Would be nice to have explicit proc to check this
5574
stack_trace("Warning, profiling stopped manually before dump.")
56-
var/json_file = file("[GLOB.log_directory]/[PROFILER_FILENAME]")
57-
if(fexists(json_file))
58-
fdel(json_file)
75+
var/prof_file = file("[GLOB.log_directory]/[PROFILER_FILENAME]")
76+
if(fexists(prof_file))
77+
fdel(prof_file)
78+
#ifdef SENDMAPS_PROFILE
79+
if(!length(current_sendmaps_data)) //Would be nice to have explicit proc to check this
80+
stack_trace("Warning, sendmaps profiling stopped manually before dump.")
81+
var/sendmaps_file = file("[GLOB.log_directory]/[SENDMAPS_FILENAME]")
82+
if(fexists(sendmaps_file))
83+
fdel(sendmaps_file)
84+
#endif
85+
5986
timer = TICK_USAGE_REAL
60-
WRITE_FILE(json_file, current_profile_data)
87+
WRITE_FILE(prof_file, current_profile_data)
88+
#ifdef SENDMAPS_PROFILE
89+
WRITE_FILE(sendmaps_file, current_sendmaps_data)
90+
#endif
6191
write_cost = MC_AVERAGE(write_cost, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer))
6292
#endif

code/controllers/subsystem/time_track.dm

+70
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,45 @@ SUBSYSTEM_DEF(time_track)
1515
var/last_tick_realtime = 0
1616
var/last_tick_byond_time = 0
1717
var/last_tick_tickcount = 0
18+
#ifdef SENDMAPS_PROFILE
19+
var/list/sendmaps_names_map = list(
20+
"SendMaps" = "send_maps",
21+
"SendMaps: Initial housekeeping" = "initial_house",
22+
"SendMaps: Cleanup" = "cleanup",
23+
"SendMaps: Client loop" = "client_loop",
24+
"SendMaps: Per client" = "per_client",
25+
"SendMaps: Per client: Deleted images" = "deleted_images",
26+
"SendMaps: Per client: HUD update" = "hud_update",
27+
"SendMaps: Per client: Statpanel update" = "statpanel_update",
28+
"SendMaps: Per client: Map data" = "map_data",
29+
"SendMaps: Per client: Map data: Check eye position" = "check_eye_pos",
30+
"SendMaps: Per client: Map data: Update chunks" = "update_chunks",
31+
"SendMaps: Per client: Map data: Send turfmap updates" = "turfmap_updates",
32+
"SendMaps: Per client: Map data: Send changed turfs" = "changed_turfs",
33+
"SendMaps: Per client: Map data: Send turf chunk info" = "turf_chunk_info",
34+
"SendMaps: Per client: Map data: Send obj changes" = "obj_changes",
35+
"SendMaps: Per client: Map data: Send mob changes" = "mob_changes",
36+
"SendMaps: Per client: Map data: Send notable turf visual contents" = "send_turf_vis_conts",
37+
"SendMaps: Per client: Map data: Send pending animations" = "pending_animations",
38+
"SendMaps: Per client: Map data: Look for movable changes" = "look_for_movable_changes",
39+
"SendMaps: Per client: Map data: Look for movable changes: Check notable turf visual contents" = "check_turf_vis_conts",
40+
"SendMaps: Per client: Map data: Look for movable changes: Check HUD/image visual contents" = "check_hud/image_vis_contents",
41+
"SendMaps: Per client: Map data: Look for movable changes: Loop through turfs in range" = "turfs_in_range",
42+
"SendMaps: Per client: Map data: Look for movable changes: Movables examined" = "movables_examined",
43+
)
44+
#endif
1845

1946
/datum/controller/subsystem/time_track/Initialize(start_timeofday)
2047
. = ..()
2148
GLOB.perf_log = "[GLOB.log_directory]/perf-[GLOB.round_id ? GLOB.round_id : "NULL"]-[SSmapping.config?.map_name].csv"
49+
#ifdef SENDMAPS_PROFILE
50+
world.Profile(PROFILE_RESTART, type = "sendmaps")
51+
//Need to do the sendmaps stuff in its own file, since it works different then everything else
52+
var/list/sendmaps_shorthands = list()
53+
for(var/proper_name in sendmaps_names_map)
54+
sendmaps_shorthands += sendmaps_names_map[proper_name]
55+
sendmaps_shorthands += "[sendmaps_names_map[proper_name]]_count"
56+
#endif
2257
log_perf(
2358
list(
2459
"time",
@@ -42,7 +77,11 @@ SUBSYSTEM_DEF(time_track)
4277
"air_network_count",
4378
"air_delta_count",
4479
"air_superconductive_count"
80+
#ifdef SENDMAPS_PROFILE
81+
) + sendmaps_shorthands
82+
#else
4583
)
84+
#endif
4685
)
4786

4887
/datum/controller/subsystem/time_track/fire()
@@ -65,6 +104,21 @@ SUBSYSTEM_DEF(time_track)
65104
last_tick_realtime = current_realtime
66105
last_tick_byond_time = current_byondtime
67106
last_tick_tickcount = current_tickcount
107+
108+
#ifdef SENDMAPS_PROFILE
109+
var/sendmaps_json = world.Profile(PROFILE_REFRESH, type = "sendmaps", format="json")
110+
var/list/send_maps_data = json_decode(sendmaps_json)
111+
var/send_maps_sort = send_maps_data.Copy() //Doing it like this guarentees us a properly sorted list
112+
113+
for(var/list/packet in send_maps_data)
114+
send_maps_sort[packet["name"]] = packet
115+
116+
var/list/send_maps_values = list()
117+
for(var/list/packet in send_maps_sort)
118+
send_maps_values += packet["value"]
119+
send_maps_values += packet["calls"]
120+
#endif
121+
68122
SSblackbox.record_feedback("associative", "time_dilation_current", 1, list("[SQLtime()]" = list("current" = "[time_dilation_current]", "avg_fast" = "[time_dilation_avg_fast]", "avg" = "[time_dilation_avg]", "avg_slow" = "[time_dilation_avg_slow]")))
69123
log_perf(
70124
list(
@@ -89,5 +143,21 @@ SUBSYSTEM_DEF(time_track)
89143
length(SSair.networks),
90144
length(SSair.high_pressure_delta),
91145
length(SSair.active_super_conductivity)
146+
#ifdef SENDMAPS_PROFILE
147+
) + send_maps_values
148+
#else
92149
)
150+
#endif
93151
)
152+
153+
#ifdef SENDMAPS_PROFILE
154+
/datum/controller/subsystem/time_track/proc/scream_maptick_data()
155+
var/current_profile_data = world.Profile(PROFILE_REFRESH, type = "sendmaps", format="json")
156+
log_world(current_profile_data)
157+
current_profile_data = json_decode(current_profile_data)
158+
var/output = ""
159+
for(var/list/entry in current_profile_data)
160+
output += "[entry["name"]],[entry["value"]],[entry["calls"]]\n"
161+
log_world(output)
162+
return output
163+
#endif

code/modules/admin/admin_verbs.dm

+11
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ GLOBAL_PROTECT(admin_verbs_debug)
183183
/client/proc/export_dynamic_json,
184184
/client/proc/run_dynamic_simulations,
185185
#endif
186+
#ifdef SENDMAPS_PROFILE
187+
/client/proc/display_sendmaps,
188+
#endif
186189
/datum/admins/proc/create_or_modify_area,
187190
/client/proc/check_timer_sources,
188191
/client/proc/toggle_cdn,
@@ -810,3 +813,11 @@ GLOBAL_PROTECT(admin_verbs_hideable)
810813

811814
var/datum/admins/admin = GLOB.admin_datums[ckey]
812815
admin?.associate(src)
816+
817+
#ifdef SENDMAPS_PROFILE
818+
/client/proc/display_sendmaps()
819+
set name = "Send Maps Profile"
820+
set category = "Debug"
821+
822+
src << link("?debug=profile&type=sendmaps&window=test")
823+
#endif

0 commit comments

Comments
 (0)