debian-mirror-gitlab/lib/gitlab/database/background_migration/batch_metrics.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1 KiB
Ruby
Raw Normal View History

2021-04-29 21:17:54 +05:30
# frozen_string_literal: true
module Gitlab
module Database
module BackgroundMigration
class BatchMetrics
attr_reader :timings
2022-06-21 17:19:12 +05:30
attr_reader :affected_rows
2021-04-29 21:17:54 +05:30
def initialize
@timings = {}
2022-06-21 17:19:12 +05:30
@affected_rows = {}
2021-04-29 21:17:54 +05:30
end
2022-06-21 17:19:12 +05:30
def time_operation(label, &blk)
instrument_operation(label, instrument_affected_rows: false, &blk)
end
def instrument_operation(label, instrument_affected_rows: true)
2021-04-29 21:17:54 +05:30
start_time = monotonic_time
2022-06-21 17:19:12 +05:30
count = yield
2021-04-29 21:17:54 +05:30
timings_for_label(label) << monotonic_time - start_time
2022-06-21 17:19:12 +05:30
affected_rows_for_label(label) << count if instrument_affected_rows && count.is_a?(Integer)
2021-04-29 21:17:54 +05:30
end
private
def timings_for_label(label)
timings[label] ||= []
end
2022-06-21 17:19:12 +05:30
def affected_rows_for_label(label)
affected_rows[label] ||= []
end
2021-04-29 21:17:54 +05:30
def monotonic_time
Gitlab::Metrics::System.monotonic_time
end
end
end
end
end