mirror of
https://github.com/FPtje/FProfiler.git
synced 2025-03-04 03:03:14 -05:00
Working focus
This commit is contained in:
parent
68aee70633
commit
c569d06e89
@ -4,11 +4,15 @@ FProfiler.UI = {}
|
||||
AddCSLuaFile()
|
||||
AddCSLuaFile("fprofiler/gather.lua")
|
||||
AddCSLuaFile("fprofiler/report.lua")
|
||||
AddCSLuaFile("fprofiler/util.lua")
|
||||
AddCSLuaFile("fprofiler/prettyprint.lua")
|
||||
|
||||
AddCSLuaFile("fprofiler/ui/model.lua")
|
||||
AddCSLuaFile("fprofiler/ui/frame.lua")
|
||||
AddCSLuaFile("fprofiler/ui/clientcontrol.lua")
|
||||
|
||||
include("fprofiler/prettyprint.lua")
|
||||
include("fprofiler/util.lua")
|
||||
include("fprofiler/gather.lua")
|
||||
include("fprofiler/report.lua")
|
||||
|
||||
|
@ -9,7 +9,7 @@ local function restartProfiling()
|
||||
update({"client", "recordTime"}, 0)
|
||||
end
|
||||
|
||||
local focus = get({"client", "focus"})
|
||||
local focus = get({"client", "focusObj"})
|
||||
|
||||
update({"client", "sessionStart"}, CurTime())
|
||||
FProfiler.start(focus)
|
||||
@ -60,3 +60,10 @@ onUpdate({"client", "status"}, function(new, old)
|
||||
if new == old then return end
|
||||
(new == "Started" and restartProfiling or stopProfiling)()
|
||||
end)
|
||||
|
||||
--[[-------------------------------------------------------------------------
|
||||
Update the current selected focus object when data is entered
|
||||
---------------------------------------------------------------------------]]
|
||||
onUpdate({"client", "focusStr"}, function(new)
|
||||
update({"client", "focusObj"}, FProfiler.funcNameToObj(new))
|
||||
end)
|
||||
|
@ -29,6 +29,63 @@ end
|
||||
|
||||
derma.DefineControl("FProfileRealmPanel", "", REALMPANEL, "Panel")
|
||||
|
||||
|
||||
local FUNCINDICATOR = {}
|
||||
|
||||
function FUNCINDICATOR:Init()
|
||||
self:SetTall(5)
|
||||
self.color = Color(0, 0, 0, 0)
|
||||
end
|
||||
|
||||
function FUNCINDICATOR:Paint()
|
||||
draw.RoundedBox(0, 0, 0, self:GetWide(), self:GetTall(), self.color)
|
||||
end
|
||||
|
||||
derma.DefineControl("FProfileFuncIndicator", "", FUNCINDICATOR, "DPanel")
|
||||
|
||||
|
||||
local FOCUSPANEL = {}
|
||||
|
||||
function FOCUSPANEL:Init()
|
||||
self:DockPadding(0, 5, 0, 0)
|
||||
self:DockMargin(5, 0, 5, 0)
|
||||
|
||||
self.focusLabel = vgui.Create("DLabel", self)
|
||||
self.focusLabel:SetDark(true)
|
||||
self.focusLabel:SetText("Profiling Focus:")
|
||||
|
||||
self.focusLabel:SizeToContents()
|
||||
self.focusLabel:Dock(TOP)
|
||||
|
||||
self.funcIndicator = vgui.Create("FProfileFuncIndicator", self)
|
||||
self.funcIndicator:Dock(BOTTOM)
|
||||
|
||||
self.focusBox = vgui.Create("DTextEntry", self)
|
||||
self.focusBox:SetText("")
|
||||
self.focusBox:Dock(BOTTOM)
|
||||
|
||||
function self.focusBox:OnChange()
|
||||
FProfiler.UI.updateCurrentRealm("focusStr", self:GetText())
|
||||
end
|
||||
|
||||
FProfiler.UI.onCurrentRealmUpdate("focusObj", function(new)
|
||||
self.funcIndicator.color = FProfiler.UI.getCurrentRealmValue("focusStr") == "" and Color(0, 0, 0, 0) or new and Color(80, 255, 80, 255) or Color(255, 80, 80, 255)
|
||||
end)
|
||||
|
||||
FProfiler.UI.onCurrentRealmUpdate("focusStr", function(new, old)
|
||||
if self.focusBox:GetText() == new then return end
|
||||
|
||||
self.focusBox:SetText(tostring(new))
|
||||
end)
|
||||
end
|
||||
|
||||
function FOCUSPANEL:PerformLayout()
|
||||
self.focusBox:SetWide(200)
|
||||
self.focusLabel:SizeToContents()
|
||||
end
|
||||
|
||||
derma.DefineControl("FProfileFocusPanel", "", FOCUSPANEL, "Panel")
|
||||
|
||||
local TIMERPANEL = {}
|
||||
|
||||
function TIMERPANEL:Init()
|
||||
@ -42,7 +99,6 @@ function TIMERPANEL:Init()
|
||||
self.timeLabel:SizeToContents()
|
||||
self.timeLabel:Dock(TOP)
|
||||
|
||||
|
||||
self.counter = vgui.Create("DLabel", self)
|
||||
self.counter:SetDark(true)
|
||||
self.counter:SetText("00:00:00")
|
||||
@ -120,6 +176,9 @@ function MAGICBAR:Init()
|
||||
|
||||
self.realmpanel:Dock(LEFT)
|
||||
|
||||
self.focuspanel = vgui.Create("FProfileFocusPanel", self)
|
||||
self.focuspanel:Dock(LEFT)
|
||||
|
||||
-- Timer
|
||||
self.timerpanel = vgui.Create("FProfileTimerPanel", self)
|
||||
self.timerpanel:Dock(RIGHT)
|
||||
@ -127,6 +186,7 @@ end
|
||||
|
||||
function MAGICBAR:PerformLayout()
|
||||
self.realmpanel:SizeToChildren(true, false)
|
||||
self.focuspanel:SizeToChildren(true, false)
|
||||
self.timerpanel:SizeToChildren(true, false)
|
||||
end
|
||||
|
||||
@ -269,6 +329,12 @@ function FUNCDETAILS:Init()
|
||||
self.focus:SetFont("DermaDefaultBold")
|
||||
self.focus:Dock(BOTTOM)
|
||||
|
||||
function self.focus:DoClick()
|
||||
local sel = FProfiler.UI.getCurrentRealmValue("currentSelected")
|
||||
if not sel then return end
|
||||
|
||||
FProfiler.UI.updateCurrentRealm("focusStr", sel.func)
|
||||
end
|
||||
|
||||
self.toConsole = vgui.Create("DButton", self)
|
||||
self.toConsole:SetText("Print Details to Console")
|
||||
|
@ -11,23 +11,27 @@ local model =
|
||||
client = {
|
||||
status = "Stopped", -- Started or Stopped
|
||||
shouldReset = true, -- Whether profiling should start anew
|
||||
focus = nil, -- Any function in focus
|
||||
recordTime = 0, -- Total time spent on the last full profiling session
|
||||
sessionStart = nil, -- When the last profiling session was started
|
||||
bottlenecks = {}, -- The list of bottleneck functions
|
||||
topLagSpikes = {}, -- Top of lagging functions
|
||||
currentSelected = nil, -- Currently selected function
|
||||
|
||||
focusObj = nil, -- The current function being focussed upon in profiling
|
||||
focusStr = "", -- The current function name being entered
|
||||
},
|
||||
|
||||
server = {
|
||||
status = "Stopped", -- Started or Stopped
|
||||
shouldReset = true, -- Whether profiling should start anew
|
||||
focus = nil, -- Any function in focus
|
||||
bottlenecks = {}, -- The list of bottleneck functions
|
||||
recordTime = 0, -- Total time spent on the last full profiling session
|
||||
sessionStart = nil, -- When the last profiling session was started
|
||||
topLagSpikes = {}, -- Top of lagging functions
|
||||
currentSelected = nil, -- Currently selected function
|
||||
|
||||
focusObj = nil, -- The current function being focussed upon in profiling
|
||||
focusStr = "", -- The current function name
|
||||
},
|
||||
}
|
||||
|
||||
|
24
lua/fprofiler/util.lua
Normal file
24
lua/fprofiler/util.lua
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
-- Try to find the function represented by a string
|
||||
function FProfiler.funcNameToObj(str)
|
||||
if isfunction(str) then return str end
|
||||
|
||||
local times = FProfiler.getInclusiveTimes()
|
||||
for func, _ in pairs(times) do
|
||||
if tostring(func) == str then return func end
|
||||
end
|
||||
|
||||
local tbl = _G
|
||||
local exploded = string.Explode(".", str, false)
|
||||
if not exploded or not exploded[1] then return end
|
||||
|
||||
for i = 1, #exploded - 1 do
|
||||
tbl = (tbl or {})[exploded[i]]
|
||||
end
|
||||
|
||||
local func = (tbl or {})[exploded[#exploded]]
|
||||
|
||||
if not isfunction(func) then return end
|
||||
|
||||
return func
|
||||
end
|
Loading…
Reference in New Issue
Block a user