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

Commit 8056e7a

Browse files
get this thing away from me
1 parent 83cec6a commit 8056e7a

File tree

7 files changed

+218
-37
lines changed

7 files changed

+218
-37
lines changed

byond-extools/src/core/core.cpp

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ExecutionContext** Core::parent_context_ptr_hack;
2323
ProcSetupEntry** Core::proc_setup_table;
2424

2525
unsigned int* Core::some_flags_including_profile;
26+
unsigned int Core::extended_profiling_insanely_hacky_check_if_its_a_new_call_or_resume;
2627

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

98-
extern "C" EXPORT const char* enable_profiling(int n_args, const char* args)
99+
extern "C" EXPORT const char* enable_profiling(int n_args, const char** args)
99100
{
100101
Core::enable_profiling();
101102
return good;
102103
}
103104

104-
extern "C" EXPORT const char* disable_profiling(int n_args, const char* args)
105+
extern "C" EXPORT const char* disable_profiling(int n_args, const char** args)
105106
{
106107
Core::disable_profiling();
107108
return good;
108109
}
109110

110-
extern "C" EXPORT const char* core_initialize(int n_args, const char* args)
111+
extern "C" EXPORT const char* core_initialize(int n_args, const char** args)
111112
{
112113
if (!Core::initialize())
113114
{
114115
Core::Alert("Core init failed!");
115116
return bad;
116117
}
117118
optimizer_initialize();
118-
extended_profiling_initialize();
119+
//extended_profiling_initialize();
119120
return good;
120121
}
121122

122-
extern "C" EXPORT const char* tffi_initialize(int n_args, const char* args)
123+
extern "C" EXPORT const char* tffi_initialize(int n_args, const char** args)
123124
{
124125
if (!(Core::initialize() && TFFI::initialize()))
125126
return bad;
126127
return good;
127128
}
128129

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

136137
void init_testing();
137138
void run_tests();
138-
extern "C" EXPORT const char* run_tests(int n_args, const char* args)
139+
extern "C" EXPORT const char* run_tests(int n_args, const char** args)
139140
{
140141
init_testing();
141142
run_tests();
142143
return good;
144+
}
145+
146+
extern "C" EXPORT const char* extended_profiling_initialize(int n_args, const char** args)
147+
{
148+
if (!(Core::initialize() && actual_extended_profiling_initialize()))
149+
return bad;
150+
return good;
151+
}
152+
153+
extern "C" EXPORT const char* enable_extended_profiling(int n_args, const char** args)
154+
{
155+
//Core::Alert("Enabling logging for " + std::string(args[0]));
156+
Core::get_proc(args[0]).extended_profile();
157+
return good;
158+
}
159+
160+
extern "C" EXPORT const char* disable_extended_profiling(int n_args, const char** args)
161+
{
162+
procs_to_profile.erase(Core::get_proc(args[0]).id); //TODO: improve consistency and reconsider how initialization works
163+
return good;
143164
}

byond-extools/src/core/core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace Core
2424
extern ExecutionContext** parent_context_ptr_hack;
2525
extern ProcSetupEntry** proc_setup_table;
2626
extern unsigned int* some_flags_including_profile;
27+
extern unsigned int extended_profiling_insanely_hacky_check_if_its_a_new_call_or_resume;
2728
ExecutionContext* get_context();
2829
ExecutionContext* _get_parent_context();
2930
unsigned int register_opcode(std::string name, opcode_handler handler);

byond-extools/src/core/hooking.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ CallGlobalProcPtr oCallGlobalProc;
1818

1919
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)
2020
{
21+
Core::extended_profiling_insanely_hacky_check_if_its_a_new_call_or_resume = proc_id;
2122
if (proc_hooks.find(proc_id) != proc_hooks.end())
2223
{
2324
trvh result = proc_hooks[proc_id](argList, argListLen);
2425
return result;
2526
}
2627
trvh result = oCallGlobalProc(unk1, unk2, proc_type, proc_id, const_0, unk3, unk4, argList, argListLen, const_0_2, const_0_3);
28+
Core::extended_profiling_insanely_hacky_check_if_its_a_new_call_or_resume = -1;
2729
return result;
2830
}
2931

byond-extools/src/core/various_testing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ trvh update_light_objects;
5454
void init_testing()
5555
{
5656
Core::enable_profiling();
57-
Core::get_proc("/datum/explosion/New").extended_profile();
57+
//Core::get_proc("/datum/explosion/New").extended_profile();
5858
//Core::get_proc("/client/verb/test_reentry").extended_profile();
5959
//Core::get_proc("/client/verb/test_extended_profiling").extended_profile();
6060
//extended_profiling_procs[.id] = true;

byond-extools/src/dm/_extools_api.dm

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
*/
5151

5252
/proc/tffi_initialize()
53-
call(EXTOOLS, "tffi_initialize")() == EXTOOLS_SUCCESS
53+
return call(EXTOOLS, "tffi_initialize")() == EXTOOLS_SUCCESS
5454

5555
var/fallback_alerted = FALSE
5656
var/next_promise_id = 0
@@ -108,4 +108,36 @@ var/next_promise_id = 0
108108
P.__resolve_callback()
109109

110110
/proc/call_wait()
111-
return call_async(arglist(args)).resolve()
111+
return call_async(arglist(args)).resolve()
112+
113+
/*
114+
Extended Profiling - High precision in-depth performance profiling.
115+
116+
Turning on extended profiling for a proc will cause each execution of it to generate a file in the ./profiles directory
117+
containing a breakdown of time spent executing the proc and each sub-proc it calls. Import the file into https://www.speedscope.app/ to
118+
view a good visual representation.
119+
120+
Be aware that sleeping counts as stopping and restarting the execution of the proc, which will generate multiple files, one between each sleep.
121+
122+
For large procs the profiles may become unusably large. Optimizations pending.
123+
124+
Example:
125+
126+
start_profiling(/datum/explosion/New)
127+
128+
- Enables profiling for /datum/explosion/New(), which will produce a detailed breakdown of each explosion that occurs afterwards.
129+
130+
stop_profiling(/datum/explosion/New)
131+
132+
- Disables profiling for explosions. Any currently running profiles will stop when the proc finishes executing or enters a sleep.
133+
134+
*/
135+
136+
/proc/profiling_initialize()
137+
return call(EXTOOLS, "extended_profiling_initialize")() == EXTOOLS_SUCCESS
138+
139+
/proc/start_profiling(procpath)
140+
call(EXTOOLS, "enable_extended_profiling")("[procpath]")
141+
142+
/proc/stop_profiling(procpath)
143+
call(EXTOOLS, "disable_extended_profiling")("[procpath]")

0 commit comments

Comments
 (0)