Class: Rack::MiniProfiler::SqlTimerStruct

Inherits:
TimerStruct
  • Object
show all
Defined in:
lib/mini_profiler/sql_timer_struct.rb

Overview

Timing system for a SQL query

Instance Method Summary collapse

Methods inherited from TimerStruct

#[], #[]=, #attributes, #to_json

Constructor Details

#initialize(query, duration_ms, page, parent, skip_backtrace = false, full_backtrace = false) ⇒ SqlTimerStruct

Returns a new instance of SqlTimerStruct.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mini_profiler/sql_timer_struct.rb', line 8

def initialize(query, duration_ms, page, parent, skip_backtrace = false, full_backtrace = false)

  stack_trace = nil 
  unless skip_backtrace 
    # Allow us to filter the stack trace
    stack_trace = ""
     # Clean up the stack trace if there are options to do so
    Kernel.caller.each do |ln|
      ln.gsub!(Rack::MiniProfiler.config.backtrace_remove, '') if Rack::MiniProfiler.config.backtrace_remove and !full_backtrace
      if full_backtrace or Rack::MiniProfiler.config.backtrace_filter.nil? or ln =~ Rack::MiniProfiler.config.backtrace_filter
        stack_trace << ln << "\n" 
      end
    end
  end

  @parent = parent
  @page = page

  super("ExecuteType" => 3, # TODO
        "FormattedCommandString" => query,
        "StackTraceSnippet" => stack_trace, 
        "StartMilliseconds" => ((Time.now.to_f * 1000).to_i - page['Started']) - duration_ms,
        "DurationMilliseconds" => duration_ms,
        "FirstFetchDurationMilliseconds" => duration_ms,
        "Parameters" => nil,
        "ParentTimingId" => nil,
        "IsDuplicate" => false)
end

Instance Method Details

#report_reader_duration(elapsed_ms) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/mini_profiler/sql_timer_struct.rb', line 37

def report_reader_duration(elapsed_ms)
  return if @reported
  @reported = true
  self["DurationMilliseconds"] += elapsed_ms
  @parent["SqlTimingsDurationMilliseconds"] += elapsed_ms
  @page["DurationMillisecondsInSql"] += elapsed_ms
end