From 0191838dcfaf345b1116949d7ca6f4004b5c857c Mon Sep 17 00:00:00 2001
From: justin <39979049+jjustns@users.noreply.github.com>
Date: Mon, 2 Mar 2026 14:41:42 -0400
Subject: [PATCH 1/3] Add "Lua time recordings" category for clients
---
[web]/performancebrowser/config.lua | 7 +++
[web]/performancebrowser/meta.xml | 1 +
.../performancebrowser/performancebrowser.lua | 8 ----
.../performancebrowser_client.lua | 48 +++++++++++++++++++
[web]/performancebrowser/target.lua | 9 ++--
[web]/performancebrowser/viewer.lua | 2 +-
6 files changed, 61 insertions(+), 14 deletions(-)
create mode 100644 [web]/performancebrowser/config.lua
diff --git a/[web]/performancebrowser/config.lua b/[web]/performancebrowser/config.lua
new file mode 100644
index 000000000..90595d3c3
--- /dev/null
+++ b/[web]/performancebrowser/config.lua
@@ -0,0 +1,7 @@
+-- Lua time recordings config
+g_LuaTimingRecordings = {
+ Enabled = true,
+ Frequency = 5000, -- in milliseconds
+ HistoryLength = 100, -- number of records to keep
+ HighCPUResourcesAmount = 10, -- percentage threshold
+}
\ No newline at end of file
diff --git a/[web]/performancebrowser/meta.xml b/[web]/performancebrowser/meta.xml
index 741f7e20e..d917198aa 100644
--- a/[web]/performancebrowser/meta.xml
+++ b/[web]/performancebrowser/meta.xml
@@ -1,6 +1,7 @@
+
diff --git a/[web]/performancebrowser/performancebrowser.lua b/[web]/performancebrowser/performancebrowser.lua
index 2161a37eb..8d23b3246 100644
--- a/[web]/performancebrowser/performancebrowser.lua
+++ b/[web]/performancebrowser/performancebrowser.lua
@@ -4,14 +4,6 @@
--
--
--- Lua time recordings config
-g_LuaTimingRecordings = {
- Enabled = true,
- Frequency = 2000, -- in milliseconds
- HistoryLength = 300, -- number of records to keep
- HighCPUResourcesAmount = 10, -- percentage threshold
-}
-
-- Global variable to store high usage resources similar to IPB
g_HighUsageResources = {}
diff --git a/[web]/performancebrowser/performancebrowser_client.lua b/[web]/performancebrowser/performancebrowser_client.lua
index c87157b58..0265050f3 100644
--- a/[web]/performancebrowser/performancebrowser_client.lua
+++ b/[web]/performancebrowser/performancebrowser_client.lua
@@ -6,6 +6,7 @@
me = localPlayer
local bSupportsStats = getPerformanceStats ~= nil
+g_HighUsageResources = {}
addEventHandler("onClientResourceStart", resourceRoot,
function (resource)
@@ -30,7 +31,54 @@ addEventHandler('onClientRequestCategories', me,
addEvent('onClientRequestStats', true)
addEventHandler('onClientRequestStats', me,
function( username, queryCategoryName, queryOptionsText, queryFilterText )
+
+ if queryCategoryName == "Lua time recordings" then
+
+ local columns, rows = getPerformanceStats( queryCategoryName, queryOptionsText, queryFilterText )
+ local a = {"Resource", "CPU Usage", "Recorded Time"}
+ local b = g_HighUsageResources
+
+ return triggerServerEvent( "onNotifyStats", resourceRoot, a, b, username, queryCategoryName, queryOptionsText, queryFilterText )
+ end
+
local a,b = getPerformanceStats( queryCategoryName, queryOptionsText, queryFilterText )
triggerServerEvent( "onNotifyStats", resourceRoot, a, b, username, queryCategoryName, queryOptionsText, queryFilterText )
end
)
+
+-- Date/time formatting function
+local function getDateTimeString()
+ local time = getRealTime()
+ local weekday = ({"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"})[time.weekday + 1]
+ -- Weekday, DD.MM.YYYY, hh:mm:ss
+ return ("%s, %02d.%02d.%d, %02d:%02d:%02d"):format(weekday, time.monthday, time.month + 1, time.year + 1900, time.hour, time.minute, time.second)
+end
+
+-- Save high CPU resources function (based on IPB alarm.lua)
+function saveHighCPUResources()
+ local columns, rows = getPerformanceStats("Lua timing")
+
+ if not rows then
+ return
+ end
+
+ for index, row in pairs(rows) do
+ local usageText = row[2]:gsub("[^0-9%.]", "")
+ local usage = math.floor(tonumber(usageText) or 0)
+
+ if (usage > g_LuaTimingRecordings.HighCPUResourcesAmount) then
+ -- Record this high usage to table
+ table.insert(g_HighUsageResources, 1, {row[1], row[2], getDateTimeString()})
+
+ -- Make sure it won't get too big
+ if #g_HighUsageResources > g_LuaTimingRecordings.HistoryLength then
+ table.remove(g_HighUsageResources, g_LuaTimingRecordings.HistoryLength)
+ end
+ end
+ end
+end
+
+-- Start monitoring timer
+if (g_LuaTimingRecordings.Enabled) then
+ setTimer(saveHighCPUResources, g_LuaTimingRecordings.Frequency, 0)
+end
\ No newline at end of file
diff --git a/[web]/performancebrowser/target.lua b/[web]/performancebrowser/target.lua
index c715289f2..f2fdf9089 100644
--- a/[web]/performancebrowser/target.lua
+++ b/[web]/performancebrowser/target.lua
@@ -69,12 +69,11 @@ end
--
---------------------------------------------------------------------------
function Target:getPerformanceStats( username, queryCategoryName, queryOptionsText, queryFilterText )
- -- Handle our custom Lua time recordings category
- if queryCategoryName == "Lua time recordings" then
- return self:getLuaTimingRecordings( queryFilterText )
- end
-
if self.bIsServer then
+ if queryCategoryName == "Lua time recordings" then
+ return self:getLuaTimingRecordings( queryFilterText )
+ end
+
local a, b = getPerformanceStats ( queryCategoryName, queryOptionsText, queryFilterText )
return a, b, true
else
diff --git a/[web]/performancebrowser/viewer.lua b/[web]/performancebrowser/viewer.lua
index 4340c4bea..79cb9c563 100644
--- a/[web]/performancebrowser/viewer.lua
+++ b/[web]/performancebrowser/viewer.lua
@@ -155,7 +155,7 @@ function Viewer:getCategoriesRaw ()
local categories = {}
for _,row in ipairs(rowList) do
table.insert( categories, row[1] )
- if ( row[1] == "Lua timing" and target.bIsServer ) then -- Add our custom Lua time recordings category
+ if ( row[1] == "Lua timing" ) then -- Add our custom Lua time recordings category
table.insert( categories, "Lua time recordings" )
end
end
From 98a477ecbb72bc544496ccfe7b8e36248b27de36 Mon Sep 17 00:00:00 2001
From: justin <39979049+jjustns@users.noreply.github.com>
Date: Tue, 3 Mar 2026 20:19:33 -0400
Subject: [PATCH 2/3] Move "Lua time recordings" functions to one shared file
---
[web]/performancebrowser/config.lua | 7 ---
[web]/performancebrowser/luaTiming.lua | 47 +++++++++++++++++++
[web]/performancebrowser/meta.xml | 2 +-
.../performancebrowser/performancebrowser.lua | 40 ----------------
.../performancebrowser_client.lua | 40 +---------------
5 files changed, 49 insertions(+), 87 deletions(-)
delete mode 100644 [web]/performancebrowser/config.lua
create mode 100644 [web]/performancebrowser/luaTiming.lua
diff --git a/[web]/performancebrowser/config.lua b/[web]/performancebrowser/config.lua
deleted file mode 100644
index 90595d3c3..000000000
--- a/[web]/performancebrowser/config.lua
+++ /dev/null
@@ -1,7 +0,0 @@
--- Lua time recordings config
-g_LuaTimingRecordings = {
- Enabled = true,
- Frequency = 5000, -- in milliseconds
- HistoryLength = 100, -- number of records to keep
- HighCPUResourcesAmount = 10, -- percentage threshold
-}
\ No newline at end of file
diff --git a/[web]/performancebrowser/luaTiming.lua b/[web]/performancebrowser/luaTiming.lua
new file mode 100644
index 000000000..57c9be274
--- /dev/null
+++ b/[web]/performancebrowser/luaTiming.lua
@@ -0,0 +1,47 @@
+-- Lua time recordings config
+g_LuaTimingRecordings = {
+ Enabled = true,
+ Frequency = 5000, -- in milliseconds
+ HistoryLength = 100, -- number of records to keep
+ HighCPUResourcesAmount = 10, -- percentage threshold
+}
+
+-- Global variable to store high usage resources similar to IPB
+g_HighUsageResources = {}
+
+-- Date/time formatting function
+local function getDateTimeString()
+ local time = getRealTime()
+ local weekday = ({"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"})[time.weekday + 1]
+ -- Weekday, DD.MM.YYYY, hh:mm:ss
+ return ("%s, %02d.%02d.%d, %02d:%02d:%02d"):format(weekday, time.monthday, time.month + 1, time.year + 1900, time.hour, time.minute, time.second)
+end
+
+-- Save high CPU resources function (based on IPB alarm.lua)
+function saveHighCPUResources()
+ local columns, rows = getPerformanceStats("Lua timing")
+
+ if not rows then
+ return
+ end
+
+ for index, row in pairs(rows) do
+ local usageText = row[2]:gsub("[^0-9%.]", "")
+ local usage = math.floor(tonumber(usageText) or 0)
+
+ if (usage > g_LuaTimingRecordings.HighCPUResourcesAmount) then
+ -- Record this high usage to table
+ table.insert(g_HighUsageResources, 1, {row[1], row[2], getDateTimeString()})
+
+ -- Make sure it won't get too big
+ if #g_HighUsageResources > g_LuaTimingRecordings.HistoryLength then
+ table.remove(g_HighUsageResources, g_LuaTimingRecordings.HistoryLength)
+ end
+ end
+ end
+end
+
+-- Start monitoring timer
+if (g_LuaTimingRecordings.Enabled) then
+ setTimer(saveHighCPUResources, g_LuaTimingRecordings.Frequency, 0)
+end
\ No newline at end of file
diff --git a/[web]/performancebrowser/meta.xml b/[web]/performancebrowser/meta.xml
index d917198aa..02caa6302 100644
--- a/[web]/performancebrowser/meta.xml
+++ b/[web]/performancebrowser/meta.xml
@@ -1,7 +1,7 @@
-
+
diff --git a/[web]/performancebrowser/performancebrowser.lua b/[web]/performancebrowser/performancebrowser.lua
index 8d23b3246..bbfb38737 100644
--- a/[web]/performancebrowser/performancebrowser.lua
+++ b/[web]/performancebrowser/performancebrowser.lua
@@ -4,48 +4,8 @@
--
--
--- Global variable to store high usage resources similar to IPB
-g_HighUsageResources = {}
-
-- Browser update
function setQuery ( counter, user, target, category, options, filter, showClients )
local viewer = getViewer(user)
return viewer:setQuery ( counter, target, category, options, filter, showClients )
-end
-
--- Date/time formatting function
-local function getDateTimeString()
- local time = getRealTime()
- local weekday = ({"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"})[time.weekday + 1]
- -- Weekday, DD.MM.YYYY, hh:mm:ss
- return ("%s, %02d.%02d.%d, %02d:%02d:%02d"):format(weekday, time.monthday, time.month + 1, time.year + 1900, time.hour, time.minute, time.second)
-end
-
--- Save high CPU resources function (based on IPB alarm.lua)
-function saveHighCPUResources()
- local columns, rows = getPerformanceStats("Lua timing")
-
- if not rows then
- return
- end
-
- for index, row in pairs(rows) do
- local usageText = row[2]:gsub("[^0-9%.]", "")
- local usage = math.floor(tonumber(usageText) or 0)
-
- if (usage > g_LuaTimingRecordings.HighCPUResourcesAmount) then
- -- Record this high usage to table
- table.insert(g_HighUsageResources, 1, {row[1], row[2], getDateTimeString()})
-
- -- Make sure it won't get too big
- if #g_HighUsageResources > g_LuaTimingRecordings.HistoryLength then
- table.remove(g_HighUsageResources, g_LuaTimingRecordings.HistoryLength)
- end
- end
- end
-end
-
--- Start monitoring timer
-if (g_LuaTimingRecordings.Enabled) then
- setTimer(saveHighCPUResources, g_LuaTimingRecordings.Frequency, 0)
end
\ No newline at end of file
diff --git a/[web]/performancebrowser/performancebrowser_client.lua b/[web]/performancebrowser/performancebrowser_client.lua
index 0265050f3..3ba10a4c2 100644
--- a/[web]/performancebrowser/performancebrowser_client.lua
+++ b/[web]/performancebrowser/performancebrowser_client.lua
@@ -6,7 +6,6 @@
me = localPlayer
local bSupportsStats = getPerformanceStats ~= nil
-g_HighUsageResources = {}
addEventHandler("onClientResourceStart", resourceRoot,
function (resource)
@@ -44,41 +43,4 @@ addEventHandler('onClientRequestStats', me,
local a,b = getPerformanceStats( queryCategoryName, queryOptionsText, queryFilterText )
triggerServerEvent( "onNotifyStats", resourceRoot, a, b, username, queryCategoryName, queryOptionsText, queryFilterText )
end
-)
-
--- Date/time formatting function
-local function getDateTimeString()
- local time = getRealTime()
- local weekday = ({"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"})[time.weekday + 1]
- -- Weekday, DD.MM.YYYY, hh:mm:ss
- return ("%s, %02d.%02d.%d, %02d:%02d:%02d"):format(weekday, time.monthday, time.month + 1, time.year + 1900, time.hour, time.minute, time.second)
-end
-
--- Save high CPU resources function (based on IPB alarm.lua)
-function saveHighCPUResources()
- local columns, rows = getPerformanceStats("Lua timing")
-
- if not rows then
- return
- end
-
- for index, row in pairs(rows) do
- local usageText = row[2]:gsub("[^0-9%.]", "")
- local usage = math.floor(tonumber(usageText) or 0)
-
- if (usage > g_LuaTimingRecordings.HighCPUResourcesAmount) then
- -- Record this high usage to table
- table.insert(g_HighUsageResources, 1, {row[1], row[2], getDateTimeString()})
-
- -- Make sure it won't get too big
- if #g_HighUsageResources > g_LuaTimingRecordings.HistoryLength then
- table.remove(g_HighUsageResources, g_LuaTimingRecordings.HistoryLength)
- end
- end
- end
-end
-
--- Start monitoring timer
-if (g_LuaTimingRecordings.Enabled) then
- setTimer(saveHighCPUResources, g_LuaTimingRecordings.Frequency, 0)
-end
\ No newline at end of file
+)
\ No newline at end of file
From e7cd6c8499906a5c8ed981badff959f35e570658 Mon Sep 17 00:00:00 2001
From: justin <39979049+jjustns@users.noreply.github.com>
Date: Tue, 3 Mar 2026 22:35:29 -0400
Subject: [PATCH 3/3] Fix filtering when viewing client lua time recordings
---
[web]/performancebrowser/luaTiming.lua | 21 ++++++++++++
.../performancebrowser_client.lua | 6 +---
[web]/performancebrowser/target.lua | 33 ++-----------------
3 files changed, 24 insertions(+), 36 deletions(-)
diff --git a/[web]/performancebrowser/luaTiming.lua b/[web]/performancebrowser/luaTiming.lua
index 57c9be274..ae4c6facb 100644
--- a/[web]/performancebrowser/luaTiming.lua
+++ b/[web]/performancebrowser/luaTiming.lua
@@ -17,6 +17,27 @@ local function getDateTimeString()
return ("%s, %02d.%02d.%d, %02d:%02d:%02d"):format(weekday, time.monthday, time.month + 1, time.year + 1900, time.hour, time.minute, time.second)
end
+function getLuaTimingRecordings( queryFilterText )
+ local columns = {"Resource", "CPU Usage", "Recorded Time"}
+ local rows = {}
+
+ -- Get the global high usage resources if it exists
+ if g_HighUsageResources then
+ for i, recording in ipairs(g_HighUsageResources) do
+ local resourceName = recording[1]
+ local cpuUsage = recording[2]
+ local recordedTime = recording[3]
+
+ -- Apply filter if specified
+ if not queryFilterText or queryFilterText == "" or string.find(string.lower(resourceName), string.lower(queryFilterText), 1, true) then
+ table.insert(rows, {resourceName, cpuUsage, recordedTime})
+ end
+ end
+ end
+
+ return columns, rows, true
+end
+
-- Save high CPU resources function (based on IPB alarm.lua)
function saveHighCPUResources()
local columns, rows = getPerformanceStats("Lua timing")
diff --git a/[web]/performancebrowser/performancebrowser_client.lua b/[web]/performancebrowser/performancebrowser_client.lua
index 3ba10a4c2..7289953de 100644
--- a/[web]/performancebrowser/performancebrowser_client.lua
+++ b/[web]/performancebrowser/performancebrowser_client.lua
@@ -32,11 +32,7 @@ addEventHandler('onClientRequestStats', me,
function( username, queryCategoryName, queryOptionsText, queryFilterText )
if queryCategoryName == "Lua time recordings" then
-
- local columns, rows = getPerformanceStats( queryCategoryName, queryOptionsText, queryFilterText )
- local a = {"Resource", "CPU Usage", "Recorded Time"}
- local b = g_HighUsageResources
-
+ local a, b = getLuaTimingRecordings( queryFilterText )
return triggerServerEvent( "onNotifyStats", resourceRoot, a, b, username, queryCategoryName, queryOptionsText, queryFilterText )
end
diff --git a/[web]/performancebrowser/target.lua b/[web]/performancebrowser/target.lua
index f2fdf9089..309da04fe 100644
--- a/[web]/performancebrowser/target.lua
+++ b/[web]/performancebrowser/target.lua
@@ -71,7 +71,7 @@ end
function Target:getPerformanceStats( username, queryCategoryName, queryOptionsText, queryFilterText )
if self.bIsServer then
if queryCategoryName == "Lua time recordings" then
- return self:getLuaTimingRecordings( queryFilterText )
+ return getLuaTimingRecordings( queryFilterText )
end
local a, b = getPerformanceStats ( queryCategoryName, queryOptionsText, queryFilterText )
@@ -157,33 +157,4 @@ addEventHandler('onNotifyStats', resourceRoot,
store.queryFilterText = queryFilterText
store.timeAdded = getTickCount()
end
-)
-
----------------------------------------------------------------------------
---
--- Target:getLuaTimingRecordings()
---
--- Get recorded high usage Lua timing data
---
----------------------------------------------------------------------------
-function Target:getLuaTimingRecordings( queryFilterText )
- local columns = {"Resource", "CPU Usage", "Recorded Time"}
- local rows = {}
-
- -- Get the global high usage resources if it exists
- if g_HighUsageResources then
- for i, recording in ipairs(g_HighUsageResources) do
- local resourceName = recording[1]
- local cpuUsage = recording[2]
- local recordedTime = recording[3]
-
- -- Apply filter if specified
- if not queryFilterText or queryFilterText == "" or string.find(string.lower(resourceName), string.lower(queryFilterText), 1, true) then
- table.insert(rows, {resourceName, cpuUsage, recordedTime})
- end
- end
- end
-
- return columns, rows, true
-end
-
+)
\ No newline at end of file