Skip to content

Instantly share code, notes, and snippets.

View EngineerSmith's full-sized avatar
🔧
🦆

Engineer Smith EngineerSmith

🔧
🦆
View GitHub Profile
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
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()
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
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")
-- 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
local appleCake = require("AppleCake")(true)
appleCake.beginSession() -- writes to "profile.json" by default
function love.quit()
appleCake.endSession()
end
local profileUpdate -- Recommended to reuse tables for commonly hit profiles to avoid recreating tables often
function love.update(dt) -- Will be profiled as "update#gettingstarted2.lua#2"
profileUpdate = appleCake.profileFunc(nil, profileUpdate)
--...
profileUpdate:stop()
end
local profileDraw
function love.draw() -- Will be profiled as "draw#gettingstarted2.lua#9"
profileDraw = appleCake.profileFunc(nil, profileDraw)
function state:start()
appleCake.mark("State X began", "t") -- marked as "t" means it won't stand out as much as a "p" in data, see docs or tracing tutorial
end
function love.keypressed(key, scancode, isrepeat)
appleCake.mark("Key pressed", nil, {key = key, code = scancode, isrepeat = isrepeat})
-- by default, nil is "p"
end
local appleCake = require("AppleCake")(true) -- Controls if AppleCake is disabled on all threads
appleCake.beginSession()
local thread
function love.quit()
appleCake.mark("Quit", "p")
thread:wait()
appleCake.endSession() -- Only the thread that started the session can end it
-- If you end the session while the the thread is still trying to use appleCake, it will throw an error that no session is active
local sceneManager = {
currentScene = nil,
nilFunc = function() end,
sceneHandlers = {
-- GAME LOOP
"load",
"unload", -- added for sceneManager
"update",
"updateNetwork", -- added with custom love.run for multiplayer
"draw",