Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YJIT: Let yjit_perf.py support perf with Python disabled #10246

Merged
merged 3 commits into from Mar 14, 2024

Conversation

k0kubun
Copy link
Member

@k0kubun k0kubun commented Mar 14, 2024

Many Linux distributions don't enable Python scripting in perf by default. perf in our production environment didn't have that either. We could change our production image to manually build perf to fix the problem too, but it's a lot of work to do it everywhere.

This PR proposes to add an alternative way to run our perf script. It adds an extra interface to parse the output of perf script to obviate Python scripting support in production environments. With this PR, we can use this script like this:

production$ perf script > /tmp/perf.txt
local$ scp production:/tmp/perf.txt /tmp/perf.txt
local$ misc/yjit_perf.py /tmp/perf.txt

@k0kubun k0kubun requested a review from a team as a code owner March 14, 2024 03:05
@maximecb
Copy link
Contributor

Can you explain a bit more how this works? With this script, you still need the perf tool to be available? This Python script parses the output of the perf program?

Can you update the documentation in yjit.md to show the complete perf workflow, including invoking YJIT to gather perf data?

doc/yjit/yjit.md Outdated
Comment on lines 508 to 530
#### 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
../ruby/misc/yjit_perf.py /tmp/perf.txt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming that this works just as well, maybe we should only give the instructions assuming people are using perf without Python support. Less confusing if we only provide one workflow that works everywhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I updated the document that way in 2abcd19. I still left the instructions to build perf from source in case we want to develop a new feature using something we currently don't parse but is available in the original perf events.

@k0kubun
Copy link
Member Author

k0kubun commented Mar 14, 2024

Can you explain a bit more how this works? With this script, you still need the perf tool to be available?

The point is that we can separate the machine to be profiled and the one to aggregate the results can be separated. The profiling target machine still needs perf tool. But it no longer requires perf with Python scripting (because Python is used only for aggregation).

This Python script parses the output of the perf program?

Correct. The example output of perf script command is left as a comment in misc/yjit_perf.py. We only need a symbol name, DSO name, and the number of cycles, and the Python scripts parses the information from each line.

Can you update the documentation in yjit.md to show the complete perf workflow, including invoking YJIT to gather perf data?

done 1d5c851

@k0kubun k0kubun merged commit b0be296 into ruby:master Mar 14, 2024
97 checks passed
@k0kubun k0kubun deleted the yjit-perf-py branch March 14, 2024 17:08
artur-intech pushed a commit to artur-intech/ruby that referenced this pull request Apr 26, 2024
* YJIT: Let yjit_perf.py support perf with Python disabled

* Update yjit.md about perf

* Recommend the extra interface by default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants