Sha256: 104022e5a1b9202093c05e4e9b5ff3247b90e3d4fcf7664b0715170cb06822ad

Contents?: true

Size: 1.63 KB

Versions: 3

Compression:

Stored size: 1.63 KB

Contents

module Rack::Insight

  class CachePanel < Panel
    require "rack/insight/panels/cache_panel/panel_app"
    require "rack/insight/panels/cache_panel/stats"

    def initialize(app)
      super

      probe(self) do
        instrument("Memcached") do
          instance_probe :decrement, :get, :increment, :set, :add,
            :replace, :delete, :prepend, :append
        end

        instrument("MemCache") do
          instance_probe :decr, :get, :get_multi, :incr, :set, :add, :delete
        end

        instrument("Dalli::Client") do
          instance_probe :perform
        end
      end

      table_setup("cache")
    end

    def request_start(env, start)
      @stats = Stats.new
    end

    def request_finish(env, st, hd, bd, timing)
      store(env, @stats)
    end

    def after_detect(method_call, timing, args, result)
      method, key = method_call.method, args.first
      if(defined? Dalli and Dalli::Client === method_call.object)
        method, key = args[0], args[1]
      end
      logger.info{ "Cache panel got #{method} #{key.inspect}" } if verbose(:high)
      @stats.record_call(method, timing.duration, !result.nil?, key)
    end

    def panel_app
      PanelApp.new
    end

    def name
      "cache"
    end

    def heading_for_request(number)
      stats = retrieve(number).first

      "Cache: %.2fms (#{stats.queries.size} calls)" % stats.time
    end

    def content_for_request(number)
      # TODO: What is this syntax with the double {{}}?
      logger.debug{{ :req_num => number }} if verbose(:debug)
      stats = retrieve(number).first
      render_template "panels/cache", :stats => stats
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rack-insight-0.5.7 lib/rack/insight/panels/cache_panel.rb
rack-insight-0.5.6 lib/rack/insight/panels/cache_panel.rb
rack-insight-0.5.5 lib/rack/insight/panels/cache_panel.rb