Skip to content
This repository has been archived by the owner on Apr 10, 2021. It is now read-only.

Commit

Permalink
get this thing away from me
Browse files Browse the repository at this point in the history
  • Loading branch information
1fbff5f83b23d39d38b1dfcb4cac8d9b committed Nov 5, 2019
1 parent 83cec6a commit 8056e7a
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 37 deletions.
35 changes: 28 additions & 7 deletions byond-extools/src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ExecutionContext** Core::parent_context_ptr_hack;
ProcSetupEntry** Core::proc_setup_table;

unsigned int* Core::some_flags_including_profile;
unsigned int Core::extended_profiling_insanely_hacky_check_if_its_a_new_call_or_resume;

std::map<unsigned int, opcode_handler> Core::opcode_handlers;
std::map<std::string, unsigned int> Core::name_to_opcode;
Expand Down Expand Up @@ -95,38 +96,38 @@ void Core::disable_profiling()
const char* good = "gucci";
const char* bad = "pain";

extern "C" EXPORT const char* enable_profiling(int n_args, const char* args)
extern "C" EXPORT const char* enable_profiling(int n_args, const char** args)
{
Core::enable_profiling();
return good;
}

extern "C" EXPORT const char* disable_profiling(int n_args, const char* args)
extern "C" EXPORT const char* disable_profiling(int n_args, const char** args)
{
Core::disable_profiling();
return good;
}

extern "C" EXPORT const char* core_initialize(int n_args, const char* args)
extern "C" EXPORT const char* core_initialize(int n_args, const char** args)
{
if (!Core::initialize())
{
Core::Alert("Core init failed!");
return bad;
}
optimizer_initialize();
extended_profiling_initialize();
//extended_profiling_initialize();
return good;
}

extern "C" EXPORT const char* tffi_initialize(int n_args, const char* args)
extern "C" EXPORT const char* tffi_initialize(int n_args, const char** args)
{
if (!(Core::initialize() && TFFI::initialize()))
return bad;
return good;
}

extern "C" EXPORT const char* proxy_initialize(int n_args, const char* args)
extern "C" EXPORT const char* proxy_initialize(int n_args, const char** args)
{
if (!(Core::initialize() && Proxy::initialize()))
return bad;
Expand All @@ -135,9 +136,29 @@ extern "C" EXPORT const char* proxy_initialize(int n_args, const char* args)

void init_testing();
void run_tests();
extern "C" EXPORT const char* run_tests(int n_args, const char* args)
extern "C" EXPORT const char* run_tests(int n_args, const char** args)
{
init_testing();
run_tests();
return good;
}

extern "C" EXPORT const char* extended_profiling_initialize(int n_args, const char** args)
{
if (!(Core::initialize() && actual_extended_profiling_initialize()))
return bad;
return good;
}

extern "C" EXPORT const char* enable_extended_profiling(int n_args, const char** args)
{
//Core::Alert("Enabling logging for " + std::string(args[0]));
Core::get_proc(args[0]).extended_profile();
return good;
}

extern "C" EXPORT const char* disable_extended_profiling(int n_args, const char** args)
{
procs_to_profile.erase(Core::get_proc(args[0]).id); //TODO: improve consistency and reconsider how initialization works
return good;
}
1 change: 1 addition & 0 deletions byond-extools/src/core/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace Core
extern ExecutionContext** parent_context_ptr_hack;
extern ProcSetupEntry** proc_setup_table;
extern unsigned int* some_flags_including_profile;
extern unsigned int extended_profiling_insanely_hacky_check_if_its_a_new_call_or_resume;
ExecutionContext* get_context();
ExecutionContext* _get_parent_context();
unsigned int register_opcode(std::string name, opcode_handler handler);
Expand Down
2 changes: 2 additions & 0 deletions byond-extools/src/core/hooking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ CallGlobalProcPtr oCallGlobalProc;

trvh __cdecl hCallGlobalProc(char unk1, int unk2, int proc_type, unsigned int proc_id, int const_0, char unk3, int unk4, Value* argList, unsigned int argListLen, int const_0_2, int const_0_3)
{
Core::extended_profiling_insanely_hacky_check_if_its_a_new_call_or_resume = proc_id;
if (proc_hooks.find(proc_id) != proc_hooks.end())
{
trvh result = proc_hooks[proc_id](argList, argListLen);
return result;
}
trvh result = oCallGlobalProc(unk1, unk2, proc_type, proc_id, const_0, unk3, unk4, argList, argListLen, const_0_2, const_0_3);
Core::extended_profiling_insanely_hacky_check_if_its_a_new_call_or_resume = -1;
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion byond-extools/src/core/various_testing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ trvh update_light_objects;
void init_testing()
{
Core::enable_profiling();
Core::get_proc("/datum/explosion/New").extended_profile();
//Core::get_proc("/datum/explosion/New").extended_profile();
//Core::get_proc("/client/verb/test_reentry").extended_profile();
//Core::get_proc("/client/verb/test_extended_profiling").extended_profile();
//extended_profiling_procs[.id] = true;
Expand Down
36 changes: 34 additions & 2 deletions byond-extools/src/dm/_extools_api.dm
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
*/

/proc/tffi_initialize()
call(EXTOOLS, "tffi_initialize")() == EXTOOLS_SUCCESS
return call(EXTOOLS, "tffi_initialize")() == EXTOOLS_SUCCESS

var/fallback_alerted = FALSE
var/next_promise_id = 0
Expand Down Expand Up @@ -108,4 +108,36 @@ var/next_promise_id = 0
P.__resolve_callback()

/proc/call_wait()
return call_async(arglist(args)).resolve()
return call_async(arglist(args)).resolve()

/*
Extended Profiling - High precision in-depth performance profiling.
Turning on extended profiling for a proc will cause each execution of it to generate a file in the ./profiles directory
containing a breakdown of time spent executing the proc and each sub-proc it calls. Import the file into https://www.speedscope.app/ to
view a good visual representation.
Be aware that sleeping counts as stopping and restarting the execution of the proc, which will generate multiple files, one between each sleep.
For large procs the profiles may become unusably large. Optimizations pending.
Example:
start_profiling(/datum/explosion/New)
- Enables profiling for /datum/explosion/New(), which will produce a detailed breakdown of each explosion that occurs afterwards.
stop_profiling(/datum/explosion/New)
- Disables profiling for explosions. Any currently running profiles will stop when the proc finishes executing or enters a sleep.
*/

/proc/profiling_initialize()
return call(EXTOOLS, "extended_profiling_initialize")() == EXTOOLS_SUCCESS

/proc/start_profiling(procpath)
call(EXTOOLS, "enable_extended_profiling")("[procpath]")

/proc/stop_profiling(procpath)
call(EXTOOLS, "disable_extended_profiling")("[procpath]")
Loading

0 comments on commit 8056e7a

Please sign in to comment.