During my testing of the Client/Server stuff in Skyline, I found that I needed some way to trace Function Calls. Checking the web I came across the following (http://springrts.com/phpbb/viewtopic.php?t=13932), which I thought you might find useful (WARNING: this will really slow Skyline down, so I would suggest using the onKeyDown code below to turn it on and off!!)
NB: This code writes to an external file in the Project/Game Folder
- Code: Select all
trace_log = sky.getDir_ProjectOrGameFolder ( )
if ( bServer ) then
fp = io.open ( trace_log .. "\\server_trace.log", "w" )
else
fp = io.open ( trace_log .. "\\client_trace.log", "w" )
end
function CreateStackTraceHook ( )
local prefix = ""
return function ( event )
local info = debug.getinfo ( 2, "S" )
if ( info.what == "C" ) then
return
end -- do not log C functions
if ( event == "call" ) then
local info2 = debug.getinfo ( 2, "n" )
local src = info.short_src
local name = info2.name or ""
local line = info.linedefined
-- Change the next line to include ( or exclude ) other functions
if ( name ~= "onServerUpdate" and name ~= "onUpdate" and name ~= "" and name ~= nil ) then
fp:write ( prefix .. src .. "(" .. line .. "): " .. name .. "\n" )
fp:flush ( )
prefix = prefix .. " "
end
elseif ( event == "return" or event == "tail return" ) then
prefix = string.sub ( prefix, 3 )
end
end
end
and my onKeyDown code:
- Code: Select all
function onKeyDown ( inKey )
if ( inKey == "t" ) then
if ( not bTrace ) then
sky.lprint ( "Trace Enabled!" )
debug.sethook ( CreateStackTraceHook ( ), "cr" ) -- hook call and return events
bTrace = true
else
sky.lprint ( "Trace Disabled!" )
debug.sethook ( )
bTrace = false
end
end
end
Hope someone finds it useful and if you have any queries, let me know and I'll see if I can help.
Regards
Shando
@SolarPortal - something else to add to your long TODO list would be a built-in graphical profiler that produces graphs etc. similar to this:
http://docs.unrealengine.com/latest/INT/Engine/Performance/Profiler/
Also, I came across this, which may make your life easier (already seems to be OGRE ready!):
http://sourceforge.net/projects/shinyprofiler/