rack-mini-profiler 0.10.7 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/README.md +7 -19
  4. data/lib/generators/rack_profiler/install_generator.rb +2 -0
  5. data/lib/generators/rack_profiler/templates/rack_profiler.rb +2 -0
  6. data/lib/html/includes.js +27 -22
  7. data/lib/mini_profiler/asset_version.rb +1 -1
  8. data/lib/mini_profiler/client_settings.rb +4 -0
  9. data/lib/mini_profiler/config.rb +46 -41
  10. data/lib/mini_profiler/context.rb +2 -0
  11. data/lib/mini_profiler/gc_profiler.rb +2 -0
  12. data/lib/mini_profiler/profiler.rb +14 -11
  13. data/lib/mini_profiler/profiling_methods.rb +2 -0
  14. data/lib/mini_profiler/storage/abstract_store.rb +2 -0
  15. data/lib/mini_profiler/storage/file_store.rb +3 -1
  16. data/lib/mini_profiler/storage/memcache_store.rb +2 -0
  17. data/lib/mini_profiler/storage/memory_store.rb +4 -2
  18. data/lib/mini_profiler/storage/redis_store.rb +2 -0
  19. data/lib/mini_profiler/timer_struct/base.rb +2 -0
  20. data/lib/mini_profiler/timer_struct/client.rb +3 -1
  21. data/lib/mini_profiler/timer_struct/custom.rb +2 -0
  22. data/lib/mini_profiler/timer_struct/page.rb +7 -3
  23. data/lib/mini_profiler/timer_struct/request.rb +2 -0
  24. data/lib/mini_profiler/timer_struct/sql.rb +2 -1
  25. data/lib/mini_profiler/version.rb +3 -1
  26. data/lib/mini_profiler_rails/railtie.rb +3 -1
  27. data/lib/patches/db/activerecord.rb +2 -0
  28. data/lib/patches/db/mongo.rb +2 -0
  29. data/lib/patches/db/moped.rb +2 -0
  30. data/lib/patches/db/mysql2.rb +2 -0
  31. data/lib/patches/db/neo4j.rb +2 -0
  32. data/lib/patches/db/nobrainer.rb +3 -1
  33. data/lib/patches/db/oracle_enhanced.rb +2 -0
  34. data/lib/patches/db/pg.rb +2 -0
  35. data/lib/patches/db/plucky.rb +2 -0
  36. data/lib/patches/db/riak.rb +2 -0
  37. data/lib/patches/db/rsolr.rb +3 -1
  38. data/lib/patches/db/sequel.rb +2 -0
  39. data/lib/patches/net_patches.rb +2 -0
  40. data/lib/patches/sql_patches.rb +2 -0
  41. data/lib/rack-mini-profiler.rb +2 -2
  42. data/rack-mini-profiler.gemspec +1 -1
  43. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00a128037529807d7766b5879fbe52bb08e166b4
4
- data.tar.gz: 0b50933b899ed619bea7c18e08f8448795d4634d
3
+ metadata.gz: 3ece809a3861e0508dd92e06d0fa272bf483de9d
4
+ data.tar.gz: 2edb42b798d5aa568008c715a56b5f521c8dac4f
5
5
  SHA512:
6
- metadata.gz: 7a18aa291f92f0ca6f33f56285eaca6dccfd07eb02b33470a6af05af23fb3f941c72588d0c35d4342fd2c34567c74e0f301de01d82be54b4c19d2433c7c2ccf7
7
- data.tar.gz: d7c07474c0bdb2df7e76129d0cc604f2622974a1080e3a41bdcc70b6556408fcb16ae7f31ab0dd46c32354ffce52eb53c30947cb0cd9d29a88c88394dce907ea
6
+ metadata.gz: 6f6f0f8477e82af1183ccf3cc38236b2cdc39c3e32801ae276bc1657649b3641fafd336b2b7ac683bf1cab74426f4cf409eaa6bac4b7be39650f53e8a3d3d5d7
7
+ data.tar.gz: 50eec3c2f3599412395699db1f850b6633b604022e059dfbe30c753d2b4fc782611c63a274b2a1e61e6c00a2a4cb01f4ed460ac4340bac1d2b8e0d6e640fb77f
@@ -1,5 +1,17 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.0.0 2017-03-29
4
+
5
+ - [BREAKING CHANGE] Ruby version 2.2.0 or later is required
6
+ - [FEATURE] use new web performance API to avoid warning @MikeRogers0
7
+ - [FEATURE] store hidden pref regarding showing mini profiler in session @MikeRogers0
8
+ - [FIX] correct jQuery 3.0 deprecations @TiSer
9
+ - [FIX] JS in IFRAME @naiyt
10
+
11
+ ## 0.10.8 2017-12-01
12
+
13
+ - [FEATURE] Add `# frozen_string_literal: true` to all `lib/**/*.rb` files
14
+
3
15
  ## 0.10.7 2017-11-24
4
16
 
5
17
  - [FEATURE] Replace Time.now with Process.clock_gettime(Process::CLOCK_MONOTONIC)
data/README.md CHANGED
@@ -4,14 +4,6 @@
4
4
 
5
5
  Middleware that displays speed badge for every html page. Designed to work both in production and in development.
6
6
 
7
- # URGENT HELP NEEDED!!!
8
-
9
- Well, not exactly mega urgent, but nice to see you are reading this.
10
-
11
- There is one very simple change I would like to see ASAP: I would like to see `# frozen_string_literal: true` on every file we ship
12
-
13
- If you pick up this task, be sure to amend the README in your PR AND add a Changelog.
14
-
15
7
  #### Features
16
8
 
17
9
  * Database profiling - Currently supports Mysql2, Postgres, Oracle (oracle_enhanced ~> 1.5.0) and Mongoid3 (with fallback support to ActiveRecord)
@@ -38,7 +30,7 @@ If you feel like taking on any of this start an issue and update us on your prog
38
30
 
39
31
  ## Installation
40
32
 
41
- Install/add to Gemfile
33
+ Install/add to Gemfile in Ruby 2.2+
42
34
 
43
35
  ```ruby
44
36
  gem 'rack-mini-profiler'
@@ -48,13 +40,12 @@ NOTE: Be sure to require rack_mini_profiler below the `pg` and `mysql` gems in y
48
40
 
49
41
  You can also include optional libraries to enable additional features.
50
42
  ```ruby
51
- # For memory profiling (requires Ruby MRI 2.1+)
43
+ # For memory profiling
52
44
  gem 'memory_profiler'
53
45
 
54
- # For call-stack profiling flamegraphs (requires Ruby MRI 2.0.0+)
46
+ # For call-stack profiling flamegraphs
55
47
  gem 'flamegraph'
56
- gem 'stackprof' # For Ruby MRI 2.1+
57
- gem 'fast_stack' # For Ruby MRI 2.0
48
+ gem 'stackprof'
58
49
  ```
59
50
 
60
51
  #### Rails
@@ -144,13 +135,10 @@ To generate [flamegraphs](http://samsaffron.com/archive/2013/03/19/flame-graphs-
144
135
  * add the [**flamegraph**](https://github.com/SamSaffron/flamegraph) gem to your Gemfile
145
136
  * visit a page in your app with `?pp=flamegraph`
146
137
 
147
- Flamegraph generation is supported in Ruby MRI 2.0+
148
-
149
138
  ### Memory Profiling
150
139
 
151
140
  Memory allocations can be measured (using the [memory_profiler](https://github.com/SamSaffron/memory_profiler) gem)
152
141
  which will show allocations broken down by gem, file location, and class and will also highlight `String` allocations.
153
- (Requires Ruby MRI 2.1.0+)
154
142
 
155
143
  Add `?pp=profile-memory` to the URL of any request while Rack::MiniProfiler is enabled to generate the report.
156
144
 
@@ -166,8 +154,8 @@ Example: `?pp=profile-memory&memory_profiler_allow_files=active_record|app`
166
154
 
167
155
  There are two additional `pp` options that can be used to analyze memory which do not require the `memory_profiler` gem
168
156
 
169
- * Use `?pp=profile-gc` to report on Garbage Collection statistics (requires Ruby MRI 1.9.3+)
170
- * Use `?pp=analyze-memory` to report on ObjectSpace statistics (requires Ruby 2.0.0+)
157
+ * Use `?pp=profile-gc` to report on Garbage Collection statistics
158
+ * Use `?pp=analyze-memory` to report on ObjectSpace statistics
171
159
 
172
160
  ## Access control in non-development environments
173
161
 
@@ -326,7 +314,7 @@ backtrace_includes|Rails: `[/^\/?(app|config|lib|test)/]`<br>Rack: `[]`|Regexes
326
314
  backtrace_remove|rails: `Rails.root`<br>Rack: `nil`|A string or regex to remove part of each line in the backtrace.
327
315
  toggle_shortcut|Alt+P|Keyboard shortcut to toggle the mini_profiler's visibility. See [jquery.hotkeys](https://github.com/jeresig/jquery.hotkeys).
328
316
  start_hidden|`false`|`false` to make mini_profiler visible on page load.
329
- backtrace_threshold_ms|`0`|Minimum SQL query elapsed time before a backtrace is recorded. Backtrace recording can take a couple of milliseconds on rubies earlier than 2.0, impacting performance for very small queries.
317
+ backtrace_threshold_ms|`0`|Minimum SQL query elapsed time before a backtrace is recorded.
330
318
  flamegraph_sample_rate|`0.5`|How often to capture stack traces for flamegraphs in milliseconds.
331
319
  disable_env_dump|`false`|`true` disables `?pp=env`, which prevents sending ENV vars over HTTP.
332
320
  base_url_path|`'/mini-profiler-resources/'`|Path for assets; added as a prefix when naming assets and sought when responding to requests.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RackProfiler
2
4
  module Generators
3
5
  class InstallGenerator < ::Rails::Generators::Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if Rails.env.development?
2
4
  require "rack-mini-profiler"
3
5
 
@@ -108,18 +108,6 @@ var MiniProfiler = (function () {
108
108
  copy.navigation.redirectCount = clientPerformance.navigation.redirectCount;
109
109
  }
110
110
  clientPerformance = copy;
111
-
112
- // hack to add chrome timings
113
- if (window.chrome && window.chrome.loadTimes) {
114
- var chromeTimes = window.chrome.loadTimes();
115
- if (chromeTimes.firstPaintTime) {
116
- clientPerformance.timing["First Paint Time"] = Math.round(chromeTimes.firstPaintTime * 1000);
117
- }
118
- if (chromeTimes.firstPaintTime) {
119
- clientPerformance.timing["First Paint After Load Time"] = Math.round(chromeTimes.firstPaintAfterLoadTime * 1000);
120
- }
121
-
122
- }
123
111
  }
124
112
  } else if (ajaxStartTime !== null && clientProbes && clientProbes.length > 0) {
125
113
  clientPerformance = { timing: { navigationStart: ajaxStartTime.getTime() } };
@@ -166,7 +154,7 @@ var MiniProfiler = (function () {
166
154
 
167
155
  totalsControl = $("<div class='profiler-result'><div class='profiler-button profiler-totals'></div></div>");
168
156
  totalsControl.appendTo(container);
169
- totalsControl.click(function(){
157
+ totalsControl.on('click', function(){
170
158
  totalsControl.parent().find('.profiler-result').show();
171
159
  totalsControl.hide();
172
160
  expandedResults = true;
@@ -192,13 +180,13 @@ var MiniProfiler = (function () {
192
180
  popup = result.find('.profiler-popup');
193
181
 
194
182
  // button will appear in corner with the total profiling duration - click to show details
195
- button.click(function () { buttonClick(button, popup); });
183
+ button.on('click', function () { buttonClick(button, popup); });
196
184
 
197
185
  // small duration steps and the column with aggregate durations are hidden by default; allow toggling
198
186
  toggleHidden(popup);
199
187
 
200
188
  // lightbox in the queries
201
- popup.find('.profiler-queries-show').click(function () { queriesShow($(this), result); });
189
+ popup.find('.profiler-queries-show').on('click', function () { queriesShow($(this), result); });
202
190
 
203
191
  // limit count
204
192
  if (container.find('.profiler-result').length > options.maxTracesToShow)
@@ -222,7 +210,7 @@ var MiniProfiler = (function () {
222
210
  popupPreventHorizontalScroll(popup);
223
211
  };
224
212
 
225
- childrenTime.add(trivial).add(trivialGaps).click(function () {
213
+ childrenTime.add(trivial).add(trivialGaps).on('click', function () {
226
214
  toggleIt(this);
227
215
  });
228
216
 
@@ -266,7 +254,7 @@ var MiniProfiler = (function () {
266
254
  var popupSetDimensions = function (button, popup) {
267
255
  var px = button.position().top - 1, // position next to the button we clicked
268
256
  windowHeight = $(window).height(),
269
- maxHeight = windowHeight - top - 40; // make sure the popup doesn't extend below the fold
257
+ maxHeight = windowHeight - 40; // make sure the popup doesn't extend below the fold
270
258
 
271
259
  popup
272
260
  .css(options.renderVerticalPosition, px)
@@ -402,6 +390,7 @@ var MiniProfiler = (function () {
402
390
  });
403
391
  $(document).on('keydown.mini-profiler', null, options.toggleShortcut, function(e) {
404
392
  $('.profiler-results').toggle();
393
+ sessionStorage['rack-mini-profiler-start-hidden'] = $('.profiler-results').is(':hidden');
405
394
  });
406
395
 
407
396
  if (typeof Turbolinks !== 'undefined' && Turbolinks.supported) {
@@ -430,7 +419,7 @@ var MiniProfiler = (function () {
430
419
  prettyPrint();
431
420
 
432
421
  // since queries are already shown, just highlight and scroll when clicking a "1 sql" link
433
- popup.find('.profiler-queries-show').click(function () {
422
+ popup.find('.profiler-queries-show').on('click', function () {
434
423
  queriesScrollIntoView($(this), $('.profiler-queries'), $(document));
435
424
  });
436
425
  });
@@ -440,7 +429,7 @@ var MiniProfiler = (function () {
440
429
  if (options.showControls) {
441
430
  controls = $('<div class="profiler-controls"><span class="profiler-min-max">m</span><span class="profiler-clear">c</span></div>').appendTo(container);
442
431
 
443
- $('.profiler-controls .profiler-min-max').click(function () {
432
+ $('.profiler-controls .profiler-min-max').on('click', function () {
444
433
  container.toggleClass('profiler-min');
445
434
  });
446
435
 
@@ -455,7 +444,7 @@ var MiniProfiler = (function () {
455
444
  }
456
445
  });
457
446
 
458
- $('.profiler-controls .profiler-clear').click(function () {
447
+ $('.profiler-controls .profiler-clear').on('click', function () {
459
448
  container.find('.profiler-result').remove();
460
449
  });
461
450
  }
@@ -636,7 +625,7 @@ var MiniProfiler = (function () {
636
625
  var children = script.getAttribute('data-children') === 'true';
637
626
  var controls = script.getAttribute('data-controls') === 'true';
638
627
  var authorized = script.getAttribute('data-authorized') === 'true';
639
- var startHidden = script.getAttribute('data-start-hidden') === 'true';
628
+ var startHidden = script.getAttribute('data-start-hidden') === 'true' || sessionStorage['rack-mini-profiler-start-hidden'] === 'true';
640
629
  var htmlContainer = script.getAttribute('data-html-container');
641
630
 
642
631
  return {
@@ -815,7 +804,7 @@ var MiniProfiler = (function () {
815
804
 
816
805
  for (var i = 0; i < clientTimings.timings.length; i++) {
817
806
  t = clientTimings.timings[i];
818
- var trivial = t.Name != "Dom Complete" && t.Name != "Response" && t.Name != "First Paint Time";
807
+ var trivial = t.Name != "Dom Complete" && t.Name != "Response"
819
808
  trivial = t.Duration < 2 ? trivial : false;
820
809
  list.push(
821
810
  {
@@ -826,6 +815,22 @@ var MiniProfiler = (function () {
826
815
  });
827
816
  }
828
817
 
818
+
819
+ // Use the Paint Timing API for render performance.
820
+ if (window.performance) {
821
+ var firstPaint = window.performance.getEntriesByName("first-paint");
822
+
823
+ if(firstPaint !== undefined && firstPaint.length >= 1){
824
+ list.push(
825
+ {
826
+ isTrivial: false,
827
+ name: "First Paint Time",
828
+ duration: firstPaint[0].duration,
829
+ start: firstPaint[0].startTime
830
+ });
831
+ }
832
+ }
833
+
829
834
  list.sort(function (a, b) { return a.start - b.start; });
830
835
  return list;
831
836
  },
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class MiniProfiler
3
- ASSET_VERSION = '812af6927f7534f73488ece21dc89b62'.freeze
3
+ ASSET_VERSION = '251162ee7dc30da30d5370581c664510'.freeze
4
4
  end
5
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  class MiniProfiler
3
5
  class ClientSettings
@@ -17,6 +19,8 @@ module Rack
17
19
  @cookie = request.cookies[COOKIE_NAME]
18
20
  @store = store
19
21
  @start = start
22
+ @backtrace_level = nil
23
+ @orig_disable_profiling = @disable_profiling = nil
20
24
 
21
25
  @allowed_tokens, @orig_auth_tokens = nil
22
26
 
@@ -1,37 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  class MiniProfiler
3
5
  class Config
6
+ def self.attr_accessor(*vars)
7
+ @attributes ||= []
8
+ @attributes.concat vars
9
+ super(*vars)
10
+ end
4
11
 
5
- def self.attr_accessor(*vars)
6
- @attributes ||= []
7
- @attributes.concat vars
8
- super(*vars)
9
- end
10
-
11
- def self.attributes
12
- @attributes
13
- end
14
-
15
- attr_accessor :authorization_mode, :auto_inject, :backtrace_ignores,
16
- :backtrace_includes, :backtrace_remove, :backtrace_threshold_ms,
17
- :base_url_path, :disable_caching, :disable_env_dump, :enabled,
18
- :flamegraph_sample_rate, :logger, :pre_authorize_cb, :skip_paths,
19
- :skip_schema_queries, :storage, :storage_failure, :storage_instance,
20
- :storage_options, :user_provider
21
- attr_accessor :skip_sql_param_names, :suppress_encoding, :max_sql_param_length
22
-
23
- # ui accessors
24
- attr_accessor :collapse_results, :max_traces_to_show, :position, :vertical_position, :horizontal_position,
25
- :show_children, :show_controls, :show_trivial, :start_hidden,
26
- :toggle_shortcut, :html_container
27
-
28
- # Deprecated options
29
- attr_accessor :use_existing_jquery
12
+ def self.attributes
13
+ @attributes
14
+ end
30
15
 
31
16
  def self.default
32
17
  new.instance_eval {
33
18
  @auto_inject = true # automatically inject on every html page
34
- @base_url_path = "/mini-profiler-resources/"
19
+ @base_url_path = "/mini-profiler-resources/".dup
35
20
  @disable_caching = true
36
21
  # called prior to rack chain, to ensure we are allowed to profile
37
22
  @pre_authorize_cb = lambda {|env| true}
@@ -54,20 +39,46 @@ module Rack
54
39
  @skip_sql_param_names = /password/ # skips parameters with the name password by default
55
40
 
56
41
  # ui parameters
57
- @autorized = true
58
- @collapse_results = true
59
- @max_traces_to_show = 20
60
- @show_children = false
61
- @show_controls = false
62
- @show_trivial = false
63
- @start_hidden = false
64
- @toggle_shortcut = 'Alt+P'
65
- @html_container = 'body'
42
+ @autorized = true
43
+ @collapse_results = true
44
+ @max_traces_to_show = 20
45
+ @show_children = false
46
+ @show_controls = false
47
+ @show_trivial = false
48
+ @start_hidden = false
49
+ @toggle_shortcut = 'Alt+P'
50
+ @html_container = 'body'
51
+ @position = "top-left"
66
52
 
67
53
  self
68
54
  }
69
55
  end
70
56
 
57
+ attr_accessor :authorization_mode, :auto_inject, :backtrace_ignores,
58
+ :backtrace_includes, :backtrace_remove, :backtrace_threshold_ms,
59
+ :base_url_path, :disable_caching, :disable_env_dump, :enabled,
60
+ :flamegraph_sample_rate, :logger, :pre_authorize_cb, :skip_paths,
61
+ :skip_schema_queries, :storage, :storage_failure, :storage_instance,
62
+ :storage_options, :user_provider
63
+ attr_accessor :skip_sql_param_names, :suppress_encoding, :max_sql_param_length
64
+
65
+ # ui accessors
66
+ attr_accessor :collapse_results, :max_traces_to_show, :position,
67
+ :show_children, :show_controls, :show_trivial, :start_hidden,
68
+ :toggle_shortcut, :html_container
69
+
70
+ # Deprecated options
71
+ attr_accessor :use_existing_jquery
72
+
73
+ def vertical_position
74
+ position.include?('bottom') ? 'bottom' : 'top'
75
+ end
76
+
77
+ def horizontal_position
78
+ position.include?('right') ? 'right' : 'left'
79
+ end
80
+
81
+
71
82
  def merge!(config)
72
83
  if config
73
84
  if Hash === config
@@ -79,14 +90,8 @@ module Rack
79
90
  }
80
91
  end
81
92
  end
82
- set_positions!
83
93
  end
84
94
 
85
- def set_positions!
86
- position = (self.position && self.position.match("-")) ? self.position.split("-") : ["top", "left"]
87
- self.vertical_position = position.first
88
- self.horizontal_position = position.last
89
- end
90
95
  end
91
96
  end
92
97
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Rack::MiniProfiler::Context
2
4
  attr_accessor :inject_js,:current_timer,:page_struct,:skip_backtrace,
3
5
  :full_backtrace,:discard, :mpt_init, :measure
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Rack::MiniProfiler::GCProfiler
2
4
 
3
5
  def initialize
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  class MiniProfiler
3
5
  class << self
@@ -109,12 +111,13 @@ module Rack
109
111
  end
110
112
 
111
113
  def generate_html(page_struct, env, result_json = page_struct.to_json)
112
- path = "#{env['RACK_MINI_PROFILER_ORIGINAL_SCRIPT_NAME']}#{@config.base_url_path}"
113
- version = MiniProfiler::ASSET_VERSION
114
- json = result_json
115
- includes = get_profile_script(env)
116
- name = page_struct[:name]
117
- duration = page_struct.duration_ms.round(1).to_s
114
+ # double-assigning to suppress "assigned but unused variable" warnings
115
+ path = path = "#{env['RACK_MINI_PROFILER_ORIGINAL_SCRIPT_NAME']}#{@config.base_url_path}"
116
+ version = version = MiniProfiler::ASSET_VERSION
117
+ json = json = result_json
118
+ includes = includes = get_profile_script(env)
119
+ name = name = page_struct[:name]
120
+ duration = duration = page_struct.duration_ms.round(1).to_s
118
121
 
119
122
  MiniProfiler.share_template.result(binding)
120
123
  end
@@ -406,13 +409,13 @@ module Rack
406
409
  end
407
410
 
408
411
  def dump_exceptions(exceptions)
409
- body = "Exceptions raised during request\n\n"
412
+ body = "Exceptions raised during request\n\n".dup
410
413
  if exceptions.empty?
411
414
  body << "No exceptions raised"
412
415
  else
413
416
  body << "Exceptions: (#{exceptions.size} total)\n"
414
- exceptions.group_by(&:class).each do |klass, exceptions|
415
- body << " #{klass.name} (#{exceptions.size})\n"
417
+ exceptions.group_by(&:class).each do |klass, exceptions_per_class|
418
+ body << " #{klass.name} (#{exceptions_per_class.size})\n"
416
419
  end
417
420
 
418
421
  body << "\nBacktraces\n"
@@ -424,7 +427,7 @@ module Rack
424
427
  end
425
428
 
426
429
  def dump_env(env)
427
- body = "Rack Environment\n---------------\n"
430
+ body = "Rack Environment\n---------------\n".dup
428
431
  env.each do |k,v|
429
432
  body << "#{k}: #{v}\n"
430
433
  end
@@ -475,7 +478,7 @@ module Rack
475
478
  str
476
479
  end
477
480
 
478
- body = "ObjectSpace stats:\n\n"
481
+ body = "ObjectSpace stats:\n\n".dup
479
482
 
480
483
  counts = ObjectSpace.count_objects
481
484
  total_strings = counts[:T_STRING]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  class MiniProfiler
3
5
  module ProfilingMethods
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  class MiniProfiler
3
5
  class AbstractStore
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  class MiniProfiler
3
5
  class FileStore < AbstractStore
@@ -16,7 +18,7 @@ module Rack
16
18
  begin
17
19
  data = ::File.open(path(key),"rb") {|f| f.read}
18
20
  return Marshal.load data
19
- rescue => e
21
+ rescue
20
22
  return nil
21
23
  end
22
24
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  class MiniProfiler
3
5
  class MemcacheStore < AbstractStore
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  class MiniProfiler
3
5
  class MemoryStore < AbstractStore
@@ -50,7 +52,7 @@ module Rack
50
52
  args ||= {}
51
53
  @expires_in_seconds = args.fetch(:expires_in) { EXPIRES_IN_SECONDS }
52
54
 
53
- @token1, @token2, @cycle_tokens_at = nil
55
+ @token1, @token2, @cycle_at = nil
54
56
 
55
57
  initialize_locks
56
58
  initialize_cleanup_thread(args)
@@ -68,7 +70,7 @@ module Rack
68
70
  def initialize_cleanup_thread(args={})
69
71
  cleanup_interval = args.fetch(:cleanup_interval) { CLEANUP_INTERVAL }
70
72
  cleanup_cycle = args.fetch(:cleanup_cycle) { CLEANUP_CYCLE }
71
- t = CacheCleanupThread.new(cleanup_interval, cleanup_cycle, self) do |t|
73
+ t = CacheCleanupThread.new(cleanup_interval, cleanup_cycle, self) do
72
74
  until Thread.current[:should_exit] do
73
75
  CacheCleanupThread.current.sleepy_run
74
76
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  class MiniProfiler
3
5
  class RedisStore < AbstractStore
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  class MiniProfiler
3
5
  module TimerStruct
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  class MiniProfiler
3
5
  module TimerStruct
@@ -15,7 +17,7 @@ module Rack
15
17
 
16
18
  # used by Railtie to instrument asset_tag for JS / CSS
17
19
  def self.instrument(name, orig)
18
- probe = "<script>mPt.probe('#{name}')</script>"
20
+ probe = "<script>mPt.probe('#{name}')</script>".dup
19
21
  wrapped = probe
20
22
  wrapped << orig
21
23
  wrapped << probe
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  class MiniProfiler
3
5
  module TimerStruct
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  class MiniProfiler
3
5
  module TimerStruct
@@ -11,12 +13,14 @@ module Rack
11
13
  def initialize(env)
12
14
  timer_id = MiniProfiler.generate_id
13
15
  page_name = env['PATH_INFO']
14
- started_at = (Process.clock_gettime(Process::CLOCK_MONOTONIC) * 1000).to_i
16
+ started_at = (Time.now.to_f * 1000).to_i
17
+ started = (Process.clock_gettime(Process::CLOCK_MONOTONIC) * 1000).to_i
15
18
  machine_name = env['SERVER_NAME']
16
19
  super(
17
20
  :id => timer_id,
18
21
  :name => page_name,
19
- :started => started_at,
22
+ :started => started,
23
+ :started_at => started_at,
20
24
  :machine_name => machine_name,
21
25
  :level => 0,
22
26
  :user => "unknown user",
@@ -66,7 +70,7 @@ module Rack
66
70
 
67
71
  def extra_json
68
72
  {
69
- :started => '/Date(%d)/' % @attributes[:started],
73
+ :started => '/Date(%d)/' % @attributes.delete(:started_at),
70
74
  :duration_milliseconds => @attributes[:root][:duration_milliseconds],
71
75
  :custom_timing_names => @attributes[:custom_timing_stats].keys.sort
72
76
  }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  class MiniProfiler
3
5
  module TimerStruct
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Rack
3
4
  class MiniProfiler
4
5
 
@@ -10,7 +11,7 @@ module Rack
10
11
  stack_trace = nil
11
12
  unless skip_backtrace || duration_ms < Rack::MiniProfiler.config.backtrace_threshold_ms
12
13
  # Allow us to filter the stack trace
13
- stack_trace = String.new
14
+ stack_trace = "".dup
14
15
  # Clean up the stack trace if there are options to do so
15
16
  Kernel.caller.each do |ln|
16
17
  ln.gsub!(Rack::MiniProfiler.config.backtrace_remove, '') if Rack::MiniProfiler.config.backtrace_remove and !full_backtrace
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rack
2
4
  class MiniProfiler
3
- VERSION = '0.10.7'
5
+ VERSION = '1.0.0'
4
6
  end
5
7
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fileutils'
2
4
 
3
5
  module Rack::MiniProfilerRails
@@ -5,7 +7,7 @@ module Rack::MiniProfilerRails
5
7
  # call direct if needed to do a defer init
6
8
  def self.initialize!(app)
7
9
 
8
- raise "MiniProfilerRails initialized twice. Set `require: false' for rack-mini-profiler in your Gemfile" if @already_initialized
10
+ raise "MiniProfilerRails initialized twice. Set `require: false' for rack-mini-profiler in your Gemfile" if defined?(@already_initialized) && @already_initialized
9
11
 
10
12
  c = Rack::MiniProfiler.config
11
13
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ## based off https://github.com/newrelic/rpm/blob/master/lib/new_relic/agent/instrumentation/active_record.rb
2
4
  ## fallback for alls sorts of weird dbs
3
5
  module Rack
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Mongo/Mongoid 5 patches
2
4
  class Mongo::Server::Connection
3
5
  def dispatch_with_timing(*args, &blk)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Mongoid 3 patches
2
4
  class Moped::Node
3
5
  alias_method :process_without_profiling, :process
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # The best kind of instrumentation is in the actual db provider, however we don't want to double instrument
2
4
 
3
5
  class Mysql2::Result
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Neo4j::Core::Query
2
4
  alias_method :response_without_miniprofiler, :response
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Rack::MiniProfiler::NoBrainerProfiler
2
4
 
3
5
  def on_query(env)
@@ -6,7 +8,7 @@ class Rack::MiniProfiler::NoBrainerProfiler
6
8
  !env[:criteria].where_indexed? &&
7
9
  !env[:criteria].model.try(:perf_warnings_disabled)
8
10
 
9
- query = ""
11
+ query = "".dup
10
12
 
11
13
  # per-model/query database overrides
12
14
  query << "[#{env[:options][:db]}] " if env[:options][:db]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ActiveRecord::Result
2
4
  alias_method :each_without_profiling, :each
3
5
  def each(&blk)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # PG patches, keep in mind exec and async_exec have a exec{|r| } semantics that is yet to be implemented
2
4
  class PG::Result
3
5
  alias_method :each_without_profiling, :each
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # mongo_mapper patches
2
4
  # TODO: Include overrides for distinct, update, cursor, and create
3
5
  class Plucky::Query
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # riak-client 2.2.2 patches
2
4
  class Riak::Multiget
3
5
  class <<self
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class RSolr::Connection
2
4
  alias_method :execute_without_profiling, :execute
3
5
  def execute_with_profiling(client, request_context)
@@ -7,7 +9,7 @@ class RSolr::Connection
7
9
  result = execute_without_profiling(client, request_context)
8
10
  elapsed_time = SqlPatches.elapsed_time(start)
9
11
 
10
- data = "#{request_context[:method].upcase} #{request_context[:uri]}"
12
+ data = "#{request_context[:method].upcase} #{request_context[:uri]}".dup
11
13
  if request_context[:method] == :post and request_context[:data]
12
14
  if request_context[:headers].include?("Content-Type") and request_context[:headers]["Content-Type"] == "text/xml"
13
15
  # it's xml, unescaping isn't needed
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Sequel
2
4
  class Database
3
5
  alias_method :log_duration_original, :log_duration
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if (defined?(Net) && defined?(Net::HTTP))
2
4
 
3
5
  Net::HTTP.class_eval do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class SqlPatches
2
4
  def self.correct_version?(required_version, klass)
3
5
  Gem::Dependency.new('', required_version).match?('', klass::VERSION)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
  require 'timeout'
3
5
  require 'thread'
@@ -25,8 +27,6 @@ require 'mini_profiler/context'
25
27
  require 'mini_profiler/client_settings'
26
28
  require 'mini_profiler/gc_profiler'
27
29
  require 'mini_profiler/profiler'
28
- # TODO
29
- # require 'mini_profiler/gc_profiler_ruby_head' if Gem::Version.new('2.1.0') <= Gem::Version.new(RUBY_VERSION)
30
30
 
31
31
  require 'patches/sql_patches'
32
32
  require 'patches/net_patches'
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  "CHANGELOG.md"
20
20
  ]
21
21
  s.add_runtime_dependency 'rack', '>= 1.2.0'
22
- s.required_ruby_version = '>= 1.9.3'
22
+ s.required_ruby_version = '>= 2.2.0'
23
23
 
24
24
  s.metadata = {
25
25
  'source_code_uri' => 'https://github.com/MiniProfiler/rack-mini-profiler',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-mini-profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.7
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-11-23 00:00:00.000000000 Z
13
+ date: 2018-03-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
@@ -213,7 +213,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
213
  requirements:
214
214
  - - ">="
215
215
  - !ruby/object:Gem::Version
216
- version: 1.9.3
216
+ version: 2.2.0
217
217
  required_rubygems_version: !ruby/object:Gem::Requirement
218
218
  requirements:
219
219
  - - ">="