Skip to content

Commit

Permalink
Saves profiler snapshots every 5 minutes (tgstation#83467) (#2168)
Browse files Browse the repository at this point in the history
## About The Pull Request
As the title says. Each saved snapshot will be named 
- `profiler-[TIME IN SECONDS].json`
- `sendmaps-[TIME IN SECONDS].json`

For example, `profiler-0.json`, `profiler-300.json`, `profiler-600.json`
would correspond to a profile at the start of the round, a profile 300
seconds into a round and a profile 600 seconds into a round.

The timings depend on world.time, so it's probably not a good idea to
rely on these timings to stay consistent.

## Why It's Good For The Game
Allows us to track performance of procs over time. Could allow us to
spot any sort of anomalies or performance sinks.

CC: @MrStonedOne @bobbah @LemonInTheDark

---------

Co-authored-by: Watermelon914 <37270891+Watermelon914@users.noreply.github.com>
Co-authored-by: Watermelon914 <3052169-Watermelon914@users.noreply.gitlab.com>
  • Loading branch information
3 people committed Jun 21, 2024
1 parent 0220641 commit 726368e
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions code/controllers/subsystem/profiler.dm
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#define PROFILER_FILENAME "profiler.json"
#define SENDMAPS_FILENAME "sendmaps.json"

SUBSYSTEM_DEF(profiler)
name = "Profiler"
init_order = INIT_ORDER_PROFILER
runlevels = RUNLEVELS_DEFAULT | RUNLEVEL_LOBBY
wait = 3000
wait = 300 SECONDS
var/fetch_cost = 0
var/write_cost = 0

Expand Down Expand Up @@ -49,12 +46,12 @@ SUBSYSTEM_DEF(profiler)

if(!length(current_profile_data)) //Would be nice to have explicit proc to check this
stack_trace("Warning, profiling stopped manually before dump.")
var/prof_file = file("[GLOB.log_directory]/[PROFILER_FILENAME]")
var/prof_file = file("[GLOB.log_directory]/profiler/profiler-[round(world.time * 0.1, 10)].json")
if(fexists(prof_file))
fdel(prof_file)
if(!length(current_sendmaps_data)) //Would be nice to have explicit proc to check this
stack_trace("Warning, sendmaps profiling stopped manually before dump.")
var/sendmaps_file = file("[GLOB.log_directory]/[SENDMAPS_FILENAME]")
var/sendmaps_file = file("[GLOB.log_directory]/profiler/sendmaps-[round(world.time * 0.1, 10)].json")
if(fexists(sendmaps_file))
fdel(sendmaps_file)

Expand All @@ -63,5 +60,3 @@ SUBSYSTEM_DEF(profiler)
WRITE_FILE(sendmaps_file, current_sendmaps_data)
write_cost = MC_AVERAGE(write_cost, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer))

#undef PROFILER_FILENAME
#undef SENDMAPS_FILENAME

0 comments on commit 726368e

Please sign in to comment.