-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Profiler logs now sort by overtime and have a proper timestamp in the…
… filename (#3588)
- Loading branch information
Showing
7 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#define INIT_PROFILE_NAME "init_profiler.json" | ||
|
||
///Subsystem exists so we can separately log init time costs from the costs of general operation | ||
///Hopefully this makes sorting out what causes problems when easier | ||
SUBSYSTEM_DEF(init_profiler) | ||
name = "Init Profiler" | ||
init_order = INIT_ORDER_INIT_PROFILER | ||
init_stage = INITSTAGE_MAX | ||
flags = SS_NO_FIRE | ||
|
||
/datum/controller/subsystem/init_profiler/Initialize() | ||
if(CONFIG_GET(flag/auto_profile)) | ||
write_init_profile() | ||
return SS_INIT_SUCCESS | ||
return SS_INIT_NO_NEED | ||
|
||
/datum/controller/subsystem/init_profiler/proc/write_init_profile() | ||
var/list/current_profile_data = world.Profile(PROFILE_REFRESH, format = "json") | ||
current_profile_data = json_decode(current_profile_data) // yes this is stupid but this gets us a list in a non-awful format | ||
CHECK_TICK | ||
sortTim(current_profile_data, GLOBAL_PROC_REF(sort_overtime_dsc)) | ||
|
||
if(!length(current_profile_data)) //Would be nice to have explicit proc to check this | ||
stack_trace("Warning, profiling stopped manually before dump.") | ||
rustg_file_write(json_encode(current_profile_data), "[GLOB.log_directory]/[INIT_PROFILE_NAME]") | ||
world.Profile(PROFILE_CLEAR) //Now that we're written this data out, dump it. We don't want it getting mixed up with our current round data | ||
|
||
#undef INIT_PROFILE_NAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/datum/controller/subsystem/profiler | ||
var/sort_cost = 0 | ||
|
||
/datum/controller/subsystem/profiler/stat_entry(msg) | ||
msg += "F:[round(fetch_cost, 1)]ms" | ||
msg += "|S:[round(sort_cost, 1)]ms" | ||
msg += "|W:[round(write_cost, 1)]ms" | ||
return msg | ||
|
||
/datum/controller/subsystem/profiler/proc/DumpFile() | ||
var/timer = TICK_USAGE_REAL | ||
var/list/current_profile_data = world.Profile(PROFILE_REFRESH, format = "json") | ||
current_profile_data = json_decode(current_profile_data) // yes this is stupid but this gets us a list in a non-awful format | ||
var/current_sendmaps_data = world.Profile(PROFILE_REFRESH, type = "sendmaps", format = "json") | ||
fetch_cost = MC_AVERAGE(fetch_cost, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer)) | ||
CHECK_TICK | ||
|
||
if(!length(current_profile_data)) //Would be nice to have explicit proc to check this | ||
stack_trace("Warning, profiling stopped manually before dump.") | ||
|
||
timer = TICK_USAGE_REAL | ||
sortTim(current_profile_data, GLOBAL_PROC_REF(sort_overtime_dsc)) | ||
sort_cost = MC_AVERAGE(sort_cost, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer)) | ||
|
||
var/timestamp = time2text(world.timeofday, "YYYY-MM-DD_hh-mm-ss") | ||
var/prof_file = "[GLOB.log_directory]/profiler/profiler-[timestamp].json" | ||
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 = "[GLOB.log_directory]/profiler/sendmaps-[timestamp].json" | ||
|
||
timer = TICK_USAGE_REAL | ||
rustg_file_write(json_encode(current_profile_data), prof_file) | ||
rustg_file_write(current_sendmaps_data, sendmaps_file) | ||
write_cost = MC_AVERAGE(write_cost, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer)) | ||
|
||
/datum/controller/subsystem/profiler/get_metrics() | ||
. = ..() | ||
.["custom"] = list( | ||
"fetch_cost" = fetch_cost, | ||
"sort_cost" = sort_cost, | ||
"write_cost" = write_cost, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters