active-profiling 0.1.2 → 2.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.
@@ -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 = if @options[: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
- begin
31
- result = yield
32
- rescue
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
- raise exception
48
- else
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
- def printer_class
58
- @printer_class ||= case @options[:printer]
59
- when :flat_with_line_numbers
60
- RubyProf::FlatPrinterWithLineNumbers
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
- 'log'
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
- file_name = [
87
- @options[:name],
88
- @options[:measure_mode],
89
- @options[:printer],
90
- time,
91
- hash,
92
- ext
93
- ].join('.')
94
-
95
- @path_and_file_name = {
96
- path: path.to_s,
97
- file_name: path.join(file_name)
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
- def write_to_stdout
103
- printer_class.new(@profiler_result).print($stdout, @options)
104
- end
96
+ def write_to_stdout
97
+ printer_class.new(@profiler_result).print($stdout, @options)
98
+ end
105
99
 
106
- def write_to_log
107
- str = StringIO.new
108
- printer_class.new(@profiler_result).print(str, @options[:printer_options])
109
- str.rewind
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
- ActiveSupport::Notifications.instrument('profiler_output.active_profiling', {
112
- :profiler_output => str.read,
113
- :title => @options[:title] || @path
114
- })
115
- end
105
+ ActiveSupport::Notifications.instrument('profiler_output.active_profiling', {
106
+ profiler_output: str.read,
107
+ title: @options[:title] || @path
108
+ })
109
+ end
116
110
 
117
- def write_to_file_or_path
118
- if call_tree_printer_file_output?
119
- write_to_path
120
- else
121
- write_to_file
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
- def write_to_file
126
- ActiveSupport::Notifications.instrument('profiler_output_to_file.active_profiling', {
127
- :file_name => path_and_file_name[:file_name]
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
- FileUtils.mkdir_p(path_and_file_name[:path])
131
- printer_class.new(@profiler_result).print(File.open(path_and_file_name[:file_name], 'w'), @options[:printer_options])
132
- end
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
- def write_to_path
135
- ActiveSupport::Notifications.instrument('profiler_output_to_file.active_profiling', {
136
- :file_name => path_and_file_name[:path]
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
- FileUtils.mkdir_p(path_and_file_name[:path])
140
- printer_class.new(@profiler_result).print(merged_printer_options(path_and_file_name))
141
- end
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
- def call_tree_prefix_option
144
- # XXX - Bit of a hack here -- newer versions of RubyProf have changed
145
- # the method signature of CallTreePrinter#print and changed how the
146
- # generated files are prefixed. To accomodate call tree viewers like
147
- # [KQ]CacheGrind, we need to hack in an appropriate file prefix.
148
- if call_tree_printer_file_output?
149
- @options[:call_tree_prefix].try(:gsub, /\.$/, '')
150
- else
151
- @options[:call_tree_prefix]
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
- def merged_printer_options(path_and_file_name)
156
- if @options[:printer] == :call_tree && @output == :file
157
- @options[:printer_options].merge(
158
- profile: call_tree_prefix_option,
159
- path: path_and_file_name[:path]
160
- )
161
- else
162
- @options[:printer_options]
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
- def call_tree_printer_file_output?
167
- printer_class.instance_method(:print).arity == -1 && printer_class == RubyProf::CallTreePrinter
168
- end
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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  require 'active-profiling/ruby_profiler/output'
3
4
 
@@ -16,5 +17,5 @@ module ActiveProfiling
16
17
  end
17
18
  end
18
19
 
19
- self.extend(RubyProfiler)
20
+ extend(RubyProfiler)
20
21
  end
@@ -1,4 +1,5 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module ActiveProfiling
3
- VERSION = '0.1.2'.freeze
4
+ VERSION = '2.0'
4
5
  end
@@ -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.1.2
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: 2020-03-25 00:00:00.000000000 Z
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: '3.0'
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: '3.0'
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: http://github.com/dark-panda/active-profiling
55
+ homepage: https://github.com/dark-panda/active-profiling
53
56
  licenses:
54
57
  - MIT
55
- metadata: {}
56
- post_install_message:
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.1.2
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: []