rack-mini-profiler 0.1.31 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rack-mini-profiler might be problematic. Click here for more details.

Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +149 -0
  3. data/README.md +285 -0
  4. data/{Ruby/lib → lib}/html/includes.css +15 -4
  5. data/{Ruby/lib → lib}/html/includes.js +95 -59
  6. data/{Ruby/lib → lib}/html/includes.less +21 -5
  7. data/{Ruby/lib → lib}/html/includes.tmpl +50 -50
  8. data/{Ruby/lib → lib}/html/jquery.1.7.1.js +0 -0
  9. data/{Ruby/lib → lib}/html/jquery.tmpl.js +0 -0
  10. data/{Ruby/lib → lib}/html/list.css +2 -2
  11. data/{Ruby/lib → lib}/html/list.js +1 -1
  12. data/lib/html/list.tmpl +34 -0
  13. data/lib/html/profile_handler.js +1 -0
  14. data/{Ruby/lib → lib}/html/share.html +2 -2
  15. data/lib/mini_profiler/asset_version.rb +5 -0
  16. data/{Ruby/lib → lib}/mini_profiler/client_settings.rb +3 -3
  17. data/lib/mini_profiler/config.rb +65 -0
  18. data/{Ruby/lib → lib}/mini_profiler/context.rb +0 -0
  19. data/lib/mini_profiler/gc_profiler.rb +181 -0
  20. data/{Ruby/lib → lib}/mini_profiler/profiler.rb +120 -96
  21. data/{Ruby/lib → lib}/mini_profiler/profiling_methods.rb +15 -17
  22. data/{Ruby/lib → lib}/mini_profiler/storage/abstract_store.rb +0 -0
  23. data/{Ruby/lib → lib}/mini_profiler/storage/file_store.rb +30 -8
  24. data/{Ruby/lib → lib}/mini_profiler/storage/memcache_store.rb +5 -7
  25. data/lib/mini_profiler/storage/memory_store.rb +115 -0
  26. data/{Ruby/lib → lib}/mini_profiler/storage/redis_store.rb +19 -11
  27. data/lib/mini_profiler/timer_struct/base.rb +33 -0
  28. data/lib/mini_profiler/timer_struct/client.rb +89 -0
  29. data/lib/mini_profiler/timer_struct/custom.rb +22 -0
  30. data/lib/mini_profiler/timer_struct/page.rb +62 -0
  31. data/lib/mini_profiler/timer_struct/request.rb +126 -0
  32. data/lib/mini_profiler/timer_struct/sql.rb +59 -0
  33. data/lib/mini_profiler/version.rb +5 -0
  34. data/{Ruby/lib → lib}/mini_profiler_rails/railtie.rb +23 -6
  35. data/lib/patches/db/activerecord.rb +42 -0
  36. data/lib/patches/db/moped.rb +12 -0
  37. data/lib/patches/db/mysql2.rb +30 -0
  38. data/lib/patches/db/pg.rb +104 -0
  39. data/lib/patches/db/plucky.rb +47 -0
  40. data/lib/patches/db/rsolr.rb +24 -0
  41. data/lib/patches/db/sequel.rb +10 -0
  42. data/{Ruby/lib → lib}/patches/net_patches.rb +0 -0
  43. data/lib/patches/sql_patches.rb +46 -0
  44. data/lib/rack-mini-profiler.rb +35 -0
  45. data/rack-mini-profiler.gemspec +28 -16
  46. metadata +171 -52
  47. data/Ruby/CHANGELOG +0 -161
  48. data/Ruby/README.md +0 -172
  49. data/Ruby/lib/html/list.tmpl +0 -34
  50. data/Ruby/lib/html/profile_handler.js +0 -1
  51. data/Ruby/lib/mini_profiler/client_timer_struct.rb +0 -78
  52. data/Ruby/lib/mini_profiler/config.rb +0 -58
  53. data/Ruby/lib/mini_profiler/custom_timer_struct.rb +0 -22
  54. data/Ruby/lib/mini_profiler/gc_profiler.rb +0 -107
  55. data/Ruby/lib/mini_profiler/gc_profiler_ruby_head.rb +0 -40
  56. data/Ruby/lib/mini_profiler/page_timer_struct.rb +0 -58
  57. data/Ruby/lib/mini_profiler/request_timer_struct.rb +0 -115
  58. data/Ruby/lib/mini_profiler/sql_timer_struct.rb +0 -58
  59. data/Ruby/lib/mini_profiler/storage/memory_store.rb +0 -65
  60. data/Ruby/lib/mini_profiler/timer_struct.rb +0 -33
  61. data/Ruby/lib/mini_profiler/version.rb +0 -5
  62. data/Ruby/lib/patches/sql_patches.rb +0 -277
  63. data/Ruby/lib/rack-mini-profiler.rb +0 -7
@@ -1,65 +0,0 @@
1
- module Rack
2
- class MiniProfiler
3
- class MemoryStore < AbstractStore
4
-
5
- EXPIRES_IN_SECONDS = 60 * 60 * 24
6
-
7
- def initialize(args = nil)
8
- args ||= {}
9
- @expires_in_seconds = args[:expires_in] || EXPIRES_IN_SECONDS
10
- @timer_struct_lock = Mutex.new
11
- @timer_struct_cache = {}
12
- @user_view_lock = Mutex.new
13
- @user_view_cache = {}
14
-
15
- # TODO: fix it to use weak ref, trouble is may be broken in 1.9 so need to use the 'ref' gem
16
- me = self
17
- Thread.new do
18
- while true do
19
- me.cleanup_cache
20
- sleep(3600)
21
- end
22
- end
23
- end
24
-
25
- def save(page_struct)
26
- @timer_struct_lock.synchronize {
27
- @timer_struct_cache[page_struct['Id']] = page_struct
28
- }
29
- end
30
-
31
- def load(id)
32
- @timer_struct_lock.synchronize {
33
- @timer_struct_cache[id]
34
- }
35
- end
36
-
37
- def set_unviewed(user, id)
38
- @user_view_lock.synchronize {
39
- @user_view_cache[user] ||= []
40
- @user_view_cache[user] << id
41
- }
42
- end
43
-
44
- def set_viewed(user, id)
45
- @user_view_lock.synchronize {
46
- @user_view_cache[user] ||= []
47
- @user_view_cache[user].delete(id)
48
- }
49
- end
50
-
51
- def get_unviewed_ids(user)
52
- @user_view_lock.synchronize {
53
- @user_view_cache[user]
54
- }
55
- end
56
-
57
- def cleanup_cache
58
- expire_older_than = ((Time.now.to_f - @expires_in_seconds) * 1000).to_i
59
- @timer_struct_lock.synchronize {
60
- @timer_struct_cache.delete_if { |k, v| v['Started'] < expire_older_than }
61
- }
62
- end
63
- end
64
- end
65
- end
@@ -1,33 +0,0 @@
1
- module Rack
2
- class MiniProfiler
3
-
4
- # A base class for timing structures
5
- class TimerStruct
6
-
7
- def initialize(attrs={})
8
- @attributes = attrs
9
- end
10
-
11
- def attributes
12
- @attributes ||= {}
13
- end
14
-
15
- def [](name)
16
- attributes[name]
17
- end
18
-
19
- def []=(name, val)
20
- attributes[name] = val
21
- self
22
- end
23
-
24
- def to_json(*a)
25
- # this does could take in an option hash, but the only interesting there is max_nesting.
26
- # if this becomes an option we could increase
27
- ::JSON.generate( @attributes, :max_nesting => 100 )
28
- end
29
-
30
- end
31
-
32
- end
33
- end
@@ -1,5 +0,0 @@
1
- module Rack
2
- class MiniProfiler
3
- VERSION = '55905d0d15f4dc1e14b29260abce19b2'.freeze
4
- end
5
- end
@@ -1,277 +0,0 @@
1
- class SqlPatches
2
-
3
- def self.patched?
4
- @patched
5
- end
6
-
7
- def self.patched=(val)
8
- @patched = val
9
- end
10
-
11
- def self.class_exists?(name)
12
- eval(name + ".class").to_s.eql?('Class')
13
- rescue NameError
14
- false
15
- end
16
-
17
- def self.module_exists?(name)
18
- eval(name + ".class").to_s.eql?('Module')
19
- rescue NameError
20
- false
21
- end
22
- end
23
-
24
- # The best kind of instrumentation is in the actual db provider, however we don't want to double instrument
25
- if SqlPatches.class_exists? "Mysql2::Client"
26
-
27
- class Mysql2::Result
28
- alias_method :each_without_profiling, :each
29
- def each(*args, &blk)
30
- return each_without_profiling(*args, &blk) unless @miniprofiler_sql_id
31
-
32
- start = Time.now
33
- result = each_without_profiling(*args,&blk)
34
- elapsed_time = ((Time.now - start).to_f * 1000).round(1)
35
-
36
- @miniprofiler_sql_id.report_reader_duration(elapsed_time)
37
- result
38
- end
39
- end
40
-
41
- class Mysql2::Client
42
- alias_method :query_without_profiling, :query
43
- def query(*args,&blk)
44
- current = ::Rack::MiniProfiler.current
45
- return query_without_profiling(*args,&blk) unless current && current.measure
46
-
47
- start = Time.now
48
- result = query_without_profiling(*args,&blk)
49
- elapsed_time = ((Time.now - start).to_f * 1000).round(1)
50
- result.instance_variable_set("@miniprofiler_sql_id", ::Rack::MiniProfiler.record_sql(args[0], elapsed_time))
51
-
52
- result
53
-
54
- end
55
- end
56
-
57
- SqlPatches.patched = true
58
- end
59
-
60
-
61
- # PG patches, keep in mind exec and async_exec have a exec{|r| } semantics that is yet to be implemented
62
- if SqlPatches.class_exists? "PG::Result"
63
-
64
- class PG::Result
65
- alias_method :each_without_profiling, :each
66
- alias_method :values_without_profiling, :values
67
-
68
- def values(*args, &blk)
69
- return values_without_profiling(*args, &blk) unless @miniprofiler_sql_id
70
-
71
- start = Time.now
72
- result = values_without_profiling(*args,&blk)
73
- elapsed_time = ((Time.now - start).to_f * 1000).round(1)
74
-
75
- @miniprofiler_sql_id.report_reader_duration(elapsed_time)
76
- result
77
- end
78
-
79
- def each(*args, &blk)
80
- return each_without_profiling(*args, &blk) unless @miniprofiler_sql_id
81
-
82
- start = Time.now
83
- result = each_without_profiling(*args,&blk)
84
- elapsed_time = ((Time.now - start).to_f * 1000).round(1)
85
-
86
- @miniprofiler_sql_id.report_reader_duration(elapsed_time)
87
- result
88
- end
89
- end
90
-
91
- class PG::Connection
92
- alias_method :exec_without_profiling, :exec
93
- alias_method :async_exec_without_profiling, :async_exec
94
- alias_method :exec_prepared_without_profiling, :exec_prepared
95
- alias_method :send_query_prepared_without_profiling, :send_query_prepared
96
- alias_method :prepare_without_profiling, :prepare
97
-
98
- def prepare(*args,&blk)
99
- # we have no choice but to do this here,
100
- # if we do the check for profiling first, our cache may miss critical stuff
101
-
102
- @prepare_map ||= {}
103
- @prepare_map[args[0]] = args[1]
104
- # dont leak more than 10k ever
105
- @prepare_map = {} if @prepare_map.length > 1000
106
-
107
- current = ::Rack::MiniProfiler.current
108
- return prepare_without_profiling(*args,&blk) unless current && current.measure
109
-
110
- prepare_without_profiling(*args,&blk)
111
- end
112
-
113
- def exec(*args,&blk)
114
- current = ::Rack::MiniProfiler.current
115
- return exec_without_profiling(*args,&blk) unless current && current.measure
116
-
117
- start = Time.now
118
- result = exec_without_profiling(*args,&blk)
119
- elapsed_time = ((Time.now - start).to_f * 1000).round(1)
120
- result.instance_variable_set("@miniprofiler_sql_id", ::Rack::MiniProfiler.record_sql(args[0], elapsed_time))
121
-
122
- result
123
- end
124
-
125
- def exec_prepared(*args,&blk)
126
- current = ::Rack::MiniProfiler.current
127
- return exec_prepared_without_profiling(*args,&blk) unless current && current.measure
128
-
129
- start = Time.now
130
- result = exec_prepared_without_profiling(*args,&blk)
131
- elapsed_time = ((Time.now - start).to_f * 1000).round(1)
132
- mapped = args[0]
133
- mapped = @prepare_map[mapped] || args[0] if @prepare_map
134
- result.instance_variable_set("@miniprofiler_sql_id", ::Rack::MiniProfiler.record_sql(mapped, elapsed_time))
135
-
136
- result
137
- end
138
-
139
- def send_query_prepared(*args,&blk)
140
- current = ::Rack::MiniProfiler.current
141
- return send_query_prepared_without_profiling(*args,&blk) unless current && current.measure
142
-
143
- start = Time.now
144
- result = send_query_prepared_without_profiling(*args,&blk)
145
- elapsed_time = ((Time.now - start).to_f * 1000).round(1)
146
- mapped = args[0]
147
- mapped = @prepare_map[mapped] || args[0] if @prepare_map
148
- result.instance_variable_set("@miniprofiler_sql_id", ::Rack::MiniProfiler.record_sql(mapped, elapsed_time))
149
-
150
- result
151
- end
152
-
153
- def async_exec(*args,&blk)
154
- current = ::Rack::MiniProfiler.current
155
- return exec_without_profiling(*args,&blk) unless current && current.measure
156
-
157
- start = Time.now
158
- result = exec_without_profiling(*args,&blk)
159
- elapsed_time = ((Time.now - start).to_f * 1000).round(1)
160
- result.instance_variable_set("@miniprofiler_sql_id", ::Rack::MiniProfiler.record_sql(args[0], elapsed_time))
161
-
162
- result
163
- end
164
-
165
- alias_method :query, :exec
166
- end
167
-
168
- SqlPatches.patched = true
169
- end
170
-
171
-
172
- # Mongoid 3 patches
173
- if SqlPatches.class_exists?("Moped::Node")
174
- class Moped::Node
175
- alias_method :process_without_profiling, :process
176
- def process(*args,&blk)
177
- current = ::Rack::MiniProfiler.current
178
- return process_without_profiling(*args,&blk) unless current && current.measure
179
-
180
- start = Time.now
181
- result = process_without_profiling(*args,&blk)
182
- elapsed_time = ((Time.now - start).to_f * 1000).round(1)
183
- result.instance_variable_set("@miniprofiler_sql_id", ::Rack::MiniProfiler.record_sql(args[0].log_inspect, elapsed_time))
184
-
185
- result
186
- end
187
- end
188
- end
189
-
190
- if SqlPatches.class_exists?("RSolr::Connection") && RSolr::VERSION[0] != "0" # requires at least v1.0.0
191
- class RSolr::Connection
192
- alias_method :execute_without_profiling, :execute
193
- def execute_with_profiling(client, request_context)
194
- current = ::Rack::MiniProfiler.current
195
- return execute_without_profiling(client, request_context) unless current && current.measure
196
-
197
- start = Time.now
198
- result = execute_without_profiling(client, request_context)
199
- elapsed_time = ((Time.now - start).to_f * 1000).round(1)
200
-
201
- data = "#{request_context[:method].upcase} #{request_context[:uri]}"
202
- if request_context[:method] == :post and request_context[:data]
203
- if request_context[:headers].include?("Content-Type") and request_context[:headers]["Content-Type"] == "text/xml"
204
- # it's xml, unescaping isn't needed
205
- data << "\n#{request_context[:data]}"
206
- else
207
- data << "\n#{Rack::Utils.unescape(request_context[:data])}"
208
- end
209
- end
210
- result.instance_variable_set("@miniprofiler_sql_id", ::Rack::MiniProfiler.record_sql(data, elapsed_time))
211
-
212
- result
213
- end
214
- alias_method :execute, :execute_with_profiling
215
- end
216
- end
217
-
218
-
219
- # Fallback for sequel
220
- if SqlPatches.class_exists?("Sequel::Database") && !SqlPatches.patched?
221
- module Sequel
222
- class Database
223
- alias_method :log_duration_original, :log_duration
224
- def log_duration(duration, message)
225
- ::Rack::MiniProfiler.record_sql(message, duration)
226
- log_duration_original(duration, message)
227
- end
228
- end
229
- end
230
- end
231
-
232
-
233
- ## based off https://github.com/newrelic/rpm/blob/master/lib/new_relic/agent/instrumentation/active_record.rb
234
- ## fallback for alls sorts of weird dbs
235
- if SqlPatches.module_exists?('ActiveRecord') && !SqlPatches.patched?
236
- module Rack
237
- class MiniProfiler
238
- module ActiveRecordInstrumentation
239
- def self.included(instrumented_class)
240
- instrumented_class.class_eval do
241
- unless instrumented_class.method_defined?(:log_without_miniprofiler)
242
- alias_method :log_without_miniprofiler, :log
243
- alias_method :log, :log_with_miniprofiler
244
- protected :log
245
- end
246
- end
247
- end
248
-
249
- def log_with_miniprofiler(*args, &block)
250
- current = ::Rack::MiniProfiler.current
251
- return log_without_miniprofiler(*args, &block) unless current && current.measure
252
-
253
- sql, name, binds = args
254
- t0 = Time.now
255
- rval = log_without_miniprofiler(*args, &block)
256
-
257
- # Don't log schema queries if the option is set
258
- return rval if Rack::MiniProfiler.config.skip_schema_queries and name =~ /SCHEMA/
259
-
260
- elapsed_time = ((Time.now - t0).to_f * 1000).round(1)
261
- Rack::MiniProfiler.record_sql(sql, elapsed_time)
262
- rval
263
- end
264
- end
265
- end
266
-
267
- def self.insert_instrumentation
268
- ActiveRecord::ConnectionAdapters::AbstractAdapter.module_eval do
269
- include ::Rack::MiniProfiler::ActiveRecordInstrumentation
270
- end
271
- end
272
-
273
- if defined?(::Rails) && !SqlPatches.patched?
274
- insert_instrumentation
275
- end
276
- end
277
- end
@@ -1,7 +0,0 @@
1
- require 'mini_profiler/profiler'
2
- require 'patches/sql_patches'
3
- require 'patches/net_patches'
4
-
5
- if defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i >= 3
6
- require 'mini_profiler_rails/railtie'
7
- end