rack-mini-profiler 0.1 → 0.1.21

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.
@@ -1,17 +1,182 @@
1
- module SqlPatches
1
+ class SqlPatches
2
+
3
+ def self.patched?
4
+ @patched
5
+ end
6
+
7
+ def self.patched=(val)
8
+ @patched = val
9
+ end
10
+
2
11
  def self.class_exists?(name)
3
12
  eval(name + ".class").to_s.eql?('Class')
4
13
  rescue NameError
5
14
  false
6
15
  end
16
+
17
+ def self.module_exists?(name)
18
+ eval(name + ".class").to_s.eql?('Module')
19
+ rescue NameError
20
+ false
21
+ end
7
22
  end
8
23
 
9
- if SqlPatches.class_exists? "Sequel::Database" then
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
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
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
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
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
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
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
+
173
+ # Fallback for sequel
174
+ if SqlPatches.class_exists?("Sequel::Database") && !SqlPatches.patched?
10
175
  module Sequel
11
176
  class Database
12
177
  alias_method :log_duration_original, :log_duration
13
178
  def log_duration(duration, message)
14
- ::Rack::MiniProfiler.instance.record_sql(message, duration) if ::Rack::MiniProfiler.instance
179
+ ::Rack::MiniProfiler.record_sql(message, duration)
15
180
  log_duration_original(duration, message)
16
181
  end
17
182
  end
@@ -20,53 +185,47 @@ end
20
185
 
21
186
 
22
187
  ## based off https://github.com/newrelic/rpm/blob/master/lib/new_relic/agent/instrumentation/active_record.rb
23
- module Rack
24
- class MiniProfiler
25
- module ActiveRecordInstrumentation
26
- def self.included(instrumented_class)
27
- instrumented_class.class_eval do
28
- unless instrumented_class.method_defined?(:log_without_miniprofiler)
29
- alias_method :log_without_miniprofiler, :log
30
- alias_method :log, :log_with_miniprofiler
31
- protected :log
188
+ ## fallback for alls sorts of weird dbs
189
+ if SqlPatches.module_exists?('ActiveRecord')
190
+ module Rack
191
+ class MiniProfiler
192
+ module ActiveRecordInstrumentation
193
+ def self.included(instrumented_class)
194
+ instrumented_class.class_eval do
195
+ unless instrumented_class.method_defined?(:log_without_miniprofiler)
196
+ alias_method :log_without_miniprofiler, :log
197
+ alias_method :log, :log_with_miniprofiler
198
+ protected :log
199
+ end
32
200
  end
33
201
  end
34
- end
35
-
36
- def log_with_miniprofiler(*args, &block)
37
- sql, name, binds = args
38
- t0 = Time.now
39
- rval = log_without_miniprofiler(*args, &block)
40
202
 
41
- # Get our MP Instance
42
- instance = ::Rack::MiniProfiler.instance
43
- return rval unless instance
203
+ def log_with_miniprofiler(*args, &block)
204
+ current = ::Rack::MiniProfiler.current
205
+ return log_without_miniprofiler(*args, &block) unless current
44
206
 
45
- # Don't log schema queries if the option is set
46
- return rval if instance.options[:skip_schema_queries] and name =~ /SCHEMA/
207
+ sql, name, binds = args
208
+ t0 = Time.now
209
+ rval = log_without_miniprofiler(*args, &block)
210
+
211
+ # Don't log schema queries if the option is set
212
+ return rval if Rack::MiniProfiler.config.skip_schema_queries and name =~ /SCHEMA/
47
213
 
48
- elapsed_time = ((Time.now - t0).to_f * 1000).round(1)
49
- instance.record_sql(sql, elapsed_time)
50
- rval
214
+ elapsed_time = ((Time.now - t0).to_f * 1000).round(1)
215
+ Rack::MiniProfiler.record_sql(sql, elapsed_time)
216
+ rval
217
+ end
51
218
  end
52
219
  end
53
- end
54
220
 
55
- def self.insert_instrumentation
56
- ActiveRecord::ConnectionAdapters::AbstractAdapter.module_eval do
57
- include ::Rack::MiniProfiler::ActiveRecordInstrumentation
221
+ def self.insert_instrumentation
222
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.module_eval do
223
+ include ::Rack::MiniProfiler::ActiveRecordInstrumentation
224
+ end
58
225
  end
59
- end
60
226
 
61
- if defined?(::Rails)
62
- if ::Rails::VERSION::MAJOR.to_i == 3
63
- # in theory this is the right thing to do for rails 3 ... but it seems to work anyway
64
- #Rails.configuration.after_initialize do
65
- insert_instrumentation
66
- #end
67
- else
227
+ if defined?(::Rails) && !SqlPatches.patched?
68
228
  insert_instrumentation
69
229
  end
70
230
  end
71
231
  end
72
-
@@ -1,6 +1,6 @@
1
- require File.expand_path('mini_profiler/profiler', File.dirname(__FILE__) )
2
- require File.expand_path('patches/sql_patches', File.dirname(__FILE__) )
1
+ require 'mini_profiler/profiler'
2
+ require 'patches/sql_patches'
3
3
 
4
- if defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i == 3
5
- require File.expand_path('mini_profiler_rails/railtie', File.dirname(__FILE__) )
4
+ if defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i >= 3
5
+ require 'mini_profiler_rails/railtie'
6
6
  end
@@ -1,21 +1,21 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "rack-mini-profiler"
3
- s.version = "0.1"
4
- s.summary = "Profiles loading speed for html pages."
5
- s.authors = ["Aleks Totic","Sam Saffron", "Robin Ward"]
6
- s.date = "2012-04-02"
7
- s.description = "Page loading speed displayed on every page. Optimize while you develop, performance is a feature."
3
+ s.version = "0.1.21"
4
+ s.summary = "Profiles loading speed for rack applications."
5
+ s.authors = ["Sam Saffron", "Robin Ward","Aleks Totic"]
6
+ s.description = "Profiling toolkit for Rack applications with Rails integration. Client Side profiling, DB profiling and Server profiling."
8
7
  s.email = "sam.saffron@gmail.com"
9
8
  s.homepage = "http://miniprofiler.com"
10
9
  s.files = [
11
10
  'rack-mini-profiler.gemspec',
12
11
  ].concat( Dir.glob('lib/**/*').reject {|f| File.directory?(f) || f =~ /~$/ } )
13
12
  s.extra_rdoc_files = [
14
- "README.md"
13
+ "README.md",
14
+ "CHANGELOG"
15
15
  ]
16
- s.add_runtime_dependency 'rack', '>= 1.1.3'
16
+ s.add_runtime_dependency 'rack', '>= 1.1.3'
17
17
  if RUBY_VERSION < "1.9"
18
- s.add_runtime_dependency 'json', '>= 1.6'
18
+ s.add_runtime_dependency 'json', '>= 1.6'
19
19
  end
20
20
 
21
21
  s.add_development_dependency 'rake'
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-mini-profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.21
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Aleks Totic
9
8
  - Sam Saffron
10
9
  - Robin Ward
10
+ - Aleks Totic
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-04-02 00:00:00.000000000 Z
14
+ date: 2012-09-16 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rack
@@ -77,33 +77,38 @@ dependencies:
77
77
  - - ~>
78
78
  - !ruby/object:Gem::Version
79
79
  version: '3.0'
80
- description: Page loading speed displayed on every page. Optimize while you develop,
81
- performance is a feature.
80
+ description: Profiling toolkit for Rack applications with Rails integration. Client
81
+ Side profiling, DB profiling and Server profiling.
82
82
  email: sam.saffron@gmail.com
83
83
  executables: []
84
84
  extensions: []
85
85
  extra_rdoc_files:
86
86
  - README.md
87
+ - CHANGELOG
87
88
  files:
88
89
  - rack-mini-profiler.gemspec
89
90
  - lib/mini_profiler/sql_timer_struct.rb
90
91
  - lib/mini_profiler/request_timer_struct.rb
91
92
  - lib/mini_profiler/timer_struct.rb
92
93
  - lib/mini_profiler/page_timer_struct.rb
93
- - lib/mini_profiler/body_add_proxy.rb
94
+ - lib/mini_profiler/client_settings.rb
95
+ - lib/mini_profiler/context.rb
96
+ - lib/mini_profiler/config.rb
97
+ - lib/mini_profiler/profiling_methods.rb
98
+ - lib/mini_profiler/gc_profiler.rb
94
99
  - lib/mini_profiler/client_timer_struct.rb
95
100
  - lib/mini_profiler/profiler.rb
96
101
  - lib/mini_profiler/storage/memory_store.rb
97
102
  - lib/mini_profiler/storage/file_store.rb
98
103
  - lib/mini_profiler/storage/redis_store.rb
99
104
  - lib/mini_profiler/storage/abstract_store.rb
105
+ - lib/mini_profiler/storage/memcache_store.rb
100
106
  - lib/rack-mini-profiler.rb
101
107
  - lib/html/jquery.1.7.1.js
102
108
  - lib/html/includes.tmpl
103
109
  - lib/html/share.html
104
110
  - lib/html/includes.less
105
111
  - lib/html/list.css
106
- - lib/html/MiniProfilerHandler.cs
107
112
  - lib/html/includes.js
108
113
  - lib/html/jquery.tmpl.js
109
114
  - lib/html/list.tmpl
@@ -113,6 +118,7 @@ files:
113
118
  - lib/mini_profiler_rails/railtie.rb
114
119
  - lib/patches/sql_patches.rb
115
120
  - README.md
121
+ - CHANGELOG
116
122
  homepage: http://miniprofiler.com
117
123
  licenses: []
118
124
  post_install_message:
@@ -127,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
133
  version: '0'
128
134
  segments:
129
135
  - 0
130
- hash: -1062659085
136
+ hash: -668836557
131
137
  required_rubygems_version: !ruby/object:Gem::Requirement
132
138
  none: false
133
139
  requirements:
@@ -136,11 +142,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
142
  version: '0'
137
143
  segments:
138
144
  - 0
139
- hash: -1062659085
145
+ hash: -668836557
140
146
  requirements: []
141
147
  rubyforge_project:
142
148
  rubygems_version: 1.8.24
143
149
  signing_key:
144
150
  specification_version: 3
145
- summary: Profiles loading speed for html pages.
151
+ summary: Profiles loading speed for rack applications.
146
152
  test_files: []