{"id":16646005,"url":"https://github.com/vitorramos/performance_features","last_synced_at":"2025-03-21T16:30:45.932Z","repository":{"id":37601779,"uuid":"158719483","full_name":"VitorRamos/performance_features","owner":"VitorRamos","description":"Python library to collect performance events","archived":false,"fork":false,"pushed_at":"2023-01-30T04:40:39.000Z","size":24792,"stargazers_count":14,"open_issues_count":7,"forks_count":2,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-18T02:51:34.098Z","etag":null,"topics":["hardware-performance-counters","linux","performance-counters","performance-monitoring"],"latest_commit_sha":null,"homepage":"","language":"Python","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/VitorRamos.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":"2018-11-22T15:35:33.000Z","updated_at":"2023-09-07T11:24:51.000Z","dependencies_parsed_at":"2023-02-16T04:00:37.393Z","dependency_job_id":null,"html_url":"https://github.com/VitorRamos/performance_features","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VitorRamos%2Fperformance_features","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VitorRamos%2Fperformance_features/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VitorRamos%2Fperformance_features/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VitorRamos%2Fperformance_features/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VitorRamos","download_url":"https://codeload.github.com/VitorRamos/performance_features/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244829376,"owners_count":20517296,"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":["hardware-performance-counters","linux","performance-counters","performance-monitoring"],"created_at":"2024-10-12T08:26:08.106Z","updated_at":"2025-03-21T16:30:45.501Z","avatar_url":"https://github.com/VitorRamos.png","language":"Python","readme":"# Performance Counters api for python\n\nA high-level abstraction API for Linux perf events with low overhead\n\n[![Continuous Integration](https://github.com/VitorRamos/performance_features/actions/workflows/main.yml/badge.svg)](https://github.com/VitorRamos/performance_features/actions/workflows/main.yml)\n\n## Table of contents\n\n- [Installation](#install)\n- [Example usage](#usage)\n- [How it works](#whatis)\n\n\n\u003ca name=\"install\"/\u003e\n\n## Install from pip\n```bash\nsudo apt install g++ gcc swig libpfm4-dev python3-dev python3-pip\npip install performance-features\n```\n\n## Install from source\n```bash\ngit clone https://github.com/VitorRamos/performance_features.git\ncd performance_features\nsudo ./install.sh\n```\n\n\u003ca name=\"usage\"/\u003e\n\n## Usage\n\n### List events\n```python\nfrom performance_features import *\n\nprint(get_supported_pmus())\nprint(get_supported_events())\n```\n\n### Sampling events\n```python\nfrom performance_features import *\n\ntry:\n    events= [['PERF_COUNT_HW_INSTRUCTIONS'],\n            ['PERF_COUNT_HW_BRANCH_INSTRUCTIONS','PERF_COUNT_HW_BRANCH_MISSES'],\n            ['PERF_COUNT_SW_PAGE_FAULTS']]\n    perf= Profiler(program_args= ['/bin/ls','/'], events_groups=events)\n    data= perf.run(sample_period= 0.01)\n    print(data)\nexcept RuntimeError as e:\n    print(e.args[0])\n```\n\n\u003ca name=\"whatis\"/\u003e\n\n## How it works:\n\nA c module create a workload using Linux ptrace to ensure we control the starting the application and collect the events data with minimal overhead. The events are setup using the perf_event_open syscall through the perfmom library.\n\n## What are the performance counters\nPerformance counters are special hardware registers available on most modern CPUs. These registers count the number of certain types of events: such as instructions executed, cache misses suffered, or branches mis-predicted without slowing down the kernel or applications. These registers can also trigger interrupts when a threshold number of events have passed and can thus be used to profile the code that runs on that CPU.\n\n## Reading Performance counters\n+ **Instructions**\n  + **rdmsr**: Reads the contents of a 64-bit model specific register (MSR) specified in the ECX register into registers EDX:EAX. This instruction must be executed at privilege level 0 or in real-address mode\n\n  + **rdpmc**: Is slightly faster that the equivelent rdmsr instruction. rdpmc can also be configured to allow access to the counters from userspace, without being priviledged.\n+ **From Userspace** (Linux) : The Linux Performance Counter subsystem provides an abstraction of these hardware capabilities. It provides per task and per CPU counters, counter groups, and it provides event capabilities on top of those. It provides \"virtual\" 64-bit counters, regardless of the width of the underlying hardware counters. Performance counters are accessed via special file descriptors. There's one file descriptor per virtual counter used. The special file descriptor is opened via the perf_event_open() system call. These system call do not use rdpmc but rdpmc is not necessarily faster than other methods for reading event values.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitorramos%2Fperformance_features","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvitorramos%2Fperformance_features","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitorramos%2Fperformance_features/lists"}