Class: GraphQL::Metrics::TimedResult

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/metrics.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(offset_time = nil) ⇒ TimedResult

Returns a new instance of TimedResult.



77
78
79
80
81
82
83
# File 'lib/graphql/metrics.rb', line 77

def initialize(offset_time = nil)
  @offset_time = offset_time
  @start_time = GraphQL::Metrics.current_time_monotonic
  @result = yield
  @duration = GraphQL::Metrics.current_time_monotonic - @start_time
  @time_since_offset = @start_time - @offset_time if @offset_time
end

Instance Attribute Details

#durationObject (readonly)

NOTE: ‘time_since_offset` is used to produce start times timed phases of execution (validation, field resolution). These start times are relative to the executed operation’s start time, which is captured at the outset of document parsing.

The times produced are intentionally similar to: github.com/apollographql/apollo-tracing#response-format

Taking a field resolver start offset example:

< start offset > |——————|———-|———> OS (t=0) FS (t=1) FE (t=2)

OS = Operation start time FS = Field resolver start time FE = Field resolver end time



75
76
77
# File 'lib/graphql/metrics.rb', line 75

def duration
  @duration
end

#resultObject (readonly)

NOTE: ‘time_since_offset` is used to produce start times timed phases of execution (validation, field resolution). These start times are relative to the executed operation’s start time, which is captured at the outset of document parsing.

The times produced are intentionally similar to: github.com/apollographql/apollo-tracing#response-format

Taking a field resolver start offset example:

< start offset > |——————|———-|———> OS (t=0) FS (t=1) FE (t=2)

OS = Operation start time FS = Field resolver start time FE = Field resolver end time



75
76
77
# File 'lib/graphql/metrics.rb', line 75

def result
  @result
end

#start_timeObject (readonly)

NOTE: ‘time_since_offset` is used to produce start times timed phases of execution (validation, field resolution). These start times are relative to the executed operation’s start time, which is captured at the outset of document parsing.

The times produced are intentionally similar to: github.com/apollographql/apollo-tracing#response-format

Taking a field resolver start offset example:

< start offset > |——————|———-|———> OS (t=0) FS (t=1) FE (t=2)

OS = Operation start time FS = Field resolver start time FE = Field resolver end time



75
76
77
# File 'lib/graphql/metrics.rb', line 75

def start_time
  @start_time
end

#time_since_offsetObject (readonly)

NOTE: ‘time_since_offset` is used to produce start times timed phases of execution (validation, field resolution). These start times are relative to the executed operation’s start time, which is captured at the outset of document parsing.

The times produced are intentionally similar to: github.com/apollographql/apollo-tracing#response-format

Taking a field resolver start offset example:

< start offset > |——————|———-|———> OS (t=0) FS (t=1) FE (t=2)

OS = Operation start time FS = Field resolver start time FE = Field resolver end time



75
76
77
# File 'lib/graphql/metrics.rb', line 75

def time_since_offset
  @time_since_offset
end