Class: Gitlab::Utils::Measuring

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/utils/measuring.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_log_data = {}) ⇒ Measuring

Returns a new instance of Measuring.


16
17
18
# File 'lib/gitlab/utils/measuring.rb', line 16

def initialize(base_log_data = {})
  @base_log_data = base_log_data
end

Class Attribute Details

.loggerObject


11
12
13
# File 'lib/gitlab/utils/measuring.rb', line 11

def logger
  @logger ||= Logger.new(STDOUT)
end

Instance Method Details

#with_measuringObject


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gitlab/utils/measuring.rb', line 20

def with_measuring
  result = nil
  with_gc_stats do
    with_count_queries do
      with_measure_time do
        result = yield
      end
    end
  end

  log_info(
    gc_stats: gc_stats,
    time_to_finish: time_to_finish,
    number_of_sql_calls: sql_calls_count,
    memory_usage: "#{Gitlab::Metrics::System.memory_usage_rss.to_f / 1024 / 1024} MiB",
    label: ::Prometheus::PidProvider.worker_id
  )

  result
end