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 +4 -4
- data/README.md +3 -2
- data/lib/process_metrics/timer.rb +43 -23
- data/lib/process_metrics/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 1d66fea7efd65b1d14fc80ef7c19375f0f491d65
         | 
| 4 | 
            +
              data.tar.gz: a9794b5b4f6e89bb26c0f4f7e1d37aa688a0219d
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: b0b559b1b6a77358920d8c04975e556908061300c986ee0ecde04a4c198791ad9fb1399a776a27a768042ffe6156e179360d11b3388bf3889c8dc33090e6537c
         | 
| 7 | 
            +
              data.tar.gz: 84121883e14637930bb658ab0ebc79392676d57923e752c380460d531a89d79249a1b8357427302f374401ec24e3107f7bb7a5afb7154d542d0d1d8b2e94778a
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,4 +1,4 @@ | |
| 1 | 
            -
            [](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 | 
            -
                     | 
| 10 | 
            -
                     | 
| 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  | 
| 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.  | 
| 36 | 
            -
                     | 
| 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])
         | 
    
        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. | 
| 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- | 
| 11 | 
            +
            date: 2014-03-20 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: hashie
         |