gm_luaprof - Lua Profiler (Beta)

http://dl.getdropbox.com/u/759758/luaprof.zip

Put it in lua/includes/modules

To start profiling:
[lua]require(“profiler”) profiler.Start()[/lua]

To end profiling:
[lua]profiler.Dump()[/lua]

For now it writes to data/profiler_functions_sorted_by_time.txt with the times for every function.

Example of the output:
http://azu.pastebin.com/m5dbec850

includes/modules/glon.lua(355)decode avg time: 3.144049 max time: 5.977328

Pretty awesome.

And, what exactly are you decoding that would take GLON 5 seconds to decode?

Very nice. Looks like from the dump the profiler just logs a chunk of code from a file, but would it be hard to add specific function profiling?

I’m not sure what you mean, it measures the time it takes for all the functions.

I think Nevec ment something like:


profiler.Start("autorun/somewhat.lua")

so that the module will just keep track of this file only.
Maybe with a second arg for specific function like:


profiler.Start("autorun/somewhat.lua",SomeFunction)

I was thinking more along the lines of…



profiler.Start( somefunc );


But now that I think of it, it’s kind of impractical, since you’re not actually calling somefunc. But would something like this work…



profiler.Start( );
somefunc( );
profiler.Dumb( );


Would that profile just that one function call? And whatever that function calls?

Great, this module is perfect for performance testing.

Will this have much of a performance impact on the server while logging?

Could I put it on a timer that dumps every 5 minutes to check what I need to optimise, without a noticable performance decrease?

Thanks.

EDIT:

Tried it for an hour, people complained about lag, stopped the log and they said the lag was fixed.

Yes, it will.

I know this is pretty old. but is there any chance of getting this fixed? It broke in a update

1>------ Build started: Project: gm_luaprof, Configuration: Release Win32 ------
1>LINK : fatal error C1047: The object or library file ‘detours.lib’ was created with an older compiler than other objects; rebuild old objects and libraries
1>LINK : fatal error LNK1257: code generation failed
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Bah fuck it i cant even get the original to compile so i obviously cant fix it

[editline]03:44PM[/editline]

Automerge?

You need an up to date version of detours.lib

I still dont think i would be able to fix it, it would be much better if AzuiSleet just could put the exports back

They’re still there. Ask around, people who’ve disassembled the dylibs in the SVN have the exports still.

Well i kinda suck at C++, so i obviously wont be able to fix this thing

[editline]07:15PM[/editline]

Thought it would be awsome if someone did

Rebuilding the solution (Ctrl+Alt+F7) usually fixes this for me.

Didnt work, im trying to write one in lua with the debug hooks, but its just :sigh:

[editline]10:38PM[/editline]

Came up with this:
[lua]local times = {}
local time = {}
function trace (event, …)
local name = debug.getinfo(2).name
if time[name] and event == “return” then
local timee = SysTime()-time[name]
if !times[name] or timee > times[name] then
times[name] = timee
end
time[name] = nil
elseif !time[name] and event == “call” then
time[name] = SysTime()
end
debug.sethook(trace, “cr”)
end

debug.sethook(trace, "cr")

function lol()
	local time = SysTime()
	while true do
		if time + 3 < SysTime() then
			break
		end
	end
end
lol()
PrintTable(times)
[/lua]

Pretty good output, but you have to put it on top of the file you wanna profile

Anyone managed to compile this? I tried for a while and ended up only in failures.

Here i recompiled it for you, but i am not sure if it works, its untested.

http://cold.netburst.co.uk/file/gm_luaprof.dll