method_meter 0.3.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/console +1 -0
- data/lib/method_meter.rb +52 -34
- data/lib/method_meter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b21e5d9564b1e2716490f84775bf00d5381d89259ffd4d5f5ebf5df90390e29
|
4
|
+
data.tar.gz: be86e7ffbc8f9fba9c0b50200625b9c62c66b2ff8196d279e5072796149c50b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3120f5ecf09523ac2a02a34a35bb80fc43fb2fa4b34d094606bb4c371542f57294a769bc0f743c62827ec6baf9059807267a54a57bda5d22baed79a606ede75
|
7
|
+
data.tar.gz: b41f1de2cdad17844289822ac761d4e2f057fd776f34432d166e8e6eea31492e1b26c7c9e0220e3024187833fbc01e3094facab2581d0f43dc2d658b6aadf535
|
data/bin/console
CHANGED
data/lib/method_meter.rb
CHANGED
@@ -9,62 +9,37 @@ module MethodMeter
|
|
9
9
|
|
10
10
|
class << self
|
11
11
|
def observe(object, excepted_methods=[])
|
12
|
-
|
13
|
-
self.exceptions = [] if self.exceptions.nil?
|
14
|
-
self.exceptions |= excepted_methods
|
12
|
+
init excepted_methods
|
15
13
|
|
16
14
|
DefinedMethods.in(object).each do |group|
|
17
15
|
group[:object].module_eval do
|
18
16
|
group[:methods].each do |method|
|
19
|
-
|
20
|
-
|
21
|
-
method_with_profiling = method.to_s + '_with_profiling'
|
22
|
-
method_without_profiling = method.to_s + '_without_profiling'
|
23
|
-
event_name = DefinedMethods.fqmn(group, method)
|
24
|
-
|
25
|
-
next if event_name =~ /_profiling/
|
26
|
-
next if MethodMeter.events.include?(event_name)
|
27
|
-
|
28
|
-
MethodMeter.events << event_name
|
29
|
-
|
30
|
-
define_method(method_with_profiling) do |*args, &block|
|
31
|
-
ActiveSupport::Notifications.instrument(event_name, args) do
|
32
|
-
send(method_without_profiling, *args, &block)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
alias_method method_without_profiling, method
|
37
|
-
alias_method method, method_with_profiling
|
38
|
-
|
39
|
-
private method_with_profiling if group[:private]
|
40
|
-
protected method_with_profiling if group[:protected]
|
17
|
+
MethodMeter.define_instrumented_method(group[:object], method, group[:private], group[:protected], group[:singleton])
|
41
18
|
end
|
42
19
|
end
|
43
20
|
end
|
44
21
|
end
|
45
22
|
|
46
23
|
def measure!(key)
|
47
|
-
|
48
|
-
self.data = {} if self.data.blank?
|
49
|
-
self.data[key] = {}
|
24
|
+
data[key] = {}
|
50
25
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
26
|
+
events.each do |event|
|
27
|
+
subscribers << ActiveSupport::Notifications.subscribe(event) do |_, started_at, finished_at, _, _|
|
28
|
+
data[key][event] = [] unless data[key].has_key?(event)
|
29
|
+
data[key][event] << (finished_at - started_at)
|
55
30
|
end
|
56
31
|
end
|
57
32
|
|
58
33
|
yield
|
59
34
|
|
60
|
-
|
35
|
+
subscribers.each do |subscriber|
|
61
36
|
ActiveSupport::Notifications.unsubscribe(subscriber)
|
62
37
|
end
|
63
38
|
end
|
64
39
|
|
65
40
|
def measurement
|
66
41
|
@measurement ||= begin
|
67
|
-
|
42
|
+
data.collect do |key, measurement_records|
|
68
43
|
_measurement = measurement_records.collect do |method_name, records|
|
69
44
|
total_calls = records.size
|
70
45
|
total_runtime = records.reduce(:+) * 1000
|
@@ -84,5 +59,48 @@ module MethodMeter
|
|
84
59
|
end
|
85
60
|
end
|
86
61
|
end
|
62
|
+
|
63
|
+
def profiling_method_names(method)
|
64
|
+
method_with_profiling = method.to_s + '_with_profiling'
|
65
|
+
method_without_profiling = method.to_s + '_without_profiling'
|
66
|
+
[method_with_profiling, method_without_profiling]
|
67
|
+
end
|
68
|
+
|
69
|
+
def instrument_method?(method, event_name)
|
70
|
+
!exceptions.include?(method) && !events.include?(event_name) && (event_name =~ /_profiling/).nil?
|
71
|
+
end
|
72
|
+
|
73
|
+
def define_instrumented_method(object, method, is_private, is_protected, is_singleton)
|
74
|
+
object.module_eval do
|
75
|
+
method_with_profiling, method_without_profiling = MethodMeter.profiling_method_names(method)
|
76
|
+
event_name = DefinedMethods.fqmn(object.to_s, method, is_singleton)
|
77
|
+
|
78
|
+
return unless MethodMeter.instrument_method?(method, event_name)
|
79
|
+
|
80
|
+
MethodMeter.events << event_name
|
81
|
+
|
82
|
+
define_method(method_with_profiling) do |*args, &block|
|
83
|
+
ActiveSupport::Notifications.instrument(event_name, args) do
|
84
|
+
send(method_without_profiling, *args, &block)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
alias_method method_without_profiling, method
|
89
|
+
alias_method method, method_with_profiling
|
90
|
+
|
91
|
+
private method_with_profiling if is_private
|
92
|
+
protected method_with_profiling if is_protected
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def init(excepted_methods)
|
99
|
+
self.events = [] if events.nil?
|
100
|
+
self.exceptions = [] if exceptions.nil?
|
101
|
+
self.exceptions |= excepted_methods
|
102
|
+
self.subscribers = []
|
103
|
+
self.data = {} if data.blank?
|
104
|
+
end
|
87
105
|
end
|
88
106
|
end
|
data/lib/method_meter/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: method_meter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wilfrido T. Nuqui Jr.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|