trying to get coverage analysis to reasonable time
This commit is contained in:
@@ -194,11 +194,29 @@ function profile.draw()
|
||||
love.graphics.print("Press - to remove 10 animated elements", 10, love.graphics.getHeight() - 45)
|
||||
end
|
||||
|
||||
function profile.keypressed(key)
|
||||
function profile.keypressed(key, profiler)
|
||||
if key == "=" or key == "+" then
|
||||
-- Create snapshot before changing animation count
|
||||
if profiler then
|
||||
local label = string.format("%d animations", profile.animationCount)
|
||||
profiler:createSnapshot(label, {
|
||||
animationCount = profile.animationCount,
|
||||
activeAnimations = #profile.animations
|
||||
})
|
||||
end
|
||||
|
||||
profile.animationCount = math.min(profile.maxAnimations, profile.animationCount + 10)
|
||||
profile.buildLayout()
|
||||
elseif key == "-" or key == "_" then
|
||||
-- Create snapshot before changing animation count
|
||||
if profiler then
|
||||
local label = string.format("%d animations", profile.animationCount)
|
||||
profiler:createSnapshot(label, {
|
||||
animationCount = profile.animationCount,
|
||||
activeAnimations = #profile.animations
|
||||
})
|
||||
end
|
||||
|
||||
profile.animationCount = math.max(profile.minAnimations, profile.animationCount - 10)
|
||||
profile.buildLayout()
|
||||
end
|
||||
|
||||
@@ -127,11 +127,29 @@ function profile.draw()
|
||||
love.graphics.print("Press - to remove 50 elements", 10, love.graphics.getHeight() - 45)
|
||||
end
|
||||
|
||||
function profile.keypressed(key)
|
||||
function profile.keypressed(key, profiler)
|
||||
if key == "=" or key == "+" then
|
||||
-- Create snapshot before changing element count
|
||||
if profiler then
|
||||
local label = string.format("%d elements", profile.elementCount)
|
||||
profiler:createSnapshot(label, {
|
||||
elementCount = profile.elementCount,
|
||||
nestingDepth = profile.nestingDepth
|
||||
})
|
||||
end
|
||||
|
||||
profile.elementCount = math.min(profile.maxElements, profile.elementCount + 50)
|
||||
profile.buildLayout()
|
||||
elseif key == "-" or key == "_" then
|
||||
-- Create snapshot before changing element count
|
||||
if profiler then
|
||||
local label = string.format("%d elements", profile.elementCount)
|
||||
profiler:createSnapshot(label, {
|
||||
elementCount = profile.elementCount,
|
||||
nestingDepth = profile.nestingDepth
|
||||
})
|
||||
end
|
||||
|
||||
profile.elementCount = math.max(10, profile.elementCount - 50)
|
||||
profile.buildLayout()
|
||||
end
|
||||
|
||||
@@ -152,11 +152,41 @@ function profile.draw()
|
||||
love.graphics.print("Press R/T/L to toggle features", 10, love.graphics.getHeight() - 50)
|
||||
end
|
||||
|
||||
function profile.keypressed(key)
|
||||
function profile.keypressed(key, profiler)
|
||||
if key == "=" or key == "+" then
|
||||
-- Create snapshot before changing element count
|
||||
if profiler then
|
||||
local label = string.format("%d elements (R:%s T:%s L:%s)",
|
||||
profile.elementCount,
|
||||
profile.showRounded and "on" or "off",
|
||||
profile.showText and "on" or "off",
|
||||
profile.showLayering and "on" or "off")
|
||||
profiler:createSnapshot(label, {
|
||||
elementCount = profile.elementCount,
|
||||
showRounded = profile.showRounded,
|
||||
showText = profile.showText,
|
||||
showLayering = profile.showLayering
|
||||
})
|
||||
end
|
||||
|
||||
profile.elementCount = math.min(profile.maxElements, profile.elementCount + 50)
|
||||
profile.buildLayout()
|
||||
elseif key == "-" or key == "_" then
|
||||
-- Create snapshot before changing element count
|
||||
if profiler then
|
||||
local label = string.format("%d elements (R:%s T:%s L:%s)",
|
||||
profile.elementCount,
|
||||
profile.showRounded and "on" or "off",
|
||||
profile.showText and "on" or "off",
|
||||
profile.showLayering and "on" or "off")
|
||||
profiler:createSnapshot(label, {
|
||||
elementCount = profile.elementCount,
|
||||
showRounded = profile.showRounded,
|
||||
showText = profile.showText,
|
||||
showLayering = profile.showLayering
|
||||
})
|
||||
end
|
||||
|
||||
profile.elementCount = math.max(profile.minElements, profile.elementCount - 50)
|
||||
profile.buildLayout()
|
||||
elseif key == "r" then
|
||||
|
||||
@@ -335,7 +335,7 @@ function love.keypressed(key)
|
||||
|
||||
if state.currentProfile and type(state.currentProfile.keypressed) == "function" then
|
||||
pcall(function()
|
||||
state.currentProfile.keypressed(key)
|
||||
state.currentProfile.keypressed(key, state.profiler)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
---@field _currentFrameStart number?
|
||||
---@field _maxHistorySize number
|
||||
---@field _lastGcCount number
|
||||
---@field _snapshots table
|
||||
---@field _currentSnapshot table?
|
||||
local PerformanceProfiler = {}
|
||||
PerformanceProfiler.__index = PerformanceProfiler
|
||||
|
||||
@@ -29,6 +31,8 @@ function PerformanceProfiler.new(config)
|
||||
self._markers = {}
|
||||
self._currentFrameStart = nil
|
||||
self._lastGcCount = collectgarbage("count")
|
||||
self._snapshots = {}
|
||||
self._currentSnapshot = nil
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -379,6 +383,42 @@ function PerformanceProfiler:reset()
|
||||
self._markers = {}
|
||||
self._currentFrameStart = nil
|
||||
self._lastGcCount = collectgarbage("count")
|
||||
-- Don't reset snapshots - they persist across resets
|
||||
end
|
||||
|
||||
--- Create a snapshot of current metrics with a label
|
||||
---@param label string Label for this snapshot (e.g., "100 elements", "500 elements")
|
||||
---@param metadata table? Additional metadata to store with snapshot
|
||||
---@return nil
|
||||
function PerformanceProfiler:createSnapshot(label, metadata)
|
||||
local report = self:getReport()
|
||||
|
||||
table.insert(self._snapshots, {
|
||||
label = label,
|
||||
timestamp = os.date("%Y-%m-%d %H:%M:%S"),
|
||||
metadata = metadata or {},
|
||||
report = report,
|
||||
})
|
||||
|
||||
-- Reset current metrics for next snapshot period
|
||||
self._frameCount = 0
|
||||
self._startTime = love.timer.getTime()
|
||||
self._frameTimes = {}
|
||||
self._fpsHistory = {}
|
||||
self._memoryHistory = {}
|
||||
self._currentFrameStart = nil
|
||||
end
|
||||
|
||||
--- Get all snapshots
|
||||
---@return table
|
||||
function PerformanceProfiler:getSnapshots()
|
||||
return self._snapshots
|
||||
end
|
||||
|
||||
--- Clear all snapshots
|
||||
---@return nil
|
||||
function PerformanceProfiler:clearSnapshots()
|
||||
self._snapshots = {}
|
||||
end
|
||||
|
||||
---@return string
|
||||
@@ -571,6 +611,45 @@ function PerformanceProfiler:_saveWithIO(filepath, profileName)
|
||||
end
|
||||
end
|
||||
|
||||
-- Snapshots (if any)
|
||||
if #self._snapshots > 0 then
|
||||
table.insert(lines, "## Snapshots")
|
||||
table.insert(lines, "")
|
||||
table.insert(lines, "> Performance metrics captured at different configuration points")
|
||||
table.insert(lines, "")
|
||||
|
||||
for i, snapshot in ipairs(self._snapshots) do
|
||||
table.insert(lines, string.format("### %d. %s", i, snapshot.label))
|
||||
table.insert(lines, "")
|
||||
table.insert(lines, string.format("**Captured:** %s", snapshot.timestamp))
|
||||
|
||||
-- Show metadata if present
|
||||
if next(snapshot.metadata) then
|
||||
table.insert(lines, "")
|
||||
table.insert(lines, "**Configuration:**")
|
||||
for key, value in pairs(snapshot.metadata) do
|
||||
table.insert(lines, string.format("- %s: `%s`", key, tostring(value)))
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(lines, "")
|
||||
|
||||
local r = snapshot.report
|
||||
|
||||
-- Compact FPS/Frame Time table
|
||||
table.insert(lines, "| FPS | Frame Time (ms) | Memory (MB) | Frames |")
|
||||
table.insert(lines, "|-----|-----------------|-------------|--------|")
|
||||
table.insert(lines, string.format("| Avg: %.1f | Avg: %.2f | Avg: %.2f | %d |",
|
||||
r.fps.average, r.frameTime.average, r.memory.average, r.frameCount))
|
||||
table.insert(lines, string.format("| 1%% Worst: **%.1f** | P99: %.2f | Peak: %.2f | Duration: %.1fs |",
|
||||
r.fps.worst_1_percent, r.frameTime.p99, r.memory.peak, r.totalTime))
|
||||
table.insert(lines, "")
|
||||
end
|
||||
|
||||
table.insert(lines, "---")
|
||||
table.insert(lines, "")
|
||||
end
|
||||
|
||||
table.insert(lines, "---")
|
||||
table.insert(lines, "")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user