Skip to content

Commit

Permalink
Merge pull request brynary#9 from oggy/redis
Browse files Browse the repository at this point in the history
AJAX support for redis panel
  • Loading branch information
pboling committed Sep 23, 2012
2 parents c15e6d0 + 00597ea commit 5f009c9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 53 deletions.
55 changes: 31 additions & 24 deletions lib/rack/insight/panels/redis_panel.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,47 @@
module Rack::Insight

class RedisPanel < Panel
require "rack/insight/panels/redis_panel/redis_extension"

require "rack/insight/panels/redis_panel/stats"

self.has_table = false

def self.record(redis_command_args, backtrace, &block)
return block.call unless Rack::Insight.enabled?

start_time = Time.now
result = block.call
total_time = Time.now - start_time
stats.record_call(total_time * 1_000, redis_command_args, backtrace)
return result
def initialize(app)
super

unless is_probing?
probe(self) do
if defined?(Redis::Client)
# Redis >= 3.0.0
instrument "Redis::Client" do
instance_probe :call
end
elsif defined?(Redis)
# Redis < 3.0.0
instrument "Redis" do
instance_probe :call_command
end
end
end
end
end

def self.reset
Thread.current["rack-insight.redis"] = Stats.new
def request_start(env, start)
@stats = Stats.new
end

def self.stats
Thread.current["rack-insight.redis"] ||= Stats.new
def request_finish(env, status, headers, body, timing)
store(env, @stats)
@stats = nil
end

def heading
"Redis: %.2fms (#{self.class.stats.queries.size} calls)" % self.class.stats.time
def after_detect(method_call, timing, args, message)
@stats.record_call(timing.duration, args, method_call)
end

def content
result = render_template "panels/redis", :stats => self.class.stats
self.class.reset
return result
def heading_for_request(number)
stats = retrieve(number).first
"Redis: %.2fms (#{stats.queries.size} calls)" % stats.time
end

def content_for_request(number)
render_template "panels/redis", :stats => retrieve(number).first
end
end

end
25 changes: 0 additions & 25 deletions lib/rack/insight/panels/redis_panel/redis_extension.rb

This file was deleted.

8 changes: 4 additions & 4 deletions lib/rack/insight/panels/redis_panel/stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ class Query
attr_reader :time
attr_reader :command

def initialize(time, command_args, backtrace)
def initialize(time, command_args, method_call)
@time = time
@command = command_args.inspect
@backtrace = backtrace
@backtrace = method_call.backtrace
end

def display_time
Expand All @@ -28,8 +28,8 @@ def initialize
@time = 0.0
end

def record_call(time, command_args, backtrace)
@queries << Query.new(time, command_args, backtrace)
def record_call(time, command_args, method_call)
@queries << Query.new(time, command_args, method_call)
@calls += 1
@time += time
end
Expand Down

0 comments on commit 5f009c9

Please sign in to comment.