gruf-profiler 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 46bfbb7bd1631ffae355f4a520b5bbf9574f6dde
4
+ data.tar.gz: 0f7e4c1a87264e8be7d683f6c6610020ab1da207
5
+ SHA512:
6
+ metadata.gz: cbc0f155cf7070e1346bbc8f2554e7887654f35769d2e29885264cfd3da627b611b0b654af90de0bd92e8e046cf7d1a912787811df5238deeb309b9252b94702
7
+ data.tar.gz: f8339f9b59ba2519f5ba8ab07ebe15d382379089040b2216dd06ca1b41183fef58c6a8a28afaa4c09a7b9fafd5cec30da077f6d82bf3616f603feb0668d25670
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ Changelog for the gruf-profiler gem.
2
+
3
+ h3. 0.1.0
4
+
5
+ - Add rubocop
6
+ - Add bundler-audit
7
+ - Add configuration options for logging for memory profiler
8
+
9
+ h3. 0.0.1
10
+
11
+ - Initial public release
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at splittingred@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # gruf-profiler - Profiler for gruf
2
+
3
+ [![Build Status](https://travis-ci.org/bigcommerce/gruf-profiler.svg?branch=master)](https://travis-ci.org/bigcommerce/gruf-profiler) [![Inline docs](http://inch-ci.org/github/bigcommerce/gruf-profiler.svg?branch=master)](http://inch-ci.org/github/bigcommerce/gruf-profiler)
4
+
5
+ Adds a profiler for [gruf](https://github.com/bigcommerce/gruf) 1.0.0 or later.
6
+
7
+ ## Installation
8
+
9
+ ```ruby
10
+ gem 'gruf-profiler'
11
+ ```
12
+
13
+ Then in an initializer or before use, after loading gruf:
14
+
15
+ ```ruby
16
+ require 'gruf/profiler'
17
+ Gruf::Hooks::Registry.add(:profiler, Gruf::Profiler::Hook)
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ gruf-profiler includes and requires the [rbtrace](https://github.com/tmm1/rbtrace/)
23
+ and [memory_profiler](https://github.com/SamSaffron/memory_profiler) gems by default.
24
+
25
+ ### rbtrace
26
+
27
+ rbtrace is automatically loaded for every gruf service. You can view the
28
+ [README](https://github.com/tmm1/rbtrace/blob/master/README.md) for rbtrace for more information,
29
+ but the general idea is that you can run against a running gruf instance to see tracing
30
+ information about a gruf server:
31
+
32
+ ```bash
33
+ rbtrace -p <PID_OF_GRUF> --firehose
34
+ ```
35
+
36
+ Other options for the rbtrace binary are detailed in the rbtrace documentation.
37
+
38
+ ### Memory Profiler
39
+
40
+ [Memory Profiler](https://github.com/SamSaffron/memory_profiler) is a gem that allows you to get
41
+ a memory usage report of a block of Ruby code. gruf-profiler automatically wraps gruf service
42
+ requests with this and provides a report to the logger (at a default level of DEBUG).
43
+
44
+ You can adjust that log level to say, INFO, like so:
45
+
46
+ ```ruby
47
+ Gruf.configure do |c|
48
+ c.hook_options[:profiler] = {
49
+ log_level: :info
50
+ }
51
+ end
52
+ ```
53
+
54
+ ## License
55
+
56
+ Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
57
+
58
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
59
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
60
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
61
+ persons to whom the Software is furnished to do so, subject to the following conditions:
62
+
63
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
64
+ Software.
65
+
66
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
67
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
68
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
69
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ # Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ #
17
+ $:.push File.expand_path("../lib", __FILE__)
18
+ require 'gruf/profiler/version'
19
+
20
+ Gem::Specification.new do |spec|
21
+ spec.name = 'gruf-profiler'
22
+ spec.version = Gruf::Profiler::VERSION
23
+ spec.authors = ['Shaun McCormick']
24
+ spec.email = ['shaun.mccormick@bigcommerce.com']
25
+
26
+ spec.summary = %q{Plugin for profiling gruf-backed gRPC requests}
27
+ spec.description = %q{Adds memory reporting and rbtrace to gruf servers}
28
+ spec.homepage = 'https://github.com/bigcommerce/gruf-profiler'
29
+ spec.license = 'MIT'
30
+
31
+ spec.files = Dir['README.md', 'CHANGELOG.md', 'CODE_OF_CONDUCT.md', 'lib/**/*', 'gruf-profiler.gemspec']
32
+ spec.require_paths = ['lib']
33
+
34
+ spec.add_development_dependency 'bundler', '~> 1.11'
35
+ spec.add_development_dependency 'rake', '~> 10.0'
36
+ spec.add_development_dependency 'rspec', '~> 3.6'
37
+ spec.add_development_dependency 'pry', '~> 0'
38
+
39
+ spec.add_runtime_dependency 'stackprof', '~> 0'
40
+ spec.add_runtime_dependency 'rbtrace', '~> 0'
41
+ spec.add_runtime_dependency 'memory_profiler', '~> 0.9'
42
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ # Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ #
17
+ require_relative 'profiler/version'
18
+ require_relative 'profiler/hook'
19
+
20
+ module Gruf
21
+ ##
22
+ # Initialization class for the profiler
23
+ #
24
+ module Profiler
25
+ end
26
+ end
@@ -0,0 +1,106 @@
1
+ # coding: utf-8
2
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ # Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ #
17
+ module Gruf
18
+ module Profiler
19
+ ##
20
+ # Gruf hook that automatically loads rbtrace and memory profiler
21
+ #
22
+ # Add to your gruf initializer:
23
+ # require 'gruf/profiler'
24
+ # Gruf::Hooks::Registry.add(:profiler, Gruf::Profiler::Hook)
25
+ #
26
+ class Hook < Gruf::Hooks::Base
27
+ ##
28
+ # Initializes the hook
29
+ #
30
+ def setup
31
+ require 'rbtrace'
32
+ require 'memory_profiler'
33
+ end
34
+
35
+ ##
36
+ # Wraps the entire gruf call and provides memory reports
37
+ #
38
+ # @param [Symbol] call_signature
39
+ # @param [Object] _request
40
+ # @param [GRPC::ActiveCall] _active_call
41
+ #
42
+ def outer_around(call_signature, _request, _active_call, &_block)
43
+ result = nil
44
+ report = MemoryProfiler.report(memory_profiler_options) do
45
+ result = yield
46
+ end
47
+ if report
48
+ pp_options = memory_profiler_options.fetch(:pretty_print_options, {})
49
+ io_obj = pp_options.fetch(:io, nil)
50
+ report_string = io_obj ? report.pretty_print(io_obj, pp_options) : report.pretty_print(pp_options)
51
+ log("gruf profile for #{service_key}.#{method_key(call_signature)}:\n#{report_string}")
52
+ else
53
+ log('Memory profiler did not return a report')
54
+ end
55
+ result
56
+ end
57
+
58
+ private
59
+
60
+ ##
61
+ # Log a message with a configurable level to the gruf logger
62
+ # @param [String]
63
+ #
64
+ def log(msg)
65
+ level = options.fetch(:log_level, :debug).to_sym
66
+ Gruf.logger.send(level, msg)
67
+ end
68
+
69
+ ##
70
+ # Parse the method signature
71
+ #
72
+ # @return [String]
73
+ #
74
+ def method_key(call_signature)
75
+ "#{service_key}.#{call_signature.to_s.gsub('_without_intercept', '')}"
76
+ end
77
+
78
+ ##
79
+ # Determine a log-friendly service key name
80
+ #
81
+ # @return [String]
82
+ #
83
+ def service_key
84
+ service.class.name.underscore.tr('/', '.')
85
+ end
86
+
87
+ ##
88
+ # Get profiler options
89
+ #
90
+ # @return [Hash]
91
+ #
92
+ def options
93
+ @options.fetch(:profiler, {})
94
+ end
95
+
96
+ ##
97
+ # Get sub-options for the memory profiler
98
+ #
99
+ # @return [Hash]
100
+ #
101
+ def memory_profiler_options
102
+ options.fetch(:memory_profiler, top: 50)
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5
+ # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7
+ # persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ # Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15
+ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ #
17
+ module Gruf
18
+ module Profiler
19
+ VERSION = '0.1.0'.freeze
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gruf-profiler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shaun McCormick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: stackprof
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rbtrace
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: memory_profiler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.9'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.9'
111
+ description: Adds memory reporting and rbtrace to gruf servers
112
+ email:
113
+ - shaun.mccormick@bigcommerce.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - CHANGELOG.md
119
+ - CODE_OF_CONDUCT.md
120
+ - README.md
121
+ - gruf-profiler.gemspec
122
+ - lib/gruf/profiler.rb
123
+ - lib/gruf/profiler/hook.rb
124
+ - lib/gruf/profiler/version.rb
125
+ homepage: https://github.com/bigcommerce/gruf-profiler
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.6.12
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Plugin for profiling gruf-backed gRPC requests
149
+ test_files: []