active-profiling 0.1.2 → 2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5722 -0
- data/.rubocop_todo.yml +20 -0
- data/FUNDING.yml +2 -0
- data/Gemfile +6 -7
- data/MIT-LICENSE +1 -1
- data/Rakefile +2 -4
- data/active-profiling.gemspec +18 -15
- data/lib/active-profiling/action_controller/action_profiling.rb +7 -10
- data/lib/active-profiling/action_controller/log_subscriber.rb +17 -18
- data/lib/active-profiling/action_controller.rb +1 -0
- data/lib/active-profiling/active_record/backtrace_log_subscriber.rb +16 -14
- data/lib/active-profiling/active_record.rb +1 -1
- data/lib/active-profiling/gc_statistics.rb +14 -19
- data/lib/active-profiling/railtie.rb +19 -18
- data/lib/active-profiling/ruby_profiler/output.rb +102 -108
- data/lib/active-profiling/ruby_profiler.rb +2 -1
- data/lib/active-profiling/version.rb +2 -1
- data/lib/active-profiling.rb +1 -1
- metadata +15 -11
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
module ActiveProfiling
|
3
4
|
module RubyProfiler
|
@@ -6,16 +7,13 @@ module ActiveProfiling
|
|
6
7
|
@options = Rails.application.config.active_profiling.profiler.merge(args.extract_options!)
|
7
8
|
@path = args.first
|
8
9
|
|
9
|
-
@output =
|
10
|
-
@options[:output]
|
11
|
-
else
|
10
|
+
@output = @options[:output] ||
|
12
11
|
case @options[:printer]
|
13
12
|
when :call_tree, :call_stack, :graph_html, :dot
|
14
13
|
:file
|
15
14
|
else
|
16
15
|
:log
|
17
16
|
end
|
18
|
-
end
|
19
17
|
end
|
20
18
|
|
21
19
|
def run
|
@@ -27,11 +25,9 @@ module ActiveProfiling
|
|
27
25
|
result = nil
|
28
26
|
exception = nil
|
29
27
|
@profiler_result = RubyProf.profile do
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
exception = $!
|
34
|
-
end
|
28
|
+
result = yield
|
29
|
+
rescue StandardError
|
30
|
+
exception = $ERROR_INFO
|
35
31
|
end
|
36
32
|
|
37
33
|
case @output
|
@@ -43,129 +39,127 @@ module ActiveProfiling
|
|
43
39
|
write_to_file_or_path
|
44
40
|
end
|
45
41
|
|
46
|
-
if exception
|
47
|
-
|
48
|
-
|
49
|
-
result
|
50
|
-
end
|
42
|
+
raise exception if exception
|
43
|
+
|
44
|
+
result
|
51
45
|
ensure
|
52
46
|
GC.enable if @options[:disable_gc]
|
53
47
|
end
|
54
48
|
|
55
49
|
private
|
56
50
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
else
|
62
|
-
RubyProf.const_get("#{@options[:printer].to_s.camelize}Printer")
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def path_and_file_name
|
67
|
-
return @path_and_file_name if defined?(@path_and_file_name)
|
68
|
-
|
69
|
-
if @path.present?
|
70
|
-
{ path: File.dirname(@path), file_name: @path }
|
71
|
-
elsif @options[:file_name]
|
72
|
-
{ path: File.dirname(@options[:file_name]), file_name: @options[:file_name] }
|
73
|
-
else
|
74
|
-
time = Time.now.strftime('%Y-%m-%d-%H:%M:%S')
|
75
|
-
hash = Digest::MD5.hexdigest(rand.to_s)[0..6]
|
76
|
-
path = Rails.root.join('log/profiling')
|
77
|
-
ext = case @options[:printer]
|
78
|
-
when :graph_html, :call_stack
|
79
|
-
'html'
|
80
|
-
when :dot
|
81
|
-
'dot'
|
51
|
+
def printer_class
|
52
|
+
@printer_class ||= case @options[:printer]
|
53
|
+
when :flat_with_line_numbers
|
54
|
+
RubyProf::FlatPrinterWithLineNumbers
|
82
55
|
else
|
83
|
-
|
56
|
+
RubyProf.const_get("#{@options[:printer].to_s.camelize}Printer")
|
84
57
|
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def path_and_file_name
|
61
|
+
return @path_and_file_name if defined?(@path_and_file_name)
|
85
62
|
|
86
|
-
|
87
|
-
@
|
88
|
-
|
89
|
-
@options[:
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
63
|
+
if @path.present?
|
64
|
+
{ path: File.dirname(@path), file_name: @path }
|
65
|
+
elsif @options[:file_name]
|
66
|
+
{ path: File.dirname(@options[:file_name]), file_name: @options[:file_name] }
|
67
|
+
else
|
68
|
+
time = Time.zone.now.strftime('%Y-%m-%d-%H:%M:%S')
|
69
|
+
hash = Digest::MD5.hexdigest(rand.to_s)[0..6]
|
70
|
+
path = Rails.root.join('log/profiling')
|
71
|
+
ext = case @options[:printer]
|
72
|
+
when :graph_html, :call_stack
|
73
|
+
'html'
|
74
|
+
when :dot
|
75
|
+
'dot'
|
76
|
+
else
|
77
|
+
'log'
|
78
|
+
end
|
79
|
+
|
80
|
+
file_name = [
|
81
|
+
@options[:name],
|
82
|
+
@options[:measure_mode],
|
83
|
+
@options[:printer],
|
84
|
+
time,
|
85
|
+
hash,
|
86
|
+
ext
|
87
|
+
].join('.')
|
88
|
+
|
89
|
+
@path_and_file_name = {
|
90
|
+
path: path.to_s,
|
91
|
+
file_name: path.join(file_name)
|
92
|
+
}
|
93
|
+
end
|
99
94
|
end
|
100
|
-
end
|
101
95
|
|
102
|
-
|
103
|
-
|
104
|
-
|
96
|
+
def write_to_stdout
|
97
|
+
printer_class.new(@profiler_result).print($stdout, @options)
|
98
|
+
end
|
105
99
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
100
|
+
def write_to_log
|
101
|
+
str = StringIO.new
|
102
|
+
printer_class.new(@profiler_result).print(str, @options[:printer_options])
|
103
|
+
str.rewind
|
110
104
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
105
|
+
ActiveSupport::Notifications.instrument('profiler_output.active_profiling', {
|
106
|
+
profiler_output: str.read,
|
107
|
+
title: @options[:title] || @path
|
108
|
+
})
|
109
|
+
end
|
116
110
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
111
|
+
def write_to_file_or_path
|
112
|
+
if call_tree_printer_file_output?
|
113
|
+
write_to_path
|
114
|
+
else
|
115
|
+
write_to_file
|
116
|
+
end
|
122
117
|
end
|
123
|
-
end
|
124
118
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
119
|
+
def write_to_file
|
120
|
+
ActiveSupport::Notifications.instrument('profiler_output_to_file.active_profiling', {
|
121
|
+
file_name: path_and_file_name[:file_name]
|
122
|
+
})
|
129
123
|
|
130
|
-
|
131
|
-
|
132
|
-
|
124
|
+
FileUtils.mkdir_p(path_and_file_name[:path])
|
125
|
+
printer_class.new(@profiler_result).print(File.open(path_and_file_name[:file_name], 'w'), @options[:printer_options])
|
126
|
+
end
|
133
127
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
128
|
+
def write_to_path
|
129
|
+
ActiveSupport::Notifications.instrument('profiler_output_to_file.active_profiling', {
|
130
|
+
file_name: path_and_file_name[:path]
|
131
|
+
})
|
138
132
|
|
139
|
-
|
140
|
-
|
141
|
-
|
133
|
+
FileUtils.mkdir_p(path_and_file_name[:path])
|
134
|
+
printer_class.new(@profiler_result).print(merged_printer_options(path_and_file_name))
|
135
|
+
end
|
142
136
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
137
|
+
def call_tree_prefix_option
|
138
|
+
# XXX - Bit of a hack here -- newer versions of RubyProf have changed
|
139
|
+
# the method signature of CallTreePrinter#print and changed how the
|
140
|
+
# generated files are prefixed. To accomodate call tree viewers like
|
141
|
+
# [KQ]CacheGrind, we need to hack in an appropriate file prefix.
|
142
|
+
if call_tree_printer_file_output?
|
143
|
+
@options[:call_tree_prefix].try(:gsub, /\.$/, '')
|
144
|
+
else
|
145
|
+
@options[:call_tree_prefix]
|
146
|
+
end
|
152
147
|
end
|
153
|
-
end
|
154
148
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
149
|
+
def merged_printer_options(path_and_file_name)
|
150
|
+
if @options[:printer] == :call_tree && @output == :file
|
151
|
+
@options[:printer_options].merge(
|
152
|
+
profile: call_tree_prefix_option,
|
153
|
+
path: path_and_file_name[:path]
|
154
|
+
)
|
155
|
+
else
|
156
|
+
@options[:printer_options]
|
157
|
+
end
|
163
158
|
end
|
164
|
-
end
|
165
159
|
|
166
|
-
|
167
|
-
|
168
|
-
|
160
|
+
def call_tree_printer_file_output?
|
161
|
+
printer_class.instance_method(:print).arity == -1 && printer_class == RubyProf::CallTreePrinter
|
162
|
+
end
|
169
163
|
end
|
170
164
|
end
|
171
165
|
end
|
data/lib/active-profiling.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
module ActiveProfiling
|
3
4
|
class << self
|
@@ -24,4 +25,3 @@ require 'active-profiling/gc_statistics'
|
|
24
25
|
require 'active-profiling/ruby_profiler'
|
25
26
|
require 'active-profiling/action_controller'
|
26
27
|
require 'active-profiling/active_record'
|
27
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active-profiling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0
|
4
|
+
version: '2.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- J Smith
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '6.0'
|
27
27
|
description: A Rails profiling suite.
|
28
28
|
email: dark.panda@gmail.com
|
29
29
|
executables: []
|
@@ -32,7 +32,10 @@ extra_rdoc_files:
|
|
32
32
|
- README.rdoc
|
33
33
|
files:
|
34
34
|
- ".gitignore"
|
35
|
+
- ".rubocop.yml"
|
36
|
+
- ".rubocop_todo.yml"
|
35
37
|
- ".sonarcloud.properties"
|
38
|
+
- FUNDING.yml
|
36
39
|
- Gemfile
|
37
40
|
- MIT-LICENSE
|
38
41
|
- README.rdoc
|
@@ -49,11 +52,12 @@ files:
|
|
49
52
|
- lib/active-profiling/ruby_profiler.rb
|
50
53
|
- lib/active-profiling/ruby_profiler/output.rb
|
51
54
|
- lib/active-profiling/version.rb
|
52
|
-
homepage:
|
55
|
+
homepage: https://github.com/dark-panda/active-profiling
|
53
56
|
licenses:
|
54
57
|
- MIT
|
55
|
-
metadata:
|
56
|
-
|
58
|
+
metadata:
|
59
|
+
rubygems_mfa_required: 'true'
|
60
|
+
post_install_message:
|
57
61
|
rdoc_options: []
|
58
62
|
require_paths:
|
59
63
|
- lib
|
@@ -61,15 +65,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
65
|
requirements:
|
62
66
|
- - ">="
|
63
67
|
- !ruby/object:Gem::Version
|
64
|
-
version: '0'
|
68
|
+
version: '3.0'
|
65
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
70
|
requirements:
|
67
71
|
- - ">="
|
68
72
|
- !ruby/object:Gem::Version
|
69
73
|
version: '0'
|
70
74
|
requirements: []
|
71
|
-
rubygems_version: 3.
|
72
|
-
signing_key:
|
75
|
+
rubygems_version: 3.4.10
|
76
|
+
signing_key:
|
73
77
|
specification_version: 4
|
74
78
|
summary: A Rails profiling suite.
|
75
79
|
test_files: []
|