Sha256: bfc6cfc7a3afad69e449d2c4325ca483c78faa97b145e0d760bb85aa144b6ad2

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

require 'benchmark'
require "socket"

module Errplane
  module Rails
    module Benchmarking
      def self.included(base)
        base.send(:alias_method_chain, :perform_action, :instrumentation)
        base.send(:alias_method_chain, :view_runtime, :instrumentation)
        base.send(:alias_method_chain, :active_record_runtime, :instrumentation)
      end

      private
      def perform_action_with_instrumentation
        ms = Benchmark.ms { perform_action_without_instrumentation }
        if Errplane.configuration.instrumentation_enabled
          Errplane.rollup "controllers", :value => ms.ceil, :dimensions => dimensions
        end
      end

      def view_runtime_with_instrumentation
        runtime = view_runtime_without_instrumentation
        if Errplane.configuration.instrumentation_enabled
          Errplane.rollup "views", :value => runtime.split.last.to_f.ceil, :dimensions => dimensions
        end
        runtime
      end

      def active_record_runtime_with_instrumentation
        runtime = active_record_runtime_without_instrumentation
        if Errplane.configuration.instrumentation_enabled
          Errplane.rollup "db", :value => runtime.split.last.to_f.ceil, :dimensions => dimensions
        end
        runtime
      end

      def dimensions
        { :method => "#{params[:controller]}##{params[:action]}", :server => Socket.gethostname }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
errplane-1.0.5 lib/errplane/rails/benchmarking.rb
errplane-1.0.4 lib/errplane/rails/benchmarking.rb
errplane-1.0.3 lib/errplane/rails/benchmarking.rb
errplane-1.0.2 lib/errplane/rails/benchmarking.rb