Skip to content

Commit

Permalink
server: byond tracy update (#4395)
Browse files Browse the repository at this point in the history
* refactor: byond tracy update

* feat: add global to track if byond-tracy is enabled
  • Loading branch information
Bizzonium authored Mar 13, 2024
1 parent 6f86e5a commit 8b1c544
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 16 deletions.
89 changes: 89 additions & 0 deletions code/__DEFINES/byond_tracy.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Implements https://github.com/mafemergency/byond-tracy
// Client https://github.com/wolfpld/tracy
// As of now, only 0.8.2 is supported as a client, this might change in the future however

// In case you need to start the capture as soon as the server boots, uncomment the following lines and recompile:

// /world/New()
// prof_init()
// . = ..()

#ifndef PROF
// Default automatic PROF detection.
// On Windows, looks in the standard places for `prof.dll`.
// On Linux, looks in `.`, `$LD_LIBRARY_PATH`, and `~/.byond/bin` for either of
// `libprof.so` (preferred) or `prof` (old).

/* This comment bypasses grep checks */ /var/__prof

/proc/__detect_prof()
if (world.system_type == UNIX)
if (fexists("./libprof.so"))
// No need for LD_LIBRARY_PATH badness.
return __prof = "./libprof.so"
else if (fexists("./prof"))
// Old dumb filename.
return __prof = "./prof"
else if (fexists("[world.GetConfig("env", "HOME")]/.byond/bin/prof"))
// Old dumb filename in `~/.byond/bin`.
return __prof = "prof"
else
// It's not in the current directory, so try others
return __prof = "libprof.so"
else
return __prof = "prof"

#define PROF (__prof || __detect_prof())
#endif

// Handle 515 call() -> call_ext() changes
#if DM_VERSION >= 515
#define PROF_CALL call_ext
#else
#define PROF_CALL call
#endif

GLOBAL_VAR_INIT(profiler_enabled, FALSE)

/client/proc/profiler_start()
set name = "Tracy Profiler Start"
set category = "Debug"
set desc = "Starts the tracy profiler and writes the data to the server's data directory."

if(holder && holder.rights != R_HOST)
return

switch(alert("Are you sure? Tracy will remain active until the server restarts.", "Tracy Init", "No", "Yes"))
if("Yes")
prof_init()

/client/proc/profiler_stop()
set name = "Tracy Profiler Stop"
set category = "Debug"
set desc = "Stop the tracy profiler."

if(holder && holder.rights != R_HOST)
return

switch(alert("Are you sure?", "Tracy Stop", "No", "Yes"))
if("Yes")
prof_stop()

/**
* Starts Tracy
*/
/proc/prof_init()
var/init = PROF_CALL(PROF, "init")()
if("0" != init) CRASH("[PROF] init error: [init]")
GLOB.profiler_enabled = TRUE

/**
* Stops Tracy
*/
/proc/prof_stop()
if(!GLOB.profiler_enabled)
return

var/destroy = PROF_CALL(PROF, "destroy")()
if("0" != destroy) CRASH("[PROF] destroy error: [destroy]")
GLOB.profiler_enabled = FALSE
18 changes: 2 additions & 16 deletions code/game/world.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ GLOBAL_DATUM(test_runner, /datum/test_runner)
/world/New()
#ifdef USE_BYOND_TRACY
#warn USE_BYOND_TRACY is enabled
init_byond_tracy()
prof_init()
#endif

dmjit_hook_main_init()
Expand Down Expand Up @@ -306,19 +306,5 @@ GLOBAL_LIST_EMPTY(world_topic_handlers)
var/debug_server = world.GetConfig("env", "AUXTOOLS_DEBUG_DLL")
if (debug_server)
CALL_EXT(debug_server, "auxtools_shutdown")()
prof_stop()
..()

/world/proc/init_byond_tracy()
var/library

switch (system_type)
if (MS_WINDOWS)
library = "prof.dll"
if (UNIX)
library = "libprof.so"
else
CRASH("Unsupported platform: [system_type]")

var/init_result = CALL_EXT(library, "init")()
if (init_result != "0")
CRASH("Error initializing byond-tracy: [init_result]")
4 changes: 4 additions & 0 deletions code/modules/admin/admin_verbs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ GLOBAL_LIST_INIT(admin_verbs_ticket, list(
verbs += GLOB.admin_verbs_proccall
if(holder.rights == R_HOST)
verbs += /client/proc/view_pingstat
verbs += /client/proc/profiler_start
verbs += /client/proc/profiler_stop
if(holder.rights & R_VIEWRUNTIMES)
verbs += /client/proc/view_runtimes
verbs += /client/proc/ss_breakdown
Expand All @@ -301,6 +303,8 @@ GLOBAL_LIST_INIT(admin_verbs_ticket, list(
GLOB.admin_verbs_permissions,
/client/proc/stealth,
/client/proc/view_pingstat,
/client/proc/profiler_start,
/client/proc/profiler_stop,
GLOB.admin_verbs_rejuv,
GLOB.admin_verbs_sounds,
GLOB.admin_verbs_spawn,
Expand Down
1 change: 1 addition & 0 deletions paradise.dme
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "code\__DEFINES\atmospherics.dm"
#include "code\__DEFINES\bots.dm"
#include "code\__DEFINES\bump_priority.dm"
#include "code\__DEFINES\byond_tracy.dm"
#include "code\__DEFINES\callbacks.dm"
#include "code\__DEFINES\cargo_quests.dm"
#include "code\__DEFINES\chat_box_defines.dm"
Expand Down

0 comments on commit 8b1c544

Please sign in to comment.