Sha256: 7985a578816e1a37909d617b0f2ad096bba82b36814ea1ba8c90d57ba47e4a82

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 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

      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

1 entries across 1 versions & 1 rubygems

Version Path
errplane-1.0.1 lib/errplane/rails/benchmarking.rb