-
-
Notifications
You must be signed in to change notification settings - Fork 465
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
[LUA] Adding C++ profiler for lua scripts. #1771
base: dev
Are you sure you want to change the base?
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
@@ -153,6 +154,8 @@ class XRSCRIPTENGINE_API CScriptEngine | |||
} | |||
|
|||
public: | |||
CScriptProfiler* m_profiler; |
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.
We already have included script_profiler.hpp
above. Why a pointer? It's better to place the instance here I think.
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.
After checking sampling variant seems like it still has to be a pointer or complex logics inside profiler. Ideally only one profiler should exist and work with scripts contexts while we have few script engines (global singleton + shaders compiling one?)
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). |
…ch hook by default, use original logics for script engine, add attach methods. Update profiler exports, add profiler type global variables. Add profiler type separation / additional methods for hook/jit based profiling. Separate env vars for different profiling.
…c naming for class members.
…are separate start methods in script export.
…ify logics flow. Configurable report saving methods. lua_profiler_status console command.
… const expressions for lua profiler commands.
99838b5
to
ee02f2a
Compare
Since lua profiler from
profiler.script
cannot 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_profiler
start game with default lua scripts profiler (hook variant right now)-lua_hook_profiler
start game with hook based scripts profiler-lua_sampling_profiler
start 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