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
13dbd663
Commit
13dbd663
authored
Dec 15, 2015
by
Yorick Peterse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow filtering of what methods to instrument
This makes it possible to determine if a method should be instrumented or not using a block.
parent
d67e2045
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
2 deletions
+33
-2
instrumentation.rb
lib/gitlab/metrics/instrumentation.rb
+17
-2
instrumentation_spec.rb
spec/lib/gitlab/metrics/instrumentation_spec.rb
+16
-0
No files found.
lib/gitlab/metrics/instrumentation.rb
View file @
13dbd663
...
...
@@ -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
...
...
spec/lib/gitlab/metrics/instrumentation_spec.rb
View file @
13dbd663
...
...
@@ -132,6 +132,14 @@ describe Gitlab::Metrics::Instrumentation do
expect
(
@dummy
).
to_not
respond_to
(
:_original_kittens
)
end
it
'can take a block to determine if a method should be instrumented'
do
described_class
.
instrument_methods
(
@dummy
)
do
false
end
expect
(
@dummy
).
to_not
respond_to
(
:_original_foo
)
end
end
describe
'.instrument_instance_methods'
do
...
...
@@ -157,5 +165,13 @@ describe Gitlab::Metrics::Instrumentation do
expect
(
@dummy
.
method_defined?
(
:_original_kittens
)).
to
eq
(
false
)
end
it
'can take a block to determine if a method should be instrumented'
do
described_class
.
instrument_instance_methods
(
@dummy
)
do
false
end
expect
(
@dummy
.
method_defined?
(
:_original_bar
)).
to
eq
(
false
)
end
end
end
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