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

Add initial Ruby support #1933

Merged
merged 4 commits into from
Aug 29, 2023
Merged

Conversation

javierhonduco
Copy link
Contributor

@javierhonduco javierhonduco commented Aug 16, 2023

This commit adds initial Ruby support by integrating rbperf's unwinder
and adapting it to this Agent.

There is more work to do, but in the spirit of keeping this commit a bit
more contained, right now:

  • only Ruby 3.0.4 is supported;
  • no focus on efficiency;
  • missing clean-ups (such as clearing the interpreter stack maps);
  • the Ruby stack is fetched even if the Ruby thread is sleeping as long
    as the native stack is on-CPU. This shows up confusingly as the Ruby stack in
    many native stacks that aren't actually running the Ruby code;
  • Ruby unwinding only works with DWARF unwinding for native stacks, this is due to how metadata is set up, this limitation can be lifted in the future;
  • there are no integration tests, this will change soon;

All the shortcomings above, and then some, will be addressed in
forthcoming commits.

Architecture

The current BPF unwinding architecture as well as the changes that this
commit makes can be seen here: https://excalidraw.com/#json=E-W6lSLZ8rTOcri7HZdAl,4AjIUmb-olsQkdbwCqyxqg

image

Test Plan

All current tests pass + running https://github.com/javierhonduco/rbperf/blob/main/tests/programs/simple_two_stacks.rb

image

Signed-off-by: Francisco Javier Honduvilla Coto javierhonduco@gmail.com

@javierhonduco javierhonduco force-pushed the add-rbperf-v0 branch 3 times, most recently from a1d49bd to e5a1dc8 Compare August 22, 2023 12:49
Copy link
Member

@kakkoyun kakkoyun left a comment

Choose a reason for hiding this comment

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

Awesome 🏆 🥇 💯

I liked the additions to the rbperf way of sending data for adapting to the parca agent way.
BPF code looks pretty solid to me.

I have left some comments for user space and as you mentioned in your comments there is a lot of room for optimizations.

I think it's sure close to be merged.

pkg/process/info.go Show resolved Hide resolved
pkg/process/info.go Show resolved Hide resolved
pkg/profiler/cpu/cpu.go Outdated Show resolved Hide resolved
pkg/profiler/cpu/cpu.go Show resolved Hide resolved
pkg/profile/profile.go Show resolved Hide resolved
pkg/profiler/cpu/cpu.go Outdated Show resolved Hide resolved
pkg/profiler/cpu/cpu.go Outdated Show resolved Hide resolved
pkg/profiler/cpu/maps.go Outdated Show resolved Hide resolved
bpf/cpu/shared.h Show resolved Hide resolved
bpf/cpu/rbperf.bpf.c Show resolved Hide resolved
@javierhonduco javierhonduco force-pushed the add-rbperf-v0 branch 5 times, most recently from 147cc10 to 7a63e3b Compare August 29, 2023 09:58
@javierhonduco javierhonduco marked this pull request as ready for review August 29, 2023 09:58
@javierhonduco javierhonduco requested a review from a team as a code owner August 29, 2023 09:58
@javierhonduco javierhonduco changed the title wip add rbperf Add initial Ruby support Aug 29, 2023
bpf/cpu/rbperf.bpf.c Show resolved Hide resolved
This commit adds initial Ruby support by integrating rbperf's unwinder
and adapting it to this Agent.

There is more work to do, but in the spirit of keeping this commit a bit
more contained, right now:
- only Ruby 3.0.4 is supported;
- no focus on efficiency;
- missing clean-ups (such as clearing the interpreter stack maps);
- the Ruby stack is fetched even if the Ruby thread is sleeping as long
  as the native stack is on-CPU. This shows up confusingly as the Ruby stack in
many native stacks that aren't actually running the Ruby code;
- there are no integration tests, this will change soon;

All the shortcomings above, and then some, will be addressed in
forthcoming commits.

Architecture
============

The current BPF unwinding architecture as well as the changes that this
commit makes can be seen here: https://excalidraw.com/#json=E-W6lSLZ8rTOcri7HZdAl,4AjIUmb-olsQkdbwCqyxqg

Test Plan
=========

All current tests pass +

Signed-off-by: Francisco Javier Honduvilla Coto <javierhonduco@gmail.com>
@kakkoyun
Copy link
Member

I'll retrigger the CI soon.

@kakkoyun
Copy link
Member

Fix for container step #1964

@kakkoyun kakkoyun merged commit bbf3f98 into parca-dev:main Aug 29, 2023
22 checks passed
@javierhonduco javierhonduco deleted the add-rbperf-v0 branch August 30, 2023 08:01

p.RawSamples = append(p.RawSamples, profile.RawSample{
TID: profile.PID(pKey.tid),
Copy link
Member

Choose a reason for hiding this comment

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

Oppsie @javierhonduco 🙈

@kakkoyun kakkoyun mentioned this pull request Sep 8, 2023
6 tasks
kakkoyun added a commit that referenced this pull request Sep 13, 2023
This PR adds initial Python support (CPython) using a dedicated unwinder
to the Agent.
There are still many things to do (like testing against various versions
even though it technically should work).

- Only Python `3.11` is thoroughly tested
- No focus on performance
- The targeted Python interpreter needs symbols to capture required
addresses to initialize unwinding. That being said, this shortcoming
will be addressed in upcoming versions.

It has the same architecture as
#1933, and it has similar
shortcomings.
All the shortcomings above, and then some, will be taken care of in the
future.

Additionally, it removes individual ruby and python metadata providers
and introduces an interpreter metadata provider.
You can find interpreterswith `intepreter="Python|Ruby"`

## TODO
- [x] Fix the issue that causing failing Kernel tests

### Test Plan
- [x] Local tests
- [x] Test against Ruby
- [x] Test against .pex files
- [x] Test against
[multiprocessing](https://docs.python.org/3/library/multiprocessing.html)
- [ ] Local Kubernetes test

---

### Single-threaded

![https://cdn.discordapp.com/attachments/963045444332695562/1148621510827835433/CleanShot_2023-09-05_at_16.11.28.png](https://cdn.discordapp.com/attachments/963045444332695562/1148621510827835433/CleanShot_2023-09-05_at_16.11.28.png)

### With Threadpool

![https://cdn.discordapp.com/attachments/963045444332695562/1149044705158496256/CleanShot_2023-09-06_at_20.12.42.png](https://cdn.discordapp.com/attachments/963045444332695562/1149044705158496256/CleanShot_2023-09-06_at_20.12.42.png)

### Using .pex (probably need further investigation. I don't have enough
knowledge on details yet)
![CleanShot 2023-09-08 at 16 30
58](https://github.com/parca-dev/parca-agent/assets/536449/0f9b2a87-f0b6-4435-a323-59cff814e9ef)
![CleanShot 2023-09-08 at 16 31
16](https://github.com/parca-dev/parca-agent/assets/536449/eba6dae1-bfb8-427a-ae78-4c710f60e4d3)

### With
[multiprocessing](https://docs.python.org/3/library/multiprocessing.html)

![CleanShot 2023-09-08 at 17 07
07](https://github.com/parca-dev/parca-agent/assets/536449/c3bf7032-25b9-4f11-9109-03f34472cab4)
@kakkoyun kakkoyun mentioned this pull request Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants