summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2015-12-15 16:31:24 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2015-12-17 17:25:48 +0100
commit13dbd663acbbe91ddac77b650a90377cd12c54b8 (patch)
tree936993d1abb579ffb3c66f64c887bf58cbe5a01f /lib
parentd67e2045a02d105bfbc7abf1805fe477eb9155ca (diff)
downloadgitlab-ce-13dbd663acbbe91ddac77b650a90377cd12c54b8.tar.gz
Allow filtering of what methods to instrument
This makes it possible to determine if a method should be instrumented or not using a block.
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/metrics/instrumentation.rb19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/gitlab/metrics/instrumentation.rb b/lib/gitlab/metrics/instrumentation.rb
index cf22aa93cdd..91e09694cd8 100644
--- a/lib/gitlab/metrics/instrumentation.rb
+++ b/lib/gitlab/metrics/instrumentation.rb
@@ -33,23 +33,38 @@ module Gitlab
# Instruments all public methods of a module.
#
+ # This method optionally takes a block that can be used to determine if a
+ # method should be instrumented or not. The block is passed the receiving
+ # module and an UnboundMethod. If the block returns a non truthy value the
+ # method is not instrumented.
+ #
# mod - The module to instrument.
def self.instrument_methods(mod)
mod.public_methods(false).each do |name|
method = mod.method(name)
- instrument_method(mod, name) if method.owner == mod.singleton_class
+ if method.owner == mod.singleton_class
+ if !block_given? || block_given? && yield(mod, method)
+ instrument_method(mod, name)
+ end
+ end
end
end
# Instruments all public instance methods of a module.
#
+ # See `instrument_methods` for more information.
+ #
# mod - The module to instrument.
def self.instrument_instance_methods(mod)
mod.public_instance_methods(false).each do |name|
method = mod.instance_method(name)
- instrument_instance_method(mod, name) if method.owner == mod
+ if method.owner == mod
+ if !block_given? || block_given? && yield(mod, method)
+ instrument_instance_method(mod, name)
+ end
+ end
end
end