Skip to content

Commit

Permalink
Update yjit.md about perf
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Mar 14, 2024
1 parent 7c50680 commit 7dd2f0b
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions doc/yjit/yjit.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,16 @@ perf script --fields +pid > /tmp/test.perf

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

#### Building 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
# [Optional] libelf-dev libunwind-dev libaudit-dev libslang2-dev libdw-dev
sudo apt-get install libpython3-dev python3-pip flex libtraceevent-dev
git clone https://github.com/torvalds/linux
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
Expand All @@ -499,3 +504,28 @@ PERF=record ruby --yjit-perf=codegen -Iharness-perf benchmarks/lobsters/benchmar
# Aggregate results
perf script -s ../ruby/misc/yjit_perf.py
```

### Using perf without 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.

```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

# Aggregate results
perf script > /tmp/perf.txt
perf script /tmp/perf.txt
```

0 comments on commit 7dd2f0b

Please sign in to comment.