mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add profile information to suite summary
This commit is contained in:
parent
34b0399654
commit
291a927f1e
4 changed files with 74 additions and 1 deletions
28
src/spectator/formatting/profile_block.cr
Normal file
28
src/spectator/formatting/profile_block.cr
Normal file
|
@ -0,0 +1,28 @@
|
|||
module Spectator::Formatting
|
||||
# Contents of a profile block.
|
||||
private struct ProfileBlock
|
||||
# Creates the block.
|
||||
def initialize(@profile : Profile)
|
||||
end
|
||||
|
||||
# Appends the block to the output.
|
||||
def to_s(io)
|
||||
io.puts(ProfileSummary.new(@profile))
|
||||
|
||||
indent = Indent.new(io)
|
||||
indent.increase do
|
||||
@profile.each do |result|
|
||||
entry(indent, result)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Adds a result entry to the output.
|
||||
private def entry(indent, result)
|
||||
indent.line(result.example)
|
||||
indent.increase do
|
||||
indent.line(SourceTiming.new(result.elapsed, result.example.source))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
29
src/spectator/formatting/profile_summary.cr
Normal file
29
src/spectator/formatting/profile_summary.cr
Normal file
|
@ -0,0 +1,29 @@
|
|||
module Spectator::Formatting
|
||||
# Top line of a profile block which gives a summary.
|
||||
private struct ProfileSummary
|
||||
# Creates the summary line.
|
||||
def initialize(@profile : Profile)
|
||||
end
|
||||
|
||||
# Appends the summary to the output.
|
||||
def to_s(io)
|
||||
io << "Top "
|
||||
io << @profile.size
|
||||
io << " slowest examples ("
|
||||
io << human_time
|
||||
io << ", "
|
||||
io.printf("%.2f", percentage)
|
||||
io << "% of total time):"
|
||||
end
|
||||
|
||||
# Creates a human-friendly string for the total time.
|
||||
private def human_time
|
||||
HumanTime.new(@profile.total_time)
|
||||
end
|
||||
|
||||
# Percentage (0 to 100) of total time.
|
||||
private def percentage
|
||||
@profile.percentage * 100
|
||||
end
|
||||
end
|
||||
end
|
16
src/spectator/formatting/source_timing.cr
Normal file
16
src/spectator/formatting/source_timing.cr
Normal file
|
@ -0,0 +1,16 @@
|
|||
module Spectator::Formatting
|
||||
# Produces the timing line in a profile block.
|
||||
# This contains the length of time, and the example's source.
|
||||
private struct SourceTiming
|
||||
# Creates the source timing line.
|
||||
def initialize(@span : Time::Span, @source : Source)
|
||||
end
|
||||
|
||||
# Appends the source timing information to the output.
|
||||
def to_s(io)
|
||||
io << HumanTime.new(@span).colorize.bold
|
||||
io << ' '
|
||||
io << @source
|
||||
end
|
||||
end
|
||||
end
|
|
@ -40,7 +40,7 @@ module Spectator::Formatting
|
|||
|
||||
# Produces the profiling section of the summary.
|
||||
private def profile(profile)
|
||||
raise NotImplementedError.new("profile")
|
||||
@io.puts ProfileBlock.new(profile)
|
||||
end
|
||||
|
||||
# Produces the statistical section of the summary.
|
||||
|
|
Loading…
Reference in a new issue