4 # Wrapper around a PG Connection that provides a report on where time was spent executing SQL
10 def initialize(wrapped_conn)
18 puts "Connection closing. Total SQL time: " + @total_time.to_s + " secs"
19 @stmts.each do |sql, info|
22 puts elapsed.to_s + " secs: " + calls.to_s + " times: " + sql
26 def exec(*args, &block)
29 result = @conn.exec(*args)
32 elapsed = (after - before)
33 remember(args[0], elapsed)
34 @total_time += elapsed
42 def exec_params(*args, &block)
45 result = @conn.exec_params(*args)
48 elapsed = (after - before)
49 remember(args[0], elapsed)
50 @total_time += elapsed
58 def remember(sql, elapsed)
59 if @stmts.has_key?(sql)
65 stmt[1] += 1 # Number of times this statement has been invoked
66 stmt[2] += elapsed # total elapsed time spent on this statement