active-record-profiler 1.2.1 → 2.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: f21bba7efa8c7b0a97c5cbb6e7f15afc0abce5f2
4
- data.tar.gz: e0cbc22689b9d89ba6e7645e8188c53fdbbc9531
3
+ metadata.gz: 5c12f1f799f5c869fcf16f72e489ac780fceec1e
4
+ data.tar.gz: 4e48ed70ce4e865c1b6455d348406758c6093a8e
5
5
  SHA512:
6
- metadata.gz: 099329047eed7c0453cc649d0cd50bbcbcb7d90da020c4849279daaee68255fd5c2c8d76b6b5dec7246272f4506d51d4f8d3f6918eb81aac63f8ce7fab4ed1a2
7
- data.tar.gz: 69b055021bc8fb38adc0f7a220ef902da16fc7faa2c6f1360f6955a1798ac3619660552c1f87836757ddda608da69606d0056422d15f4d1cb4ffe536ea96eba1
6
+ metadata.gz: 0ab8ee51d8c05c57b3e66b509c66da56950b9e0a56bcd675878139324195059c63e48035b69c1b874cb8ed3b6e2aadf0a489e140feca165289de3cea2c3bf31c
7
+ data.tar.gz: 1c85774fa1246002d9dbca6b845d87ab5adac01451fd2ea0111c96d9a6bd29641784a85939b626a6281fe36255d5398c603437ce2d61aa142f977a504380dfd5
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  test/dummy/log/*
2
2
  test/dummy/db/*.sqlite3
3
- test/dummy/tmp/*
3
+ test/dummy/tmp/*
4
+ Gemfile.lock
@@ -1 +1 @@
1
- 2.1.5
1
+ 2.2.4
@@ -1,3 +1,7 @@
1
+ # 2.0.0
2
+
3
+ * Rails 5 compatibility
4
+
1
5
  # 1.2.0
2
6
 
3
7
  * Support for registering alternate editor URL schemes (see README)
@@ -7,7 +11,7 @@
7
11
  * Add self-profiling for the logger component
8
12
  * Prevent calling a logger.add block twice in the unusual case where the block returns a nil message.
9
13
  * Convert duration in events from milliseconds to seconds (doh!). You'll want to clear old profiler data when upgrading.
10
- * Don't accumulate statistics for queries fulfilled by the CACHE
14
+ * Don't accumulate statistics for queries fulfilled by the CACHE
11
15
 
12
16
  # 1.0
13
17
 
data/README.md CHANGED
@@ -24,6 +24,12 @@ Add it to your Gemfile, like so:
24
24
  gem 'active-record-profiler'
25
25
  ```
26
26
 
27
+ If you are using a version of Rails older than 5, you'll want the 1.2 release:
28
+
29
+ ```ruby
30
+ gem 'active-record-profiler', '~> 1.2.1'
31
+ ```
32
+
27
33
  Then do `bundle install`, and then add a new initializer, `config/initializers/active_record_profiler.rb`:
28
34
 
29
35
  ```ruby
@@ -21,8 +21,8 @@ EOF
21
21
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_dependency "rails", "~> 4.0"
25
- spec.add_dependency "jquery-rails", ">= 3.1", "< 4.1"
24
+ spec.add_dependency "rails", ">= 5.0"
25
+ spec.add_dependency "jquery-rails"
26
26
 
27
27
  spec.add_development_dependency "bundler", "~> 1.3"
28
28
  spec.add_development_dependency "rake", "~> 10.3"
@@ -23,5 +23,9 @@ module ActiveRecordProfiler
23
23
  def location_description(path, line_number)
24
24
  "#{breakable_path(path)}: #{h(line_number)}".html_safe
25
25
  end
26
+
27
+ def report_params
28
+ @_report_params ||= params.permit(:sort, :date)
29
+ end
26
30
  end
27
31
  end
@@ -3,16 +3,16 @@
3
3
  <tr>
4
4
  <th class="location">Location</th>
5
5
  <th class="duration">
6
- <%= report_column_header_link(ActiveRecordProfiler::Collector::DURATION, @report_options[:sort], 'Total Duration (s)', params) %>
6
+ <%= report_column_header_link(ActiveRecordProfiler::Collector::DURATION, @report_options[:sort], 'Total Duration (s)', report_params) %>
7
7
  </th>
8
8
  <th class="count">
9
- <%= report_column_header_link(ActiveRecordProfiler::Collector::COUNT, @report_options[:sort], 'Count', params) %>
9
+ <%= report_column_header_link(ActiveRecordProfiler::Collector::COUNT, @report_options[:sort], 'Count', report_params) %>
10
10
  </th>
11
11
  <th class="average-duration">
12
- <%= report_column_header_link(ActiveRecordProfiler::Collector::AVG_DURATION, @report_options[:sort], 'Avg. Duration (ms)', params) %>
12
+ <%= report_column_header_link(ActiveRecordProfiler::Collector::AVG_DURATION, @report_options[:sort], 'Avg. Duration (ms)', report_params) %>
13
13
  </th>
14
14
  <th class="max-duration">
15
- <%= report_column_header_link(ActiveRecordProfiler::Collector::LONGEST, @report_options[:sort], 'Max. Duration (ms)', params) %>
15
+ <%= report_column_header_link(ActiveRecordProfiler::Collector::LONGEST, @report_options[:sort], 'Max. Duration (ms)', report_params) %>
16
16
  </th>
17
17
  <th class="max-duration-sql">SQL for Max Duration</th>
18
18
  </tr>
@@ -4,5 +4,6 @@ ActiveRecordProfiler.sql_ignore_pattern =
4
4
  /^(SHOW (:?FULL )?FIELDS |SET SQL_AUTO_IS_NULL|SET NAMES |EXPLAIN |BEGIN|COMMIT|PRAGMA )/i
5
5
  ActiveRecordProfiler.app_path_pattern = Regexp.new(Regexp.quote("#{Rails.root.expand_path}/") + "(:?app|lib|vendor)/")
6
6
  ActiveRecordProfiler.trim_root_path = "#{Rails.root.expand_path}/"
7
+ ActiveRecordProfiler.trim_cache_id_pattern = /___?[0-9]+_[0-9]+(?=')/
7
8
  ActiveRecordProfiler.profile_self = false
8
9
  ActiveRecordProfiler.link_location = false
@@ -7,8 +7,9 @@ require "active-record-profiler/engine" if defined?(Rails)
7
7
  module ActiveRecordProfiler
8
8
  require 'fileutils'
9
9
  require 'json'
10
-
11
- mattr_accessor :link_location, :stats_flush_period, :profile_dir,
12
- :sql_ignore_pattern, :app_path_pattern, :trim_root_path, :profile_self
10
+
11
+ mattr_accessor :link_location, :stats_flush_period, :profile_dir,
12
+ :sql_ignore_pattern, :app_path_pattern, :trim_root_path,
13
+ :trim_cache_id_pattern, :profile_self
13
14
  end
14
15
 
@@ -42,7 +42,11 @@ module ActiveRecordProfiler
42
42
 
43
43
  # This prefix will be removed from location names, for brevity.
44
44
  cattr_accessor :trim_root_path
45
-
45
+
46
+ # This pattern will be removed from location names, to remove cache ids that change
47
+ # when templates are recompiled.
48
+ cattr_accessor :trim_cache_id_pattern
49
+
46
50
  # Controls whether or not to record profiling data for time spent in the
47
51
  # profiler code itself.
48
52
  cattr_accessor :profile_self
@@ -188,8 +192,8 @@ module ActiveRecordProfiler
188
192
  protected
189
193
 
190
194
  def find_app_call_location(call_stack)
191
- call_stack = caller
192
- while frame = call_stack.shift
195
+ call_stack ||= caller(2)
196
+ call_stack.each do |frame|
193
197
  if app_path_pattern.match(frame)
194
198
  return trim_location(frame)
195
199
  end
@@ -198,7 +202,7 @@ module ActiveRecordProfiler
198
202
  end
199
203
 
200
204
  def trim_location(loc)
201
- loc.sub(trim_root_path, '')
205
+ loc.sub(trim_root_path, '').sub(trim_cache_id_pattern, '')
202
206
  end
203
207
 
204
208
  def update_counts(location, seconds, count, sql, longest = nil)
@@ -8,10 +8,12 @@ module ActiveRecordProfiler
8
8
 
9
9
  initializer "active_record_profiler.apply_default" do
10
10
  # Copy module settings to collector class
11
- [:stats_flush_period, :profile_dir, :sql_ignore_pattern,
12
- :app_path_pattern, :trim_root_path, :profile_self
11
+ [
12
+ :stats_flush_period, :profile_dir, :sql_ignore_pattern,
13
+ :app_path_pattern, :trim_root_path, :trim_cache_id_pattern,
14
+ :profile_self
13
15
  ].each do |config_item|
14
- ActiveRecordProfiler::Collector.send("#{config_item}=".to_sym,
16
+ ActiveRecordProfiler::Collector.send("#{config_item}=".to_sym,
15
17
  ActiveRecordProfiler.send(config_item))
16
18
  end
17
19
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordProfiler
2
- VERSION = "1.2.1"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -0,0 +1,41 @@
1
+ require 'test_helper.rb'
2
+
3
+ module ActiveRecordProfiler
4
+ class CollectorTest < ActiveSupport::TestCase
5
+ def setup
6
+ @test_log = StringIO.new
7
+ ActiveRecord::Base.logger = ActiveSupport::Logger.new(@test_log)
8
+ end
9
+
10
+ def test_template_path_removes_app_root
11
+ stack_locations = [
12
+ "/var/deploy/current/app/views/users/_row.html.erb:34:in `_app_views_users__row_html_erb___3709568271919910637_70125680359900'",
13
+ "/var/deploy/current/app/views/users/index.html.erb:34:in `_app_views_users_index_html_erb__1553888856029099377_70230900703660'",
14
+ "/var/deploy/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/actionview-5.1.4/lib/action_view/template.rb:352:in `instrument_render_template'",
15
+ ]
16
+ location = app_collector.call_location_name(stack_locations)
17
+
18
+ assert_match(%r{\A/app/views/users/_row.html.erb:34:in `}, location)
19
+ end
20
+
21
+ def test_template_path_includes_only_real_path_components
22
+ stack_locations = [
23
+ "/var/deploy/current/app/views/users/_row.html.erb:34:in `_app_views_users__row_html_erb___3709568271919910637_70125680359900'",
24
+ "/var/deploy/current/app/views/users/index.html.erb:34:in `_app_views_users_index_html_erb__1553888856029099377_70230900703660'",
25
+ "/var/deploy/rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/actionview-5.1.4/lib/action_view/template.rb:352:in `instrument_render_template'",
26
+ ]
27
+ location = app_collector.call_location_name(stack_locations)
28
+
29
+ assert_match(/in `.*app.*views.*users.*row.*html.*erb'\z/, location)
30
+ end
31
+
32
+ private
33
+
34
+ def app_collector(app_root: "/var/deploy/current")
35
+ @app_collector ||= Collector.new.tap do |collector|
36
+ collector.app_path_pattern = Regexp.new(Regexp.quote("/var/deploy/current"))
37
+ collector.trim_root_path = "/var/deploy/current"
38
+ end
39
+ end
40
+ end
41
+ end
@@ -7,13 +7,13 @@ class ActiveRecordProfilerTest < ActiveSupport::TestCase
7
7
  ActiveRecord::Base.logger = ActiveRecordProfiler::Logger.new(
8
8
  ActiveSupport::Logger.new(@test_log))
9
9
  end
10
-
10
+
11
11
  def test_caller_location_appears_in_log
12
12
  sql = 'SELECT 1 FROM widgets'
13
13
  ActiveRecord::Base.connection.select_value(sql)
14
14
  @test_log.rewind
15
15
  log_data = @test_log.read
16
- assert_match Regexp.new(Regexp.quote(sql) + '.*' + Regexp.quote('active_record_profiler_test.rb')), log_data
16
+ assert_match Regexp.new(Regexp.quote(sql)), log_data
17
17
  end
18
18
 
19
19
  def test_profiler_records_query_site
@@ -17,9 +17,6 @@ module Dummy
17
17
  # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
18
18
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
19
19
  # config.i18n.default_locale = :de
20
-
21
- # Do not swallow errors in after_commit/after_rollback callbacks.
22
- config.active_record.raise_in_transactional_callbacks = true
23
20
  end
24
21
  end
25
22
 
metadata CHANGED
@@ -1,49 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-record-profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Turner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-20 00:00:00.000000000 Z
11
+ date: 2018-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '5.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: '4.0'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: jquery-rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '3.1'
34
- - - "<"
35
- - !ruby/object:Gem::Version
36
- version: '4.1'
33
+ version: '0'
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
38
  - - ">="
42
39
  - !ruby/object:Gem::Version
43
- version: '3.1'
44
- - - "<"
45
- - !ruby/object:Gem::Version
46
- version: '4.1'
40
+ version: '0'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: bundler
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -140,6 +134,7 @@ files:
140
134
  - lib/active-record-profiler/version.rb
141
135
  - screenshots/enhanced-log.png
142
136
  - screenshots/web-reports.png
137
+ - test/active_record_profiler/collector_test.rb
143
138
  - test/active_record_profiler_test.rb
144
139
  - test/database.yml
145
140
  - test/dummy/README.rdoc
@@ -213,11 +208,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
208
  version: '0'
214
209
  requirements: []
215
210
  rubyforge_project:
216
- rubygems_version: 2.4.5
211
+ rubygems_version: 2.6.13
217
212
  signing_key:
218
213
  specification_version: 4
219
214
  summary: Enhances ActiveRecord logging and profiles queries
220
215
  test_files:
216
+ - test/active_record_profiler/collector_test.rb
221
217
  - test/active_record_profiler_test.rb
222
218
  - test/database.yml
223
219
  - test/dummy/README.rdoc