graphql-flamegraph 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +12 -0
- data/Appraisals +7 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +64 -0
- data/LICENSE.txt +21 -0
- data/README.md +68 -0
- data/Rakefile +6 -0
- data/bin/console +10 -0
- data/bin/setup +9 -0
- data/gemfiles/graphql_1.10.gemfile +14 -0
- data/gemfiles/graphql_1.10.gemfile.lock +65 -0
- data/gemfiles/graphql_1.9.gemfile +14 -0
- data/gemfiles/graphql_1.9.gemfile.lock +65 -0
- data/graphql-flamegraph.gemspec +33 -0
- data/lib/graphql/flamegraph.rb +16 -0
- data/lib/graphql/flamegraph/instrumentation.rb +56 -0
- data/lib/graphql/flamegraph/result.rb +16 -0
- data/lib/graphql/flamegraph/tracing.rb +73 -0
- data/lib/graphql/flamegraph/version.rb +5 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e04ed55ec831103af37f0942d515cdeaabf8de252263021aa89679b69ee6d74f
|
4
|
+
data.tar.gz: e4b9512fbf90b0a44806a0aafcda93828e9fcc8516b1b89fe21b7e7161d27993
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0febf1999b3efb77cc56ce7d73f2ef3ce6a2c03fe2477ef29652e9c0c1f209281c899a607ce38df1ae7101f474009e8382ef95e67d54400c41839350b949fafb
|
7
|
+
data.tar.gz: ea3af78b62689c674380360785968fb8515f6c285a2d04cedd05bd28b87755e3433b4504af13c4c066f7b01059f43ed70f5318ba01f27c45bbd88d84519bd3b4
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Appraisals
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
6
|
+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## 0.1.0 - 2020-03-20
|
9
|
+
|
10
|
+
- Initial release of graphql-flamegraph gem. [@Envek]
|
11
|
+
|
12
|
+
[@Envek]: https://github.com/Envek "Andrey Novikov"
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
graphql-flamegraph (0.1.0)
|
5
|
+
graphql (~> 1.9)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
appraisal (2.2.0)
|
11
|
+
bundler
|
12
|
+
rake
|
13
|
+
thor (>= 0.14.0)
|
14
|
+
byebug (11.1.1)
|
15
|
+
coderay (1.1.2)
|
16
|
+
diff-lcs (1.3)
|
17
|
+
graphql (1.10.5)
|
18
|
+
graphql-batch (0.4.2)
|
19
|
+
graphql (>= 1.3, < 2)
|
20
|
+
promise.rb (~> 0.7.2)
|
21
|
+
method_source (0.9.2)
|
22
|
+
promise.rb (0.7.4)
|
23
|
+
pry (0.12.2)
|
24
|
+
coderay (~> 1.1.0)
|
25
|
+
method_source (~> 0.9.0)
|
26
|
+
pry-byebug (3.8.0)
|
27
|
+
byebug (~> 11.0)
|
28
|
+
pry (~> 0.10)
|
29
|
+
pry-inline (1.0.5)
|
30
|
+
pry (> 0.10.0, <= 0.12.2)
|
31
|
+
unicode (~> 0.4.4)
|
32
|
+
rake (13.0.1)
|
33
|
+
rspec (3.9.0)
|
34
|
+
rspec-core (~> 3.9.0)
|
35
|
+
rspec-expectations (~> 3.9.0)
|
36
|
+
rspec-mocks (~> 3.9.0)
|
37
|
+
rspec-core (3.9.1)
|
38
|
+
rspec-support (~> 3.9.1)
|
39
|
+
rspec-expectations (3.9.1)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.9.0)
|
42
|
+
rspec-mocks (3.9.1)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.9.0)
|
45
|
+
rspec-support (3.9.2)
|
46
|
+
thor (1.0.1)
|
47
|
+
unicode (0.4.4.4)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
appraisal
|
54
|
+
bundler
|
55
|
+
graphql-batch
|
56
|
+
graphql-flamegraph!
|
57
|
+
pry
|
58
|
+
pry-byebug
|
59
|
+
pry-inline
|
60
|
+
rake (~> 13.0)
|
61
|
+
rspec (~> 3.0)
|
62
|
+
|
63
|
+
BUNDLED WITH
|
64
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Andrey Novikov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# GraphQL::Flamegraph
|
2
|
+
|
3
|
+
Collects data for visualizing performance of your GraphQL request resolving for applications built with [GraphQL-Ruby].
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
1. Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'graphql-flamegraph'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```shell script
|
16
|
+
$ bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
2. Plug it into your GraphQL schema:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
class YourAppSchema < GraphQL::Schema
|
23
|
+
use GraphQL::Flamegraph, path: Rails.root.join("tmp")
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
To generate flamegraph for some query, set `flamegraph` option to `true` in your context.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
result = YourAppSchema.execute(
|
33
|
+
query: "query { products { id title quantity … } }",
|
34
|
+
context: { flamegraph: true },
|
35
|
+
variables: {},
|
36
|
+
)
|
37
|
+
```
|
38
|
+
|
39
|
+
Path to the generated file will be printed to standard output like this:
|
40
|
+
|
41
|
+
```
|
42
|
+
Check your flamegraph at /tmp/graphql-flamegraph-20200320-90923-px3494.txt
|
43
|
+
Open it in https://www.speedscope.app/ or in local speedscope:
|
44
|
+
|
45
|
+
speedscope /tmp/graphql-flamegraph-20200320-90923-px3494.txt
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
Also you will be able to access collected data via `result.context[:flamegraph].to_s`
|
50
|
+
|
51
|
+
You can view it with your favorite flamegraph visualizer.
|
52
|
+
|
53
|
+
## Development
|
54
|
+
|
55
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
56
|
+
|
57
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Envek/graphql-flamegraph.
|
62
|
+
|
63
|
+
|
64
|
+
## License
|
65
|
+
|
66
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
67
|
+
|
68
|
+
[GraphQL-Ruby]: https://graphql-ruby.org/ "Ruby implementation of GraphQL"
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "graphql/flamegraph"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
require "pry"
|
10
|
+
Pry.start
|
data/bin/setup
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "graphql", "~> 1.10.0"
|
6
|
+
|
7
|
+
group :development, :test do
|
8
|
+
gem "pry"
|
9
|
+
gem "pry-inline"
|
10
|
+
gem "pry-byebug", platform: :mri
|
11
|
+
gem "graphql-batch"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec path: "../"
|
@@ -0,0 +1,65 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
graphql-flamegraph (0.1.0)
|
5
|
+
graphql (~> 1.9)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
appraisal (2.2.0)
|
11
|
+
bundler
|
12
|
+
rake
|
13
|
+
thor (>= 0.14.0)
|
14
|
+
byebug (11.1.1)
|
15
|
+
coderay (1.1.2)
|
16
|
+
diff-lcs (1.3)
|
17
|
+
graphql (1.10.5)
|
18
|
+
graphql-batch (0.4.2)
|
19
|
+
graphql (>= 1.3, < 2)
|
20
|
+
promise.rb (~> 0.7.2)
|
21
|
+
method_source (0.9.2)
|
22
|
+
promise.rb (0.7.4)
|
23
|
+
pry (0.12.2)
|
24
|
+
coderay (~> 1.1.0)
|
25
|
+
method_source (~> 0.9.0)
|
26
|
+
pry-byebug (3.8.0)
|
27
|
+
byebug (~> 11.0)
|
28
|
+
pry (~> 0.10)
|
29
|
+
pry-inline (1.0.5)
|
30
|
+
pry (> 0.10.0, <= 0.12.2)
|
31
|
+
unicode (~> 0.4.4)
|
32
|
+
rake (13.0.1)
|
33
|
+
rspec (3.9.0)
|
34
|
+
rspec-core (~> 3.9.0)
|
35
|
+
rspec-expectations (~> 3.9.0)
|
36
|
+
rspec-mocks (~> 3.9.0)
|
37
|
+
rspec-core (3.9.1)
|
38
|
+
rspec-support (~> 3.9.1)
|
39
|
+
rspec-expectations (3.9.1)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.9.0)
|
42
|
+
rspec-mocks (3.9.1)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.9.0)
|
45
|
+
rspec-support (3.9.2)
|
46
|
+
thor (1.0.1)
|
47
|
+
unicode (0.4.4.4)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
appraisal
|
54
|
+
bundler
|
55
|
+
graphql (~> 1.10.0)
|
56
|
+
graphql-batch
|
57
|
+
graphql-flamegraph!
|
58
|
+
pry
|
59
|
+
pry-byebug
|
60
|
+
pry-inline
|
61
|
+
rake (~> 13.0)
|
62
|
+
rspec (~> 3.0)
|
63
|
+
|
64
|
+
BUNDLED WITH
|
65
|
+
2.1.4
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "graphql", "~> 1.9.0"
|
6
|
+
|
7
|
+
group :development, :test do
|
8
|
+
gem "pry"
|
9
|
+
gem "pry-inline"
|
10
|
+
gem "pry-byebug", platform: :mri
|
11
|
+
gem "graphql-batch"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec path: "../"
|
@@ -0,0 +1,65 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
graphql-flamegraph (0.1.0)
|
5
|
+
graphql (~> 1.9)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
appraisal (2.2.0)
|
11
|
+
bundler
|
12
|
+
rake
|
13
|
+
thor (>= 0.14.0)
|
14
|
+
byebug (11.1.1)
|
15
|
+
coderay (1.1.2)
|
16
|
+
diff-lcs (1.3)
|
17
|
+
graphql (1.9.19)
|
18
|
+
graphql-batch (0.4.2)
|
19
|
+
graphql (>= 1.3, < 2)
|
20
|
+
promise.rb (~> 0.7.2)
|
21
|
+
method_source (0.9.2)
|
22
|
+
promise.rb (0.7.4)
|
23
|
+
pry (0.12.2)
|
24
|
+
coderay (~> 1.1.0)
|
25
|
+
method_source (~> 0.9.0)
|
26
|
+
pry-byebug (3.8.0)
|
27
|
+
byebug (~> 11.0)
|
28
|
+
pry (~> 0.10)
|
29
|
+
pry-inline (1.0.5)
|
30
|
+
pry (> 0.10.0, <= 0.12.2)
|
31
|
+
unicode (~> 0.4.4)
|
32
|
+
rake (13.0.1)
|
33
|
+
rspec (3.9.0)
|
34
|
+
rspec-core (~> 3.9.0)
|
35
|
+
rspec-expectations (~> 3.9.0)
|
36
|
+
rspec-mocks (~> 3.9.0)
|
37
|
+
rspec-core (3.9.1)
|
38
|
+
rspec-support (~> 3.9.1)
|
39
|
+
rspec-expectations (3.9.1)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.9.0)
|
42
|
+
rspec-mocks (3.9.1)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.9.0)
|
45
|
+
rspec-support (3.9.2)
|
46
|
+
thor (1.0.1)
|
47
|
+
unicode (0.4.4.4)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
appraisal
|
54
|
+
bundler
|
55
|
+
graphql (~> 1.9.0)
|
56
|
+
graphql-batch
|
57
|
+
graphql-flamegraph!
|
58
|
+
pry
|
59
|
+
pry-byebug
|
60
|
+
pry-inline
|
61
|
+
rake (~> 13.0)
|
62
|
+
rspec (~> 3.0)
|
63
|
+
|
64
|
+
BUNDLED WITH
|
65
|
+
2.1.4
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'lib/graphql/flamegraph/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "graphql-flamegraph"
|
5
|
+
spec.version = GraphQL::Flamegraph::VERSION
|
6
|
+
spec.authors = ["Andrey Novikov"]
|
7
|
+
spec.email = ["envek@envek.name"]
|
8
|
+
|
9
|
+
spec.summary = "Measure and visualize resolve runtime of every GraphQL field"
|
10
|
+
spec.homepage = "http://github.com/Envek/graphql-flamegraph"
|
11
|
+
spec.license = "MIT"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
+
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
spec.metadata["source_code_uri"] = "http://github.com/Envek/graphql-flamegraph"
|
16
|
+
spec.metadata["changelog_uri"] = "https://github.com/Envek/graphql-flamegraph/blob/master/CHANGELOG.md"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_runtime_dependency "graphql", "~> 1.9"
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler"
|
30
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
+
spec.add_development_dependency "appraisal"
|
33
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "graphql/flamegraph/version"
|
2
|
+
require "graphql/flamegraph/instrumentation"
|
3
|
+
require "graphql/flamegraph/tracing"
|
4
|
+
|
5
|
+
module GraphQL
|
6
|
+
module Flamegraph
|
7
|
+
class Error < StandardError; end
|
8
|
+
|
9
|
+
def self.use(schema, enabled: true, path: nil)
|
10
|
+
return unless enabled
|
11
|
+
|
12
|
+
schema.instrument(:query, Instrumentation.new(path: path))
|
13
|
+
schema.use Tracing, trace_scalars: true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'tmpdir'
|
2
|
+
require "graphql/flamegraph/result"
|
3
|
+
|
4
|
+
module GraphQL
|
5
|
+
module Flamegraph
|
6
|
+
class Instrumentation
|
7
|
+
def initialize(path: nil)
|
8
|
+
validate_directory!(path) if path
|
9
|
+
@path = path
|
10
|
+
end
|
11
|
+
|
12
|
+
def before_query(query)
|
13
|
+
reset_cache!(query)
|
14
|
+
end
|
15
|
+
|
16
|
+
def after_query(query)
|
17
|
+
return unless enabled?(query)
|
18
|
+
|
19
|
+
result = Result.new(cache(query))
|
20
|
+
query.context[:flamegraph] = result
|
21
|
+
return unless @path
|
22
|
+
|
23
|
+
file_path = Dir::Tmpname.create(['graphql-flamegraph-', '.txt'], @path) {}
|
24
|
+
File.write(file_path, result.serialize)
|
25
|
+
puts <<~MESSAGE
|
26
|
+
Check your flamegraph at #{file_path}
|
27
|
+
Open it in https://www.speedscope.app/ or in local speedscope:
|
28
|
+
|
29
|
+
speedscope #{file_path}
|
30
|
+
|
31
|
+
MESSAGE
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def enabled?(query)
|
37
|
+
!!query.context[:flamegraph]
|
38
|
+
end
|
39
|
+
|
40
|
+
def validate_directory!(path)
|
41
|
+
return if Dir.exist?(path) && File.writable?(path)
|
42
|
+
|
43
|
+
raise ArgumentError, "Path for graphql-flamegraph must be a writable directory!"
|
44
|
+
end
|
45
|
+
|
46
|
+
def cache(query)
|
47
|
+
query.context.namespace(GraphQL::Flamegraph)[:field_runtime_cache]
|
48
|
+
end
|
49
|
+
|
50
|
+
def reset_cache!(query)
|
51
|
+
query.context.namespace(GraphQL::Flamegraph)[:field_runtime_cache] =
|
52
|
+
Hash.new { |h,k| h[k] = 0.0 }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require "graphql/tracing/platform_tracing"
|
2
|
+
|
3
|
+
module GraphQL
|
4
|
+
module Flamegraph
|
5
|
+
class Tracing < ::GraphQL::Tracing::PlatformTracing
|
6
|
+
|
7
|
+
self.platform_keys = {
|
8
|
+
'lex' => "graphql.lex",
|
9
|
+
'parse' => "graphql.parse",
|
10
|
+
'validate' => "graphql.validate",
|
11
|
+
'analyze_query' => "graphql.analyze",
|
12
|
+
'analyze_multiplex' => "graphql.analyze",
|
13
|
+
'execute_multiplex' => "graphql.execute",
|
14
|
+
'execute_query' => "graphql.execute",
|
15
|
+
'execute_query_lazy' => "graphql.execute",
|
16
|
+
'execute_field' => "graphql.execute",
|
17
|
+
'execute_field_lazy' => "graphql.execute"
|
18
|
+
}
|
19
|
+
|
20
|
+
def platform_trace(_platform_key, key, data, &block)
|
21
|
+
start = ::Process.clock_gettime ::Process::CLOCK_MONOTONIC, :microsecond
|
22
|
+
result = block.call
|
23
|
+
duration = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, :microsecond) - start
|
24
|
+
|
25
|
+
case key
|
26
|
+
when "lex", "parse"
|
27
|
+
# No access to query context here to write results into :-(
|
28
|
+
# See https://graphql-ruby.org/api-doc/1.10.5/GraphQL/Tracing
|
29
|
+
when "execute_query", "execute_query_lazy"
|
30
|
+
# Nothing useful for us as they already includes timings for fields
|
31
|
+
when "validate", "analyze"
|
32
|
+
context = data[:query].context
|
33
|
+
cache(context)[[key]] = duration
|
34
|
+
when "execute_field", "execute_field_lazy"
|
35
|
+
_field, path, query = extract_field_trace_data(data)
|
36
|
+
cache = cache(query.context)
|
37
|
+
cache[[key] + path] += duration
|
38
|
+
when "authorized", "authorized_lazy", "resolve_type", "resolve_type_lazy"
|
39
|
+
cache(data[:context])[[key] + data[:path]] = duration
|
40
|
+
end
|
41
|
+
|
42
|
+
result
|
43
|
+
end
|
44
|
+
|
45
|
+
# See https://graphql-ruby.org/api-doc/1.10.5/GraphQL/Tracing
|
46
|
+
def extract_field_trace_data(data)
|
47
|
+
if data[:context] # Legacy non-interpreter mode
|
48
|
+
[data[:context].field, data[:context].path, data[:context].query]
|
49
|
+
else # Interpreter mode
|
50
|
+
data.values_at(:field, :path, :query)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def cache(context)
|
55
|
+
context.namespace(GraphQL::Flamegraph)[:field_runtime_cache]
|
56
|
+
end
|
57
|
+
|
58
|
+
# graphql-ruby require us to declare these
|
59
|
+
|
60
|
+
def platform_field_key(type, field)
|
61
|
+
"#{type.graphql_name}.#{field.graphql_name}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def platform_authorized_key(type)
|
65
|
+
"#{type.graphql_name}.authorized"
|
66
|
+
end
|
67
|
+
|
68
|
+
def platform_resolve_type_key(type)
|
69
|
+
"#{type.graphql_name}.resolve_type"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: graphql-flamegraph
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrey Novikov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-03-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: graphql
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '13.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '13.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: appraisal
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- envek@envek.name
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Appraisals
|
94
|
+
- CHANGELOG.md
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- gemfiles/graphql_1.10.gemfile
|
103
|
+
- gemfiles/graphql_1.10.gemfile.lock
|
104
|
+
- gemfiles/graphql_1.9.gemfile
|
105
|
+
- gemfiles/graphql_1.9.gemfile.lock
|
106
|
+
- graphql-flamegraph.gemspec
|
107
|
+
- lib/graphql/flamegraph.rb
|
108
|
+
- lib/graphql/flamegraph/instrumentation.rb
|
109
|
+
- lib/graphql/flamegraph/result.rb
|
110
|
+
- lib/graphql/flamegraph/tracing.rb
|
111
|
+
- lib/graphql/flamegraph/version.rb
|
112
|
+
homepage: http://github.com/Envek/graphql-flamegraph
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata:
|
116
|
+
homepage_uri: http://github.com/Envek/graphql-flamegraph
|
117
|
+
source_code_uri: http://github.com/Envek/graphql-flamegraph
|
118
|
+
changelog_uri: https://github.com/Envek/graphql-flamegraph/blob/master/CHANGELOG.md
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: 2.3.0
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubygems_version: 3.1.2
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: Measure and visualize resolve runtime of every GraphQL field
|
138
|
+
test_files: []
|