mirror of
https://github.com/FPtje/FProfiler.git
synced 2025-03-04 03:03:14 -05:00
Fixed up printing a function's details for serverside stuff
This commit is contained in:
parent
a280bb70f3
commit
2fa0ecf742
@ -51,8 +51,23 @@ end)
|
||||
--[[-------------------------------------------------------------------------
|
||||
Update info when a different line is selected
|
||||
---------------------------------------------------------------------------]]
|
||||
FProfiler.UI.onModelUpdate({"client", "currentSelected"}, function(new)
|
||||
onUpdate({"client", "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
|
||||
|
||||
FProfiler.UI.updateModel({"client", "sourceText"}, FProfiler.readSource(new.info.short_src, new.info.linedefined, new.info.lastlinedefined))
|
||||
update({"client", "sourceText"}, FProfiler.readSource(new.info.short_src, new.info.linedefined, new.info.lastlinedefined))
|
||||
end)
|
||||
|
||||
--[[-------------------------------------------------------------------------
|
||||
When a function is to be printed to console
|
||||
---------------------------------------------------------------------------]]
|
||||
onUpdate({"client", "toConsole"}, function(data)
|
||||
if not data then return end
|
||||
|
||||
update({"client", "toConsole"}, nil)
|
||||
show(data)
|
||||
|
||||
file.CreateDir("fprofiler")
|
||||
file.Write("fprofiler/profiledata.txt", showStr(data))
|
||||
MsgC(Color(200, 200, 200), "-----", Color(120, 120, 255), "NOTE", Color(200, 200, 200), "---------------\n")
|
||||
MsgC(Color(200, 200, 200), "If the above function does not fit in console, you can find it in data/fprofiler/profiledata.txt\n\n")
|
||||
end)
|
||||
|
@ -354,14 +354,7 @@ function FUNCDETAILS:Init()
|
||||
self.toConsole:Dock(BOTTOM)
|
||||
|
||||
function self.toConsole:DoClick()
|
||||
local data = FProfiler.UI.getCurrentRealmValue("currentSelected")
|
||||
|
||||
show(data)
|
||||
|
||||
file.CreateDir("fprofiler")
|
||||
file.Write("fprofiler/profiledata.txt", showStr(data))
|
||||
MsgC(Color(200, 200, 200), "-----", Color(120, 120, 255), "NOTE", Color(200, 200, 200), "---------------\n")
|
||||
MsgC(Color(200, 200, 200), "If the above function does not fit in console, you can find it in data/fprofiler/profiledata.txt\n\n")
|
||||
FProfiler.UI.updateCurrentRealm("toConsole", FProfiler.UI.getCurrentRealmValue("currentSelected"))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -20,6 +20,8 @@ local model =
|
||||
focusObj = nil, -- The current function being focussed upon in profiling
|
||||
focusStr = "", -- The current function name being entered
|
||||
|
||||
toConsole = nil, -- Any functions that should be printed to console
|
||||
|
||||
sourceText = "" -- The text of the source function (if available)
|
||||
},
|
||||
|
||||
@ -35,6 +37,8 @@ local model =
|
||||
focusObj = nil, -- The current function being focussed upon in profiling
|
||||
focusStr = "", -- The current function name
|
||||
|
||||
toConsole = nil, -- Any functions that should be printed to console
|
||||
|
||||
sourceText = "" -- The text of the source function (if available)
|
||||
},
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ util.AddNetworkString("FProfile_startProfiling")
|
||||
util.AddNetworkString("FProfile_stopProfiling")
|
||||
util.AddNetworkString("FProfile_focusObj")
|
||||
util.AddNetworkString("FProfile_getSource")
|
||||
util.AddNetworkString("FProfile_printFunction")
|
||||
|
||||
|
||||
--[[-------------------------------------------------------------------------
|
||||
@ -161,3 +162,40 @@ receive("FProfile_getSource", function(_, ply)
|
||||
net.WriteString(FProfiler.readSource(info.short_src, info.linedefined, info.lastlinedefined) or "")
|
||||
net.Send(ply)
|
||||
end)
|
||||
|
||||
--[[-------------------------------------------------------------------------
|
||||
Print the details of a function
|
||||
---------------------------------------------------------------------------]]
|
||||
receive("FProfile_printFunction", function(_, ply)
|
||||
local source = net.ReadBool() -- true is from bottlenecks, false is from Top-N
|
||||
local dataSource = source and model.bottlenecks or model.topLagSpikes
|
||||
local func = net.ReadString()
|
||||
|
||||
local data
|
||||
|
||||
for _, row in ipairs(dataSource or {}) do
|
||||
if tostring(row.func) == func then data = row break end
|
||||
end
|
||||
|
||||
if not data then return end
|
||||
|
||||
-- Show the data
|
||||
show(data)
|
||||
local plaintext = showStr(data)
|
||||
|
||||
-- Write to file if necessary
|
||||
file.CreateDir("fprofiler")
|
||||
file.Write("fprofiler/profiledata.txt", plaintext)
|
||||
MsgC(Color(200, 200, 200), "-----", Color(120, 120, 255), "NOTE", Color(200, 200, 200), "---------------\n")
|
||||
MsgC(Color(200, 200, 200), "If the above function does not fit in console, you can find it in data/fprofiler/profiledata.txt\n\n")
|
||||
|
||||
-- Listen server hosts already see the server console
|
||||
if ply:IsListenServerHost() then return end
|
||||
|
||||
-- Send a plaintext version to the client
|
||||
local binary = util.Compress(plaintext)
|
||||
|
||||
net.Start("FProfile_printFunction")
|
||||
net.WriteData(binary, #binary)
|
||||
net.Send(ply)
|
||||
end)
|
||||
|
@ -117,3 +117,34 @@ end)
|
||||
net.Receive("FProfile_getSource", function()
|
||||
FProfiler.UI.updateModel({"server", "sourceText"}, net.ReadString())
|
||||
end)
|
||||
|
||||
--[[-------------------------------------------------------------------------
|
||||
When a function is to be printed to console
|
||||
---------------------------------------------------------------------------]]
|
||||
onUpdate({"server", "toConsole"}, function(data)
|
||||
if not data then return end
|
||||
|
||||
update({"server", "toConsole"}, nil)
|
||||
|
||||
net.Start("FProfile_printFunction")
|
||||
net.WriteBool(data.total_called and true or false) -- true for bottleneck function, false for top-n function
|
||||
net.WriteString(tostring(data.func))
|
||||
net.SendToServer()
|
||||
end)
|
||||
|
||||
net.Receive("FProfile_printFunction", function(len)
|
||||
local data = net.ReadData(len)
|
||||
local decompressed = util.Decompress(data)
|
||||
|
||||
-- Print the text line by line, otherwise big parts of big data will not be printed
|
||||
local split = string.Explode("\n", decompressed, false)
|
||||
for _, line in ipairs(split) do
|
||||
MsgN(line)
|
||||
end
|
||||
|
||||
-- Write the thing to a file
|
||||
file.CreateDir("fprofiler")
|
||||
file.Write("fprofiler/profiledata.txt", showStr(data))
|
||||
MsgC(Color(200, 200, 200), "-----", Color(120, 120, 255), "NOTE", Color(200, 200, 200), "---------------\n")
|
||||
MsgC(Color(200, 200, 200), "In the server's console you can find a colour coded version of the above output.\nIf the above function does not fit in console, you can find it in data/fprofiler/profiledata.txt\n\n")
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user