Resources
Skyline resources; Third party applications, Demo Scenes, Action plug-ins, Action Scripts, Presets etc any thing that can be used by Skyline

Debugging & Profiling Lua

Debugging & Profiling Lua

Postby Shando » 02 Nov 2017, 04:27

Hi All,

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/
Alienware 17 (i7-4700MQ 2.4GHz 16GB GTX770M Win 10 64)

Love, Hope, Strength http://www.lovehopestrength.co.uk
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 480
Joined: 06 Mar 2013, 22:35
Location: Kings Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: Debugging & Profiling Lua

Postby SolarPortal » 02 Nov 2017, 12:05

awesome! nice find shando.. would certainly be a good addition for profiling lua with graphs :P
Conceive, Quantify & Do!
Skyline Game Engine - Lead Developer.
Please provide as much information as possible when asking for help.


Specs: OS: Win 10 64bit, CPU: Intel i7 3770 3.4ghz x 4 core(8 threads), GPU: Nvidia GTX 1060 6GB, Ram: 16gig DDR3, Windows on 250gb Samsung Evo 860
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3118
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer


Return to Resources

Who is online

Users browsing this forum: No registered users and 2 guests

cron