Class: ActiveRecordQueryCounter::QueryInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record_query_counter/query_info.rb

Overview

Data structure for storing information about a query executed within a transaction. Note that the start and end times are monotonic time and not wall clock time. Bind parameter values are deliberately not stored since they can contain sensitive data.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sql:, name:, row_count:, start_time:, end_time:, gc_time: 0.0, cpu_time: 0.0, connection_time: 0.0) ⇒ QueryInfo

Returns a new instance of QueryInfo.



10
11
12
13
14
15
16
17
18
19
# File 'lib/active_record_query_counter/query_info.rb', line 10

def initialize(sql:, name:, row_count:, start_time:, end_time:, gc_time: 0.0, cpu_time: 0.0, connection_time: 0.0)
  @sql = sql
  @name = name
  @row_count = row_count
  @start_time = start_time
  @end_time = end_time
  @gc_time = gc_time
  @cpu_time = cpu_time
  @connection_time = connection_time
end

Instance Attribute Details

#connection_timeObject (readonly)

Returns the value of attribute connection_time.



8
9
10
# File 'lib/active_record_query_counter/query_info.rb', line 8

def connection_time
  @connection_time
end

#cpu_timeObject (readonly)

Returns the value of attribute cpu_time.



8
9
10
# File 'lib/active_record_query_counter/query_info.rb', line 8

def cpu_time
  @cpu_time
end

#end_timeObject (readonly)

Returns the value of attribute end_time.



8
9
10
# File 'lib/active_record_query_counter/query_info.rb', line 8

def end_time
  @end_time
end

#gc_timeObject (readonly)

Returns the value of attribute gc_time.



8
9
10
# File 'lib/active_record_query_counter/query_info.rb', line 8

def gc_time
  @gc_time
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/active_record_query_counter/query_info.rb', line 8

def name
  @name
end

#row_countObject (readonly)

Returns the value of attribute row_count.



8
9
10
# File 'lib/active_record_query_counter/query_info.rb', line 8

def row_count
  @row_count
end

#sqlObject (readonly)

Returns the value of attribute sql.



8
9
10
# File 'lib/active_record_query_counter/query_info.rb', line 8

def sql
  @sql
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



8
9
10
# File 'lib/active_record_query_counter/query_info.rb', line 8

def start_time
  @start_time
end

Instance Method Details

#elapsed_timeFloat

Return the wall clock time spent executing the query.

Returns:

  • (Float)


24
25
26
# File 'lib/active_record_query_counter/query_info.rb', line 24

def elapsed_time
  end_time - start_time
end