-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathWritWorthy_Profiler.lua
45 lines (37 loc) · 1.16 KB
/
WritWorthy_Profiler.lua
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
local WritWorthy = _G['WritWorthy'] -- defined in WritWorthy_Define.lua
WritWorthy.Profiler = { stats = {} }
local Profiler = WritWorthy.Profiler
local function time_ms()
return GetGameTimeMilliseconds()
end
function Profiler.GetStats(func_name)
if not Profiler.stats[func_name] then
Profiler.stats[func_name] = { call_ct = 0
, dur_ms = 0
, start_ms = 0
}
end
return Profiler.stats[func_name]
end
function Profiler.Call(func_name)
if not Profiler.enabled then return end
local s = Profiler.GetStats(func_name)
s.call_ct = s.call_ct + 1
s.start_ms = time_ms()
end
function Profiler.End(func_name)
if not Profiler.enabled then return end
local s = Profiler.GetStats(func_name)
local dur_ms = time_ms() - s.start_ms
s.dur_ms = s.dur_ms + dur_ms
s.start_ms = nil
end
function Profiler.Start()
Profiler.enabled = true
WritWorthy.savedVariables.profiler_stats = Profiler.stats
d("Profiler enabled")
end
function Profiler.Stop()
Profiler.enabled = false
d("Profiler disabled")
end