Skip to content

Commit

Permalink
Add a count of the number of mongo calls recorded
Browse files Browse the repository at this point in the history
  • Loading branch information
tomafro committed May 17, 2011
1 parent a20ef27 commit e997490
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions lib/mongo/rails/instrumentation/log_subscriber.rb
@@ -1,20 +1,32 @@
require 'mongo/rails/instrumentation'

class Mongo::Rails::Instrumentation::LogSubscriber < ActiveSupport::LogSubscriber
RUNTIME_KEY = name + "#runtime"
COUNT_KEY = name + "#count"

def self.runtime=(value)
Thread.current["mongo_mongo_runtime"] = value
Thread.current[RUNTIME_KEY] = value
end

def self.runtime
Thread.current["mongo_mongo_runtime"] ||= 0
Thread.current[RUNTIME_KEY] ||= 0
end

def self.count=(value)
Thread.current[COUNT_KEY] = value
end

def self.count
Thread.current[COUNT_KEY] ||= 0
end

def self.reset_runtime
rt, self.runtime = runtime, 0
rt, self.runtime, self.count = runtime, 0, 0
rt
end

def mongo(event)
self.class.runtime += event.duration
self.class.count += 1
end
end
2 changes: 1 addition & 1 deletion lib/mongo/rails/instrumentation/version.rb
@@ -1,7 +1,7 @@
module Mongo
module Rails
module Instrumentation
VERSION = "0.2.2"
VERSION = '0.2.3'
end
end
end

0 comments on commit e997490

Please sign in to comment.