{"id":13730761,"url":"https://github.com/hrydgard/minitrace","last_synced_at":"2025-05-15T22:10:57.545Z","repository":{"id":15410160,"uuid":"18142241","full_name":"hrydgard/minitrace","owner":"hrydgard","description":"Simple C/C++ library for producing JSON traces suitable for Chrome's built-in trace viewer (about:tracing).","archived":false,"fork":false,"pushed_at":"2024-10-21T12:26:40.000Z","size":57,"stargazers_count":382,"open_issues_count":7,"forks_count":68,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-08T09:09:15.611Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","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/hrydgard.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":"2014-03-26T15:05:16.000Z","updated_at":"2025-04-05T12:01:01.000Z","dependencies_parsed_at":"2024-02-07T11:29:28.058Z","dependency_job_id":"ec5c51de-d24e-48fd-bd32-a8f9bc4fe9a4","html_url":"https://github.com/hrydgard/minitrace","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrydgard%2Fminitrace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrydgard%2Fminitrace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrydgard%2Fminitrace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrydgard%2Fminitrace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hrydgard","download_url":"https://codeload.github.com/hrydgard/minitrace/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254430331,"owners_count":22069909,"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":[],"created_at":"2024-08-03T02:01:19.069Z","updated_at":"2025-05-15T22:10:57.520Z","avatar_url":"https://github.com/hrydgard.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"minitrace\n=========\nby Henrik Rydgård 2014 (hrydgard+minitrace@gmail.com)\n\nMIT licensed, feel free to use however you want. If you use it for something cool, I'd love to hear about it!\n\nThis is a C library with C++ helpers for producing JSON traces suitable for Chrome's excellent built-in trace viewer (chrome://tracing).\n\nExtremely simple to build and use. Tested on Mac and Windows, but should compile anywhere you can use ANSI C with few or no changes.\n\nSample output (see example code below):\n\n![minitrace](http://www.ppsspp.org/img/minitrace.png)\n\nRemember to be careful when interpreting the output. This is not a sampling profiler, so it only records start and stop times for blocks. This means that blocks grow even when the CPU is off running another thread, and that it can look like work is being done on more blocks at a time than you have CPUs.\n\n\nHow to use\n----------\n\n  1. Include `minitrace.c` and `minitrace.h` in your project. `#include minitrace.h` in some common header.\n\n  2. In your initialization code:\n\n      ```c\n      mtr_init(\"trace.json\");\n      ```\n\n  3. In your exit code:\n\n      ```c\n      mtr_shutdown();\n      ```\n\n  4. Make sure `MTR_ENABLED` is defined globally when you want to profile, for example `-DMTR_ENABLED`\n\n  5. In all functions you want to profile:\n\n      ```c\n      // C\n      MTR_BEGIN(\"GFX\", \"RasterizeTriangle\")\n      ...\n      MTR_END(\"GFX\", \"RasterizeTriangle\")\n      ```\n\n      ```c++\n      // C++\n      MTR_SCOPE(\"GFX\", \"RasterizeTriangle\")\n      ```\n\n  6. In Google Chrome open \"about:tracing\"\n\n  7. Click Open, and choose your `trace.json`\n\n  8. Navigate the trace view using the WASD keys, and Look for bottlenecks and optimize your application.\n\n  9. In your final release build, don't forget to remove `-DMTR_ENABLED` or however you set the define.\n\n\nBy default, it will collect 1 million tracepoints and then stop. You can change this behaviour, see the\ntop of the header file.\n\nNote: Please only use string literals in MTR statements.\n\nExample code\n------------\n\n```c\nint main(int argc, const char *argv[]) {\n  int i;\n  mtr_init(\"trace.json\");\n\n  MTR_META_PROCESS_NAME(\"minitrace_test\");\n  MTR_META_THREAD_NAME(\"main thread\");\n\n  int long_running_thing_1;\n  int long_running_thing_2;\n\n  MTR_START(\"background\", \"long_running\", \u0026long_running_thing_1);\n  MTR_START(\"background\", \"long_running\", \u0026long_running_thing_2);\n\n  MTR_BEGIN(\"main\", \"outer\");\n  usleep(80000);\n  for (i = 0; i \u003c 3; i++) {\n    MTR_BEGIN(\"main\", \"inner\");\n    usleep(40000);\n    MTR_END(\"main\", \"inner\");\n    usleep(10000);\n  }\n  MTR_STEP(\"background\", \"long_running\", \u0026long_running_thing_1, \"middle step\");\n  usleep(80000);\n  MTR_END(\"main\", \"outer\");\n\n  usleep(50000);\n  MTR_INSTANT(\"main\", \"the end\");\n  usleep(10000);\n  MTR_FINISH(\"background\", \"long_running\", \u0026long_running_thing_1);\n  MTR_FINISH(\"background\", \"long_running\", \u0026long_running_thing_2);\n\n  mtr_flush();\n  mtr_shutdown();\n  return 0;\n}\n```\n\nThe output will result in something looking a little like the picture at the top of this readme.\n\nFuture plans:\n\n  * Builtin background flush thread support with better synchronization, no more fixed limit\n  * Support for more trace arguments, more tracing types\n\nIf you use this, feel free to tell me how, and what issues you may have had. hrydgard+minitrace@gmail.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhrydgard%2Fminitrace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhrydgard%2Fminitrace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhrydgard%2Fminitrace/lists"}