Skip to content
Snippets Groups Projects

Instrument private methods and instance private methods

Merged Paco Guzman requested to merge 18527-instrument-private-methods into master

What does this MR do?

Instrument private methods and instance methods by default not just public methods

Why was this MR needed?

To have more visibility of the performance of the code

What are the relevant issue numbers?

#18527 (closed)

Does this MR meet the acceptance criteria?

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
11 11
12 class << self
13 def buzz(text = 'buzz')
14 text
15 end
16 private :buzz
17 end
18
12 19 def bar(text = 'bar')
13 20 text
14 21 end
22
23 def wadus(text = 'wadus')
24 text
25 end
26 private :wadus
  • Paco Guzman Marked the task Tests as completed

    Marked the task Tests as completed

  • Paco Guzman Marked the task Added for this feature/bug as completed

    Marked the task Added for this feature/bug as completed

  • Paco Guzman Marked the task All builds are passing as completed

    Marked the task All builds are passing as completed

  • 65 65 #
    66 66 # mod - The module to instrument.
    67 67 def self.instrument_methods(mod)
    68 mod.public_methods(false).each do |name|
    68 methods = mod.public_methods(false) + mod.private_methods(false)
    69 methods.each do |name|
  • 253 281
    254 282 described_class.instrument_instance_methods(@dummy)
    255 283
    256 expect(@dummy.method_defined?(:_original_kittens)).to eq(false)
    284 expect(@dummy.new.method(:kittens).source_location.first).not_to match(/instrumentation\.rb/)
    • What's the reason for this change? _original_kittens only exists if the method is instrumented so checking for said method should suffice to determine if the source method (kittens) was instrumented or not.

    • Author Contributor

      I think that was a previous implementation that maybe was doing alias_method or something like that. If you check the specs that asserts the method is instrumented are not checking that :_original_foo or whatever is defined is just checking that the proxy_module is inserted, that's why I decided to do this way so we assert in the same way both cases (when the method is instrumented and when is not instrumented).

      Maybe here instead using not_to maybe we want to use to and match about the location which is this current file.

    • Author Contributor

      What I wanted to say with the previous implementation of the specs is that is wrong, if you instrument that method the :_original_kittens won't be defined never

    • Author Contributor

      What I meant is that previous spec implementation is not right, we're not defining that method never

    • Author Contributor

      What I meant is that spec is not right, that method are never defined

    • @pacoguzman: Ah yes correct, the aliases are no longer used. In that case using the source location is probably the best way to go.

    • @pacoguzman: Ah yes you're right, the aliasing is no longer used. In that case using the source location is probably the best way of doing it.

  • Added ~18308 label

  • yorickpeterse-staging Milestone changed to %8.9

    Milestone changed to %8.9

  • Paco Guzman Added 1 commit:

    Added 1 commit:

    • db267f21 - Instrument private/protected methods
  • Paco Guzman Added 21 commits:

    Added 21 commits:

    • db267f21...0c0ef7df - 20 commits from branch master
    • 4da191c5 - Instrument private/protected methods
  • Some of my notes appear to be disappearing, so I'll leave the last one here regarding the aliasing test:

    @pacoguzman: Ah yes you're right, the aliasing is no longer used. In that case using the source location is probably the best way of doing it.

  • Author Contributor

    @yorickpeterse work done! and build is green!

  • @pacoguzman: There's a merge conflict in doc/development/instrumentation.md which seems to be caused by your MR to add CPU timings. Could you rebase and resolve the conflict? Other than that everything looks fine.

  • Paco Guzman Added 69 commits:

    Added 69 commits:

    • 4da191c5...fdcafe72 - 68 commits from branch master
    • dadc5313 - Instrument private/protected methods
  • Author Contributor

    @yorickpeterse build green and without conflicts

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading