{"id":16985067,"url":"https://github.com/hejsil/ez-profile","last_synced_at":"2025-03-22T01:20:48.325Z","repository":{"id":224140949,"uuid":"762531524","full_name":"Hejsil/ez-profile","owner":"Hejsil","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-13T12:55:33.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-26T19:27:38.793Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Zig","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/Hejsil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["Hejsil"]}},"created_at":"2024-02-24T01:24:47.000Z","updated_at":"2024-09-13T12:55:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"5ecb26ac-13af-4fa5-8632-39417eb4c6d3","html_url":"https://github.com/Hejsil/ez-profile","commit_stats":null,"previous_names":["hejsil/ez-profile"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hejsil%2Fez-profile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hejsil%2Fez-profile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hejsil%2Fez-profile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hejsil%2Fez-profile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hejsil","download_url":"https://codeload.github.com/Hejsil/ez-profile/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244890898,"owners_count":20527164,"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-10-14T02:36:46.596Z","updated_at":"2025-03-22T01:20:48.307Z","avatar_url":"https://github.com/Hejsil.png","language":"Zig","funding_links":["https://github.com/sponsors/Hejsil"],"categories":[],"sub_categories":[],"readme":"\u003c!---\nREADME.md is autogenerated. Please edit example/README.md.template instead.\n--\u003e\n# ez-profile\n\nA small library for quick and dirty profiling. It's a single file, so you can just copy it into\nyour project to get started.\n\nTo use `ez-profile`, add the following lines to the functions you want to trace:\n```zig\nconst trace = @import(\"ez-profile.zig\").trace(@src(), opaque{});\ndefer trace.end();\n```\n\nAnd add the following line where you want `ez-profile` to report its measurements:\n```zig\ndefer @import(\"ez-profile.zig\").report();\n```\n\nYou can also add it as a module in your `build.zig` and import it with `@import(\"ez-profile\")` from\nanywhere.\n\n`ez-profile` outputs a small json file called `./ez-profile-out.json`. You can use command line\ntools `jq` to get a table:\n\n```\n$ jq -r '(.[] | [(.loc | \"\\(.file):\\(.line):\\(.column): \\(.fn_name)\" ), .samples, .total_time]) | @tsv' ez-profile-out.json |\n    sort -k3 -h |\n    column -t -s \"$(printf '\\t')\"\nexample/example.zig:20:28: createList                1  49464\nexample/example.zig:33:28: createListAssumeCapacity  1  15008\nexample/example.zig:47:28: sortItems                 2  180622\nexample/example.zig:54:28: printItems                2  1613993\n```\n\nOr simply paste the data into a website like https://www.convertjson.com/json-to-html-table.htm\n\n## Example\n\n```zig\nconst ez = @import(\"ez-profile\");\nconst std = @import(\"std\");\n\npub fn main() !void {\n    defer ez.report();\n\n    const list = try createList(std.heap.page_allocator);\n    defer list.deinit();\n\n    const list2 = try createListAssumeCapacity(std.heap.page_allocator);\n    defer list2.deinit();\n\n    sortItems(list.items);\n    sortItems(list2.items);\n    try printItems(list.items);\n    try printItems(list2.items);\n}\n\nfn createList(alloctor: std.mem.Allocator) !std.ArrayList(usize) {\n    const trace = ez.trace(@src(), opaque {});\n    defer trace.end();\n\n    var res = std.ArrayList(usize).init(alloctor);\n    errdefer res.deinit();\n\n    for (0..1024) |item|\n        try res.append(item);\n\n    return res;\n}\n\nfn createListAssumeCapacity(alloctor: std.mem.Allocator) !std.ArrayList(usize) {\n    const trace = ez.trace(@src(), opaque {});\n    defer trace.end();\n\n    var res = std.ArrayList(usize).init(alloctor);\n    errdefer res.deinit();\n\n    try res.ensureTotalCapacityPrecise(1024);\n    for (0..1024) |item|\n        res.appendAssumeCapacity(item);\n\n    return res;\n}\n\nfn sortItems(slice: []usize) void {\n    const trace = ez.trace(@src(), opaque {});\n    defer trace.end();\n\n    std.sort.insertion(usize, slice, {}, std.sort.desc(usize));\n}\n\nfn printItems(slice: []usize) !void {\n    const trace = ez.trace(@src(), opaque {});\n    defer trace.end();\n\n    const stdout = std.io.getStdOut();\n    var buf_stdout = std.io.bufferedWriter(stdout.writer());\n    const out = buf_stdout.writer();\n\n    for (slice, 0..) |item, i|\n        try out.print(\"[{}] = {}\\n\", .{ i, item });\n\n    try buf_stdout.flush();\n}\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhejsil%2Fez-profile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhejsil%2Fez-profile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhejsil%2Fez-profile/lists"}