-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.lua
More file actions
50 lines (48 loc) · 2.21 KB
/
Copy pathserver.lua
File metadata and controls
50 lines (48 loc) · 2.21 KB
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
49
50
local Webhook = "https://discord.com/api/webhooks/" -- replace with your own webhook URL
local UseWebhook = true -- set to true to send to discord webhook
--Don't mess with anything below this line
local ProfRunning = false
RegisterConsoleListener(function(channel, message)
if string.find(message, "server thread hitch warning") then
if not ProfRunning then
print("Hitch warning detected, starting profiler")
ExecuteCommand("profiler record 100")
ProfRunning = true
end
end
if string.find(message, "Stopped the recording") then
local resname = GetCurrentResourceName()
local respath = GetResourcePath(resname)
ExecuteCommand("profiler saveJSON " .. respath .. "/profiler.json")
end
if string.find(message, "Save complete") then
local oldnamets = 0
local oldname = None
local warnmessage = "The following resources are using more tick time than recommended, please check them out:"
local discordmessage = warnmessage .. "\n"
local json2 = LoadResourceFile(GetCurrentResourceName(), "profiler.json")
local traceEvents = json.decode(json2).traceEvents
print(warnmessage)
for k,v in pairs(traceEvents) do
if string.find(v.name, "tick") then
if oldname == v.name then
local ticktime = v.ts - oldnamets
if ticktime > 5000 then
local name = string.gsub(v.name, "tick", "")
local name = string.gsub(name, "%(", "")
local name = string.gsub(name, "%)", "")
local name = string.gsub(name, " ", "")
print(name .. ": " .. ticktime / 1000 .. "ms")
discordmessage = discordmessage .. name .. ": " .. ticktime / 1000 .. "ms\n"
end
end
oldname = v.name
oldnamets = v.ts
end
end
if UseWebhook then
PerformHttpRequest(Webhook, function(err, text, headers) end, 'POST', json.encode({content = discordmessage}), { ['Content-Type'] = 'application/json' })
end
ProfRunning = false
end
end)