rack-mini-profiler 2.2.0 → 2.3.2

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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -0
  3. data/README.md +25 -11
  4. data/lib/html/includes.js +213 -182
  5. data/lib/html/includes.tmpl +4 -1
  6. data/lib/html/speedscope/LICENSE +21 -0
  7. data/lib/html/speedscope/README.md +3 -0
  8. data/lib/html/speedscope/demangle-cpp.1768f4cc.js +4 -0
  9. data/lib/html/speedscope/favicon-16x16.f74b3187.png +0 -0
  10. data/lib/html/speedscope/favicon-32x32.bc503437.png +0 -0
  11. data/lib/html/speedscope/file-format-schema.json +324 -0
  12. data/lib/html/speedscope/fonts/source-code-pro-regular.css +8 -0
  13. data/lib/html/speedscope/fonts/source-code-pro-v13-regular.woff +0 -0
  14. data/lib/html/speedscope/fonts/source-code-pro-v13-regular.woff2 +0 -0
  15. data/lib/html/speedscope/import.cf0fa83f.js +115 -0
  16. data/lib/html/speedscope/index.html +2 -0
  17. data/lib/html/speedscope/release.txt +3 -0
  18. data/lib/html/speedscope/reset.8c46b7a1.css +2 -0
  19. data/lib/html/speedscope/source-map.438fa06b.js +24 -0
  20. data/lib/html/speedscope/speedscope.44364064.js +200 -0
  21. data/lib/html/vendor.js +2 -2
  22. data/lib/mini_profiler/asset_version.rb +1 -1
  23. data/lib/mini_profiler/client_settings.rb +5 -5
  24. data/lib/mini_profiler/config.rb +19 -1
  25. data/lib/mini_profiler/profiler.rb +82 -20
  26. data/lib/mini_profiler/profiling_methods.rb +3 -1
  27. data/lib/mini_profiler/snapshots_transporter.rb +31 -6
  28. data/lib/mini_profiler/storage/abstract_store.rb +1 -1
  29. data/lib/mini_profiler/timer_struct/page.rb +9 -3
  30. data/lib/mini_profiler/version.rb +1 -1
  31. data/lib/mini_profiler_rails/railtie.rb +1 -1
  32. data/lib/patches/db/mysql2.rb +4 -27
  33. data/lib/patches/db/mysql2/alias_method.rb +30 -0
  34. data/lib/patches/db/mysql2/prepend.rb +34 -0
  35. data/lib/prepend_mysql2_patch.rb +5 -0
  36. data/rack-mini-profiler.gemspec +5 -4
  37. metadata +46 -14
@@ -115,6 +115,9 @@ module Rack
115
115
  end
116
116
  end
117
117
  end
118
+ if klass.respond_to?(:ruby2_keywords, true)
119
+ klass.send(:ruby2_keywords, with_profiling)
120
+ end
118
121
  klass.send :alias_method, method, with_profiling
119
122
  end
120
123
 
@@ -154,7 +157,6 @@ module Rack
154
157
  def clean_method_name(method)
155
158
  method.to_s.gsub(/[\?\!]/, "")
156
159
  end
157
-
158
160
  end
159
161
  end
160
162
  end
@@ -23,16 +23,18 @@ class ::Rack::MiniProfiler::SnapshotsTransporter
23
23
  end
24
24
 
25
25
  attr_reader :buffer
26
- attr_accessor :max_buffer_size
26
+ attr_accessor :max_buffer_size, :gzip_requests
27
27
 
28
28
  def initialize(config)
29
29
  @uri = URI(config.snapshots_transport_destination_url)
30
30
  @auth_key = config.snapshots_transport_auth_key
31
+ @gzip_requests = config.snapshots_transport_gzip_requests
31
32
  @thread = nil
32
33
  @thread_mutex = Mutex.new
33
34
  @buffer = []
34
35
  @buffer_mutex = Mutex.new
35
36
  @max_buffer_size = 100
37
+ @consecutive_failures_count = 0
36
38
  @testing = false
37
39
  end
38
40
 
@@ -49,12 +51,24 @@ class ::Rack::MiniProfiler::SnapshotsTransporter
49
51
  @buffer.dup if @buffer.size > 0
50
52
  end
51
53
  if buffer_content
52
- request = Net::HTTP::Post.new(
53
- @uri,
54
+ headers = {
54
55
  'Content-Type' => 'application/json',
55
56
  'Mini-Profiler-Transport-Auth' => @auth_key
56
- )
57
- request.body = { snapshots: buffer_content }.to_json
57
+ }
58
+ json = { snapshots: buffer_content }.to_json
59
+ body = if @gzip_requests
60
+ require 'zlib'
61
+ io = StringIO.new
62
+ gzip_writer = Zlib::GzipWriter.new(io)
63
+ gzip_writer.write(json)
64
+ gzip_writer.close
65
+ headers['Content-Encoding'] = 'gzip'
66
+ io.string
67
+ else
68
+ json
69
+ end
70
+ request = Net::HTTP::Post.new(@uri, headers)
71
+ request.body = body
58
72
  http = Net::HTTP.new(@uri.hostname, @uri.port)
59
73
  http.use_ssl = @uri.scheme == 'https'
60
74
  res = http.request(request)
@@ -64,19 +78,30 @@ class ::Rack::MiniProfiler::SnapshotsTransporter
64
78
  @buffer_mutex.synchronize do
65
79
  @buffer -= buffer_content
66
80
  end
81
+ @consecutive_failures_count = 0
67
82
  else
68
83
  @@failed_http_requests_count += 1
84
+ @consecutive_failures_count += 1
69
85
  end
70
86
  end
71
87
  end
72
88
 
89
+ def requests_interval
90
+ [30 + backoff_delay, 60 * 60].min
91
+ end
92
+
73
93
  private
74
94
 
95
+ def backoff_delay
96
+ return 0 if @consecutive_failures_count == 0
97
+ 2**@consecutive_failures_count
98
+ end
99
+
75
100
  def start_thread
76
101
  return if @thread&.alive? || @testing
77
102
  @thread = Thread.new do
78
103
  while true
79
- sleep 10
104
+ sleep requests_interval
80
105
  flush_buffer
81
106
  end
82
107
  end
@@ -36,7 +36,7 @@ module Rack
36
36
  ""
37
37
  end
38
38
 
39
- # a list of tokens that are permitted to access profiler in whitelist mode
39
+ # a list of tokens that are permitted to access profiler in explicit mode
40
40
  def allowed_tokens
41
41
  raise NotImplementedError.new("allowed_tokens is not implemented")
42
42
  end
@@ -87,7 +87,9 @@ module Rack
87
87
  executed_non_queries: 0,
88
88
  custom_timing_names: [],
89
89
  custom_timing_stats: {},
90
- custom_fields: {}
90
+ custom_fields: {},
91
+ has_flamegraph: false,
92
+ flamegraph: nil
91
93
  )
92
94
  self[:request_method] = env['REQUEST_METHOD']
93
95
  self[:request_path] = env['PATH_INFO']
@@ -111,12 +113,16 @@ module Rack
111
113
  @attributes[:root]
112
114
  end
113
115
 
116
+ def attributes_to_serialize
117
+ @attributes.keys - [:flamegraph]
118
+ end
119
+
114
120
  def to_json(*a)
115
- ::JSON.generate(@attributes.merge(self.extra_json))
121
+ ::JSON.generate(@attributes.slice(*attributes_to_serialize).merge(extra_json))
116
122
  end
117
123
 
118
124
  def as_json(options = nil)
119
- super(options).merge!(extra_json)
125
+ super(options).slice(*attributes_to_serialize.map(&:to_s)).merge!(extra_json)
120
126
  end
121
127
 
122
128
  def extra_json
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rack
4
4
  class MiniProfiler
5
- VERSION = '2.2.0'
5
+ VERSION = '2.3.2'
6
6
  end
7
7
  end
@@ -35,7 +35,7 @@ module Rack::MiniProfilerRails
35
35
  end
36
36
 
37
37
  unless Rails.env.development? || Rails.env.test?
38
- c.authorization_mode = :whitelist
38
+ c.authorization_mode = :allow_authorized
39
39
  end
40
40
 
41
41
  if Rails.logger
@@ -1,30 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # The best kind of instrumentation is in the actual db provider, however we don't want to double instrument
4
-
5
- class Mysql2::Result
6
- alias_method :each_without_profiling, :each
7
- def each(*args, &blk)
8
- return each_without_profiling(*args, &blk) unless defined?(@miniprofiler_sql_id)
9
-
10
- start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
11
- result = each_without_profiling(*args, &blk)
12
- elapsed_time = SqlPatches.elapsed_time(start)
13
-
14
- @miniprofiler_sql_id.report_reader_duration(elapsed_time)
15
- result
16
- end
17
- end
18
-
19
- class Mysql2::Client
20
- alias_method :query_without_profiling, :query
21
- def query(*args, &blk)
22
- return query_without_profiling(*args, &blk) unless SqlPatches.should_measure?
23
-
24
- result, record = SqlPatches.record_sql(args[0]) do
25
- query_without_profiling(*args, &blk)
26
- end
27
- result.instance_variable_set("@miniprofiler_sql_id", record) if result
28
- result
29
- end
3
+ if defined?(Rack::MINI_PROFILER_PREPEND_MYSQL2_PATCH)
4
+ require "patches/db/mysql2/prepend"
5
+ else
6
+ require "patches/db/mysql2/alias_method"
30
7
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The best kind of instrumentation is in the actual db provider, however we don't want to double instrument
4
+
5
+ class Mysql2::Result
6
+ alias_method :each_without_profiling, :each
7
+ def each(*args, &blk)
8
+ return each_without_profiling(*args, &blk) unless defined?(@miniprofiler_sql_id)
9
+
10
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
11
+ result = each_without_profiling(*args, &blk)
12
+ elapsed_time = SqlPatches.elapsed_time(start)
13
+
14
+ @miniprofiler_sql_id.report_reader_duration(elapsed_time)
15
+ result
16
+ end
17
+ end
18
+
19
+ class Mysql2::Client
20
+ alias_method :query_without_profiling, :query
21
+ def query(*args, &blk)
22
+ return query_without_profiling(*args, &blk) unless SqlPatches.should_measure?
23
+
24
+ result, record = SqlPatches.record_sql(args[0]) do
25
+ query_without_profiling(*args, &blk)
26
+ end
27
+ result.instance_variable_set("@miniprofiler_sql_id", record) if result
28
+ result
29
+ end
30
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Mysql2::Result
4
+ module MiniProfiler
5
+ def each(*args, &blk)
6
+ return super unless defined?(@miniprofiler_sql_id)
7
+
8
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
9
+ result = super
10
+ elapsed_time = SqlPatches.elapsed_time(start)
11
+
12
+ @miniprofiler_sql_id.report_reader_duration(elapsed_time)
13
+ result
14
+ end
15
+ end
16
+
17
+ prepend MiniProfiler
18
+ end
19
+
20
+ class Mysql2::Client
21
+ module MiniProfiler
22
+ def query(*args, &blk)
23
+ return super unless SqlPatches.should_measure?
24
+
25
+ result, record = SqlPatches.record_sql(args[0]) do
26
+ super
27
+ end
28
+ result.instance_variable_set("@miniprofiler_sql_id", record) if result
29
+ result
30
+ end
31
+ end
32
+
33
+ prepend MiniProfiler
34
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rack
4
+ MINI_PROFILER_PREPEND_MYSQL2_PATCH = true
5
+ end
@@ -28,21 +28,22 @@ Gem::Specification.new do |s|
28
28
  'changelog_uri' => 'https://github.com/MiniProfiler/rack-mini-profiler/blob/master/CHANGELOG.md'
29
29
  }
30
30
 
31
- s.add_development_dependency 'rake', '< 11'
31
+ s.add_development_dependency 'rake'
32
32
  s.add_development_dependency 'rack-test'
33
33
  s.add_development_dependency 'dalli'
34
34
  s.add_development_dependency 'rspec', '~> 3.6.0'
35
35
  s.add_development_dependency 'redis'
36
36
  s.add_development_dependency 'sassc'
37
- s.add_development_dependency 'flamegraph'
37
+ s.add_development_dependency 'stackprof'
38
38
  s.add_development_dependency 'rubocop'
39
39
  s.add_development_dependency 'mini_racer'
40
40
  s.add_development_dependency 'nokogiri'
41
41
  s.add_development_dependency 'rubocop-discourse'
42
42
  s.add_development_dependency 'listen'
43
- s.add_development_dependency 'webpacker', '~> 5.1'
44
- s.add_development_dependency 'rails', '~> 5.1'
43
+ s.add_development_dependency 'webpacker'
44
+ s.add_development_dependency 'rails', '~> 6.0'
45
45
  s.add_development_dependency 'webmock', '3.9.1'
46
+ s.add_development_dependency 'rubyzip'
46
47
 
47
48
  s.require_paths = ["lib"]
48
49
  end
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: 2.2.0
4
+ version: 2.3.2
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: 2020-10-20 00:00:00.000000000 Z
13
+ date: 2021-04-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
@@ -30,16 +30,16 @@ dependencies:
30
30
  name: rake
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - "<"
33
+ - - ">="
34
34
  - !ruby/object:Gem::Version
35
- version: '11'
35
+ version: '0'
36
36
  type: :development
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - "<"
40
+ - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: '11'
42
+ version: '0'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: rack-test
45
45
  requirement: !ruby/object:Gem::Requirement
@@ -111,7 +111,7 @@ dependencies:
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  - !ruby/object:Gem::Dependency
114
- name: flamegraph
114
+ name: stackprof
115
115
  requirement: !ruby/object:Gem::Requirement
116
116
  requirements:
117
117
  - - ">="
@@ -198,30 +198,30 @@ dependencies:
198
198
  name: webpacker
199
199
  requirement: !ruby/object:Gem::Requirement
200
200
  requirements:
201
- - - "~>"
201
+ - - ">="
202
202
  - !ruby/object:Gem::Version
203
- version: '5.1'
203
+ version: '0'
204
204
  type: :development
205
205
  prerelease: false
206
206
  version_requirements: !ruby/object:Gem::Requirement
207
207
  requirements:
208
- - - "~>"
208
+ - - ">="
209
209
  - !ruby/object:Gem::Version
210
- version: '5.1'
210
+ version: '0'
211
211
  - !ruby/object:Gem::Dependency
212
212
  name: rails
213
213
  requirement: !ruby/object:Gem::Requirement
214
214
  requirements:
215
215
  - - "~>"
216
216
  - !ruby/object:Gem::Version
217
- version: '5.1'
217
+ version: '6.0'
218
218
  type: :development
219
219
  prerelease: false
220
220
  version_requirements: !ruby/object:Gem::Requirement
221
221
  requirements:
222
222
  - - "~>"
223
223
  - !ruby/object:Gem::Version
224
- version: '5.1'
224
+ version: '6.0'
225
225
  - !ruby/object:Gem::Dependency
226
226
  name: webmock
227
227
  requirement: !ruby/object:Gem::Requirement
@@ -236,6 +236,20 @@ dependencies:
236
236
  - - '='
237
237
  - !ruby/object:Gem::Version
238
238
  version: 3.9.1
239
+ - !ruby/object:Gem::Dependency
240
+ name: rubyzip
241
+ requirement: !ruby/object:Gem::Requirement
242
+ requirements:
243
+ - - ">="
244
+ - !ruby/object:Gem::Version
245
+ version: '0'
246
+ type: :development
247
+ prerelease: false
248
+ version_requirements: !ruby/object:Gem::Requirement
249
+ requirements:
250
+ - - ">="
251
+ - !ruby/object:Gem::Version
252
+ version: '0'
239
253
  description: Profiling toolkit for Rack applications with Rails integration. Client
240
254
  Side profiling, DB profiling and Server profiling.
241
255
  email: sam.saffron@gmail.com
@@ -261,6 +275,21 @@ files:
261
275
  - lib/html/rack-mini-profiler.css
262
276
  - lib/html/rack-mini-profiler.js
263
277
  - lib/html/share.html
278
+ - lib/html/speedscope/LICENSE
279
+ - lib/html/speedscope/README.md
280
+ - lib/html/speedscope/demangle-cpp.1768f4cc.js
281
+ - lib/html/speedscope/favicon-16x16.f74b3187.png
282
+ - lib/html/speedscope/favicon-32x32.bc503437.png
283
+ - lib/html/speedscope/file-format-schema.json
284
+ - lib/html/speedscope/fonts/source-code-pro-regular.css
285
+ - lib/html/speedscope/fonts/source-code-pro-v13-regular.woff
286
+ - lib/html/speedscope/fonts/source-code-pro-v13-regular.woff2
287
+ - lib/html/speedscope/import.cf0fa83f.js
288
+ - lib/html/speedscope/index.html
289
+ - lib/html/speedscope/release.txt
290
+ - lib/html/speedscope/reset.8c46b7a1.css
291
+ - lib/html/speedscope/source-map.438fa06b.js
292
+ - lib/html/speedscope/speedscope.44364064.js
264
293
  - lib/html/vendor.js
265
294
  - lib/mini_profiler/asset_version.rb
266
295
  - lib/mini_profiler/client_settings.rb
@@ -288,6 +317,8 @@ files:
288
317
  - lib/patches/db/mongo.rb
289
318
  - lib/patches/db/moped.rb
290
319
  - lib/patches/db/mysql2.rb
320
+ - lib/patches/db/mysql2/alias_method.rb
321
+ - lib/patches/db/mysql2/prepend.rb
291
322
  - lib/patches/db/neo4j.rb
292
323
  - lib/patches/db/nobrainer.rb
293
324
  - lib/patches/db/oracle_enhanced.rb
@@ -298,6 +329,7 @@ files:
298
329
  - lib/patches/db/sequel.rb
299
330
  - lib/patches/net_patches.rb
300
331
  - lib/patches/sql_patches.rb
332
+ - lib/prepend_mysql2_patch.rb
301
333
  - lib/prepend_net_http_patch.rb
302
334
  - lib/rack-mini-profiler.rb
303
335
  - rack-mini-profiler.gemspec
@@ -322,7 +354,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
322
354
  - !ruby/object:Gem::Version
323
355
  version: '0'
324
356
  requirements: []
325
- rubygems_version: 3.0.3
357
+ rubygems_version: 3.2.2
326
358
  signing_key:
327
359
  specification_version: 4
328
360
  summary: Profiles loading speed for rack applications.