| Class | Amalgalite::ProfileTap |
| In: |
lib/amalgalite/profile_tap.rb
|
| Parent: | Object |
| samplers | [R] |
Create a new ProfileTap object that wraps the given object and calls the method named in send_to ever time a profile event happens.
# File lib/amalgalite/profile_tap.rb, line 107
107: def initialize( wrapped_obj, send_to = 'profile' )
108: unless wrapped_obj.respond_to?( send_to )
109: raise Amalgalite::Error, "#{wrapped_obj.class.name} does not respond to #{send_to.to_s} "
110: end
111:
112: @delegate_obj = wrapped_obj
113: @delegate_method = send_to
114: @samplers = {}
115: end
Record the profile information and send the delegate object the msg and time information.
# File lib/amalgalite/profile_tap.rb, line 121
121: def profile( msg, time )
122: unless sampler = @samplers[msg]
123: msg = msg.gsub(/\s+/,' ')
124: sampler = @samplers[msg] = ProfileSampler.new( msg )
125: end
126: sampler.sample( time )
127: @delegate_obj.send( @delegate_method, msg, time )
128: end