Piefiller/README.md

133 lines
2.4 KiB
Markdown
Raw Normal View History

2015-11-07 11:18:57 +00:00
# Piefiller
2017-07-27 03:48:46 +00:00
Graphical profiler for Love2D >= 0.9.2
Originally by devfirefly, heavily modified by Guard13007.
2017-07-27 06:21:15 +00:00
Note that a lot of functionality is undocumented right now, and that some functionality doesn't work as originally intended (such as setting the position and scale of the profiler). The default settings should get you going pretty easily, the key thing to maybe change is calling the constructor with a table with its own `scale` value.
# Usage
2017-07-27 03:48:46 +00:00
1) Require the file:
2015-11-07 11:44:49 +00:00
```lua
2017-07-27 06:21:15 +00:00
local Piefiller = require("piefiller")
2015-11-07 11:44:49 +00:00
```
2017-07-27 03:48:46 +00:00
2) Make a new instance of piefiller:
2015-11-07 11:44:49 +00:00
```lua
2017-07-27 06:21:15 +00:00
local pie = Piefiller()
2015-11-07 11:44:49 +00:00
```
2017-07-27 03:48:46 +00:00
3) Attach the piefiller to the part of your application that you want to monitor (love.update and love.draw typically are good places):
2015-11-07 11:44:49 +00:00
```lua
function love.update()
2017-07-27 06:21:15 +00:00
pie:attach()
2015-11-07 11:44:49 +00:00
-- do something
2017-07-27 06:21:15 +00:00
pie:detach()
2015-11-07 11:44:49 +00:00
end
```
2017-07-27 05:15:35 +00:00
4) Draw the output and pass key events to your piefiller:
2015-11-07 11:44:49 +00:00
```lua
function love.draw()
2017-07-27 06:21:15 +00:00
pie:draw()
2015-11-07 11:44:49 +00:00
end
2017-07-27 03:48:46 +00:00
function love.keypressed(key)
2017-07-27 06:21:15 +00:00
pie:keypressed(key)
2015-11-07 11:44:49 +00:00
end
```
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 %
----------------
```
2017-07-27 03:48:46 +00:00
# Keys
2015-11-07 11:44:49 +00:00
2017-07-27 03:48:46 +00:00
p = shows/hides the profiler
r = resets the pie
up = decreases depth
2015-11-07 11:44:49 +00:00
2017-07-27 03:48:46 +00:00
down = increases depth
2015-11-07 11:44:49 +00:00
\- = decreases step size
2015-11-07 11:44:49 +00:00
2017-07-27 03:48:46 +00:00
= = increases step size
2015-11-07 11:44:49 +00:00
s = shortens the names displayed
2017-07-27 03:48:46 +00:00
h = shows/hides hidden processes
e = saves to file called "Profile.txt" and opens directory for you
2015-11-07 11:44:49 +00:00
2015-11-09 16:45:48 +00:00
## To redefine these:
2017-07-27 03:48:46 +00:00
Commands available:
2015-11-09 16:54:44 +00:00
```lua
reset
increase_depth
decrease_depth
increase_step_size
decrease_step_size
shorten_names
show_hidden
save_to_file
2017-07-27 03:48:46 +00:00
show_profiler
2015-11-09 16:54:44 +00:00
```
2017-07-27 03:48:46 +00:00
To redefine only one of the keys:
2015-11-09 16:54:44 +00:00
```lua
2017-07-27 06:21:15 +00:00
pie:setKey(command, key)
2015-11-09 16:54:44 +00:00
```
example:
```lua
2017-07-27 06:21:15 +00:00
pie:setKey("increase_depth","up")
2015-11-09 16:54:44 +00:00
```
2017-07-27 03:48:46 +00:00
2015-11-09 16:45:48 +00:00
To redefine all of the keys:
2015-11-09 16:54:44 +00:00
```lua
table = {
"increase_depth" = "up"
}
2017-07-27 06:21:15 +00:00
pie:setKey(table)
2015-11-09 16:54:44 +00:00
```
2017-07-27 03:48:46 +00:00
# For your own interpretation
2017-07-27 06:21:15 +00:00
If you wish to interpret the data on your own use `pie:unpack()`.
Output is a table as such:
2017-07-27 03:48:46 +00:00
2015-11-09 16:54:44 +00:00
```lua
data = {
2017-07-27 03:48:46 +00:00
items = {
{
2015-11-09 16:54:44 +00:00
name,
2017-07-27 03:48:46 +00:00
line_defined,
2015-11-09 16:54:44 +00:00
current_line,
source,
2017-07-27 03:48:46 +00:00
time_taken,
2015-11-09 16:54:44 +00:00
percentage,
caller,
}
2017-07-27 03:48:46 +00:00
},
2015-11-09 16:54:44 +00:00
about = {
depth,
2017-07-27 03:48:46 +00:00
step,
2015-11-09 16:54:44 +00:00
totalTime,
2017-07-27 03:48:46 +00:00
},
}
2015-11-09 16:54:44 +00:00
```
2017-07-27 03:48:46 +00:00
2015-11-07 11:44:49 +00:00
# Additional notes
2017-07-27 03:48:46 +00:00
The best depth to search in is usually 2 and sometimes 3.
When used in large applications the output may be too much to read, however you
most likely will only be wanting to optimize the most expensive items. (And you
can always output the data to review later.)