Sha256: 883bd0697a5c3d05c5526fb10fe4f6f7ea041aafe226d881821c6f690054a3e7

Contents?: true

Size: 655 Bytes

Versions: 13

Compression:

Stored size: 655 Bytes

Contents

class Remnant
  class Filters
    module ClassMethods
      def record(filter_type, filter_name, &block)
        start_time = Time.now
        result = block.call
        time = Time.now - start_time
        filters << {:type => filter_type, :name => filter_name, :time => time, :ms => time * 1000}

        return result
      end

      def reset
        @total_time = nil
        Thread.current['remnant.filters.set'] = []
      end

      def filters
        Thread.current['remnant.filters.set'] ||= []
      end

      def total_time
        @total_time ||= filters.map {|filter| filter[:ms]}.sum
      end
    end
    extend ClassMethods
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
remnant-1.0.0 lib/remnant/filters.rb
remnant-0.4.5 lib/remnant/filters.rb
remnant-0.9.5 lib/remnant/filters.rb
remnant-0.9.4 lib/remnant/filters.rb
remnant-0.4.4 lib/remnant/filters.rb
remnant-0.9.3 lib/remnant/filters.rb
remnant-0.9.2 lib/remnant/filters.rb
remnant-0.9.1 lib/remnant/filters.rb
remnant-0.9.0 lib/remnant/filters.rb
remnant-0.4.3 lib/remnant/filters.rb
remnant-0.4.2 lib/remnant/filters.rb
remnant-0.4.1 lib/remnant/filters.rb
remnant-0.4.0 lib/remnant/filters.rb