Class: Amalgalite::ProfileTap

Inherits:
Object
  • Object
show all
Defined in:
lib/amalgalite/profile_tap.rb

Overview

A Profile Tap recives profile events from SQLite which involve the number of nanoseconds in wall-clock time it took for a particular thing to happen. In general this thing is an SQL statement.

It has a well known profile method which when invoked will write the event to a delegate object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wrapped_obj, send_to = 'profile') ⇒ ProfileTap

Create a new ProfileTap object that wraps the given object and calls the method named in send_to ever time a profile event happens.



108
109
110
111
112
113
114
115
116
# File 'lib/amalgalite/profile_tap.rb', line 108

def initialize( wrapped_obj, send_to = 'profile' )
  unless wrapped_obj.respond_to?( send_to ) 
    raise Amalgalite::Error, "#{wrapped_obj.class.name} does not respond to #{send_to.to_s} "
  end

  @delegate_obj    = wrapped_obj
  @delegate_method = send_to
  @samplers        = {}
end

Instance Attribute Details

#samplersObject (readonly)

Returns the value of attribute samplers.



102
103
104
# File 'lib/amalgalite/profile_tap.rb', line 102

def samplers
  @samplers
end

Instance Method Details

#profile(msg, time) ⇒ Object

Record the profile information and send the delegate object the msg and time information.



122
123
124
125
126
127
128
129
# File 'lib/amalgalite/profile_tap.rb', line 122

def profile( msg, time )
  msg = msg.gsub(/\s+/,' ')
  unless sampler = @samplers[msg]
    sampler = @samplers[msg] = ProfileSampler.new( msg )
  end
  sampler.sample( time )
  @delegate_obj.send( @delegate_method, msg, time )
end