Skip to content

Commit

Permalink
Make active record instrumentation more thread safe, Issue #10
Browse files Browse the repository at this point in the history
  • Loading branch information
noahd1 committed Jul 20, 2011
1 parent 0198645 commit 5f340e7
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/oink/instrumentation/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,27 @@ module ActiveRecord
def self.included(klass)
klass.class_eval do

@@instantiated = {}
@@total = nil

def self.reset_instance_type_count
@@instantiated = {}
@@total = nil
self.instantiated_hash = {}
Thread.current['oink.activerecord.instantiations_count'] = nil
end

def self.increment_instance_type_count
@@instantiated[base_class.name] ||= 0
@@instantiated[base_class.name] += 1
self.instantiated_hash ||= {}
self.instantiated_hash[base_class.name] ||= 0
self.instantiated_hash[base_class.name] += 1
end

def self.instantiated_hash
@@instantiated
Thread.current['oink.activerecord.instantiations']
end

def self.instantiated_hash=(hsh)
Thread.current['oink.activerecord.instantiations'] = hsh
end

def self.total_objects_instantiated
@@total ||= @@instantiated.values.sum
Thread.current['oink.activerecord.instantiations_count'] ||= self.instantiated_hash.values.sum
end

unless Oink.extended_active_record?
Expand Down

0 comments on commit 5f340e7

Please sign in to comment.