mirror of
https://github.com/TangentFoxy/Piefiller.git
synced 2024-11-19 17:14:23 +00:00
lots of tweaks, adding compatibility to 0.10.2
This commit is contained in:
parent
7657f31fd1
commit
6ce2e48317
2
LICENSE
2
LICENSE
@ -1,6 +1,7 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 devfirefly
|
||||
Some modifications copyright (c) 2017 Guard13007
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@ -19,4 +20,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
12
README.md
12
README.md
@ -37,7 +37,15 @@ currently reworking it.
|
||||
Pie:mousepressed(...)
|
||||
end
|
||||
```
|
||||
5) With sufficient output, press the "E" key to output to file.
|
||||
5) With sufficient output, press the `E` key to output to file. Example output:
|
||||
```
|
||||
-----drawRectangles-----
|
||||
source:@main.lua:20
|
||||
current line: 22
|
||||
time: 548.325
|
||||
percentage: 98 %
|
||||
----------------
|
||||
```
|
||||
|
||||
# Keys
|
||||
|
||||
@ -49,7 +57,7 @@ up = decreases depth
|
||||
|
||||
down = increases depth
|
||||
|
||||
- = decreases step size
|
||||
\- = decreases step size
|
||||
|
||||
= = increases step size
|
||||
|
||||
|
10
main.lua
10
main.lua
@ -60,3 +60,13 @@ end
|
||||
function love.mousepressed(...)
|
||||
profiler:mousepressed(...)
|
||||
end
|
||||
|
||||
-- temporarily allowing for old behavior in 0.10.2
|
||||
function love.wheelmoved(x, y)
|
||||
local X, Y = love.mouse.getPosition()
|
||||
if y > 0 then
|
||||
love.mousepressed(X, Y, "wu")
|
||||
else
|
||||
love.mousepressed(X, Y, "wd")
|
||||
end
|
||||
end
|
||||
|
116
piefiller.lua
116
piefiller.lua
@ -1,8 +1,12 @@
|
||||
local path = ...
|
||||
local piefiller = {}
|
||||
|
||||
local function hsvToRgb(h, s, v)
|
||||
local h,s,v = h,1,1
|
||||
local h,s,v = math.fmod(h,360),s,v
|
||||
local i, f, p, q, t, r, g, b -- was polluting with globals
|
||||
|
||||
-- local h,s,v = h,1,1 -- was ignoring s/v values entirely
|
||||
h = math.fmod(h, 360)
|
||||
|
||||
if s == 0 then return {v, v, v} end
|
||||
h=h/60
|
||||
i=math.floor(h)
|
||||
@ -24,6 +28,7 @@ local function hsvToRgb(h, s, v)
|
||||
b = b * 255
|
||||
return {r, g, b}
|
||||
end
|
||||
|
||||
local function copy(t)
|
||||
local ret = {}
|
||||
for i,v in pairs(t) do
|
||||
@ -34,12 +39,20 @@ local function copy(t)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
function setColor(...)
|
||||
|
||||
local function setColor(...) -- was global
|
||||
local args = {...}
|
||||
love.graphics.setColor(args[1] or 255, args[2] or 255, args[3] or 255, args[4] or 255)
|
||||
end
|
||||
|
||||
-- TODO verify these do not break if using multiple profilers
|
||||
local color_data = {}
|
||||
local colors = {}
|
||||
local colors = {} -- the pool of available colors is removed from every time a new time is used
|
||||
|
||||
for i=0,300 do
|
||||
table.insert( colors, hsvToRgb(i, 1, 1) )
|
||||
end
|
||||
|
||||
function piefiller:new()
|
||||
local self = {}
|
||||
setmetatable( self, {__index = piefiller} )
|
||||
@ -47,7 +60,6 @@ function piefiller:new()
|
||||
self.parsed = {}
|
||||
self.last = 0
|
||||
self.timer = 0
|
||||
self:reset()
|
||||
self.depth = 2
|
||||
self.small = false
|
||||
self.x = 0
|
||||
@ -58,34 +70,36 @@ function piefiller:new()
|
||||
reset = "r",
|
||||
increase_depth = "down",
|
||||
decrease_depth = "up",
|
||||
increase_step_size = ",",
|
||||
decrease_step_size = ".",
|
||||
shorten_names = "s",
|
||||
show_hidden = "c",
|
||||
save_to_file = "p",
|
||||
-- TODO changing step_size should trigger a reset (by default, make it optional), because else the data is invalid
|
||||
increase_step_size = "=", -- changed default to "+" button
|
||||
decrease_step_size = "-", -- changed default to "-" button
|
||||
shorten_names = "z", -- changed default (based on assumption WASD is common control scheme)
|
||||
show_hidden = "h", -- changed default
|
||||
save_to_file = "e", -- changed default -> e for export
|
||||
show_profiler = "p", -- added new control to show/hide the profiler, default p
|
||||
}
|
||||
return self
|
||||
end
|
||||
|
||||
function piefiller:reset()
|
||||
self.data = {}
|
||||
-- why should these be reset? only the data matters
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
self.scale = 1
|
||||
for i=0,300 do
|
||||
table.insert(colors,hsvToRgb(i,100,100))
|
||||
end
|
||||
end
|
||||
function piefiller:setKey(table_or_mode,key)
|
||||
if type(table_or_mode) == "table" then
|
||||
self.keys = table_or_mode
|
||||
for i,v in pairs(table_or_mode) do
|
||||
|
||||
function piefiller:setKey(table_or_command,key)
|
||||
if type(table_or_command) == "table" then
|
||||
self.keys = table_or_command
|
||||
for i,v in pairs(table_or_command) do
|
||||
if self.keys[i] then self.keys[i] = v end
|
||||
end
|
||||
elseif type(table_or_mode) == "string" then
|
||||
if not self.keys[table_or_mode] then error("Invalid mode: "..tostring(table_or_mode)) end
|
||||
self.keys[table_or_mode] = key
|
||||
elseif type(table_or_command) == "string" then
|
||||
if not self.keys[table_or_command] then error("Invalid command: "..tostring(table_or_command)) end
|
||||
self.keys[table_or_command] = key
|
||||
else
|
||||
error("Expected table or string got:"..type(table_or_mode))
|
||||
error("Expected table or string, got: "..type(table_or_command))
|
||||
end
|
||||
end
|
||||
|
||||
@ -103,8 +117,10 @@ function piefiller:parse(caller,parent)
|
||||
kids = {},
|
||||
}
|
||||
end
|
||||
|
||||
function piefiller:attach()
|
||||
self.last = os.clock()
|
||||
|
||||
local function hook()
|
||||
local depth = self.depth
|
||||
local caller = debug.getinfo(depth)
|
||||
@ -140,16 +156,20 @@ function piefiller:attach()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local step = 10^self.step
|
||||
if self.step < 0 then
|
||||
step = 1/-self.step
|
||||
end
|
||||
|
||||
debug.sethook(hook, "", step)
|
||||
end
|
||||
function piefiller:detach(stop)
|
||||
|
||||
function piefiller:detach(stop) -- TODO figure out what stop is useful for
|
||||
local totaltime = 0
|
||||
local parsed = {}
|
||||
local no = 0
|
||||
|
||||
for i,v in pairs(self.data) do
|
||||
no = no + 1
|
||||
totaltime = totaltime + v.time
|
||||
@ -162,6 +182,7 @@ function piefiller:detach(stop)
|
||||
parsed[i].cur = v.info.currentline
|
||||
parsed[i].item = v
|
||||
parsed[i].caller = v.info
|
||||
|
||||
if not color_data[v.func] then
|
||||
local i = math.random(#colors)
|
||||
color_data[v.func] = colors[i]
|
||||
@ -170,22 +191,26 @@ function piefiller:detach(stop)
|
||||
|
||||
parsed[i].color = color_data[v.func]
|
||||
end
|
||||
|
||||
local prc = totaltime/100
|
||||
for i,v in ipairs(parsed) do
|
||||
parsed[i].prc = v.time/prc
|
||||
end
|
||||
self.parsed = parsed
|
||||
self.totaltime = totaltime
|
||||
|
||||
if not stop then debug.sethook() end
|
||||
end
|
||||
|
||||
local largeFont = love.graphics.newFont(25)
|
||||
function piefiller:draw(args)
|
||||
local loading
|
||||
local oldFont = love.graphics.getFont()
|
||||
local args = args or {}
|
||||
local rad = args["rad"] or 200
|
||||
local mode = args["mode"] or "simple"
|
||||
local ret = args["return"]
|
||||
local rad = args.rad or 200
|
||||
-- these weren't even being used
|
||||
-- local mode = args["mode"] or "simple"
|
||||
-- local ret = args["return"]
|
||||
local pi = math.pi
|
||||
local arc = love.graphics.arc
|
||||
local w,h = love.graphics.getDimensions()
|
||||
@ -198,22 +223,24 @@ function piefiller:draw(args)
|
||||
if self.parsed and self.totaltime > 0 then
|
||||
local lastangle = 0
|
||||
local font = love.graphics.getFont()
|
||||
|
||||
for i,v in ipairs(self.parsed) do
|
||||
local color = v.color
|
||||
local cx,cy = w/2,h/2
|
||||
local angle = math.rad(3.6*v.prc)
|
||||
setColor(color)
|
||||
arc("fill",cx,cy,rad,lastangle,lastangle + angle)
|
||||
setColor(colors.black)
|
||||
-- setColor(colors.black) -- not defined, actually needs to be white
|
||||
setColor(255, 255, 255, 255)
|
||||
if v.prc > 1 then
|
||||
arc("line",cx,cy,rad,lastangle,lastangle + angle)
|
||||
end
|
||||
lastangle = lastangle + angle
|
||||
setColor()
|
||||
end
|
||||
|
||||
lastangle = 0
|
||||
for i,v in ipairs(self.parsed) do
|
||||
|
||||
local color = v.color
|
||||
local cx,cy = w/2,h/2
|
||||
local angle = math.rad(3.6*v.prc)
|
||||
@ -242,10 +269,12 @@ function piefiller:draw(args)
|
||||
else
|
||||
loading = true
|
||||
end
|
||||
|
||||
self.timer = self.timer + love.timer.getDelta()
|
||||
if self.timer > 20 then
|
||||
self.timer = 0
|
||||
end
|
||||
|
||||
love.graphics.setFont(largeFont)
|
||||
local t = "Depth: "..self.depth.." with step: "..self.step
|
||||
local fw = largeFont:getWidth(t)
|
||||
@ -261,6 +290,7 @@ function piefiller:draw(args)
|
||||
|
||||
love.graphics.setFont(oldFont)
|
||||
end
|
||||
|
||||
function piefiller:mousepressed(x,y,b)
|
||||
if b == "wu" then
|
||||
local scale = self.scale - math.floor((0.05*self.scale)*1000)/1000
|
||||
@ -293,33 +323,34 @@ function piefiller:mousepressed(x,y,b)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function piefiller:keypressed(key)
|
||||
local mode
|
||||
local command
|
||||
for i,v in pairs(self.keys) do
|
||||
if key == v then
|
||||
mode = i
|
||||
command = i
|
||||
break
|
||||
end
|
||||
end
|
||||
if mode then
|
||||
if mode == "reset" then
|
||||
if command then
|
||||
if command == "reset" then
|
||||
self:reset()
|
||||
elseif mode == "increase_depth" then
|
||||
elseif command == "increase_depth" then
|
||||
self:reset()
|
||||
self.depth = self.depth + 1
|
||||
elseif mode == "decrease_depth" then
|
||||
elseif command == "decrease_depth" then
|
||||
self:reset()
|
||||
self.depth = self.depth - 1
|
||||
elseif mode == "increase_step_size" then
|
||||
elseif command == "increase_step_size" then
|
||||
self.step = self.step - 1
|
||||
elseif mode == "decrease_step_size" then
|
||||
elseif command == "decrease_step_size" then
|
||||
self.step = self.step +1
|
||||
elseif mode == "shorten_names" then
|
||||
elseif command == "shorten_names" then
|
||||
self.small = not self.small
|
||||
elseif mode == "show_hidden" then
|
||||
elseif command == "show_hidden" then
|
||||
self:reset()
|
||||
self.view_children = not self.view_children
|
||||
elseif mode == "save_to_file" then
|
||||
elseif command == "save_to_file" then
|
||||
local parsed = copy(self.parsed)
|
||||
table.sort(parsed,function(a,b)
|
||||
return a.prc > b.prc
|
||||
@ -341,11 +372,12 @@ function piefiller:keypressed(key)
|
||||
table.insert(d,table.concat(instance))
|
||||
end
|
||||
local data = table.concat(d)
|
||||
love.filesystem.write("Profile",data)
|
||||
love.system.openURL(love.filesystem.getRealDirectory("Profile"))
|
||||
love.filesystem.write("Profile.txt",data)
|
||||
love.system.openURL(love.filesystem.getRealDirectory("Profile.txt"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function piefiller:unpack(fn)
|
||||
local data = {
|
||||
items = {},
|
||||
@ -355,6 +387,7 @@ function piefiller:unpack(fn)
|
||||
totalTime = self.totaltime,
|
||||
},
|
||||
}
|
||||
|
||||
for i,v in ipairs(self.parsed) do
|
||||
local a = {
|
||||
name = v.name,
|
||||
@ -366,11 +399,12 @@ function piefiller:unpack(fn)
|
||||
caller = v.caller,
|
||||
}
|
||||
if fn then
|
||||
assert(type(fn) == "function","Expected function got:"..type(fn))
|
||||
assert(type(fn) == "function", "Expected function, got: "..type(fn))
|
||||
fn(a)
|
||||
end
|
||||
table.insert(data.items, a)
|
||||
end
|
||||
return data
|
||||
end
|
||||
|
||||
return piefiller
|
||||
|
Loading…
Reference in New Issue
Block a user