class GraphQL::Flamegraph::Tracing
Public Instance Methods
cache(context)
click to toggle source
# File lib/graphql/flamegraph/tracing.rb, line 54 def cache(context) context.namespace(GraphQL::Flamegraph)[:field_runtime_cache] end
extract_field_trace_data(data)
click to toggle source
See graphql-ruby.org/api-doc/1.10.5/GraphQL/Tracing
# File lib/graphql/flamegraph/tracing.rb, line 46 def extract_field_trace_data(data) if data[:context] # Legacy non-interpreter mode [data[:context].field, data[:context].path, data[:context].query] else # Interpreter mode data.values_at(:field, :path, :query) end end
platform_field_key(type, field)
click to toggle source
graphql-ruby require us to declare these
# File lib/graphql/flamegraph/tracing.rb, line 60 def platform_field_key(type, field) "#{type.graphql_name}.#{field.graphql_name}" end
platform_resolve_type_key(type)
click to toggle source
# File lib/graphql/flamegraph/tracing.rb, line 68 def platform_resolve_type_key(type) "#{type.graphql_name}.resolve_type" end
platform_trace(_platform_key, key, data, &block)
click to toggle source
# File lib/graphql/flamegraph/tracing.rb, line 20 def platform_trace(_platform_key, key, data, &block) start = ::Process.clock_gettime ::Process::CLOCK_MONOTONIC, :microsecond result = block.call duration = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :microsecond) - start case key when "lex", "parse" # No access to query context here to write results into :-( # See https://graphql-ruby.org/api-doc/1.10.5/GraphQL/Tracing when "execute_query", "execute_query_lazy" # Nothing useful for us as they already includes timings for fields when "validate", "analyze" context = data[:query].context cache(context)[[key]] = duration when "execute_field", "execute_field_lazy" _field, path, query = extract_field_trace_data(data) cache = cache(query.context) cache[[key] + path] += duration when "authorized", "authorized_lazy", "resolve_type", "resolve_type_lazy" cache(data[:context])[[key] + data[:path]] = duration end result end