1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2026-06-20 16:32:28 +02:00

profiler - now usable when game is ongoing

for now, only usable by me and mew or if _DEBUG is enabled by everyone.
This commit is contained in:
Gerkiz
2020-12-29 00:08:53 +01:00
parent ce0420e7b3
commit 53aa78896e
2 changed files with 42 additions and 4 deletions
+1
View File
@@ -15,6 +15,7 @@ require 'utils.datastore.jail_data'
require 'utils.datastore.quickbar_data'
require 'utils.datastore.message_on_join_data'
require 'utils.datastore.player_tag_data'
require 'utils.profiler'
require 'chatbot'
require 'commands'
require 'antigrief'
+41 -4
View File
@@ -2,6 +2,7 @@ local table_sort = table.sort
local string_rep = string.rep
local string_format = string.format
local debug_getinfo = debug.getinfo
local Color = require 'utils.color_presets'
local Profiler = {
-- Call
@@ -9,6 +10,13 @@ local Profiler = {
IsRunning = false
}
-- we can have this on runtime,
-- but never ever can a player run this without notifying us.
local allowed = {
['Gerkiz'] = true,
['mewmew'] = true
}
local ignoredFunctions = {
[debug.sethook] = true
}
@@ -18,10 +26,40 @@ local namedSources = {
}
local function startCommand(command)
Profiler.Start(command.parameter ~= nil)
local player = game.player
if player then
if player ~= nil then
if not player.admin then
local p = player.print
p('[ERROR] Only admins are allowed to run this command!', Color.fail)
return
else
if allowed[player.name] then
Profiler.Start(command.parameter ~= nil)
elseif _DEBUG then
Profiler.Start(command.parameter ~= nil)
end
end
end
end
end
local function stopCommand(command)
Profiler.Stop(command.parameter ~= nil, nil)
local player = game.player
if player then
if player ~= nil then
if not player.admin then
local p = player.print
p('[ERROR] Only admins are allowed to run this command!', Color.fail)
return
else
if allowed[player.name] then
Profiler.Stop(command.parameter ~= nil, nil)
elseif _DEBUG then
Profiler.Stop(command.parameter ~= nil, nil)
end
end
end
end
end
ignoredFunctions[startCommand] = true
ignoredFunctions[stopCommand] = true
@@ -167,8 +205,7 @@ local function DumpTree(averageMs)
call.profiler.divide(call.calls)
end
str[line + 1] =
string_format('\n%s%dx %s. %s ', string_rep('\t', depth), call.calls, call.name, averageMs and 'Average' or 'Total')
str[line + 1] = string_format('\n%s%dx %s. %s ', string_rep('\t', depth), call.calls, call.name, averageMs and 'Average' or 'Total')
str[line + 2] = call.profiler
line = line + 2