/usr/lib/ruby/vendor_ruby/rspec/core/formatters/profile_formatter.rb is in ruby-rspec-core 3.7.0c1e0m0s1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | RSpec::Support.require_rspec_core "formatters/console_codes"
module RSpec
module Core
module Formatters
# @api private
# Formatter for providing profile output.
class ProfileFormatter
Formatters.register self, :dump_profile
def initialize(output)
@output = output
end
# @private
attr_reader :output
# @api public
#
# This method is invoked after the dumping the summary if profiling is
# enabled.
#
# @param profile [ProfileNotification] containing duration,
# slowest_examples and slowest_example_groups
def dump_profile(profile)
dump_profile_slowest_examples(profile)
dump_profile_slowest_example_groups(profile)
end
private
def dump_profile_slowest_examples(profile)
@output.puts "\nTop #{profile.slowest_examples.size} slowest " \
"examples (#{Helpers.format_seconds(profile.slow_duration)} " \
"seconds, #{profile.percentage}% of total time):\n"
profile.slowest_examples.each do |example|
@output.puts " #{example.full_description}"
@output.puts " #{bold(Helpers.format_seconds(example.execution_result.run_time))} " \
"#{bold("seconds")} #{format_caller(example.location)}"
end
end
def dump_profile_slowest_example_groups(profile)
return if profile.slowest_groups.empty?
@output.puts "\nTop #{profile.slowest_groups.size} slowest example groups:"
profile.slowest_groups.each do |loc, hash|
average = "#{bold(Helpers.format_seconds(hash[:average]))} #{bold("seconds")} average"
total = "#{Helpers.format_seconds(hash[:total_time])} seconds"
count = Helpers.pluralize(hash[:count], "example")
@output.puts " #{hash[:description]}"
@output.puts " #{average} (#{total} / #{count}) #{loc}"
end
end
def format_caller(caller_info)
RSpec.configuration.backtrace_formatter.backtrace_line(
caller_info.to_s.split(':in `block').first)
end
def bold(text)
ConsoleCodes.wrap(text, :bold)
end
end
end
end
end
|