-
-
Notifications
You must be signed in to change notification settings - Fork 495
[LUA] Adding C++ profiler for lua scripts. #1771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Please, consider using LuaJIT's built-in profiler: |
|
@Xottab-DUTY sounds better |
|
@Xottab-DUTY |
The suggestion is to use it here, on the C++ side. |
|
@Xottab-DUTY Will try to add simplistic variant with luajit mode to compare it / switch in runtime. I think it will not be too complex if we just print some stats here. Later something similar to https://github.com/cdsama/LuaProfiler/blob/master/lua_profiler.cpp can be considered, but still need some R&D to understand if I can build traces correctly here.
|
| u64 total_count = 0; | ||
| u64 total_duration = 0; | ||
|
|
||
| std::vector<decltype(m_profiling_portions)::iterator> entries; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always use xr_vector.
If the data isn't too big, you can even use buffer_vector with xr_alloca (there are examples in the code base).
| std::vector<decltype(m_profiling_portions)::iterator> entries; | |
| xr_vector<decltype(m_profiling_portions)::iterator> entries; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me it was 3-4k records in average. I believe it will be <10k pointers almost always
9902f58 to
d3d5aa3
Compare
|
Example report console log with hook profiler: |
|
Exported hook profiler data (trimmed, 4460 lines in the file): |
|
Console reported log for sampling profiler: |
|
Sampling profiler report example is above. Also I found out that we have tracy integration and tracy methods allow to track down specific zones. Will explore it as separate part in my project (I can try override AST nodes building from typescript to lua and add zones absolutely everywhere behind some building flag). |
99838b5 to
ee02f2a
Compare
|
@Xottab-DUTY Before: After: |
d5e6b1a to
246055a
Compare
|
@Xottab-DUTY Also seems like files naming is primary problem usage of blocking LUA code breakpoints (https://github.com/WheretIB/LuaDkmDebugger). With few line adjustments we can use them with openxray project. |
… const expressions for lua profiler commands.
4e4558f to
f0ee679
Compare
|
@Neloreck, is it ready for review/merge? |
Can you send a PR to https://github.com/WheretIB/LuaDkmDebugger? |
|
Yes, can be tested/reviewed WheretIB/LuaDkmDebugger#26 -> can reopen, not sure about review time |
|
Opened WheretIB/LuaDkmDebugger#29 |
c3ffa4d to
09b0b99
Compare
1. Removed pch.hpp includes. Never include precompiled headers into headers! 2. Moved luajit.h to script_profiler_portions.hpp because xrScriptEngine.hpp is included globally, but we don't need LuaJIT functions to be publicly available. script_profiler.hpp include is removed from globally used script_engine.hpp for that too.
9016204 to
ae21921
Compare
|
Thanks so much! |
|
I have one question: why shared_str was used? Are there many string duplicates? Ideally, we would like to minimize dynamic allocations as much as possible to minimize runtime overhead. Both |
|
Which ones specifically? After another check I see that we can re-review part with constant values and remove dynamic str for profiler type etc. The biggest usage comes from profile-portions keys which are used as map keys and collected based on call trace |
|
@Neloreck can you provide more info about
I also using tracy for lua part, but marking zone in lua much more complicated compared to c++ because of missing automatic destruction of variables in lua |
|
@joye-ramone You still can mark problematic places manually and add tracy marking, but you should add start zone and then attach zone end manually in all possible return clauses. If you miss some conditional return / else-if block you will get memory leak and crash of tracy/game |
|
very interesting solution... definity will take a look. |











Since lua profiler from
profiler.scriptcannot be revived, adding c++ based profiler. For not it is draft with basic POC part, will try to improve it based on other existing implementations. Will add more details in description over time.Changes
New command line arguments
-lua_profilerstart game with default lua scripts profiler (hook variant right now)-lua_hook_profilerstart game with hook based scripts profiler-lua_sampling_profilerstart game with hook based scripts profilerNew console commands
lua_profiler_status- print profiler type/statuslua_profiler_start- start profiler in default mode (or provide type as argument)lua_profiler_start_hook_mode- start profiler in hook mdoeua_profiler_start_sampling_mode- start in sampling mode with 10ms interval (or provide as argument)lua_profiler_stop- stop profilerlua_profiler_reset- reset profiler datalua_profiler_log- log 128 profiler entries (or provide count as argument)lua_profiler_save- save profiling report in a separate .perf/.log fileNew Lua exports
PROFILER_TYPE_NONE- constant with profiler none typePROFILER_TYPE_HOOK- constant with profiler hook typePROFILER_TYPE_SAMPLING- constant with profiler sampling typeprofiler.is_active- whether profiler is active nowprofiler.get_type- currently active profiler typeprofiler.start- start profiler (default)profiler.start_sampling_mode- start profiler in sampling modeprofiler.start_hook_mode- start profiler in hook modeprofiler.stop- stop profilerprofiler.reset- reset profiler dataprofiler.log_report- log profiling reportprofiler.save_report- save profiling reportTesting
Links