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 facilities to produce pprof profiles #53

Merged
merged 1 commit into from
Jul 23, 2024
Merged

Add facilities to produce pprof profiles #53

merged 1 commit into from
Jul 23, 2024

Conversation

javierhonduco
Copy link
Owner

This (rather large) commit adds pprof profile generation to lightswitch. They can be dumped to disk and the read with pprof tooling (see test plan) as well as sent to a remote server with a new collector. By default profiles are written to dis as flamegraphs in svg format.

Test Plan / Demo

build with: nix develop --command 'cargo build --release'

$ sudo target/release/lightswitch --duration=5

produces a flamegraph in svg format

$ sudo target/release/lightswitch --duration=5 --profile-format=pprof

produces a pprof file (uncompressed) that can be read with standard tooling

$ go tool pprof profile.pb
For tag pid used unit task-tgid, also encountered unit(s) task-id
File: ruby
Build ID: gnu-bae4d9744266cf1f3e27a1ba7512c1c97b5e4a86
lightswitch
Type: cpu
Time: Jul 23, 2024 at 10:03am (BST)
Duration: 5s, Total samples = 1.70s (34.07%)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top
For tag pid used unit task-tgid, also encountered unit(s) task-id
Showing nodes accounting for 703.70ms, 41.30% of 1703.70ms total
Showing top 10 nodes out of 140
      flat  flat%   sum%        cum   cum%
  111.11ms  6.52%  6.52%   148.15ms  8.70%  BSD_vfprintf
  111.11ms  6.52% 13.04%   259.26ms 15.22%  lightswitch::unwind_info::UnwindInfoBuilder::process
  111.11ms  6.52% 19.57%   222.22ms 13.04%  n_tty_inherit_ops
   74.07ms  4.35% 23.91%   111.11ms  6.52%  __memcpy_avx_unaligned_erms
   74.07ms  4.35% 28.26%   407.41ms 23.91%  do_syscall_64
   74.07ms  4.35% 32.61%    74.07ms  4.35%  queue_work_on
   37.04ms  2.17% 34.78%    37.04ms  2.17%  __GI___pthread_enable_asynccancel
   37.04ms  2.17% 36.96%   444.44ms 26.09%  __GI___writev
   37.04ms  2.17% 39.13%    37.04ms  2.17%  __malloc_usable_size
   37.04ms  2.17% 41.30%    37.04ms  2.17%  __probestub_page_fault_kernel
$ sudo target/release/lightswitch --duration=5 --sender=remote

Performs an HTTP POST with the pprof as the body to a hardcoded server URL (this will change in the future).

This (rather large) commit adds pprof profile generation to lightswitch.
They can be dumped to disk and the read with pprof tooling (see test
plan) as well as sent to a remote server with a new collector. By
default profiles are written to dis as flamegraphs in svg format.

Test Plan / Demo
================

build with: `nix develop --command 'cargo build --release'`

```
$ sudo target/release/lightswitch --duration=5
```

produces a flamegraph in svg format

```
$ sudo target/release/lightswitch --duration=5 --profile-format=pprof
```

produces a pprof file (uncompressed) that can be read with standard
tooling

```
$ go tool pprof profile.pb
For tag pid used unit task-tgid, also encountered unit(s) task-id
File: ruby
Build ID: gnu-bae4d9744266cf1f3e27a1ba7512c1c97b5e4a86
lightswitch
Type: cpu
Time: Jul 23, 2024 at 10:03am (BST)
Duration: 5s, Total samples = 1.70s (34.07%)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top
For tag pid used unit task-tgid, also encountered unit(s) task-id
Showing nodes accounting for 703.70ms, 41.30% of 1703.70ms total
Showing top 10 nodes out of 140
      flat  flat%   sum%        cum   cum%
  111.11ms  6.52%  6.52%   148.15ms  8.70%  BSD_vfprintf
  111.11ms  6.52% 13.04%   259.26ms 15.22%  lightswitch::unwind_info::UnwindInfoBuilder::process
  111.11ms  6.52% 19.57%   222.22ms 13.04%  n_tty_inherit_ops
   74.07ms  4.35% 23.91%   111.11ms  6.52%  __memcpy_avx_unaligned_erms
   74.07ms  4.35% 28.26%   407.41ms 23.91%  do_syscall_64
   74.07ms  4.35% 32.61%    74.07ms  4.35%  queue_work_on
   37.04ms  2.17% 34.78%    37.04ms  2.17%  __GI___pthread_enable_asynccancel
   37.04ms  2.17% 36.96%   444.44ms 26.09%  __GI___writev
   37.04ms  2.17% 39.13%    37.04ms  2.17%  __malloc_usable_size
   37.04ms  2.17% 41.30%    37.04ms  2.17%  __probestub_page_fault_kernel
```

```
$ sudo target/release/lightswitch --duration=5 --sender=remote
```

Performs an HTTP POST with the pprof as the body to a hardcoded server
URL (this will change in the future).
@javierhonduco javierhonduco requested a review from gmarler July 23, 2024 09:35
Box::new(AggregatorCollector::new()) as Box<dyn Collector + Send>
}
ProfileSender::Remote => {
Box::new(StreamingCollector::new(PPROF_INGEST_URL)) as Box<dyn Collector + Send>
Copy link
Owner Author

Choose a reason for hiding this comment

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

There must be a better way to do this... 🤔

@javierhonduco javierhonduco merged commit f108aaf into main Jul 23, 2024
8 checks passed
@javierhonduco javierhonduco deleted the pprof branch July 23, 2024 09:40
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.

1 participant