Open hschne opened 2 years ago
On this note, it would be great if we could profile ViewComponents! I would be interested in taking a stab at this PR if you could provide some guidance on your thoughts for a plugin system.
Hey @topherfangio, that's a great idea. I'd love to see some support for ViewComponents (or other view libraries such as Phlex), and I'll take any help I can get :grin:
Now, as you've probably seen I haven't actively worked on RMP for a while, but this seems like a good opportunity. As to guidelines, I'll do my best to recollect what I was thinking when I created this issue originally.
'Pluginsin RMP are basically what
Tracersare now. Users can (theoretically even now) create new
Tracerclasses and register them with
Registry(see also
Configurationfor how built-in tracers are registered). Tracers specify which ActiveSupport events RMP subscribes to and which data from those events gets stored in the database. They also specify a
TracePresenterclass that governs how the event will be rendered in the UI (see, e.g.,
SequelTracePresenter`).
So, in theory (I haven't tested any of this) you could already create a plugin with the existing code by adding something like this to your app:
class CustomTracer < RailsMiniProfiler::Tracers::Tracer
class << self
def subscribes_to
`render.viewcomponent`
end
def presents
ViewComponentTracePresenter
end
end
end
class ViewComponentTracePresenter < RailsMiniProfiler::Presenters::TracePresenter
def label
'ViewComponentTrace'
end
end
# RMP Config
RailsMiniProfiler.configure do |config|
# Customize when Rails Mini Profiler should run
config.tracers = %i[controller instantiation sequel view rmp view_component]
end
Luckily, ViewComponent already provides instrumentation; for other libraries, RMP may have to add instrumentation itself.
Apart from checking if what I wrote above actually works there are two things that need doing (that I can think of on top of my head):
_trace_list_header.erb
). Shouldn't bee to rough adding this though.
<% trace_names = %w[process_action.action_controller sql.active_record instantiation.active_record render_template.action_view render_partial.action_view] %>
Tracers
and registries and stuff isn't user friendly I feel. Might require some naming changes, even if its just aliasing some classes. I'm very open to suggestions! :smile: Let me know your thoughts! I think it's seriously awesome if you were to take a stab at this, be happy to support in any way I can :bow:
@hschne Thanks! I've been on vacation but will take a look at this this week and see how far I can get!
Right now, which traces are profiled, and how they are rendered, is hardcoded.
Add some sort of plugin architecture that allows users to add custom profilers