Lua function call duration profiler in c++.
Target version : lua 5.3
- compiler support c++17
- cmake
- vcpkg
- fmtlib
- rapidjson
- lua
Add this below to settings in vscode to link deps library as static:
"cmake.configureArgs": [
"-DVCPKG_TARGET_TRIPLET=x64-windows-static"
],
click Configure button or use cmake command line tool:
mkdir build
cd build
cmake .. -G "Visual Studio 15 2017 Win64" -DVCPKG_TARGET_TRIPLET=x64-windows-static
In vscode with cmake extension just press F7
.
or
mkdir build
cmake --build ./build --config MinSizeRel --target libLuaProfiler
- Link libLuaProfiler to your project.
- Include or copy content
lua_profiler.h
. - Openlib with code at startup :
luaopen_profiler(L);
. - require and use function in lua.
local luaprofiler = require("luaprofiler")
--[[
start profile by set hook
should call it best outside (before function call)
what you want to profile
]]--
luaprofiler.start()
--[[
stop profile with remove hook
should call it best outside (after function return)
what you want to profile
]]--
luaprofiler.stop()
--[[
clear all data
should call it after report
]]--
luaprofiler.clear()
--[[
**deprecated**
report profiling result in string
should print or log or save it to file
]]--
-- luaprofiler.report_tree()
-- luaprofiler.report_list()
--[[
report profiling result to file
it will save it at the current working directory
the first part of file name is timestamp
]]--
luaprofiler.report_to_file("json")
-- *.lua_profile_json.txt
luaprofiler.report_to_file("list")
-- *.lua_profile_list.txt
luaprofiler.report_to_file("tree")
-- *.lua_profile_tree.txt
pyinstaller json_viewer_main.py -w -F
just drag *.lua_profile_json.txt
to main window.
Tips: Installing
everything
on windows helps to find files instantly.
- click on the arrow to expand/fold stack
- double click to expand the first child recursively
- double click to fold
- click
Function Time Top
to change tab - click header to sort column to descending order