Class: Rack::MiniProfiler::TimerStruct::Sql
- Defined in:
- lib/mini_profiler/timer_struct/sql.rb
Instance Method Summary collapse
-
#initialize(query, duration_ms, page, parent, skip_backtrace = false, full_backtrace = false) ⇒ Sql
constructor
A new instance of Sql.
- #report_reader_duration(elapsed_ms) ⇒ Object
Methods inherited from Base
#[], #[]=, #attributes, #to_json
Constructor Details
#initialize(query, duration_ms, page, parent, skip_backtrace = false, full_backtrace = false) ⇒ Sql
Returns a new instance of Sql.
7 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 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mini_profiler/timer_struct/sql.rb', line 7 def initialize(query, duration_ms, page, parent, skip_backtrace = false, full_backtrace = false) stack_trace = nil unless skip_backtrace || duration_ms < Rack::MiniProfiler.config.backtrace_threshold_ms # 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_includes.nil? or Rack::MiniProfiler.config.backtrace_includes.all?{|regex| ln =~ regex} ) and ( Rack::MiniProfiler.config.backtrace_ignores.nil? or Rack::MiniProfiler.config.backtrace_ignores.all?{|regex| !(ln =~ regex)} ) ) stack_trace << ln << "\n" end end end @parent = parent @page = page start_millis = ((Time.now.to_f * 1000).to_i - page[:started]) - duration_ms super( :execute_type => 3, # TODO :formatted_command_string => query, :stack_trace_snippet => stack_trace, :start_milliseconds => start_millis, :duration_milliseconds => duration_ms, :first_fetch_duration_milliseconds => duration_ms, :parameters => nil, :parent_timing_id => nil, :is_duplicate => false ) end |
Instance Method Details
#report_reader_duration(elapsed_ms) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/mini_profiler/timer_struct/sql.rb', line 48 def report_reader_duration(elapsed_ms) return if @reported @reported = true self[:duration_milliseconds] += elapsed_ms @parent[:sql_timings_duration_milliseconds] += elapsed_ms @page[:duration_milliseconds_in_sql] += elapsed_ms end |