Profiler: create class and base functional. Close #36
This commit is contained in:
@@ -32,7 +32,8 @@
|
|||||||
"vector",
|
"vector",
|
||||||
"Ensure",
|
"Ensure",
|
||||||
"string",
|
"string",
|
||||||
"string_utf8"
|
"string_utf8",
|
||||||
|
"Profiler"
|
||||||
],
|
],
|
||||||
"globalsRegex": []
|
"globalsRegex": []
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ dofile(core.get_modpath('smc__system__logger')..'/init.lua')
|
|||||||
-- Math
|
-- Math
|
||||||
dofile(core.get_modpath('smc__system__math')..'/init.lua')
|
dofile(core.get_modpath('smc__system__math')..'/init.lua')
|
||||||
|
|
||||||
|
-- Profile
|
||||||
|
dofile(core.get_modpath('smc__system__profiler')..'/init.lua')
|
||||||
|
|
||||||
-- Require
|
-- Require
|
||||||
dofile(core.get_modpath('smc__system__require')..'/init.lua')
|
dofile(core.get_modpath('smc__system__require')..'/init.lua')
|
||||||
|
|
||||||
|
|||||||
55
mods/SYSTEM/Profiler/init.lua
Normal file
55
mods/SYSTEM/Profiler/init.lua
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
local getInstance = Class.getInstance
|
||||||
|
local getUsTime = core.get_us_time
|
||||||
|
|
||||||
|
---@alias Profiler.TimeUnits 'sec'|'us'
|
||||||
|
|
||||||
|
---@class Profiler
|
||||||
|
---@field name string
|
||||||
|
---@field startTime number
|
||||||
|
---@field endTime number
|
||||||
|
---@field deltaTime number
|
||||||
|
Profiler = {
|
||||||
|
timers = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
---@param name string?
|
||||||
|
---@return Profiler
|
||||||
|
function Profiler:new(name)
|
||||||
|
local instance = getInstance(self, {})
|
||||||
|
instance.name = name or 'NoName'
|
||||||
|
|
||||||
|
return instance
|
||||||
|
end
|
||||||
|
|
||||||
|
---Marks the time when the timer starts.
|
||||||
|
function Profiler:startTimer()
|
||||||
|
self.startTime = getUsTime()
|
||||||
|
self.deltaTime = nil
|
||||||
|
self.endTime = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
---Marks the end time of the timer.
|
||||||
|
function Profiler:endTimer()
|
||||||
|
self.endTime = getUsTime()
|
||||||
|
|
||||||
|
self.deltaTime = self.endTime - self.startTime
|
||||||
|
end
|
||||||
|
|
||||||
|
---Returns the time difference between the start and stop of the timer in seconds (`sec`) or microseconds (`us`).
|
||||||
|
---@param units Profiler.TimeUnits? Units of time measurement. Default 'us'.
|
||||||
|
function Profiler:getDeltaTime(units)
|
||||||
|
if units == nil then
|
||||||
|
units = 'us'
|
||||||
|
end
|
||||||
|
|
||||||
|
if units == 'us' then
|
||||||
|
return self.deltaTime
|
||||||
|
elseif units == 'sec' then
|
||||||
|
return self.deltaTime/1000000
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---Displays the time difference in the chat using `core.log`.
|
||||||
|
function Profiler:logDeltaTime()
|
||||||
|
core.log(('DeltaTime[%s]: %.3f'):format(self:getDeltaTime()))
|
||||||
|
end
|
||||||
2
mods/SYSTEM/Profiler/mod.conf
Normal file
2
mods/SYSTEM/Profiler/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
name = smc__system__profiler
|
||||||
|
depends = smc__system__class, smc__system__table
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
name = smc__system__system_loader
|
name = smc__system__system_loader
|
||||||
description = Include this mod in your `depends` to ensure all necessary Libs are loaded for your mod
|
description = Include this mod in your `depends` to ensure all necessary Libs are loaded for your mod
|
||||||
depends = smc__system__ensure, smc__system__math, smc__system__mod, smc__system__require, smc__system__table, smc__system__string, smc__system__utf8, smc__system__class, smc__system__helper_lib
|
depends = smc__system__ensure, smc__system__math, smc__system__mod, smc__system__require, smc__system__table, smc__system__string, smc__system__utf8, smc__system__class, smc__system__helper_lib, smc__system__profiler
|
||||||
|
|||||||
Reference in New Issue
Block a user