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

Broken label with profile_singleton_method #483

Open
semaperepelitsa opened this issue Feb 25, 2021 · 2 comments
Open

Broken label with profile_singleton_method #483

semaperepelitsa opened this issue Feb 25, 2021 · 2 comments
Labels

Comments

@semaperepelitsa
Copy link
Contributor

Example:

Rack::MiniProfiler.profile_singleton_method SomeModule, :lookup

It uses this label:

#<Class:SomeModule> lookup

But the label is not HTML-escaped, so it ends up looking like this:

# lookup

Besides escaping, it could also generate a better label, e.g. "SomeModule.lookup" for class/module methods, and "SomeClass#lookup" for instance methods.

@semaperepelitsa
Copy link
Contributor Author

Patch:

module MiniProfilerExt
  # The default label is "Object#method" instead of "Object method"
  def profile_method(klass, method, type = :profile, &blk)
    label = "#{klass.name}##{method}" # "Class#method"
    blk ||= proc{ label }
    super(klass, method, type, &blk)
  end

  # The default label is "Object.method" instead of "#<Class:Object> method"
  # https://github.com/MiniProfiler/rack-mini-profiler/issues/483
  def profile_singleton_method(klass, method, type = :profile, &blk)
    label = "#{klass.name}.#{method}"
    blk ||= proc{ label }
    profile_method(klass.singleton_class, method, type, &blk)
  end
end

Rack::MiniProfiler.extend(MiniProfilerExt)

@kbrock
Copy link
Contributor

kbrock commented Jun 1, 2021

@semaperepelitsa if you put this into a PR, it may be easier to review and get this great patch into the code.

(I am not part of the core of this project, so that is just a suggestion from a bystander)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants