jx_client_neibu/lua_probject/tolua_project/jit/zone.lua

45 lines
1013 B
Lua
Raw Normal View History

2025-04-01 10:48:36 +08:00
----------------------------------------------------------------------------
-- LuaJIT profiler zones.
--
-- Copyright (C) 2005-2017 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*")
-- ...
2025-04-11 12:49:08 +08:00
-- -- print(zone:get()) --> "A*"
2025-04-01 10:48:36 +08:00
-- ...
-- zone()
-- ...
2025-04-11 12:49:08 +08:00
-- -- print(zone:get()) --> "AI"
2025-04-01 10:48:36 +08:00
-- ...
-- zone()
--
----------------------------------------------------------------------------
local remove = table.remove
return setmetatable({
flush = function(t)
2025-04-11 12:49:08 +08:00
for i = #t, 1, -1 do t[i] = nil end
2025-04-01 10:48:36 +08:00
end,
get = function(t)
return t[#t]
end
}, {
__call = function(t, zone)
if zone then
2025-04-11 12:49:08 +08:00
t[#t + 1] = zone
2025-04-01 10:48:36 +08:00
else
return (assert(remove(t), "empty zone stack"))
end
end
})