mirror of
https://github.com/FPtje/FProfiler.git
synced 2025-03-04 03:03:14 -05:00
Show source of function
This commit is contained in:
parent
02e5163197
commit
f9bcee73ce
@ -6,6 +6,7 @@ The server is involved in the ui in the sense that it interacts with its model
|
||||
util.AddNetworkString("FProfile_startProfiling")
|
||||
util.AddNetworkString("FProfile_stopProfiling")
|
||||
util.AddNetworkString("FProfile_focusObj")
|
||||
util.AddNetworkString("FProfile_getSource")
|
||||
|
||||
|
||||
--[[-------------------------------------------------------------------------
|
||||
@ -99,9 +100,21 @@ end
|
||||
|
||||
-- Sends the top n functions
|
||||
local function writeTopN()
|
||||
net.WriteUInt(#model.topLagSpikes, 8)
|
||||
local count = #model.topLagSpikes
|
||||
|
||||
-- All top N f
|
||||
for i = count, 0, -1 do
|
||||
if model.topLagSpikes[i].info then break end -- Entry exists
|
||||
count = i
|
||||
end
|
||||
|
||||
net.WriteUInt(count, 8)
|
||||
|
||||
for i = 1, count do
|
||||
local row = model.topLagSpikes[i]
|
||||
|
||||
if not row.info then break end
|
||||
|
||||
for i, row in ipairs(model.topLagSpikes) do
|
||||
writeRowData(row)
|
||||
|
||||
net.WriteString(row.info.name or "")
|
||||
@ -109,6 +122,8 @@ local function writeTopN()
|
||||
net.WriteDouble(row.runtime)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[-------------------------------------------------------------------------
|
||||
Receive a stop profiling signal
|
||||
---------------------------------------------------------------------------]]
|
||||
@ -128,3 +143,21 @@ receive("FProfile_stopProfiling", function(_, ply)
|
||||
writeTopN()
|
||||
net.Send(ply)
|
||||
end)
|
||||
|
||||
|
||||
--[[-------------------------------------------------------------------------
|
||||
Send the source of a function to a client
|
||||
---------------------------------------------------------------------------]]
|
||||
receive("FProfile_getSource", function(_, ply)
|
||||
local func = FProfiler.funcNameToObj(net.ReadString())
|
||||
|
||||
if not func then return end
|
||||
|
||||
local info = debug.getinfo(func)
|
||||
|
||||
if not info then return end
|
||||
|
||||
net.Start("FProfile_getSource")
|
||||
net.WriteString(FProfiler.readSource(info.short_src, info.linedefined, info.lastlinedefined) or "")
|
||||
net.Send(ply)
|
||||
end)
|
||||
|
@ -102,3 +102,18 @@ onUpdate({"server", "status"}, function(new, old)
|
||||
if new == old then return end
|
||||
(new == "Started" and restartProfiling or stopProfiling)()
|
||||
end)
|
||||
|
||||
--[[-------------------------------------------------------------------------
|
||||
Update info when a different line is selected
|
||||
---------------------------------------------------------------------------]]
|
||||
FProfiler.UI.onModelUpdate({"server", "currentSelected"}, function(new)
|
||||
if not new or not new.info or not new.info.linedefined or not new.info.lastlinedefined or not new.info.short_src then return end
|
||||
|
||||
net.Start("FProfile_getSource")
|
||||
net.WriteString(tostring(new.func))
|
||||
net.SendToServer()
|
||||
end)
|
||||
|
||||
net.Receive("FProfile_getSource", function()
|
||||
FProfiler.UI.updateModel({"server", "sourceText"}, net.ReadString())
|
||||
end)
|
||||
|
@ -3,7 +3,7 @@
|
||||
function FProfiler.funcNameToObj(str)
|
||||
if isfunction(str) then return str end
|
||||
|
||||
local times = FProfiler.getInclusiveTimes()
|
||||
local times = FProfiler.getCallCounts()
|
||||
for func, _ in pairs(times) do
|
||||
if tostring(func) == str then return func end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user