Skip to content

Commit

Permalink
Rust (#1)
Browse files Browse the repository at this point in the history
* Relicense

* Remove old code

* Cargo init! + add binary.rs

* Add process.rs

* Add profile.rs

* Compile BPF program

* Add bindgen

* Add initial binary

* Split cli + beginning of error handling changes

* Ignore currently generated output

* Use libbpf

* WIP improvements in stack walking and others

* Pass Profile as a mutable argument

* Initial support for multiple Ruby versions

Including Ruby 3

* Add cpu and syscall subcommands

Doesn't implement syscall tracing just yet

* Add syscall tracing support

* Add integration tests

* Various improvements

* Move sampling config to the right place

* Explicitly set the BPF program type for CPU sampling

* Update crates

* Use log for logging

* Set the initial timestamp just before profiling

* Add non-x86 arch warning

As it's not being tested that much on arm64 and other architectures
so far

* Move Ruby ABI configuration to its own file

Some day this should be automatically generated with bindgen

* Removed hardcoded main thread + ec offsets

* Run clippy

Some of the ruby_readers helpers were copied / inspired from
- https://stackoverflow.com/questions/42066381/how-to-get-a-str-from-a-nul-terminated-byte-slice-if-the-nul-terminator-isnt
- https://stackoverflow.com/questions/28127165/how-to-convert-struct-to-u8

* Add program index to rbperf.h and rename read_ruby_frames

* Add initial docs

* Move bpf to src/bpf

* Split dev dependencies + pin the catchall versions

* Add more info in Cargo.toml

* Append date to output

* Fix Ruby 3 stack unwinding

Before, we were accessing `ruby_current_vm_ptr.ractor->main_thread->ec`, but turns
that, in some cases, perhaps when there's multiple ractors, this
execution context is not the one actually running and we should access `ruby_current_vm_ptr.ractor->main_ractor.threads->running_ec` instead.

Accessing this member introduces an issue that isn't addressed in this
PR. Just before the `threads` field, there's `rb_nativethread_cond_t`[1] which on UNIX platforms is typedef'd to `pthread_cond_t`. In other words, we aren't just depending on Ruby's ABI, but on pthread's as well

[1] https://github.com/ruby/ruby/blob/a892e5599ec8ec441a8d8b878efa855ef283ed08/include/ruby/thread_native.h#L38

* Ignore the new output format files

* Write flamegraphs as SVGs

As they aren't really HTML files and this messes up with the width, too

* WIPWIPWIWP more docs

* Add server test program running Sinatra + webrick

Using webrick as the image builds faster due to the lack of native
extensions

* Add support for ruby 2.7.6

* Do not read past last frame

as don't zero-fill the frames

* Add support for Ruby 3.1.2

`rb_control_frame_struct` got an extra field https://github.com/ruby/ruby/blob/08cee2bf804d22dc51002b0df023aea7ec044d8d/vm_core.h#L839

* Ensure that we clean up test processes even on panic

* bpf: Fix broken frame count calculation

* Initial support for native functions

TODO:
- Check that this frame is indeed, a native frame
- Retrieve funciton's name

* Run cargo update

* Move Ruby configuration to files

This way we will be able to generate these files during build with
bindgen, instead of manually generating them!

* Improve docs

* Link elfutils and zlib statically

* Remove unused bcc dependency

* tools: Add script to pull the Ruby container images

* Test Ruby 2.7.4

* Enable anyhow backtraces in stable

Increases the binary size, but it's good to have as much info as
we can to debug issues, especially in the beginning :D

* Run clang-format

`clang-format -i src/bpf/rbperf*`

* Add acknowledgements and improve docs a bit

* Do not print folded profiles

* Set current version to 0.1.0-beta

* Add CI
  • Loading branch information
javierhonduco committed Jul 3, 2022
1 parent fcda748 commit 50231c3
Show file tree
Hide file tree
Showing 87 changed files with 3,339 additions and 9,240 deletions.
4 changes: 0 additions & 4 deletions .gitattributes

This file was deleted.

97 changes: 97 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: CI

on:
push:
pull_request:

jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust: [stable]
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@1.64.0
with:
toolchain: ${{matrix.rust}}
components: rust-src, rustfmt
- name: Install build system dependencies
run: |
export DEBIAN_FRONTEND=noninteractive
sudo apt-get -y install --no-install-recommends \
curl \
ca-certificates \
clang \
make \
pkg-config \
libelf-dev \
zlib1g-dev
- name: Build
run: |
export RUSTFLAGS='-L /usr/lib/x86_64-linux-gnu'
cargo build
lint:
name: Lint
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust: [stable]
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@1.64.0
with:
toolchain: ${{matrix.rust}}
components: rust-src, rustfmt
- name: Run cargo fmt
run: |
# This file is generated at build time, so rustfmt will fail
# with Error writing files: failed to resolve mod `bpf` if it
# does not exist
touch src/bpf/mod.rs
cargo fmt
git diff --exit-code
test:
name: Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust: [stable]
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@1.64.0
with:
toolchain: ${{matrix.rust}}
components: rust-src, rustfmt
- name: Install build system dependencies
run: |
export DEBIAN_FRONTEND=noninteractive
sudo apt-get -y install --no-install-recommends \
curl \
ca-certificates \
clang \
make \
pkg-config \
libelf-dev \
zlib1g-dev
- name: Run unittests
run: |
export RUSTFLAGS='-L /usr/lib/x86_64-linux-gnu'
export RUST_BACKTRACE=1
cargo test -- --skip rbperf::tests::rbperf_test
- name: Install podman
run: sudo apt-get -y install --no-install-recommends podman
- name: Pull Ruby containers
run: tools/pull_ruby_images
- name: Run integration tests
run: |
export RUST_BACKTRACE=1
# Running only 3.1.2 for a bit, will enable the rest once we make sure
# that things are looking good
ls target/debug/deps/rbperf-* | grep -v "\.d" | xargs -I{} sudo {} rbperf::tests::rbperf_test_3_1_2
104 changes: 0 additions & 104 deletions .github/workflows/ci.yml

This file was deleted.

139 changes: 4 additions & 135 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,137 +1,6 @@
# rbperf specifics
index.html

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
/target
src/bpf/mod.rs

*.swp
*rbperf*.data
.mypy_cache/
samples.txt

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
rbperf_out*
rbperf_flame*

0 comments on commit 50231c3

Please sign in to comment.