mirror of
https://github.com/TangentFoxy/Piefiller.git
synced 2025-09-15 13:02:29 +00:00
removed stupid amounts of extra whitespace
This commit is contained in:
320
piefiller.lua
320
piefiller.lua
@@ -10,7 +10,7 @@ local function hsvToRgb(h, s, v)
|
|||||||
p=v*(1-s)
|
p=v*(1-s)
|
||||||
q=v*(1-s*f)
|
q=v*(1-s*f)
|
||||||
t=v*(1-s*(1-f))
|
t=v*(1-s*(1-f))
|
||||||
|
|
||||||
if i==0 then r=v g=t b=p
|
if i==0 then r=v g=t b=p
|
||||||
elseif i==1 then r=q g=v b=p
|
elseif i==1 then r=q g=v b=p
|
||||||
elseif i==2 then r=p g=v b=t
|
elseif i==2 then r=p g=v b=t
|
||||||
@@ -18,45 +18,45 @@ local function hsvToRgb(h, s, v)
|
|||||||
elseif i==4 then r=t g=p b=v
|
elseif i==4 then r=t g=p b=v
|
||||||
else r=v g=p b=q
|
else r=v g=p b=q
|
||||||
end
|
end
|
||||||
|
|
||||||
r=r*255
|
r=r*255
|
||||||
g=g*255
|
g=g*255
|
||||||
b=b*255
|
b=b*255
|
||||||
return { r,g,b }
|
return { r,g,b }
|
||||||
end
|
end
|
||||||
local function copy(t)
|
local function copy(t)
|
||||||
local ret = {}
|
local ret = {}
|
||||||
for i,v in pairs(t) do
|
for i,v in pairs(t) do
|
||||||
ret[i] = v
|
ret[i] = v
|
||||||
if type(v) == "table" then
|
if type(v) == "table" then
|
||||||
ret[i] = copy(v)
|
ret[i] = copy(v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
function setColor(...)
|
function setColor(...)
|
||||||
local args = {...}
|
local args = {...}
|
||||||
love.graphics.setColor(args[1] or 255,args[2] or 255,args[3] or 255,args[4] or 255)
|
love.graphics.setColor(args[1] or 255,args[2] or 255,args[3] or 255,args[4] or 255)
|
||||||
end
|
end
|
||||||
local color_data = {}
|
local color_data = {}
|
||||||
local colors = {}
|
local colors = {}
|
||||||
function piefiller:new()
|
function piefiller:new()
|
||||||
local self = {}
|
local self = {}
|
||||||
setmetatable(self,{__index = piefiller})
|
setmetatable(self,{__index = piefiller})
|
||||||
self.data = {}
|
self.data = {}
|
||||||
self.parsed = {}
|
self.parsed = {}
|
||||||
self.last = 0
|
self.last = 0
|
||||||
self.timer = 0
|
self.timer = 0
|
||||||
self:reset()
|
self:reset()
|
||||||
self.depth = 2
|
self.depth = 2
|
||||||
self.small = false
|
self.small = false
|
||||||
self.x = 0
|
self.x = 0
|
||||||
self.y = 0
|
self.y = 0
|
||||||
self.scale = 1
|
self.scale = 1
|
||||||
self.step = 1
|
self.step = 1
|
||||||
self.keys = {
|
self.keys = {
|
||||||
reset = "r",
|
reset = "r",
|
||||||
increase_depth = "down",
|
increase_depth = "down",
|
||||||
decrease_depth = "up",
|
decrease_depth = "up",
|
||||||
increase_step_size = ",",
|
increase_step_size = ",",
|
||||||
decrease_step_size = ".",
|
decrease_step_size = ".",
|
||||||
@@ -67,27 +67,27 @@ function piefiller:new()
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
function piefiller:reset()
|
function piefiller:reset()
|
||||||
self.data = {}
|
self.data = {}
|
||||||
self.x = 0
|
self.x = 0
|
||||||
self.y = 0
|
self.y = 0
|
||||||
self.scale = 1
|
self.scale = 1
|
||||||
for i=0,300 do
|
for i=0,300 do
|
||||||
table.insert(colors,hsvToRgb(i,100,100))
|
table.insert(colors,hsvToRgb(i,100,100))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function piefiller:setKey(table_or_mode,key)
|
function piefiller:setKey(table_or_mode,key)
|
||||||
if type(table_or_mode) == "table" then
|
if type(table_or_mode) == "table" then
|
||||||
self.keys = table_or_mode
|
self.keys = table_or_mode
|
||||||
for i,v in pairs(table_or_mode) do
|
for i,v in pairs(table_or_mode) do
|
||||||
if self.keys[i] then self.keys[i] = v end
|
if self.keys[i] then self.keys[i] = v end
|
||||||
end
|
end
|
||||||
elseif type(table_or_mode) == "string" then
|
elseif type(table_or_mode) == "string" then
|
||||||
if not self.keys[table_or_mode] then error("Invalid mode: "..tostring(table_or_mode)) end
|
if not self.keys[table_or_mode] then error("Invalid mode: "..tostring(table_or_mode)) end
|
||||||
self.keys[table_or_mode] = key
|
self.keys[table_or_mode] = key
|
||||||
else
|
else
|
||||||
error("Expected table or string got:"..type(table_or_mode))
|
error("Expected table or string got:"..type(table_or_mode))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function piefiller:parse(caller,parent)
|
function piefiller:parse(caller,parent)
|
||||||
return {
|
return {
|
||||||
@@ -95,172 +95,172 @@ function piefiller:parse(caller,parent)
|
|||||||
func = caller.func,
|
func = caller.func,
|
||||||
count = 0,
|
count = 0,
|
||||||
time = 0,
|
time = 0,
|
||||||
child_time = 0,
|
child_time = 0,
|
||||||
named_child_time = 0,
|
named_child_time = 0,
|
||||||
children = {},
|
children = {},
|
||||||
children_time = {},
|
children_time = {},
|
||||||
info = caller,
|
info = caller,
|
||||||
kids = {},
|
kids = {},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
function piefiller:attach()
|
function piefiller:attach()
|
||||||
self.last = os.clock()
|
self.last = os.clock()
|
||||||
local function hook()
|
local function hook()
|
||||||
local depth = self.depth
|
local depth = self.depth
|
||||||
local caller = debug.getinfo(depth)
|
local caller = debug.getinfo(depth)
|
||||||
local taken = os.clock() - self.last
|
local taken = os.clock() - self.last
|
||||||
if caller then
|
if caller then
|
||||||
local last_caller
|
local last_caller
|
||||||
local own = string.find(caller.source,path)
|
local own = string.find(caller.source,path)
|
||||||
if caller.func ~= hook and not own then
|
if caller.func ~= hook and not own then
|
||||||
while caller do
|
while caller do
|
||||||
if last_caller and not self.view_children then
|
if last_caller and not self.view_children then
|
||||||
local name = caller.func
|
local name = caller.func
|
||||||
local lc = self.data[last_caller.func]
|
local lc = self.data[last_caller.func]
|
||||||
if not lc.kids[name] then
|
if not lc.kids[name] then
|
||||||
lc.kids[name] = self:parse(caller,last_caller)
|
lc.kids[name] = self:parse(caller,last_caller)
|
||||||
end
|
end
|
||||||
local kid = lc.kids[name]
|
local kid = lc.kids[name]
|
||||||
kid.count = kid.count + 1
|
kid.count = kid.count + 1
|
||||||
kid.time = kid.time + taken
|
kid.time = kid.time + taken
|
||||||
else
|
else
|
||||||
local name = caller.func
|
local name = caller.func
|
||||||
local raw = self.data[name]
|
local raw = self.data[name]
|
||||||
if not raw then
|
if not raw then
|
||||||
self.data[name] = self:parse(caller,last_caller)
|
self.data[name] = self:parse(caller,last_caller)
|
||||||
end
|
end
|
||||||
raw = self.data[name]
|
raw = self.data[name]
|
||||||
raw.count = raw.count + 1
|
raw.count = raw.count + 1
|
||||||
raw.time = raw.time + taken
|
raw.time = raw.time + taken
|
||||||
last_caller = caller
|
last_caller = caller
|
||||||
end
|
end
|
||||||
depth = depth + 1
|
depth = depth + 1
|
||||||
caller = debug.getinfo(depth)
|
caller = debug.getinfo(depth)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local step = 10^self.step
|
local step = 10^self.step
|
||||||
if self.step < 0 then
|
if self.step < 0 then
|
||||||
step = 1/-self.step
|
step = 1/-self.step
|
||||||
end
|
end
|
||||||
debug.sethook(hook,"",step)
|
debug.sethook(hook,"",step)
|
||||||
end
|
end
|
||||||
function piefiller:detach(stop)
|
function piefiller:detach(stop)
|
||||||
local totaltime = 0
|
local totaltime = 0
|
||||||
local parsed = {}
|
local parsed = {}
|
||||||
local no = 0
|
local no = 0
|
||||||
for i,v in pairs(self.data) do
|
for i,v in pairs(self.data) do
|
||||||
no = no + 1
|
no = no + 1
|
||||||
totaltime = totaltime + v.time
|
totaltime = totaltime + v.time
|
||||||
local i = no
|
local i = no
|
||||||
parsed[i] = {}
|
parsed[i] = {}
|
||||||
parsed[i].name = v.info.name
|
parsed[i].name = v.info.name
|
||||||
parsed[i].time = v.time
|
parsed[i].time = v.time
|
||||||
parsed[i].src = v.info.source
|
parsed[i].src = v.info.source
|
||||||
parsed[i].def = v.info.linedefined
|
parsed[i].def = v.info.linedefined
|
||||||
parsed[i].cur = v.info.currentline
|
parsed[i].cur = v.info.currentline
|
||||||
parsed[i].item = v
|
parsed[i].item = v
|
||||||
parsed[i].caller = v.info
|
parsed[i].caller = v.info
|
||||||
if not color_data[v.func] then
|
if not color_data[v.func] then
|
||||||
local i = math.random(#colors)
|
local i = math.random(#colors)
|
||||||
color_data[v.func] = colors[i]
|
color_data[v.func] = colors[i]
|
||||||
table.remove(colors,i)
|
table.remove(colors,i)
|
||||||
end
|
end
|
||||||
|
|
||||||
parsed[i].color = color_data[v.func]
|
parsed[i].color = color_data[v.func]
|
||||||
end
|
end
|
||||||
local prc = totaltime/100
|
local prc = totaltime/100
|
||||||
for i,v in ipairs(parsed) do
|
for i,v in ipairs(parsed) do
|
||||||
parsed[i].prc = v.time/prc
|
parsed[i].prc = v.time/prc
|
||||||
end
|
end
|
||||||
self.parsed = parsed
|
self.parsed = parsed
|
||||||
self.totaltime = totaltime
|
self.totaltime = totaltime
|
||||||
if not stop then debug.sethook() end
|
if not stop then debug.sethook() end
|
||||||
end
|
end
|
||||||
local largeFont = love.graphics.newFont(25)
|
local largeFont = love.graphics.newFont(25)
|
||||||
function piefiller:draw(args)
|
function piefiller:draw(args)
|
||||||
local loading
|
local loading
|
||||||
local oldFont = love.graphics.getFont()
|
local oldFont = love.graphics.getFont()
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local rad = args["rad"] or 200
|
local rad = args["rad"] or 200
|
||||||
local mode = args["mode"] or "simple"
|
local mode = args["mode"] or "simple"
|
||||||
local ret = args["return"]
|
local ret = args["return"]
|
||||||
local pi = math.pi
|
local pi = math.pi
|
||||||
local arc = love.graphics.arc
|
local arc = love.graphics.arc
|
||||||
local w,h = love.graphics.getDimensions()
|
local w,h = love.graphics.getDimensions()
|
||||||
|
|
||||||
love.graphics.push()
|
love.graphics.push()
|
||||||
|
|
||||||
love.graphics.translate(self.x,self.y)
|
love.graphics.translate(self.x,self.y)
|
||||||
love.graphics.scale(self.scale)
|
love.graphics.scale(self.scale)
|
||||||
|
|
||||||
if self.parsed and self.totaltime > 0 then
|
if self.parsed and self.totaltime > 0 then
|
||||||
local lastangle = 0
|
local lastangle = 0
|
||||||
local font = love.graphics.getFont()
|
local font = love.graphics.getFont()
|
||||||
for i,v in ipairs(self.parsed) do
|
for i,v in ipairs(self.parsed) do
|
||||||
local color = v.color
|
local color = v.color
|
||||||
local cx,cy = w/2,h/2
|
local cx,cy = w/2,h/2
|
||||||
local angle = math.rad(3.6*v.prc)
|
local angle = math.rad(3.6*v.prc)
|
||||||
setColor(color)
|
setColor(color)
|
||||||
arc("fill",cx,cy,rad,lastangle,lastangle + angle)
|
arc("fill",cx,cy,rad,lastangle,lastangle + angle)
|
||||||
setColor(colors.black)
|
setColor(colors.black)
|
||||||
if v.prc > 1 then
|
if v.prc > 1 then
|
||||||
arc("line",cx,cy,rad,lastangle,lastangle + angle)
|
arc("line",cx,cy,rad,lastangle,lastangle + angle)
|
||||||
end
|
end
|
||||||
lastangle = lastangle + angle
|
lastangle = lastangle + angle
|
||||||
setColor()
|
setColor()
|
||||||
end
|
end
|
||||||
lastangle = 0
|
lastangle = 0
|
||||||
for i,v in ipairs(self.parsed) do
|
for i,v in ipairs(self.parsed) do
|
||||||
|
|
||||||
local color = v.color
|
local color = v.color
|
||||||
local cx,cy = w/2,h/2
|
local cx,cy = w/2,h/2
|
||||||
local angle = math.rad(3.6*v.prc)
|
local angle = math.rad(3.6*v.prc)
|
||||||
local x = cx + rad * math.cos(lastangle + angle/2)
|
local x = cx + rad * math.cos(lastangle + angle/2)
|
||||||
local y = cy + rad * math.sin(lastangle + angle/2)
|
local y = cy + rad * math.sin(lastangle + angle/2)
|
||||||
if self.small then
|
if self.small then
|
||||||
txt = tostring(v.src).." @: "..tostring(v.name)
|
txt = tostring(v.src).." @: "..tostring(v.name)
|
||||||
else
|
else
|
||||||
txt = tostring(math.ceil(v.prc)).." % "..tostring(v.name).." : "..tostring(v.src).." @: "..tostring(v.def)
|
txt = tostring(math.ceil(v.prc)).." % "..tostring(v.name).." : "..tostring(v.src).." @: "..tostring(v.def)
|
||||||
end
|
end
|
||||||
local fw = font:getWidth(txt)
|
local fw = font:getWidth(txt)
|
||||||
local sx = 1
|
local sx = 1
|
||||||
if cx < x then
|
if cx < x then
|
||||||
sx = -1
|
sx = -1
|
||||||
fw = 0
|
fw = 0
|
||||||
end
|
end
|
||||||
if cy + rad/2 < y then
|
if cy + rad/2 < y then
|
||||||
y = y + font:getHeight()
|
y = y + font:getHeight()
|
||||||
elseif cy + rad/2 > y then
|
elseif cy + rad/2 > y then
|
||||||
y = y - font:getHeight()
|
y = y - font:getHeight()
|
||||||
end
|
end
|
||||||
local ofx
|
local ofx
|
||||||
love.graphics.print(txt,((x) + (-(fw+20))*sx),y)
|
love.graphics.print(txt,((x) + (-(fw+20))*sx),y)
|
||||||
lastangle = lastangle + angle
|
lastangle = lastangle + angle
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
loading = true
|
loading = true
|
||||||
end
|
end
|
||||||
self.timer = self.timer + love.timer.getDelta()
|
self.timer = self.timer + love.timer.getDelta()
|
||||||
if self.timer > 20 then
|
if self.timer > 20 then
|
||||||
self.timer = 0
|
self.timer = 0
|
||||||
end
|
end
|
||||||
love.graphics.setFont(largeFont)
|
love.graphics.setFont(largeFont)
|
||||||
local t = "Depth: "..self.depth.." with step: "..self.step
|
local t = "Depth: "..self.depth.." with step: "..self.step
|
||||||
local fw = largeFont:getWidth(t)
|
local fw = largeFont:getWidth(t)
|
||||||
local fh = largeFont:getHeight()
|
local fh = largeFont:getHeight()
|
||||||
love.graphics.print(t,w/2 - fw/2,(fh+5))
|
love.graphics.print(t,w/2 - fw/2,(fh+5))
|
||||||
if loading then
|
if loading then
|
||||||
t = "Loading..."
|
t = "Loading..."
|
||||||
fw = largeFont:getWidth(t)
|
fw = largeFont:getWidth(t)
|
||||||
love.graphics.print("Loading...",w/2 - fw/2,h/2)
|
love.graphics.print("Loading...",w/2 - fw/2,h/2)
|
||||||
end
|
end
|
||||||
|
|
||||||
love.graphics.pop()
|
love.graphics.pop()
|
||||||
|
|
||||||
love.graphics.setFont(oldFont)
|
love.graphics.setFont(oldFont)
|
||||||
end
|
end
|
||||||
function piefiller:mousepressed(x,y,b)
|
function piefiller:mousepressed(x,y,b)
|
||||||
if b == "wu" then
|
if b == "wu" then
|
||||||
local scale = self.scale - math.floor((0.05*self.scale)*1000)/1000
|
local scale = self.scale - math.floor((0.05*self.scale)*1000)/1000
|
||||||
@@ -291,86 +291,86 @@ function piefiller:mousepressed(x,y,b)
|
|||||||
else
|
else
|
||||||
self.scale = 20
|
self.scale = 20
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function piefiller:keypressed(key)
|
function piefiller:keypressed(key)
|
||||||
local mode
|
local mode
|
||||||
for i,v in pairs(self.keys) do
|
for i,v in pairs(self.keys) do
|
||||||
if key == v then
|
if key == v then
|
||||||
mode = i
|
mode = i
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if mode then
|
if mode then
|
||||||
if mode == "reset" then
|
if mode == "reset" then
|
||||||
self:reset()
|
self:reset()
|
||||||
elseif mode == "increase_depth" then
|
elseif mode == "increase_depth" then
|
||||||
self:reset()
|
self:reset()
|
||||||
self.depth = self.depth + 1
|
self.depth = self.depth + 1
|
||||||
elseif mode == "decrease_depth" then
|
elseif mode == "decrease_depth" then
|
||||||
self:reset()
|
self:reset()
|
||||||
self.depth = self.depth - 1
|
self.depth = self.depth - 1
|
||||||
elseif mode == "increase_step_size" then
|
elseif mode == "increase_step_size" then
|
||||||
self.step = self.step - 1
|
self.step = self.step - 1
|
||||||
elseif mode == "decrease_step_size" then
|
elseif mode == "decrease_step_size" then
|
||||||
self.step = self.step +1
|
self.step = self.step +1
|
||||||
elseif mode == "shorten_names" then
|
elseif mode == "shorten_names" then
|
||||||
self.small = not self.small
|
self.small = not self.small
|
||||||
elseif mode == "show_hidden" then
|
elseif mode == "show_hidden" then
|
||||||
self:reset()
|
self:reset()
|
||||||
self.view_children = not self.view_children
|
self.view_children = not self.view_children
|
||||||
elseif mode == "save_to_file" then
|
elseif mode == "save_to_file" then
|
||||||
local parsed = copy(self.parsed)
|
local parsed = copy(self.parsed)
|
||||||
table.sort(parsed,function(a,b)
|
table.sort(parsed,function(a,b)
|
||||||
return a.prc > b.prc
|
return a.prc > b.prc
|
||||||
end)
|
end)
|
||||||
local d = {"Depth: "..self.depth.." with step: "..self.step.."\r\n".."Total time: "..self.totaltime.."\r\n"}
|
local d = {"Depth: "..self.depth.." with step: "..self.step.."\r\n".."Total time: "..self.totaltime.."\r\n"}
|
||||||
|
|
||||||
for i,v in ipairs(parsed) do
|
for i,v in ipairs(parsed) do
|
||||||
local instance = {
|
local instance = {
|
||||||
"-----"..(v.name or "def@"..v.def).."-----",
|
"-----"..(v.name or "def@"..v.def).."-----",
|
||||||
"source:"..v.src..":"..v.def,
|
"source:"..v.src..":"..v.def,
|
||||||
"current line: "..v.cur,
|
"current line: "..v.cur,
|
||||||
"time: "..v.time,
|
"time: "..v.time,
|
||||||
"percentage: "..math.ceil(v.prc).." %",
|
"percentage: "..math.ceil(v.prc).." %",
|
||||||
"----------------",
|
"----------------",
|
||||||
}
|
}
|
||||||
for i,v in ipairs(instance) do
|
for i,v in ipairs(instance) do
|
||||||
instance[i] = v.."\r\n"
|
instance[i] = v.."\r\n"
|
||||||
end
|
end
|
||||||
table.insert(d,table.concat(instance))
|
table.insert(d,table.concat(instance))
|
||||||
end
|
end
|
||||||
local data = table.concat(d)
|
local data = table.concat(d)
|
||||||
love.filesystem.write("Profile",data)
|
love.filesystem.write("Profile",data)
|
||||||
love.system.openURL(love.filesystem.getRealDirectory("Profile"))
|
love.system.openURL(love.filesystem.getRealDirectory("Profile"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function piefiller:unpack(fn)
|
function piefiller:unpack(fn)
|
||||||
local data = {
|
local data = {
|
||||||
items = {},
|
items = {},
|
||||||
about = {
|
about = {
|
||||||
depth = self.depth,
|
depth = self.depth,
|
||||||
step = self.step,
|
step = self.step,
|
||||||
totalTime = self.totaltime,
|
totalTime = self.totaltime,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for i,v in ipairs(self.parsed) do
|
for i,v in ipairs(self.parsed) do
|
||||||
local a = {
|
local a = {
|
||||||
name = v.name,
|
name = v.name,
|
||||||
line_defined = v.def,
|
line_defined = v.def,
|
||||||
current_line = v.cur,
|
current_line = v.cur,
|
||||||
source = v.src,
|
source = v.src,
|
||||||
time_taken = v.time,
|
time_taken = v.time,
|
||||||
percentage = v.prc,
|
percentage = v.prc,
|
||||||
caller = v.caller,
|
caller = v.caller,
|
||||||
}
|
}
|
||||||
if fn then
|
if fn then
|
||||||
assert(type(fn) == "function","Expected function got:"..type(fn))
|
assert(type(fn) == "function","Expected function got:"..type(fn))
|
||||||
fn(a)
|
fn(a)
|
||||||
end
|
end
|
||||||
table.insert(data.items,a)
|
table.insert(data.items,a)
|
||||||
end
|
end
|
||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
return piefiller
|
return piefiller
|
||||||
|
Reference in New Issue
Block a user