-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathprofile.lua
More file actions
48 lines (36 loc) · 964 Bytes
/
profile.lua
File metadata and controls
48 lines (36 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
local c = require "profile.c"
c.init()
local mark = c.mark
local M = {
start = c.start,
stop = c.stop,
}
local old_co_create = coroutine.create
local old_co_wrap = coroutine.wrap
function coroutine.create(f)
return old_co_create(function (...)
mark()
return f(...)
end)
end
function coroutine.wrap(f)
return old_co_wrap(function (...)
mark()
return f(...)
end)
end
function M.dump(records)
local ret = {"------- dump profile -------"}
for i,v in ipairs(records) do
local s = string.format("[%d] %s name:%s file:[%s]%s:%d count:%d total:%fs ave:%fs percent:%.4g%%",
i, v.point, v.name, v.flag, v.source, v.line, v.count, v.all_cost, v.ave_cost, v.percent*100)
ret[#ret+1] = s
end
return table.concat(ret, "\n")
end
function M.dstop(count)
local records = c.stop(count)
local s = M.dump(records)
print(s)
end
return M