From b186fb835efb82757b973db224ec3be39d0ad501 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Mon, 2 Sep 2013 01:55:20 +0200 Subject: Add low-overhead profiler. Part 2: low-level Lua API. --- src/jit/zone.lua | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/jit/zone.lua (limited to 'src/jit') diff --git a/src/jit/zone.lua b/src/jit/zone.lua new file mode 100644 index 00000000..da2eccb0 --- /dev/null +++ b/src/jit/zone.lua @@ -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 +}) + -- cgit v1.2.3-55-g6feb