process_metrics 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cbf3017d3862823d521621348082d8dd46df0fde
4
- data.tar.gz: 2870f25914e46b7977f52cdf50540e1eb1b50ac1
3
+ metadata.gz: 1d66fea7efd65b1d14fc80ef7c19375f0f491d65
4
+ data.tar.gz: a9794b5b4f6e89bb26c0f4f7e1d37aa688a0219d
5
5
  SHA512:
6
- metadata.gz: b53d0da4d45c960362f752aa57ebb3cb860e1d1469d275c4649c931eee8b942e0308be2051d8952fd8315e06702fbc626e34fa2b1ea8a4711bdd3506498bae6f
7
- data.tar.gz: 5eb11c12cffbde2ca6e455250c75fd479600fe51cca361ff536ad7a48c3e15cd6fcaeb21ac53db1aa7219a115f5ff9c439aad5478db11f2a79d586d510736012
6
+ metadata.gz: b0b559b1b6a77358920d8c04975e556908061300c986ee0ecde04a4c198791ad9fb1399a776a27a768042ffe6156e179360d11b3388bf3889c8dc33090e6537c
7
+ data.tar.gz: 84121883e14637930bb658ab0ebc79392676d57923e752c380460d531a89d79249a1b8357427302f374401ec24e3107f7bb7a5afb7154d542d0d1d8b2e94778a
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Code Climate](https://codeclimate.com/github/lucasuyezu/metric.png)](https://codeclimate.com/github/lucasuyezu/metric)
1
+ [![Code Climate](https://codeclimate.com/github/locaweb/process_metrics.png)](https://codeclimate.com/github/locaweb/process_metrics)
2
2
 
3
3
  Process Metrics
4
4
  ===============
@@ -130,6 +130,7 @@ Configuration
130
130
  One time, in a migration
131
131
  ------------------------
132
132
  ```ruby
133
+ ProcessMetrics::Persistence::ActiveRecord.table_name = 'onon' # optional
133
134
  ProcessMetrics::Persistence::ActiveRecord.setup!
134
135
  ```
135
136
 
@@ -137,6 +138,6 @@ Then, in an initializer
137
138
  -----------------------
138
139
 
139
140
  ```ruby
140
- ProcessMetrics.logger = Rails.logger
141
+ ProcessMetrics.config.logger = Rails.logger
141
142
  ProcessMetrics.persistence = Metric::Persistence::ActiveRecord # Default is Logger
142
143
  ```
@@ -3,40 +3,24 @@ module ProcessMetrics
3
3
  @@replacing = false
4
4
 
5
5
  def measure(*methods_names)
6
+ methods_names.flatten!
6
7
  options = extract_options(methods_names)
7
8
 
8
9
  methods_names.each do |method_name|
9
- measure_method_name = :"measure_#{method_name}"
10
- raw_method_name = :"raw_#{method_name}"
11
- self.send(:define_method, measure_method_name) do |*args, &block|
12
- parent_uuid = parent_uuid(options)
13
- process_name = "#{self.class.name}##{method_name}"
14
- parent = ProcessMetrics::Base.new(process_name)
15
- parent.uuid = parent_uuid
16
-
17
- ProcessMetrics.measure(process_name, parent) do |metric|
18
- ProcessMetrics.config.logger.debug "About to send #{raw_method_name} with args #{args.inspect} and block #{block.inspect} to #{self}"
19
- metric.data = {args: args, block: block}
20
-
21
- send(raw_method_name, *args, &block)
22
- end
23
- end
10
+ define_wrapper_method(method_name, options)
11
+ wrap_method(method_name) if method_exists?(method_name)
24
12
  end
25
13
  end
26
14
 
27
15
  def method_added(method_name)
28
- return if @@replacing || method_name =~ /^measure_/ || method_name =~ /^raw_/
16
+ return if method_name =~ /^measure_/ || method_name =~ /^raw_/
29
17
  ProcessMetrics.config.logger.debug "Adding method #{method_name} in #{self}"
30
18
 
31
19
  measure_method_name = :"measure_#{method_name}"
32
- raw_method_name = :"raw_#{method_name}"
33
20
 
34
21
  if self.instance_methods.include? measure_method_name
35
- ProcessMetrics.config.logger.debug "#{self}##{measure_method_name} exists. Replacing..."
36
- @@replacing = true
37
- alias_method raw_method_name, method_name
38
- alias_method method_name, measure_method_name
39
- @@replacing = false
22
+ ProcessMetrics.config.logger.debug "#{self}##{measure_method_name} exists. Wrapping..."
23
+ wrap_method(method_name)
40
24
  else
41
25
  ProcessMetrics.config.logger.debug "#{self}##{measure_method_name} does not exist. Exiting..."
42
26
  end
@@ -46,6 +30,42 @@ module ProcessMetrics
46
30
  def extract_options(array)
47
31
  array.last && array.last.is_a?(Hash) ? array.pop : nil
48
32
  end
33
+
34
+ def define_wrapper_method(method_name, options)
35
+ measure_method_name = :"measure_#{method_name}"
36
+ raw_method_name = :"raw_#{method_name}"
37
+
38
+ self.send(:define_method, measure_method_name) do |*args, &block|
39
+ parent_uuid = parent_uuid(options)
40
+ process_name = "#{self.class.name}##{method_name}"
41
+ parent = ProcessMetrics::Base.new(process_name)
42
+ parent.uuid = parent_uuid
43
+
44
+ ProcessMetrics.measure(process_name, parent) do |metric|
45
+ ProcessMetrics.config.logger.debug "About to send #{raw_method_name} with args #{args.inspect} and block #{block.inspect} to #{self}"
46
+ metric.data = {args: args, block: block}
47
+
48
+ send(raw_method_name, *args, &block)
49
+ end
50
+ end
51
+ end
52
+
53
+ def method_exists?(method_name)
54
+ self.instance_methods.include? method_name
55
+ end
56
+
57
+ def wrap_method(method_name)
58
+ return if @@replacing
59
+
60
+ measure_method_name = :"measure_#{method_name}"
61
+ raw_method_name = :"raw_#{method_name}"
62
+
63
+ @@replacing = true
64
+ alias_method raw_method_name, method_name
65
+ alias_method method_name, measure_method_name
66
+ @@replacing = false
67
+ nil
68
+ end
49
69
  end
50
70
 
51
71
  module Timer
@@ -58,7 +78,7 @@ module ProcessMetrics
58
78
 
59
79
  if options[:parent_uuid].respond_to?(:call)
60
80
  # It's a proc. parent_uuid is the return value
61
- options[:parent_uuid].call
81
+ options[:parent_uuid].call(self)
62
82
  elsif options[:parent_uuid].is_a?(Symbol)
63
83
  # It's a symbol. Call method on object and parent_uuid is its result.
64
84
  send(options[:parent_uuid])
@@ -1,3 +1,3 @@
1
1
  module ProcessMetrics
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: process_metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Uyezu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-18 00:00:00.000000000 Z
11
+ date: 2014-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie