Skip to content

Commit

Permalink
Recommend the extra interface by default
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Mar 14, 2024
1 parent 1d5c851 commit 2bda5ea
Showing 1 changed file with 15 additions and 31 deletions.
46 changes: 15 additions & 31 deletions doc/yjit/yjit.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,19 +479,9 @@ perf script --fields +pid > /tmp/test.perf

You can also profile the number of cycles consumed by code generated by each YJIT function.

#### Using perf with Python support

`misc/yjit_perf.py` is a script for `perf script -s` command.
By default, it doesn't support Python scripts, so you need to build `perf` from source.

```bash
# Build perf from source for Python support
sudo apt-get install libpython3-dev python3-pip flex libtraceevent-dev \
libelf-dev libunwind-dev libaudit-dev libslang2-dev libdw-dev
git clone --depth=1 https://github.com/torvalds/linux
cd linux/tools/perf
make
make install
# Install perf
apt-get install linux-tools-common linux-tools-generic linux-tools-`uname -r`

# [Optional] Allow running perf without sudo
echo 0 | sudo tee /proc/sys/kernel/kptr_restrict
Expand All @@ -502,30 +492,24 @@ cd ../yjit-bench
PERF=record ruby --yjit-perf=codegen -Iharness-perf benchmarks/lobsters/benchmark.rb

# Aggregate results
perf script -s ../ruby/misc/yjit_perf.py
perf script > /tmp/perf.txt
../ruby/misc/yjit_perf.py /tmp/perf.txt
```

#### Using perf without Python support
#### Building perf with Python support

`misc/yjit_perf.py` also has an extra interface to support `perf` without Python support.
You need to run `perf script` (instead of `perf script -s`) first, and feed the output to `misc/yjit_perf.py`.

This interface exists primarily for production environments. You can run `perf script` in production,
export the output locally, and run the script using it.
`misc/yjit_perf.py` was originally created for `perf script -s`.
You need to build `perf` from source, but it has a handy interface.

```bash
# Install perf
apt-get install linux-tools-common linux-tools-generic linux-tools-`uname -r`

# [Optional] Allow running perf without sudo
echo 0 | sudo tee /proc/sys/kernel/kptr_restrict
echo -1 | sudo tee /proc/sys/kernel/perf_event_paranoid

# Profile Ruby with --yjit-perf=codegen
cd ../yjit-bench
PERF=record ruby --yjit-perf=codegen -Iharness-perf benchmarks/lobsters/benchmark.rb
# Build perf from source for Python support
sudo apt-get install libpython3-dev python3-pip flex libtraceevent-dev \
libelf-dev libunwind-dev libaudit-dev libslang2-dev libdw-dev
git clone --depth=1 https://github.com/torvalds/linux
cd linux/tools/perf
make
make install

# Aggregate results
perf script > /tmp/perf.txt
../ruby/misc/yjit_perf.py /tmp/perf.txt
perf script -s ../ruby/misc/yjit_perf.py
```

0 comments on commit 2bda5ea

Please sign in to comment.