Commit febd8595 authored by Matthias Kaeppler's avatar Matthias Kaeppler

Log all GC stats to stdout

There are more interesting stats than just GC runs so let's
not throw these away.
parent a6b7f91b
...@@ -11,7 +11,7 @@ module Gitlab ...@@ -11,7 +11,7 @@ module Gitlab
def with_measuring def with_measuring
logger.info "Measuring enabled..." logger.info "Measuring enabled..."
with_gc_counter do with_gc_stats do
with_count_queries do with_count_queries do
with_measure_time do with_measure_time do
yield yield
...@@ -39,15 +39,17 @@ module Gitlab ...@@ -39,15 +39,17 @@ module Gitlab
logger.info "Number of sql calls: #{count}" logger.info "Number of sql calls: #{count}"
end end
def with_gc_counter def with_gc_stats
gc_counts_before = GC.stat.select { |k, _v| k =~ /count/ } GC.start # perform a full mark-and-sweep
stats_before = GC.stat
yield yield
gc_counts_after = GC.stat.select { |k, _v| k =~ /count/ } stats_after = GC.stat
stats = gc_counts_before.merge(gc_counts_after) { |_k, vb, va| va - vb } stats_diff = stats_after.map do |key, after_value|
before_value = stats_before[key]
logger.info "Total GC count: #{stats[:count]}" [key, before: before_value, after: after_value, diff: after_value - before_value]
logger.info "Minor GC count: #{stats[:minor_gc_count]}" end.to_h
logger.info "Major GC count: #{stats[:major_gc_count]}" logger.info "GC stats:"
logger.info JSON.pretty_generate(stats_diff)
end end
def with_measure_time def with_measure_time
......
...@@ -5,7 +5,7 @@ RSpec.shared_examples 'measurable' do ...@@ -5,7 +5,7 @@ RSpec.shared_examples 'measurable' do
let(:measurement_enabled) { true } let(:measurement_enabled) { true }
it 'prints measurement results' do it 'prints measurement results' do
expect { subject }.to output(including('Measuring enabled...', 'Number of sql calls:', 'Total GC count:', 'Total GC count:')).to_stdout expect { subject }.to output(including('Measuring enabled...', 'Number of sql calls:', 'GC stats:')).to_stdout
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment