This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local appleCake = require("AppleCake")(true) | |
| appleCake.beginSession() -- writes to "profile.json" by default | |
| function love.quit() | |
| appleCake.endSession() | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Point of entry, e.g. main.lua | |
| local appleCake = require("lib.AppleCake")(true) -- turn on profiling for entire project (default) | |
| local appleCake = require("lib.AppleCake")(false) -- turn off profiling for entire project | |
| -- Other files and threads | |
| local appleCake = require("lib.AppleCake")() -- get whatever appleCake has been loaded by the first call |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local k = 0 | |
| function love.update(dt) | |
| if k % 15 == 0 then -- Adds a mark every 15 frames | |
| appleCake.countMemory() | |
| end | |
| k = k + 1 | |
| end | |
| appleCake.countMemory("byte") | |
| appleCake.countMemory("megabyte") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| appleCake.mark("event") | |
| local function state.begin() | |
| appleCake.mark("State entered begin", "t") | |
| end | |
| local function isValid(foo) | |
| appleCake.mark("Validating", nil, foo) -- nil will be replaced with "p" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| appleCake.profile("FooBar"):stop() --Stops and records the profile instantly, a mark would be better use to mark timeless events | |
| local function foo() -- foo@profile:stop.lua#3 | |
| local profile = appleCake.profileFunc() | |
| --... | |
| profile:stop() -- Stop's and pushes profile to be written to file | |
| end | |
| local profileBar -- recommended to reuse tables than creating new ones | |
| local function bar() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local function bar() -- [email protected]#1 | |
| local _profileBar = appleCake.profileFunc({}) -- Initalizing args to an empty table as it's nil by default | |
| --... | |
| _profileBar.args.value = 12 | |
| --... | |
| _profileBar:stop() | |
| end | |
| local _profile --Example of reusing profiles to save creating garbage, recommended | |
| local function foo() -- [email protected]#10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local _profile = appleCake.profile("love.update") | |
| local function bar() | |
| local _profileBar = appleCake.profile("bar", {}) -- Initalizing args to an empty table as it's nil by default | |
| --... | |
| local _profileBarSet = appleCake.profile("bar set") -- Example of nested profiling | |
| _profileBar.args.value = 12 | |
| _profileBarSet:stop() -- This could stop after _profileBar:stop() if you wanted | |
| --... | |
| _profileBar:stop() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| appleCake.endSession() | |
| function love.quit() | |
| appleCake.endSession() | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| appleCake.beginSession() -- Default "profile.json" in the save direcotry | |
| appleCake.beginSession("profile.json") | |
| appleCake.beginSession("/profiles/profile.json") | |
| appleCake.beginSession(nil, "Best Project") | |
| appleCake.beginSession("profile.json", "Game4000") | |
| if love.filesystem.isFused() then | |
| local dir = love.filesystem.getSourceBaseDirectory() | |
| love.filesystem.mount(dir, "gameSource") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local appleCake = require("AppleCake")() -- Will be disabled if the main thread set AppleCake to false | |
| -- Note we don't set buffering so everything is pushed to the save thread as soon as it can be | |
| local function foo() -- "[email protected]#3" | |
| local profile = appleCake.profileFunc() | |
| local n = 0 | |
| for i=0, 100000 do | |
| n = n + i | |
| end | |
| profile:stop() |