Commit ad69ba57 authored by Yorick Peterse's avatar Yorick Peterse

Proper method instrumentation for special symbols

This ensures that methods such as "==" can be instrumented without
producing syntax errors.
parent 1b077d2d
...@@ -30,7 +30,8 @@ module Gitlab ...@@ -30,7 +30,8 @@ module Gitlab
def self.instrument(type, mod, name) def self.instrument(type, mod, name)
return unless Metrics.enabled? return unless Metrics.enabled?
alias_name = "_original_#{name}" name = name.to_sym
alias_name = :"_original_#{name}"
target = type == :instance ? mod : mod.singleton_class target = type == :instance ? mod : mod.singleton_class
if type == :instance if type == :instance
...@@ -42,14 +43,14 @@ module Gitlab ...@@ -42,14 +43,14 @@ module Gitlab
end end
target.class_eval <<-EOF, __FILE__, __LINE__ + 1 target.class_eval <<-EOF, __FILE__, __LINE__ + 1
alias_method :#{alias_name}, :#{name} alias_method #{alias_name.inspect}, #{name.inspect}
def #{name}(*args, &block) def #{name}(*args, &block)
trans = Gitlab::Metrics::Instrumentation.transaction trans = Gitlab::Metrics::Instrumentation.transaction
if trans if trans
start = Time.now start = Time.now
retval = #{alias_name}(*args, &block) retval =
duration = (Time.now - start) * 1000.0 duration = (Time.now - start) * 1000.0
trans.add_metric(Gitlab::Metrics::Instrumentation::SERIES, trans.add_metric(Gitlab::Metrics::Instrumentation::SERIES,
...@@ -58,7 +59,7 @@ module Gitlab ...@@ -58,7 +59,7 @@ module Gitlab
retval retval
else else
#{alias_name}(*args, &block) __send__(#{alias_name.inspect}, *args, &block)
end end
end end
EOF EOF
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment