gruf-profiler 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46bfbb7bd1631ffae355f4a520b5bbf9574f6dde
4
- data.tar.gz: 0f7e4c1a87264e8be7d683f6c6610020ab1da207
3
+ metadata.gz: c9c14f9f878d1d5ce008eebb556adc64de1cde19
4
+ data.tar.gz: cf0e4090eb21bb266b796a89fb2b0d756c640355
5
5
  SHA512:
6
- metadata.gz: cbc0f155cf7070e1346bbc8f2554e7887654f35769d2e29885264cfd3da627b611b0b654af90de0bd92e8e046cf7d1a912787811df5238deeb309b9252b94702
7
- data.tar.gz: f8339f9b59ba2519f5ba8ab07ebe15d382379089040b2216dd06ca1b41183fef58c6a8a28afaa4c09a7b9fafd5cec30da077f6d82bf3616f603feb0668d25670
6
+ metadata.gz: fb30135dd11b0b76cc4e7ccc22fd19d4aefeea049af33d26495b59139f7e6a8818416b33346456da7f89d6eaa4102304016111a3808dc5aa14911eca63af9a1c
7
+ data.tar.gz: c5b5907e9ad2790f8e9164c8866fd379bfcf7ce4d75d26e73af1e87edde8bd3eca47f51337e02f8ecb151bd36310fcda04d677161c944ce293a6e05ff381dbab
@@ -1,5 +1,9 @@
1
1
  Changelog for the gruf-profiler gem.
2
2
 
3
+ h3. 1.0.0
4
+
5
+ - Support for gruf 2.0
6
+
3
7
  h3. 0.1.0
4
8
 
5
9
  - Add rubocop
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # gruf-profiler - Profiler for gruf
2
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)
3
+ [![Build Status](https://travis-ci.org/bigcommerce/gruf-profiler.svg?branch=master)](https://travis-ci.org/bigcommerce/gruf-profiler) [![Gem Version](https://badge.fury.io/rb/gruf-profiler.svg)](https://badge.fury.io/rb/gruf-profiler) [![Inline docs](http://inch-ci.org/github/bigcommerce/gruf-profiler.svg?branch=master)](http://inch-ci.org/github/bigcommerce/gruf-profiler)
4
4
 
5
- Adds a profiler for [gruf](https://github.com/bigcommerce/gruf) 1.0.0 or later.
5
+ Adds a profiler interceptor for [gruf](https://github.com/bigcommerce/gruf) 2.0.0 or later.
6
6
 
7
7
  ## Installation
8
8
 
@@ -14,7 +14,10 @@ Then in an initializer or before use, after loading gruf:
14
14
 
15
15
  ```ruby
16
16
  require 'gruf/profiler'
17
- Gruf::Hooks::Registry.add(:profiler, Gruf::Profiler::Hook)
17
+
18
+ Gruf.configure do |c|
19
+ c.interceptors[Gruf::Profiler::Interceptor] = {}
20
+ end
18
21
  ```
19
22
 
20
23
  ## Usage
@@ -45,7 +48,7 @@ You can adjust that log level to say, INFO, like so:
45
48
 
46
49
  ```ruby
47
50
  Gruf.configure do |c|
48
- c.hook_options[:profiler] = {
51
+ c.interceptors[Gruf::Profiler::Interceptor] = {
49
52
  log_level: :info
50
53
  }
51
54
  end
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
2
  #
4
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
@@ -15,8 +14,11 @@
15
14
  # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
15
  #
17
16
  require_relative 'profiler/version'
18
- require_relative 'profiler/hook'
17
+ require_relative 'profiler/interceptor'
19
18
 
19
+ ##
20
+ # Base gruf module
21
+ #
20
22
  module Gruf
21
23
  ##
22
24
  # Initialization class for the profiler
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
2
  #
4
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
@@ -14,6 +13,9 @@
14
13
  # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15
14
  # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
15
  #
16
+ require 'rbtrace'
17
+ require 'memory_profiler'
18
+
17
19
  module Gruf
18
20
  module Profiler
19
21
  ##
@@ -21,34 +23,21 @@ module Gruf
21
23
  #
22
24
  # Add to your gruf initializer:
23
25
  # require 'gruf/profiler'
24
- # Gruf::Hooks::Registry.add(:profiler, Gruf::Profiler::Hook)
26
+ # Gruf.configure do |c|
27
+ # c.interceptors[Gruf::Profiler::Interceptor] = {}
28
+ # end
25
29
  #
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
-
30
+ class Interceptor < Gruf::Interceptors::ServerInterceptor
35
31
  ##
36
32
  # Wraps the entire gruf call and provides memory reports
37
33
  #
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)
34
+ def call
43
35
  result = nil
44
36
  report = MemoryProfiler.report(memory_profiler_options) do
45
37
  result = yield
46
38
  end
47
39
  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}")
40
+ profile(report)
52
41
  else
53
42
  log('Memory profiler did not return a report')
54
43
  end
@@ -58,48 +47,41 @@ module Gruf
58
47
  private
59
48
 
60
49
  ##
61
- # Log a message with a configurable level to the gruf logger
62
- # @param [String]
50
+ # Profile the given report to logs
63
51
  #
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
52
+ # @param [MemoryProfiler::Reporter] report
71
53
  #
72
- # @return [String]
73
- #
74
- def method_key(call_signature)
75
- "#{service_key}.#{call_signature.to_s.gsub('_without_intercept', '')}"
54
+ def profile(report)
55
+ io_obj = pretty_print_options.fetch(:io, nil)
56
+ report_string = io_obj ? report.pretty_print(io_obj, pretty_print_options) : report.pretty_print(pretty_print_options)
57
+ log("gruf profile for #{request.method_name}:\n#{report_string}")
76
58
  end
77
59
 
78
60
  ##
79
- # Determine a log-friendly service key name
80
- #
81
- # @return [String]
61
+ # Log a message with a configurable level to the gruf logger
62
+ # @param [String]
82
63
  #
83
- def service_key
84
- service.class.name.underscore.tr('/', '.')
64
+ def log(msg)
65
+ level = options.fetch(:log_level, :debug).to_sym
66
+ Gruf.logger.send(level, msg)
85
67
  end
86
68
 
87
69
  ##
88
- # Get profiler options
70
+ # Get sub-options for the memory profiler
89
71
  #
90
72
  # @return [Hash]
91
73
  #
92
- def options
93
- @options.fetch(:profiler, {})
74
+ def memory_profiler_options
75
+ options.fetch(:memory_profiler, top: 50)
94
76
  end
95
77
 
96
78
  ##
97
- # Get sub-options for the memory profiler
79
+ # Get sub-options for pretty printing
98
80
  #
99
81
  # @return [Hash]
100
82
  #
101
- def memory_profiler_options
102
- options.fetch(:memory_profiler, top: 50)
83
+ def pretty_print_options
84
+ memory_profiler_options.fetch(:pretty_print_options, {})
103
85
  end
104
86
  end
105
87
  end
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  # Copyright (c) 2017-present, BigCommerce Pty. Ltd. All rights reserved
3
2
  #
4
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
@@ -16,6 +15,6 @@
16
15
  #
17
16
  module Gruf
18
17
  module Profiler
19
- VERSION = '0.1.0'.freeze
18
+ VERSION = '1.0.0'.freeze
20
19
  end
21
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gruf-profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun McCormick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-13 00:00:00.000000000 Z
11
+ date: 2017-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -120,7 +120,7 @@ files:
120
120
  - README.md
121
121
  - gruf-profiler.gemspec
122
122
  - lib/gruf/profiler.rb
123
- - lib/gruf/profiler/hook.rb
123
+ - lib/gruf/profiler/interceptor.rb
124
124
  - lib/gruf/profiler/version.rb
125
125
  homepage: https://github.com/bigcommerce/gruf-profiler
126
126
  licenses: