Add low-overhead profiler. Part 2: low-level Lua API.

This commit is contained in:
Mike Pall
2013-09-02 01:55:20 +02:00
parent 8a9519a5f4
commit b186fb835e
2 changed files with 142 additions and 0 deletions

41
src/jit/zone.lua Normal file
View File

@@ -0,0 +1,41 @@
----------------------------------------------------------------------------
-- LuaJIT profiler zones.
--
-- Copyright (C) 2005-2013 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h
----------------------------------------------------------------------------
--
-- This module implements a simple hierarchical zone model.
--
-- Example usage:
--
-- local zone = require("jit.zone")
-- zone("AI")
-- ...
-- zone("A*")
-- ...
-- print(zone:get()) --> "A*"
-- ...
-- zone()
-- ...
-- print(zone:get()) --> "AI"
-- ...
-- zone()
--
----------------------------------------------------------------------------
local remove = table.remove
return setmetatable({
flush = function(t)
for i=#t,1,-1 do t[i] = nil end
end,
get = function(t)
return t[#t]
end
}, {
__call = function(t, zone)
if zone then t[#t+1] = zone else return assert(remove(t)) end
end
})