Class: GraphQL::Flamegraph::Instrumentation
- Inherits:
-
Object
- Object
- GraphQL::Flamegraph::Instrumentation
- Defined in:
- lib/graphql/flamegraph/instrumentation.rb
Instance Method Summary collapse
- #after_query(query) ⇒ Object
- #before_query(query) ⇒ Object
-
#initialize(path: nil) ⇒ Instrumentation
constructor
A new instance of Instrumentation.
Constructor Details
#initialize(path: nil) ⇒ Instrumentation
Returns a new instance of Instrumentation.
7 8 9 10 |
# File 'lib/graphql/flamegraph/instrumentation.rb', line 7 def initialize(path: nil) validate_directory!(path) if path @path = path end |
Instance Method Details
#after_query(query) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/graphql/flamegraph/instrumentation.rb', line 16 def after_query(query) return unless enabled?(query) result = Result.new(cache(query)) query.context[:flamegraph] = result return unless @path file_path = Dir::Tmpname.create(['graphql-flamegraph-', '.txt'], @path) {} File.write(file_path, result.serialize) puts <<~MESSAGE Check your flamegraph at #{file_path} Open it in https://www.speedscope.app/ or in local speedscope: speedscope #{file_path} MESSAGE end |
#before_query(query) ⇒ Object
12 13 14 |
# File 'lib/graphql/flamegraph/instrumentation.rb', line 12 def before_query(query) reset_cache!(query) end |