Commit 74cc831c authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'sh-fix-total-time-flat-printer' into 'master'

Fix command-line profiling with ruby-prof

See merge request gitlab-org/gitlab!24555
parents 92b7aadf 32eae963
......@@ -24,7 +24,7 @@ module Gitlab
sum += method.self_time
@output << "%6.2f %9.3f %9.3f %9.3f %9.3f %8d %s%s\n" % [
@output << "%6.2f %9.3f %9.3f %9.3f %9.3f %8d %s%-30s %s\n" % [
method.self_time / total_time * 100, # %self
method.total_time, # total
method.self_time, # self
......@@ -32,7 +32,8 @@ module Gitlab
method.children_time, # children
method.called, # calls
method.recursive? ? "*" : " ", # cycle
method_name(method) # name
method.full_name, # method_name
method_location(method) # location
]
end
end
......
......@@ -192,4 +192,43 @@ describe Gitlab::Profiler do
expect(described_class.log_load_times_by_model(null_logger)).to be_nil
end
end
describe '.print_by_total_time' do
let(:stdout) { StringIO.new }
let(:output) do
stdout.rewind
stdout.read
end
let_it_be(:result) do
RubyProf.profile do
sleep 0.1
1.to_s
end
end
before do
stub_const('STDOUT', stdout)
end
it 'prints a profile result sorted by total time' do
described_class.print_by_total_time(result)
total_times =
output
.scan(/^\s+\d+\.\d+\s+(\d+\.\d+)/)
.map { |(total)| total.to_f }
expect(output).to include('Kernel#sleep')
expect(total_times).to eq(total_times.sort.reverse)
expect(total_times).not_to eq(total_times.uniq)
end
it 'accepts a max_percent option' do
described_class.print_by_total_time(result, max_percent: 50)
expect(output).not_to include('Kernel#sleep')
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