{"id":13526009,"url":"https://github.com/EngineerSmith/AppleCake","last_synced_at":"2025-04-01T06:30:53.896Z","repository":{"id":116641912,"uuid":"238286321","full_name":"EngineerSmith/AppleCake","owner":"EngineerSmith","description":"Visual Profiling tool for Love2D using Chromium's tracing tool","archived":false,"fork":false,"pushed_at":"2024-10-01T11:11:36.000Z","size":91,"stargazers_count":26,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T21:48:35.621Z","etag":null,"topics":["love2d","lua","profiler"],"latest_commit_sha":null,"homepage":"https://engineersmith.github.io/AppleCake-Docs/","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EngineerSmith.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-04T19:19:48.000Z","updated_at":"2025-02-22T04:58:07.000Z","dependencies_parsed_at":"2024-11-02T10:31:28.648Z","dependency_job_id":null,"html_url":"https://github.com/EngineerSmith/AppleCake","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EngineerSmith%2FAppleCake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EngineerSmith%2FAppleCake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EngineerSmith%2FAppleCake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EngineerSmith%2FAppleCake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EngineerSmith","download_url":"https://codeload.github.com/EngineerSmith/AppleCake/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246596632,"owners_count":20802857,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["love2d","lua","profiler"],"created_at":"2024-08-01T06:01:24.286Z","updated_at":"2025-04-01T06:30:53.616Z","avatar_url":"https://github.com/EngineerSmith.png","language":"Lua","readme":"# AppleCake\nVisual Profiling tool for Love2D using Chromium's trace tool. AppleCake 2 has been tested to work in Love 11.4 and Love 12.0\n## Features\n* **Profile** how long functions take, with profile nesting!\n* **Mark** timeless events\n* **Track** variable changes onto a graph\n* **View Variables** in trace tool as args\n* Profile **Lua memory** usage\n* **Multi-threaded profiling** support\n* **Disable for release** easily\n* Recover **Crashed** data with ease\n* Switch to and from **jprof** easily so you can try it out on your project\n## AppleCake Docs\nYou can view the docs at https://engineersmith.github.io/AppleCake-Docs/ or open the `index.html` locally from that repo\n## Installing\nrun `git clone https://github.com/EngineerSmith/AppleCake` in your project's lib folder or where you choose  \nYou should be able to pull it into your project by requiring the folder you cloned the repository to, as the repository includes a `init.lua` file. See documentation for further details of how to require AppleCake correctly.\n```lua\n-- Point of entry, e.g. main.lua\nlocal appleCake = require(\"lib.AppleCake\")(true)  -- turn on profiling\nlocal appleCake = require(\"lib.AppleCake\")(false) -- turn off profiling\n\n-- Other files and threads\nlocal appleCake = require(\"lib.AppleCake\")()      -- get whatever appleCake has been loaded by the first call\n```\n## Example\nAn example of AppleCake in a love2d project. You can see many more examples and how to use AppleCake in [AppleCake Docs](#AppleCake-Docs)\n```lua\nlocal appleCake = require(\"lib.AppleCake\")(true) -- Set to false will remove the profiling tool from the project\nappleCake.setBuffer(true) -- Buffer any profile calls to increase performance\nappleCake.beginSession() --Will write to \"profile.json\" by default in the save directory\nappleCake.setName(\"Example\")\n\nfunction love.quit()\n  appleCake.endSession() -- Close the session when the program ends\nend\n\nfunction love.load()\n  appleCake.mark(\"Started load\") -- Adds a mark, can be used to show a timeless events or other details\nend\n\nlocal function loop(count)\n  local profileLoop = appleCake.profile(\"Loop \"..count)\n  local n = 0\n  for i=0,count do\n    if i % 10 == 0 then\n      n = n + i\n      appleCake.counter(\"loop\", {n}) -- not best practice; an example of what you can do\n    end\n  end\n  appleCake.counter(\"loop\", {0}) -- reset graph to 0 after counting has stopped\n  profileLoop:stop()\nend\n\nlocal r, mem = 0, 0\nlocal profileUpdate --Example of reusing profile tables to avoid garbage\nfunction love.update(dt)\n  profileUpdate = appleCake.profileFunc(nil, profileUpdate)\n  r = r + 0.5 * dt\n  loop(100000) -- Example of nested profiling, as the function has it's own profile\n  profileUpdate:stop()\n  mem = mem + dt\n  if mem \u003c 0.5 then -- We do it every 0.5 seconds to over strain the system\n    appleCake.countMemory() -- Adds counter with details of current Lua memory usage, this becomes a graph\n    mem = 0\n  end\nend\n\nlocal lg = love.graphics\nfunction love.draw()\n  local _profileDraw = appleCake.profileFunc() -- This will create new profile table every time this function is ran\n  lg.push()\n  lg.rotate(r)\n  lg.rectangle(\"fill\", 0,0,30,30)\n  lg.pop()\n  _profileDraw.args = lg.getStats() -- Set args that we can view later in the viewer\n  _profileDraw:stop() -- By setting it to love.graphics.getStats we can see details of the draw\n  appleCake.flush() -- Flush any profiling data to be saved\nend\n\nfunction love.keypressed(key)\n  appleCake.mark(\"Key Pressed\", \"p\", {key=key}) -- Adds a mark every time a key is pressed, with the key as an argument\nend\n```\n## Viewing AppleCake profiling data\nOpen your Chromium browser (Chrome and Edge have been tested to work) and go to `about://tracing`. If you don't have a Chromium browser, you can go to https://ui.perfetto.dev/v23.0-b574f45ca/assets/catapult_trace_viewer.html and it should work the same.\n\nOnce the page has loaded, you can drag and drop the created profile JSON into the page. This will then load and show you the data. You can use the tools to move around, but it's recommended to use the keyboard shortcuts. Press `?` on your keyboard or in the top right of the page to see the shortcuts.\nExample of a frame of data, see the docs for more examples and details.\n![example](https://i.imgur.com/6SBDkSc.png \"Example of chrome tracing\")\n## Jprof\nTo help make it easier to try out or migrate, you can easily use existing jprof calls. Below shows off how, with 2 additional functions to make it fit into AppleCake's workflow.\n```lua\nlocal appleCake = require(\"lib.AppleCake\")(true) -- Set to false will remove the profiling tool from the project, and all other threads\n\nlocal jprof = appleCake.jprof\n-- One of the different function from normal jprof\njprof.START() -- takes in filename to know where it should write to\n-- equally can call appleCake.beginSession(filename)\n\nfunction love.quit()\n  jprof.write()\n  -- similar to the orginal, except appleCake needs an open file from the start to work (see above),\n  -- so this closes the current file and opens the given file to start writing to\n  -- You can call `appleCake.endSession` to close the current file without opening a file again\nend\n\nlocal function loop(count)\n  jprof.push(\"Loop \"..count)\n  local n = 0\n  for i=0,count do\n    if i % 10 == 0 then\n      n = n + i\n    end\n  end\n  jprof.pop(\"Loop \"..count)\nend\n\nlocal r = 0\nfunction love.update(dt)\n  jprof.push(\"frame\")\n  jprof.push(\"love.update\")\n  r = r + 0.5 * dt\n  loop(100000)\n  \n  jprof.COUNTMEMORY() -- tracks memory; as we don't track memory each time push is called like jprof\n  -- renamed function from appleCake.countMemory\n  -- Recommended to count memory only every few frames to decrease file size of the resulting profiled session\n  jprof.pop(\"love.update\")\nend\n\nlocal lg = love.graphics\nfunction love.draw()\n  jprof.push(\"love.draw\")\n  lg.push()\n  lg.translate(30*math.sqrt(2),30*math.sqrt(2))\n  lg.rotate(r)\n  lg.rectangle(\"fill\", 0,0,30,30)\n  lg.pop()\n  jprof.pop(\"love.draw\")\n  jprof.pop(\"frame\")\nend\n```","funding_links":[],"categories":["Performance"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEngineerSmith%2FAppleCake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FEngineerSmith%2FAppleCake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEngineerSmith%2FAppleCake/lists"}