mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Move profile JSON formatting into Profile class
This commit is contained in:
parent
bd34b87e22
commit
12f06abf11
2 changed files with 19 additions and 13 deletions
|
@ -33,20 +33,8 @@ module Spectator::Formatting
|
|||
|
||||
# Adds the profiling information to the document.
|
||||
def dump_profile(notification)
|
||||
profile = notification.profile
|
||||
|
||||
@json.field("profile") do
|
||||
@json.object do
|
||||
@json.field("examples") do
|
||||
@json.array do
|
||||
profile.each(&.to_json(@json))
|
||||
end
|
||||
end
|
||||
|
||||
@json.field("slowest", profile.max_of(&.result.elapsed).total_seconds)
|
||||
@json.field("total", profile.time.total_seconds)
|
||||
@json.field("percentage", profile.percentage)
|
||||
end
|
||||
notification.profile.to_json(@json)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
require "json"
|
||||
require "./example"
|
||||
|
||||
module Spectator
|
||||
# Information about the runtimes of examples.
|
||||
class Profile
|
||||
|
@ -39,5 +42,20 @@ module Spectator
|
|||
def percentage
|
||||
time / @total_time * 100
|
||||
end
|
||||
|
||||
# Produces a JSON fragment containing the profiling information.
|
||||
def to_json(json : JSON::Builder)
|
||||
json.object do
|
||||
json.field("examples") do
|
||||
json.array do
|
||||
@slowest.each(&.to_json(json))
|
||||
end
|
||||
end
|
||||
|
||||
json.field("slowest", @slowest.max_of(&.result.elapsed).total_seconds)
|
||||
json.field("total", time.total_seconds)
|
||||
json.field("percentage", percentage)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue