diff options
author | Mike Pall <mike> | 2013-09-02 01:55:20 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2013-09-02 01:55:20 +0200 |
commit | b186fb835efb82757b973db224ec3be39d0ad501 (patch) | |
tree | ce594240025d4b4a2301413ccb530a55002856a4 /src/jit | |
parent | 8a9519a5f442726bafa954f5beecf67b0df3cf45 (diff) | |
download | luajit-b186fb835efb82757b973db224ec3be39d0ad501.tar.gz luajit-b186fb835efb82757b973db224ec3be39d0ad501.tar.bz2 luajit-b186fb835efb82757b973db224ec3be39d0ad501.zip |
Add low-overhead profiler. Part 2: low-level Lua API.
Diffstat (limited to 'src/jit')
-rw-r--r-- | src/jit/zone.lua | 41 |
1 files changed, 41 insertions, 0 deletions
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 @@ | |||
1 | ---------------------------------------------------------------------------- | ||
2 | -- LuaJIT profiler zones. | ||
3 | -- | ||
4 | -- Copyright (C) 2005-2013 Mike Pall. All rights reserved. | ||
5 | -- Released under the MIT license. See Copyright Notice in luajit.h | ||
6 | ---------------------------------------------------------------------------- | ||
7 | -- | ||
8 | -- This module implements a simple hierarchical zone model. | ||
9 | -- | ||
10 | -- Example usage: | ||
11 | -- | ||
12 | -- local zone = require("jit.zone") | ||
13 | -- zone("AI") | ||
14 | -- ... | ||
15 | -- zone("A*") | ||
16 | -- ... | ||
17 | -- print(zone:get()) --> "A*" | ||
18 | -- ... | ||
19 | -- zone() | ||
20 | -- ... | ||
21 | -- print(zone:get()) --> "AI" | ||
22 | -- ... | ||
23 | -- zone() | ||
24 | -- | ||
25 | ---------------------------------------------------------------------------- | ||
26 | |||
27 | local remove = table.remove | ||
28 | |||
29 | return setmetatable({ | ||
30 | flush = function(t) | ||
31 | for i=#t,1,-1 do t[i] = nil end | ||
32 | end, | ||
33 | get = function(t) | ||
34 | return t[#t] | ||
35 | end | ||
36 | }, { | ||
37 | __call = function(t, zone) | ||
38 | if zone then t[#t+1] = zone else return assert(remove(t)) end | ||
39 | end | ||
40 | }) | ||
41 | |||