diff options
author | Philipp Gesang <phg42.2a@gmail.com> | 2013-07-23 14:50:58 -0700 |
---|---|---|
committer | Philipp Gesang <phg42.2a@gmail.com> | 2013-07-23 14:50:58 -0700 |
commit | d287bf5f8bc24ad366a3ff8e07dcb93d0f48bd03 (patch) | |
tree | ede13cd011ffb59c4bd165a55a703f5ddf41a153 /lualibs-trac-inf.lua | |
parent | 32b7ab871a07f20c73187a577dedb737cc8b18fd (diff) | |
parent | f2f3234465dd965a9915b97bc8b3ac77bd40c464 (diff) | |
download | lualibs-d287bf5f8bc24ad366a3ff8e07dcb93d0f48bd03.tar.gz |
Merge pull request #15 from phi-gamma/master
update to 2.0c
Diffstat (limited to 'lualibs-trac-inf.lua')
-rw-r--r-- | lualibs-trac-inf.lua | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/lualibs-trac-inf.lua b/lualibs-trac-inf.lua index eefc15a..79cbdba 100644 --- a/lualibs-trac-inf.lua +++ b/lualibs-trac-inf.lua @@ -11,20 +11,24 @@ if not modules then modules = { } end modules ['trac-inf'] = { -- get warnings about assignments. This is more efficient than using rawset -- and rawget. -local type, tonumber = type, tonumber +local type, tonumber, select = type, tonumber, select local format, lower = string.format, string.lower local concat = table.concat local clock = os.gettimeofday or os.clock -- should go in environment -statistics = statistics or { } -local statistics = statistics +local setmetatableindex = table.setmetatableindex +local serialize = table.serialize +local formatters = string.formatters -statistics.enable = true -statistics.threshold = 0.01 +statistics = statistics or { } +local statistics = statistics + +statistics.enable = true +statistics.threshold = 0.01 local statusinfo, n, registered, timers = { }, 0, { }, { } -table.setmetatableindex(timers,function(t,k) +setmetatableindex(timers,function(t,k) local v = { timing = 0, loadtime = 0 } t[k] = v return v @@ -178,6 +182,19 @@ function statistics.timed(action) report("total runtime: %s",elapsedtime("run")) end +-- goodie + +function statistics.tracefunction(base,tag,...) + for i=1,select("#",...) do + local name = select(i,...) + local stat = { } + local func = base[name] + setmetatableindex(stat,function(t,k) t[k] = 0 return 0 end) + base[name] = function(n,k,v) stat[k] = stat[k] + 1 return func(n,k,v) end + statistics.register(formatters["%s.%s"](tag,name),function() return serialize(stat,"calls") end) + end +end + -- where, not really the best spot for this: commands = commands or { } |