Module: PG::Connection::MiniProfiler

Included in:
PG::Connection
Defined in:
lib/patches/db/pg/prepend.rb

Instance Method Summary collapse

Instance Method Details

#async_exec(*args, &blk) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/patches/db/pg/prepend.rb', line 108

def async_exec(*args, &blk)
  return super unless SqlPatches.should_measure?

  start        = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  result       = super
  elapsed_time = SqlPatches.elapsed_time(start)
  record       = ::Rack::MiniProfiler.record_sql(
    args[0], elapsed_time, ::Rack::MiniProfiler.binds_to_params(args[1])
  )
  result.instance_variable_set("@miniprofiler_sql_id", record) if result

  result
end

#exec(*args, &blk) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/patches/db/pg/prepend.rb', line 46

def exec(*args, &blk)
  return super unless SqlPatches.should_measure?

  start        = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  result       = super
  elapsed_time = SqlPatches.elapsed_time(start)
  record       = ::Rack::MiniProfiler.record_sql(
    args[0], elapsed_time, ::Rack::MiniProfiler.binds_to_params(args[1])
  )
  result.instance_variable_set("@miniprofiler_sql_id", record) if result

  result
end

#exec_params(*args, &blk) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/patches/db/pg/prepend.rb', line 61

def exec_params(*args, &blk)
  return super unless SqlPatches.should_measure?

  start        = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  result       = super
  elapsed_time = SqlPatches.elapsed_time(start)
  record       = ::Rack::MiniProfiler.record_sql(
    args[0], elapsed_time, ::Rack::MiniProfiler.binds_to_params(args[1])
  )
  result.instance_variable_set("@miniprofiler_sql_id", record) if result

  result
end

#exec_prepared(*args, &blk) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/patches/db/pg/prepend.rb', line 76

def exec_prepared(*args, &blk)
  return super unless SqlPatches.should_measure?

  start        = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  result       = super
  elapsed_time = SqlPatches.elapsed_time(start)
  mapped       = args[0]
  mapped       = @prepare_map[mapped] || args[0] if @prepare_map
  record       = ::Rack::MiniProfiler.record_sql(
    mapped, elapsed_time, ::Rack::MiniProfiler.binds_to_params(args[1])
  )
  result.instance_variable_set("@miniprofiler_sql_id", record) if result

  result
end

#prepare(*args, &blk) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/patches/db/pg/prepend.rb', line 33

def prepare(*args, &blk)
  # we have no choice but to do this here,
  # if we do the check for profiling first, our cache may miss critical stuff

  @prepare_map ||= {}
  @prepare_map[args[0]] = args[1]
  # dont leak more than 10k ever
  @prepare_map = {} if @prepare_map.length > 1000

  return super unless SqlPatches.should_measure?
  super
end

#send_query_prepared(*args, &blk) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/patches/db/pg/prepend.rb', line 92

def send_query_prepared(*args, &blk)
  return super unless SqlPatches.should_measure?

  start        = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  result       = super
  elapsed_time = SqlPatches.elapsed_time(start)
  mapped       = args[0]
  mapped       = @prepare_map[mapped] || args[0] if @prepare_map
  record       = ::Rack::MiniProfiler.record_sql(
    mapped, elapsed_time, ::Rack::MiniProfiler.binds_to_params(args[1])
  )
  result.instance_variable_set("@miniprofiler_sql_id", record) if result

  result
end