rack-mini-profiler 2.1.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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -0
  3. data/README.md +37 -9
  4. data/lib/html/includes.css +3 -1
  5. data/lib/html/includes.js +225 -179
  6. data/lib/html/includes.scss +4 -1
  7. data/lib/html/includes.tmpl +29 -8
  8. data/lib/html/profile_handler.js +1 -1
  9. data/lib/html/speedscope/LICENSE +21 -0
  10. data/lib/html/speedscope/README.md +3 -0
  11. data/lib/html/speedscope/demangle-cpp.1768f4cc.js +4 -0
  12. data/lib/html/speedscope/favicon-16x16.f74b3187.png +0 -0
  13. data/lib/html/speedscope/favicon-32x32.bc503437.png +0 -0
  14. data/lib/html/speedscope/file-format-schema.json +324 -0
  15. data/lib/html/speedscope/fonts/source-code-pro-regular.css +8 -0
  16. data/lib/html/speedscope/fonts/source-code-pro-v13-regular.woff +0 -0
  17. data/lib/html/speedscope/fonts/source-code-pro-v13-regular.woff2 +0 -0
  18. data/lib/html/speedscope/import.cf0fa83f.js +115 -0
  19. data/lib/html/speedscope/index.html +2 -0
  20. data/lib/html/speedscope/release.txt +3 -0
  21. data/lib/html/speedscope/reset.8c46b7a1.css +2 -0
  22. data/lib/html/speedscope/source-map.438fa06b.js +24 -0
  23. data/lib/html/speedscope/speedscope.44364064.js +200 -0
  24. data/lib/html/vendor.js +5 -5
  25. data/lib/mini_profiler/asset_version.rb +1 -1
  26. data/lib/mini_profiler/client_settings.rb +6 -5
  27. data/lib/mini_profiler/config.rb +28 -2
  28. data/lib/mini_profiler/profiler.rb +104 -25
  29. data/lib/mini_profiler/profiling_methods.rb +11 -2
  30. data/lib/mini_profiler/snapshots_transporter.rb +109 -0
  31. data/lib/mini_profiler/storage/abstract_store.rb +14 -8
  32. data/lib/mini_profiler/timer_struct/page.rb +57 -4
  33. data/lib/mini_profiler/timer_struct/sql.rb +2 -2
  34. data/lib/mini_profiler/version.rb +1 -1
  35. data/lib/mini_profiler_rails/railtie.rb +1 -1
  36. data/lib/patches/db/mysql2.rb +4 -27
  37. data/lib/patches/db/mysql2/alias_method.rb +30 -0
  38. data/lib/patches/db/mysql2/prepend.rb +34 -0
  39. data/lib/prepend_mysql2_patch.rb +5 -0
  40. data/lib/rack-mini-profiler.rb +1 -0
  41. data/rack-mini-profiler.gemspec +6 -4
  42. metadata +61 -14
@@ -10,6 +10,53 @@ module Rack
10
10
  # :has_many TimerStruct::Sql children
11
11
  # :has_many TimerStruct::Custom children
12
12
  class Page < TimerStruct::Base
13
+ class << self
14
+ def from_hash(hash)
15
+ hash = symbolize_hash(hash)
16
+ if hash.key?(:custom_timing_names)
17
+ hash[:custom_timing_names] = []
18
+ end
19
+ hash.delete(:started_formatted)
20
+ if hash.key?(:duration_milliseconds)
21
+ hash[:duration_milliseconds] = 0
22
+ end
23
+ page = self.allocate
24
+ page.instance_variable_set(:@attributes, hash)
25
+ page
26
+ end
27
+
28
+ private
29
+
30
+ def symbolize_hash(hash)
31
+ new_hash = {}
32
+ hash.each do |k, v|
33
+ sym_k = String === k ? k.to_sym : k
34
+ if Hash === v
35
+ new_hash[sym_k] = symbolize_hash(v)
36
+ elsif Array === v
37
+ new_hash[sym_k] = symbolize_array(v)
38
+ else
39
+ new_hash[sym_k] = v
40
+ end
41
+ end
42
+ new_hash
43
+ end
44
+
45
+ def symbolize_array(array)
46
+ array.map do |item|
47
+ if Array === item
48
+ symbolize_array(item)
49
+ elsif Hash === item
50
+ symbolize_hash(item)
51
+ else
52
+ item
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ attr_reader :attributes
59
+
13
60
  def initialize(env)
14
61
  timer_id = MiniProfiler.generate_id
15
62
  page_name = env['PATH_INFO']
@@ -40,7 +87,9 @@ module Rack
40
87
  executed_non_queries: 0,
41
88
  custom_timing_names: [],
42
89
  custom_timing_stats: {},
43
- custom_fields: {}
90
+ custom_fields: {},
91
+ has_flamegraph: false,
92
+ flamegraph: nil
44
93
  )
45
94
  self[:request_method] = env['REQUEST_METHOD']
46
95
  self[:request_path] = env['PATH_INFO']
@@ -64,17 +113,21 @@ module Rack
64
113
  @attributes[:root]
65
114
  end
66
115
 
116
+ def attributes_to_serialize
117
+ @attributes.keys - [:flamegraph]
118
+ end
119
+
67
120
  def to_json(*a)
68
- ::JSON.generate(@attributes.merge(self.extra_json))
121
+ ::JSON.generate(@attributes.slice(*attributes_to_serialize).merge(extra_json))
69
122
  end
70
123
 
71
124
  def as_json(options = nil)
72
- super(options).merge!(extra_json)
125
+ super(options).slice(*attributes_to_serialize.map(&:to_s)).merge!(extra_json)
73
126
  end
74
127
 
75
128
  def extra_json
76
129
  {
77
- started: '/Date(%d)/' % @attributes[:started_at],
130
+ started_formatted: '/Date(%d)/' % @attributes[:started_at],
78
131
  duration_milliseconds: @attributes[:root][:duration_milliseconds],
79
132
  custom_timing_names: @attributes[:custom_timing_stats].keys.sort
80
133
  }
@@ -38,12 +38,12 @@ module Rack
38
38
  start_millis = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) * 1000).to_i - page[:started]) - duration_ms
39
39
  super(
40
40
  execute_type: 3, # TODO
41
- formatted_command_string: ERB::Util.html_escape(query),
41
+ formatted_command_string: query ? ERB::Util.html_escape(query) : nil,
42
42
  stack_trace_snippet: stack_trace,
43
43
  start_milliseconds: start_millis,
44
44
  duration_milliseconds: duration_ms,
45
45
  first_fetch_duration_milliseconds: duration_ms,
46
- parameters: trim_binds(params),
46
+ parameters: query ? trim_binds(params) : nil,
47
47
  parent_timing_id: nil,
48
48
  is_duplicate: false
49
49
  )
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rack
4
4
  class MiniProfiler
5
- VERSION = '2.1.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
@@ -26,6 +26,7 @@ require 'mini_profiler/profiling_methods'
26
26
  require 'mini_profiler/context'
27
27
  require 'mini_profiler/client_settings'
28
28
  require 'mini_profiler/gc_profiler'
29
+ require 'mini_profiler/snapshots_transporter'
29
30
  require 'mini_profiler/profiler'
30
31
  require 'patches/sql_patches'
31
32
  require 'patches/net_patches'
@@ -28,20 +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
+ s.add_development_dependency 'webmock', '3.9.1'
46
+ s.add_development_dependency 'rubyzip'
45
47
 
46
48
  s.require_paths = ["lib"]
47
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.1.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-09-17 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,58 @@ 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
+ - !ruby/object:Gem::Dependency
226
+ name: webmock
227
+ requirement: !ruby/object:Gem::Requirement
228
+ requirements:
229
+ - - '='
230
+ - !ruby/object:Gem::Version
231
+ version: 3.9.1
232
+ type: :development
233
+ prerelease: false
234
+ version_requirements: !ruby/object:Gem::Requirement
235
+ requirements:
236
+ - - '='
237
+ - !ruby/object:Gem::Version
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'
225
253
  description: Profiling toolkit for Rack applications with Rails integration. Client
226
254
  Side profiling, DB profiling and Server profiling.
227
255
  email: sam.saffron@gmail.com
@@ -247,6 +275,21 @@ files:
247
275
  - lib/html/rack-mini-profiler.css
248
276
  - lib/html/rack-mini-profiler.js
249
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
250
293
  - lib/html/vendor.js
251
294
  - lib/mini_profiler/asset_version.rb
252
295
  - lib/mini_profiler/client_settings.rb
@@ -255,6 +298,7 @@ files:
255
298
  - lib/mini_profiler/gc_profiler.rb
256
299
  - lib/mini_profiler/profiler.rb
257
300
  - lib/mini_profiler/profiling_methods.rb
301
+ - lib/mini_profiler/snapshots_transporter.rb
258
302
  - lib/mini_profiler/storage/abstract_store.rb
259
303
  - lib/mini_profiler/storage/file_store.rb
260
304
  - lib/mini_profiler/storage/memcache_store.rb
@@ -273,6 +317,8 @@ files:
273
317
  - lib/patches/db/mongo.rb
274
318
  - lib/patches/db/moped.rb
275
319
  - lib/patches/db/mysql2.rb
320
+ - lib/patches/db/mysql2/alias_method.rb
321
+ - lib/patches/db/mysql2/prepend.rb
276
322
  - lib/patches/db/neo4j.rb
277
323
  - lib/patches/db/nobrainer.rb
278
324
  - lib/patches/db/oracle_enhanced.rb
@@ -283,6 +329,7 @@ files:
283
329
  - lib/patches/db/sequel.rb
284
330
  - lib/patches/net_patches.rb
285
331
  - lib/patches/sql_patches.rb
332
+ - lib/prepend_mysql2_patch.rb
286
333
  - lib/prepend_net_http_patch.rb
287
334
  - lib/rack-mini-profiler.rb
288
335
  - rack-mini-profiler.gemspec
@@ -307,7 +354,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
307
354
  - !ruby/object:Gem::Version
308
355
  version: '0'
309
356
  requirements: []
310
- rubygems_version: 3.0.3
357
+ rubygems_version: 3.2.2
311
358
  signing_key:
312
359
  specification_version: 4
313
360
  summary: Profiles loading speed for rack applications.