Class: GraphQL::Flamegraph::Tracing
- Inherits:
-
Tracing::PlatformTracing
- Object
- Tracing::PlatformTracing
- GraphQL::Flamegraph::Tracing
- Defined in:
- lib/graphql/flamegraph/tracing.rb
Instance Method Summary collapse
- #cache(context) ⇒ Object
- #extract_field_trace_data(data) ⇒ Object
- #platform_authorized_key(type) ⇒ Object
-
#platform_field_key(type, field) ⇒ Object
graphql-ruby require us to declare these.
- #platform_resolve_type_key(type) ⇒ Object
- #platform_trace(_platform_key, key, data, &block) ⇒ Object
Instance Method Details
#cache(context) ⇒ Object
54 55 56 |
# File 'lib/graphql/flamegraph/tracing.rb', line 54 def cache(context) context.namespace(GraphQL::Flamegraph)[:field_runtime_cache] end |
#extract_field_trace_data(data) ⇒ Object
46 47 48 49 50 51 52 |
# 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_authorized_key(type) ⇒ Object
64 65 66 |
# File 'lib/graphql/flamegraph/tracing.rb', line 64 def (type) "#{type.graphql_name}.authorized" end |
#platform_field_key(type, field) ⇒ Object
graphql-ruby require us to declare these
60 61 62 |
# 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) ⇒ Object
68 69 70 |
# 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) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# 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 |