gruf-profiler 0.1.0 → 1.0.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +7 -4
- data/lib/gruf/profiler.rb +4 -2
- data/lib/gruf/profiler/{hook.rb → interceptor.rb} +26 -44
- data/lib/gruf/profiler/version.rb +1 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9c14f9f878d1d5ce008eebb556adc64de1cde19
|
4
|
+
data.tar.gz: cf0e4090eb21bb266b796a89fb2b0d756c640355
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb30135dd11b0b76cc4e7ccc22fd19d4aefeea049af33d26495b59139f7e6a8818416b33346456da7f89d6eaa4102304016111a3808dc5aa14911eca63af9a1c
|
7
|
+
data.tar.gz: c5b5907e9ad2790f8e9164c8866fd379bfcf7ce4d75d26e73af1e87edde8bd3eca47f51337e02f8ecb151bd36310fcda04d677161c944ce293a6e05ff381dbab
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# gruf-profiler - Profiler for gruf
|
2
2
|
|
3
|
-
[](https://travis-ci.org/bigcommerce/gruf-profiler) [](http://inch-ci.org/github/bigcommerce/gruf-profiler)
|
3
|
+
[](https://travis-ci.org/bigcommerce/gruf-profiler) [](https://badge.fury.io/rb/gruf-profiler) [](http://inch-ci.org/github/bigcommerce/gruf-profiler)
|
4
4
|
|
5
|
-
Adds a profiler for [gruf](https://github.com/bigcommerce/gruf)
|
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
|
-
|
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.
|
51
|
+
c.interceptors[Gruf::Profiler::Interceptor] = {
|
49
52
|
log_level: :info
|
50
53
|
}
|
51
54
|
end
|
data/lib/gruf/profiler.rb
CHANGED
@@ -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/
|
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
|
26
|
+
# Gruf.configure do |c|
|
27
|
+
# c.interceptors[Gruf::Profiler::Interceptor] = {}
|
28
|
+
# end
|
25
29
|
#
|
26
|
-
class
|
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
|
-
|
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
|
-
|
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
|
-
#
|
62
|
-
# @param [String]
|
50
|
+
# Profile the given report to logs
|
63
51
|
#
|
64
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
75
|
-
"#{
|
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
|
-
#
|
80
|
-
#
|
81
|
-
# @return [String]
|
61
|
+
# Log a message with a configurable level to the gruf logger
|
62
|
+
# @param [String]
|
82
63
|
#
|
83
|
-
def
|
84
|
-
|
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
|
70
|
+
# Get sub-options for the memory profiler
|
89
71
|
#
|
90
72
|
# @return [Hash]
|
91
73
|
#
|
92
|
-
def
|
93
|
-
|
74
|
+
def memory_profiler_options
|
75
|
+
options.fetch(:memory_profiler, top: 50)
|
94
76
|
end
|
95
77
|
|
96
78
|
##
|
97
|
-
# Get sub-options for
|
79
|
+
# Get sub-options for pretty printing
|
98
80
|
#
|
99
81
|
# @return [Hash]
|
100
82
|
#
|
101
|
-
def
|
102
|
-
|
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 = '
|
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:
|
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-
|
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/
|
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:
|