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
a93a32a2
Commit
a93a32a2
authored
Dec 15, 2015
by
Yorick Peterse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for instrumenting class hierarchies
This will be used to (for example) instrument all ActiveRecord models.
parent
a41287d8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
0 deletions
+56
-0
instrumentation.rb
lib/gitlab/metrics/instrumentation.rb
+23
-0
instrumentation_spec.rb
spec/lib/gitlab/metrics/instrumentation_spec.rb
+33
-0
No files found.
lib/gitlab/metrics/instrumentation.rb
View file @
a93a32a2
...
...
@@ -31,6 +31,29 @@ module Gitlab
instrument
(
:instance
,
mod
,
name
)
end
# Recursively instruments all subclasses of the given root module.
#
# This can be used to for example instrument all ActiveRecord models (as
# these all inherit from ActiveRecord::Base).
#
# This method can optionally take a block to pass to `instrument_methods`
# and `instrument_instance_methods`.
#
# root - The root module for which to instrument subclasses. The root
# module itself is not instrumented.
def
self
.
instrument_class_hierarchy
(
root
,
&
block
)
visit
=
root
.
subclasses
until
visit
.
empty?
klass
=
visit
.
pop
instrument_methods
(
klass
,
&
block
)
instrument_instance_methods
(
klass
,
&
block
)
klass
.
subclasses
.
each
{
|
c
|
visit
<<
c
}
end
end
# Instruments all public methods of a module.
#
# This method optionally takes a block that can be used to determine if a
...
...
spec/lib/gitlab/metrics/instrumentation_spec.rb
View file @
a93a32a2
...
...
@@ -133,6 +133,39 @@ describe Gitlab::Metrics::Instrumentation do
end
end
describe
'.instrument_class_hierarchy'
do
before
do
allow
(
Gitlab
::
Metrics
).
to
receive
(
:enabled?
).
and_return
(
true
)
@child1
=
Class
.
new
(
@dummy
)
do
def
self
.
child1_foo
;
end
def
child1_bar
;
end
end
@child2
=
Class
.
new
(
@child1
)
do
def
self
.
child2_foo
;
end
def
child2_bar
;
end
end
end
it
'recursively instruments a class hierarchy'
do
described_class
.
instrument_class_hierarchy
(
@dummy
)
expect
(
@child1
).
to
respond_to
(
:_original_child1_foo
)
expect
(
@child2
).
to
respond_to
(
:_original_child2_foo
)
expect
(
@child1
.
method_defined?
(
:_original_child1_bar
)).
to
eq
(
true
)
expect
(
@child2
.
method_defined?
(
:_original_child2_bar
)).
to
eq
(
true
)
end
it
'does not instrument the root module'
do
described_class
.
instrument_class_hierarchy
(
@dummy
)
expect
(
@dummy
).
to_not
respond_to
(
:_original_foo
)
expect
(
@dummy
.
method_defined?
(
:_original_bar
)).
to
eq
(
false
)
end
end
describe
'.instrument_methods'
do
before
do
allow
(
Gitlab
::
Metrics
).
to
receive
(
:enabled?
).
and_return
(
true
)
...
...
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