BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
b66a16c8
Commit
b66a16c8
authored
Dec 10, 2015
by
Yorick Peterse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use string evaluation for method instrumentation
This is faster than using define_method since we don't have to keep block bindings around.
parent
60a6a240
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
13 deletions
+16
-13
instrumentation.rb
lib/gitlab/metrics/instrumentation.rb
+9
-7
method_call.rb
lib/gitlab/metrics/subscribers/method_call.rb
+2
-2
instrumentation_spec.rb
spec/lib/gitlab/metrics/instrumentation_spec.rb
+4
-2
method_call_spec.rb
spec/lib/gitlab/metrics/subscribers/method_call_spec.rb
+1
-2
No files found.
lib/gitlab/metrics/instrumentation.rb
View file @
b66a16c8
...
...
@@ -31,16 +31,18 @@ module Gitlab
alias_name
=
"_original_
#{
name
}
"
target
=
type
==
:instance
?
mod
:
mod
.
singleton_class
target
.
class_eval
do
alias_method
(
alias_name
,
name
)
target
.
class_eval
<<-
EOF
,
__FILE__
,
__LINE__
+
1
alias_method
:
#{
alias_name
}
, :
#{
name
}
define_method
(
name
)
do
|*
args
,
&
block
|
ActiveSupport
::
Notifications
.
instrument
(
"
#{
type
}
_method.method_call"
,
module:
mod
,
name:
name
)
do
__send__
(
alias_name
,
*
args
,
&
block
)
def
#{
name
}
(*args, &block)
ActiveSupport::Notifications
.instrument("
#{
type
}
_method.method_call",
module:
#{
mod
.
name
.
inspect
}
,
name:
#{
name
.
inspect
}
) do
#{
alias_name
}
(*args, &block)
end
end
end
EOF
end
end
end
...
...
lib/gitlab/metrics/subscribers/method_call.rb
View file @
b66a16c8
...
...
@@ -10,7 +10,7 @@ module Gitlab
def
instance_method
(
event
)
return
unless
current_transaction
label
=
"
#{
event
.
payload
[
:module
]
.
name
}
#
#{
event
.
payload
[
:name
]
}
"
label
=
"
#{
event
.
payload
[
:module
]
}
#
#{
event
.
payload
[
:name
]
}
"
add_metric
(
label
,
event
.
duration
)
end
...
...
@@ -18,7 +18,7 @@ module Gitlab
def
class_method
(
event
)
return
unless
current_transaction
label
=
"
#{
event
.
payload
[
:module
]
.
name
}
.
#{
event
.
payload
[
:name
]
}
"
label
=
"
#{
event
.
payload
[
:module
]
}
.
#{
event
.
payload
[
:name
]
}
"
add_metric
(
label
,
event
.
duration
)
end
...
...
spec/lib/gitlab/metrics/instrumentation_spec.rb
View file @
b66a16c8
...
...
@@ -11,6 +11,8 @@ describe Gitlab::Metrics::Instrumentation do
text
end
end
allow
(
@dummy
).
to
receive
(
:name
).
and_return
(
'Dummy'
)
end
describe
'.instrument_method'
do
...
...
@@ -31,7 +33,7 @@ describe Gitlab::Metrics::Instrumentation do
it
'fires an ActiveSupport notification upon calling the method'
do
expect
(
ActiveSupport
::
Notifications
).
to
receive
(
:instrument
).
with
(
'class_method.method_call'
,
module:
@dummy
,
name: :foo
)
with
(
'class_method.method_call'
,
module:
'Dummy'
,
name: :foo
)
@dummy
.
foo
end
...
...
@@ -69,7 +71,7 @@ describe Gitlab::Metrics::Instrumentation do
it
'fires an ActiveSupport notification upon calling the method'
do
expect
(
ActiveSupport
::
Notifications
).
to
receive
(
:instrument
).
with
(
'instance_method.method_call'
,
module:
@dummy
,
name: :bar
)
with
(
'instance_method.method_call'
,
module:
'Dummy'
,
name: :bar
)
@dummy
.
new
.
bar
end
...
...
spec/lib/gitlab/metrics/subscribers/method_call_spec.rb
View file @
b66a16c8
...
...
@@ -6,8 +6,7 @@ describe Gitlab::Metrics::Subscribers::MethodCall do
let
(
:subscriber
)
{
described_class
.
new
}
let
(
:event
)
do
double
(
:event
,
duration:
0.2
,
payload:
{
module:
double
(
:mod
,
name:
'Foo'
),
name: :foo
})
double
(
:event
,
duration:
0.2
,
payload:
{
module:
'Foo'
,
name: :foo
})
end
before
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment