https://github.com/tonycoz/perl5-linux-libperf-simple
Simple XS wrapper around Linux libperf
https://github.com/tonycoz/perl5-linux-libperf-simple
Last synced: 4 months ago
JSON representation
Simple XS wrapper around Linux libperf
- Host: GitHub
- URL: https://github.com/tonycoz/perl5-linux-libperf-simple
- Owner: tonycoz
- Created: 2024-11-18T12:50:32.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-01-17T09:40:05.000Z (5 months ago)
- Last Synced: 2025-01-17T10:01:53.419Z (5 months ago)
- Language: XS
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Linux::libperf::Simple
This module is a simple wrapper around Linux `libperf`.
It is intended for use in measuring in-process execution time for
precise benchmarking, whether it will actually be useful for that
remains to be seen.You will need to install the package (Redhat-ish) or build from source
(Debian-ish at this time). `libperf` is supplied as part of the
Linux source tree, it is *not* `theonewolf/libperf` from Github.To build from source extract the linux sources, the more recent the
better:```
cd tools/lib/perf
make prefix=/where/to/install install
```When configuring `Linux-libperf-Simple`, ensure `libperf.pc` from the `libperf` build is in the `PKG_CONFIG_PATH` environment variable, eg.:
```
PKG_CONFIG_PATH=~/local/libperf/lib64/pkgconfig/ perl Makefile.PL
```To actually use this module you will either need to be root, or
`kernel.perf_event_paranoid` may need to be set to a lower value than
the default, look this up before using it.If you have a one-liner you want to test:
```
$ perl -Mblib -MLinux::libperf::Simple=report -e 'report(sub { for (1.. 100_000_000) { } })'
branch-misses: 5,236
branches: 2,133,471,368
bus-cycles: 15,710,865
cache-misses: 3,377
cache-references: 29,733
context-switches: 3
cpu-migrations: 1
cycles: 2,373,174,556
instructions: 10,194,546,708
page-faults: 0
task-clock: 916,441,424
```Otherwise you can create an object and start and stop stats
collection, and finally fetch the results:```
use Linux::libperf::Simple;
my $perf = Linux::libperf::Simple->new;
$perf->enable;
# code to benchmark here
...
$perf->disable;
my $results = $perf->results;
use Data::Dumper;
print Dumper($results);
```# Troubleshooting
Unfortunately `libperf`'s reporting isn't very good, if libperf fails
to initialize try using `strace` to see details on which system call
actually failed, eg you might try:```
strace -o trace.txt perl -MLinux::libperf::Simple=run -e 'run(sub {})'
```
and look over `trace.txt` to see why it failed.