jhawthorn / vernier

📏 next generation CRuby profiler
https://vernier.prof/
MIT License
718 stars 15 forks source link

Epic: Library/framework integrations #34

Closed jhawthorn closed 2 months ago

jhawthorn commented 7 months ago

One cool feature of Vernier (and the firefox profiler we use as a viewer) is that it supports tracing via "markers", which record events which happened during the profile.

When Aaron and I showcased Vernier, we cheated (slightly) and added some small hooks to trace Rails and Sidekiq. I do something pretty similar in examples/rails.rb.

Vernier.trace(out: "rails.json") do |collector|
  ActiveSupport::Notifications.monotonic_subscribe do |name, start, finish, id, payload|
    collector.add_marker(
      name:,
      start: (start * 1_000_000_000).to_i,
      finish: (finish * 1_000_000_000).to_i,
    )
  end

That's simple enough, it subscribes to every ActiveSupport::Notifications topic and forwards them, but it doesn't provide as much information as it could and it doesn't happen by default.

Let's do this better and automatically detect and instrumenting popular libraries!

- [x] Detect Rails and install the subscriber above
- [ ] Detect Sidekiq and install instrumentation
- [ ] Add configuration for enabling/disabling these integrations
- [x] Add more details to the markers by adding to the "marker schema"
- [x] Disable integrations when profiling ends
- [ ] Figure out if there's a way to detect Rails/sidekiq/whatever being loaded _after_ the profile starts
PedroAugustoRamalhoDuarte commented 2 months ago

@jhawthorn thanks for this awesome library. I search I little bit and I cannot find an easy way to set up vernier with rails.

I saw the example with the minimal app, and it's working great, but how I can achieve that with a conventional rails app?

benoittgt commented 2 weeks ago

@PedroAugustoRamalhoDuarte I know it's not shortest answer but I recommend looking at https://youtu.be/9nvX3OHykGQ