{"id":17912016,"url":"https://github.com/tezc/goperf","last_synced_at":"2025-06-25T04:35:14.428Z","repository":{"id":57569378,"uuid":"326636522","full_name":"tezc/goperf","owner":"tezc","description":"Print performance counters summary in Go applications","archived":false,"fork":false,"pushed_at":"2021-03-04T14:12:42.000Z","size":18,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-19T00:03:39.600Z","etag":null,"topics":["perf","performance-counters"],"latest_commit_sha":null,"homepage":"","language":"Go","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/tezc.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":"2021-01-04T09:45:34.000Z","updated_at":"2021-05-24T21:41:57.000Z","dependencies_parsed_at":"2022-08-23T17:40:23.001Z","dependency_job_id":null,"html_url":"https://github.com/tezc/goperf","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tezc%2Fgoperf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tezc%2Fgoperf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tezc%2Fgoperf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tezc%2Fgoperf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tezc","download_url":"https://codeload.github.com/tezc/goperf/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245179866,"owners_count":20573559,"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":["perf","performance-counters"],"created_at":"2024-10-28T19:42:35.672Z","updated_at":"2025-03-23T22:34:07.064Z","avatar_url":"https://github.com/tezc.png","language":"Go","readme":"## Performance counters for Go\n\nJust a wrapper around [perf_event_open](https://man7.org/linux/man-pages/man2/perf_event_open.2.html).\n\nUseful when you want to get performance counters for some code snippet.  \nNormally, you use 'perf' itself but it's not always possible to extract  \nsome piece of code from your project and isolate it for performance counters.\n\n## Notes\n- CPUs have limited PMU registers. So, performance counters can be activated at the same time are limited. Some performance counters can be scheduled on specific PMU only. So, combination of some performance counters may not work or they might be multiplexed. Check out \"Measurement Time\" section in the report to see if it's multiplexed. (less than %100) . Also, not all counters are supported by Linux or your CPU. If you are surprised that some counters does not work, search scheduling algorithm of performance counters online.\n- This tool will measure all threads of the process, including gc threads.\n- This tool is direct translation from C version, just for experimental purposes. : https://github.com/tezc/sc/tree/master/perf\n\n\n## Config\nTo allow recording kernel events, you may need to run :\n\n```\nsudo sh -c 'echo 1 \u003e/proc/sys/kernel/perf_event_paranoid'\n```\n\n## Usage :\n\n\n```go\npackage main\n\nimport (\n\t\"github.com/tezc/goperf\"\n\t\"hash/crc32\"\n\t\"os\"\n)\n\nfunc main() {\n\n\tvar x uint32 = 0\n\tdata := []byte(\"hello world!\")\n\n\tgoperf.Start()\n\n\t// long running code\n\tfor i := 0; i \u003c 10000000; i++ {\n\t\tx += crc32.ChecksumIEEE(data)\n\t}\n\n\tgoperf.End()\n\n\tos.Exit(int(x))\n}\n\n```\n\nOutput : \n\n```\n| Event                     | Value              | Measurement time  \n---------------------------------------------------------------\n| time (seconds)            | 0.22               | (100,00%)  \n| cpu-clock                 | 219,754,463.00     | (100.00%)  \n| task-clock                | 219,754,469.00     | (100.00%)  \n| page-faults               | 4.00               | (100.00%)  \n| context-switches          | 0.00               | (100.00%)  \n| cpu-migrations            | 0.00               | (100.00%)  \n| page-fault-minor          | 4.00               | (100.00%)  \n| cpu-cycles                | 911,266,695.00     | (100.00%)  \n| instructions              | 2,300,365,430.00   | (100.00%)  \n| cache-misses              | 14,812.00          | (100.00%)  \n| L1D-read-miss             | 11,385.00          | (100.00%)  \n| L1I-read-miss             | 48,424.00          | (100.00%)  \n \n```\n\n\nYou can add or disable counters, check Counters table for the full list :  \n\n\n```go\npackage main\n\nimport (\n\t\"github.com/tezc/goperf\"\n\t\"hash/crc32\"\n\t\"os\"\n)\n\nfunc main() {\n\n\tvar x uint32 = 0\n\tdata := []byte(\"hello world!\")\n\n\tgoperf.Disable(\"page-faults\")\n\tgoperf.Disable(\"context-switches\")\n\tgoperf.Enable(\"L1D-read-miss\")\n\tgoperf.Start()\n\n\t// long running code\n\tfor i := 0; i \u003c 10000000; i++ {\n\t\tx += crc32.ChecksumIEEE(data)\n\t}\n\n\tgoperf.End()\n\n\tos.Exit(int(x))\n}\n```\n\nRun multiple time : \n\n```go\npackage main\n\nimport (\n\t\"github.com/tezc/goperf\"\n\t\"hash/crc32\"\n\t\"os\"\n)\n\nfunc main() {\n\n\tvar x uint32 = 0\n\tdata := []byte(\"hello world!\")\n\t\n\tgoperf.Start()\n\t// long running code\n\tfor i := 0; i \u003c 10000000; i++ {\n\t\tx += crc32.ChecksumIEEE(data)\n\t}\n\tgoperf.End()\n\n\t\n\t\n\ttest := []byte(\"test!\")\n\n\tgoperf.Start()\n\t// long running code\n\tfor i := 0; i \u003c 10000000; i++ {\n\t\tx += crc32.ChecksumIEEE(test)\n\t}\n\tgoperf.End()\n\t\n\n\tos.Exit(int(x))\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftezc%2Fgoperf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftezc%2Fgoperf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftezc%2Fgoperf/lists"}