Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/profiler_spec.rb')
-rw-r--r--spec/lib/gitlab/profiler_spec.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/lib/gitlab/profiler_spec.rb b/spec/lib/gitlab/profiler_spec.rb
index 8f6fb6eda65..0186d48fd1b 100644
--- a/spec/lib/gitlab/profiler_spec.rb
+++ b/spec/lib/gitlab/profiler_spec.rb
@@ -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