Class: Gitlab::Database::Batch::Metrics

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/database/batch/metrics.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMetrics

Returns a new instance of Metrics.



9
10
11
12
# File 'lib/gitlab/database/batch/metrics.rb', line 9

def initialize
  @timings = {}
  @affected_rows = {}
end

Instance Attribute Details

#affected_rowsObject (readonly)

Returns the value of attribute affected_rows.



7
8
9
# File 'lib/gitlab/database/batch/metrics.rb', line 7

def affected_rows
  @affected_rows
end

#timingsObject (readonly)

Returns the value of attribute timings.



7
8
9
# File 'lib/gitlab/database/batch/metrics.rb', line 7

def timings
  @timings
end

Instance Method Details

#instrument_operation(label, instrument_affected_rows: true) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/gitlab/database/batch/metrics.rb', line 18

def instrument_operation(label, instrument_affected_rows: true)
  start_time = monotonic_time

  count = yield

  timings_for_label(label) << (monotonic_time - start_time)
  affected_rows_for_label(label) << count if instrument_affected_rows && count.is_a?(Integer)
end

#time_operation(label, &blk) ⇒ Object



14
15
16
# File 'lib/gitlab/database/batch/metrics.rb', line 14

def time_operation(label, &blk)
  instrument_operation(label, instrument_affected_rows: false, &blk)
end