{"id":13730816,"url":"https://github.com/stolk/ThreadTracer","last_synced_at":"2025-05-08T03:31:54.958Z","repository":{"id":65304685,"uuid":"108791850","full_name":"stolk/ThreadTracer","owner":"stolk","description":"Lightweight inline profiler that measures wall-time, cpu-time and premptive context switches for threads.","archived":false,"fork":false,"pushed_at":"2022-06-07T16:12:20.000Z","size":31,"stargazers_count":72,"open_issues_count":0,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-08-04T02:09:49.560Z","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/stolk.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}},"created_at":"2017-10-30T02:27:01.000Z","updated_at":"2024-03-02T10:24:30.000Z","dependencies_parsed_at":"2023-01-16T17:30:35.092Z","dependency_job_id":null,"html_url":"https://github.com/stolk/ThreadTracer","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/stolk%2FThreadTracer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stolk%2FThreadTracer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stolk%2FThreadTracer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stolk%2FThreadTracer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stolk","download_url":"https://codeload.github.com/stolk/ThreadTracer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224695719,"owners_count":17354465,"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.822Z","updated_at":"2024-11-14T21:31:37.390Z","avatar_url":"https://github.com/stolk.png","language":"C","readme":"# ThreadTracer\n\n## Summary\n\nLightweight inline profiler that measures wall-time, cpu-time and premptive context switches for threads.\n\n## Features\n\nThreadTracer is an inline profiler that is special in the following ways:\n* Fully supports multi threaded applications.\n* Will never cause your thread to go to sleep because of profiling.\n* Will not miss events.\n* Will detect if threads were context-switched by scheduler, preemptively or voluntarily.\n* Computes duty-cycle for each scope: not just how long it ran, but also how much of that time, it was scheduled on a core.\n* Small light weight system, written in C. Just one header and one small implementation file.\n* Zero dependencies.\n\n## Limitations\n* Doesn't show a live profile, but creates a report after the run, [viewable with Google Chrome](https://www.gamasutra.com/view/news/176420/Indepth_Using_Chrometracing_to_view_your_inline_profiling_data.php).\n* Currently does not support asynchronous events that start on one thread, and finish on another.\n\n## Usage\n\n\n```\n#include \u003cthreadtracer.h\u003e\n\n// Each thread that will be generating profiling events needs to be made known to the system.\n// If you sign in with threadid TT_CALLING_THREAD, the threadid of calling thread will be used.\n\ntt_signin( TT_CALLING_THREAD, \"mainthread\" );\n\n// C Programs need to wrap sections of code with a begin and end macro.\n\nTT_BEGIN( \"simulation\" );\nsimulate( dt );\nTT_END( \"simulation\" );\n\n// C++ can also use a scoped tag. Event automatically ends when it goes out of scope.\nvoid draw_all(void)\n{\n\tTT_SCOPE( \"draw\" );\n\tdraw_world();\n\tif ( !overlay )\n\t\treturn;\n\tdraw_info();\n}\n\n// When you are done profiling, typically at program end, or earlier, you can generate the profile report.\n\ntt_report(NULL);\n```\n\n## Platforms\n\nThreadTracer has been tested on:\n* Linux amd64\n* Linux x86\n* Linux RISCV\n* FreeBSD amd64\n\n## Building\n\nJust add threadtracer.c to your project, and compile your sources with ```-D_GNU_SOURCE``` flag so that RUSAGE_THREAD support is available for the getrusage() call.\n\n## Viewing the report\n\nStart the Google Chrome browser, and in the URL bar, type ```chrome://tracing``` and then load the genererated threadtracer.json file.\n\n![screenshot](https://pbs.twimg.com/media/DNZe7tRVwAAm2_-.png)\n\nNote that for the highlighted task, the detail view shows that the thread got interrupted once preemptively, which causes it to run on a CPU core for only 81% of the time that the task took to complete.\n\nThe shading of the time slices shows the duty cycle: how much of the time was spend running on a core.\n\n## Skipping samples at launch.\n\nTo avoid recording samples right after launch, you can skip the first seconds of recording with an environment variable. To skip the first five seconds, do:\n\n```\n$ THREADTRACERSKIP=5 ./foo\nThreadTracer: clock resolution: 1 nsec.\nThreadTracer: skipping the first 5 seconds before recording.\nThreadTracer: Wrote 51780 events (6 discarded) to threadtracer.json\n```\n\n## Acknowledgements\n\n* [chrome://tracing](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool) for their excellent in-browser visualization.\n* [Remotery](https://github.com/Celtoys/Remotery) and [Minitrace!](https://github.com/hrydgard/minitrace) for the inspiration, and showing how powerful inline profiling can be.\n* [Frogtoss](https://www.frogtoss.com/) for contributing and testing.\n","funding_links":[],"categories":["C++"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstolk%2FThreadTracer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstolk%2FThreadTracer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstolk%2FThreadTracer/lists"}