rack-mini-profiler 0.1.18 → 0.1.23

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.

Potentially problematic release.


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

Files changed (38) hide show
  1. data/{CHANGELOG → Ruby/CHANGELOG} +107 -83
  2. data/{README.md → Ruby/README.md} +22 -9
  3. data/{lib → Ruby/lib}/html/includes.css +0 -0
  4. data/{lib → Ruby/lib}/html/includes.js +80 -16
  5. data/{lib → Ruby/lib}/html/includes.less +0 -0
  6. data/{lib → Ruby/lib}/html/includes.tmpl +39 -15
  7. data/{lib → Ruby/lib}/html/jquery.1.7.1.js +1 -1
  8. data/{lib → Ruby/lib}/html/jquery.tmpl.js +1 -1
  9. data/{lib → Ruby/lib}/html/list.css +0 -0
  10. data/{lib → Ruby/lib}/html/list.js +7 -6
  11. data/{lib → Ruby/lib}/html/list.tmpl +0 -0
  12. data/Ruby/lib/html/profile_handler.js +1 -0
  13. data/{lib → Ruby/lib}/html/share.html +0 -0
  14. data/{lib → Ruby/lib}/mini_profiler/client_settings.rb +0 -0
  15. data/{lib → Ruby/lib}/mini_profiler/client_timer_struct.rb +1 -1
  16. data/{lib → Ruby/lib}/mini_profiler/config.rb +54 -52
  17. data/{lib → Ruby/lib}/mini_profiler/context.rb +0 -0
  18. data/Ruby/lib/mini_profiler/custom_timer_struct.rb +22 -0
  19. data/Ruby/lib/mini_profiler/gc_profiler.rb +103 -0
  20. data/{lib → Ruby/lib}/mini_profiler/page_timer_struct.rb +7 -2
  21. data/{lib → Ruby/lib}/mini_profiler/profiler.rb +81 -21
  22. data/{lib → Ruby/lib}/mini_profiler/profiling_methods.rb +10 -2
  23. data/{lib → Ruby/lib}/mini_profiler/request_timer_struct.rb +20 -1
  24. data/{lib → Ruby/lib}/mini_profiler/sql_timer_struct.rb +0 -0
  25. data/{lib → Ruby/lib}/mini_profiler/storage/abstract_store.rb +0 -0
  26. data/{lib → Ruby/lib}/mini_profiler/storage/file_store.rb +0 -0
  27. data/Ruby/lib/mini_profiler/storage/memcache_store.rb +51 -0
  28. data/{lib → Ruby/lib}/mini_profiler/storage/memory_store.rb +0 -0
  29. data/{lib → Ruby/lib}/mini_profiler/storage/redis_store.rb +44 -44
  30. data/{lib → Ruby/lib}/mini_profiler/timer_struct.rb +0 -0
  31. data/Ruby/lib/mini_profiler/version.rb +5 -0
  32. data/{lib → Ruby/lib}/mini_profiler_rails/railtie.rb +3 -2
  33. data/Ruby/lib/patches/net_patches.rb +14 -0
  34. data/{lib → Ruby/lib}/patches/sql_patches.rb +20 -1
  35. data/{lib → Ruby/lib}/rack-mini-profiler.rb +2 -1
  36. data/rack-mini-profiler.gemspec +8 -6
  37. metadata +45 -40
  38. data/lib/html/profile_handler.js +0 -62
@@ -71,8 +71,16 @@ module Rack
71
71
  return self.send without_profiling, *args, &orig unless Rack::MiniProfiler.current
72
72
 
73
73
  name = default_name
74
- name = blk.bind(self).call(*args) if blk
75
-
74
+ if blk
75
+ name =
76
+ if respond_to?(:instance_exec)
77
+ instance_exec(*args, &blk)
78
+ else
79
+ # deprecated in Rails 4.x
80
+ blk.bind(self).call(*args)
81
+ end
82
+ end
83
+
76
84
  parent_timer = Rack::MiniProfiler.current.current_timer
77
85
  page_struct = Rack::MiniProfiler.current.page_struct
78
86
  result = nil
@@ -33,7 +33,9 @@ module Rack
33
33
  "Depth"=> parent ? parent.depth + 1 : 0,
34
34
  "ExecutedReaders"=> 0,
35
35
  "ExecutedScalars"=> 0,
36
- "ExecutedNonQueries"=> 0)
36
+ "ExecutedNonQueries"=> 0,
37
+ "CustomTimingStats" => {},
38
+ "CustomTimings" => {})
37
39
  @children_duration = 0
38
40
  @start = Time.now
39
41
  @parent = parent
@@ -79,6 +81,23 @@ module Rack
79
81
  timer
80
82
  end
81
83
 
84
+ def add_custom(type, elapsed_ms, page)
85
+ timer = CustomTimerStruct.new(type, elapsed_ms, page, self)
86
+ timer['ParentTimingId'] = self['Id']
87
+ self['CustomTimings'][type] ||= []
88
+ self['CustomTimings'][type].push(timer)
89
+
90
+ self['CustomTimingStats'][type] ||= {"Count" => 0, "Duration" => 0.0}
91
+ self['CustomTimingStats'][type]['Count'] += 1
92
+ self['CustomTimingStats'][type]['Duration'] += elapsed_ms
93
+
94
+ page['CustomTimingStats'][type] ||= {"Count" => 0, "Duration" => 0.0}
95
+ page['CustomTimingStats'][type]['Count'] += 1
96
+ page['CustomTimingStats'][type]['Duration'] += elapsed_ms
97
+
98
+ timer
99
+ end
100
+
82
101
  def record_time(milliseconds = nil)
83
102
  milliseconds ||= (Time.now - @start) * 1000
84
103
  self['DurationMilliseconds'] = milliseconds
@@ -0,0 +1,51 @@
1
+ module Rack
2
+ class MiniProfiler
3
+ class MemcacheStore < AbstractStore
4
+
5
+ EXPIRE_SECONDS = 60*60*24
6
+ MAX_RETRIES = 10
7
+
8
+ def initialize(client = nil, prefix = "MPMemcacheStore")
9
+ require 'dalli' unless defined? Dalli
10
+ @prefix = prefix
11
+ @client = client || Dalli::Client.new(['localhost:11211'])
12
+ end
13
+
14
+ def save(page_struct)
15
+ @client.set("#{@prefix}#{page_struct['Id']}", Marshal::dump(page_struct), EXPIRE_SECONDS)
16
+ end
17
+
18
+ def load(id)
19
+ raw = @client.get("#{@prefix}#{id}")
20
+ if raw
21
+ Marshal::load raw
22
+ end
23
+ end
24
+
25
+ def set_unviewed(user, id)
26
+ @client.add("#{@prefix}-#{user}-v", [], EXPIRE_SECONDS)
27
+ MAX_RETRIES.times do
28
+ break if @client.cas("#{@prefix}-#{user}-v", EXPIRE_SECONDS) do |ids|
29
+ ids << id unless ids.include?(id)
30
+ ids
31
+ end
32
+ end
33
+ end
34
+
35
+ def set_viewed(user, id)
36
+ @client.add("#{@prefix}-#{user}-v", [], EXPIRE_SECONDS)
37
+ MAX_RETRIES.times do
38
+ break if @client.cas("#{@prefix}-#{user}-v", EXPIRE_SECONDS) do |ids|
39
+ ids.delete id
40
+ ids
41
+ end
42
+ end
43
+ end
44
+
45
+ def get_unviewed_ids(user)
46
+ @client.get("#{@prefix}-#{user}-v") || []
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -1,44 +1,44 @@
1
- module Rack
2
- class MiniProfiler
3
- class RedisStore < AbstractStore
4
-
5
- EXPIRE_SECONDS = 60 * 60 * 24
6
-
7
- def initialize(args)
8
- args ||= {}
9
- @prefix = args[:prefix] || 'MPRedisStore'
10
- end
11
-
12
- def save(page_struct)
13
- redis.setex "#{@prefix}#{page_struct['Id']}", EXPIRE_SECONDS, Marshal::dump(page_struct)
14
- end
15
-
16
- def load(id)
17
- raw = redis.get "#{@prefix}#{id}"
18
- if raw
19
- Marshal::load raw
20
- end
21
- end
22
-
23
- def set_unviewed(user, id)
24
- redis.sadd "#{@prefix}-#{user}-v", id
25
- end
26
-
27
- def set_viewed(user, id)
28
- redis.srem "#{@prefix}-#{user}-v", id
29
- end
30
-
31
- def get_unviewed_ids(user)
32
- redis.smembers "#{@prefix}-#{user}-v"
33
- end
34
-
35
- private
36
-
37
- def redis
38
- require 'redis' unless defined? Redis
39
- Redis.new
40
- end
41
-
42
- end
43
- end
44
- end
1
+ module Rack
2
+ class MiniProfiler
3
+ class RedisStore < AbstractStore
4
+
5
+ EXPIRE_SECONDS = 60 * 60 * 24
6
+
7
+ def initialize(args)
8
+ @args = args || {}
9
+ @prefix = @args.delete(:prefix) || 'MPRedisStore'
10
+ end
11
+
12
+ def save(page_struct)
13
+ redis.setex "#{@prefix}#{page_struct['Id']}", EXPIRE_SECONDS, Marshal::dump(page_struct)
14
+ end
15
+
16
+ def load(id)
17
+ raw = redis.get "#{@prefix}#{id}"
18
+ if raw
19
+ Marshal::load raw
20
+ end
21
+ end
22
+
23
+ def set_unviewed(user, id)
24
+ redis.sadd "#{@prefix}-#{user}-v", id
25
+ end
26
+
27
+ def set_viewed(user, id)
28
+ redis.srem "#{@prefix}-#{user}-v", id
29
+ end
30
+
31
+ def get_unviewed_ids(user)
32
+ redis.smembers "#{@prefix}-#{user}-v"
33
+ end
34
+
35
+ private
36
+
37
+ def redis
38
+ require 'redis' unless defined? Redis
39
+ Redis.new @args
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class MiniProfiler
3
+ VERSION = '33d69ecf833daec8db07a9a0b6cf0bd3'.freeze
4
+ end
5
+ end
@@ -9,11 +9,12 @@ module MiniProfilerRails
9
9
 
10
10
  # By default, only show the MiniProfiler in development mode, in production allow profiling if post_authorize_cb is set
11
11
  c.pre_authorize_cb = lambda { |env|
12
- Rails.env.development? || Rails.env.production?
12
+ !Rails.env.test?
13
13
  }
14
14
 
15
+ c.skip_paths ||= []
16
+
15
17
  if Rails.env.development?
16
- c.skip_paths ||= []
17
18
  c.skip_paths << "/assets/"
18
19
  c.skip_schema_queries = true
19
20
  end
@@ -0,0 +1,14 @@
1
+ if (defined?(Net) && defined?(Net::HTTP))
2
+
3
+ Net::HTTP.class_eval do
4
+ def request_with_mini_profiler(*args, &block)
5
+ request = args[0]
6
+ Rack::MiniProfiler.step("Net::HTTP #{request.method} #{request.path}") do
7
+ request_without_mini_profiler(*args, &block)
8
+ end
9
+ end
10
+ alias request_without_mini_profiler request
11
+ alias request request_with_mini_profiler
12
+ end
13
+
14
+ end
@@ -169,6 +169,25 @@ if SqlPatches.class_exists? "PG::Result"
169
169
  end
170
170
 
171
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
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
+
172
191
 
173
192
  # Fallback for sequel
174
193
  if SqlPatches.class_exists?("Sequel::Database") && !SqlPatches.patched?
@@ -186,7 +205,7 @@ end
186
205
 
187
206
  ## based off https://github.com/newrelic/rpm/blob/master/lib/new_relic/agent/instrumentation/active_record.rb
188
207
  ## fallback for alls sorts of weird dbs
189
- if SqlPatches.module_exists?('ActiveRecord')
208
+ if SqlPatches.module_exists?('ActiveRecord') && !SqlPatches.patched?
190
209
  module Rack
191
210
  class MiniProfiler
192
211
  module ActiveRecordInstrumentation
@@ -1,6 +1,7 @@
1
1
  require 'mini_profiler/profiler'
2
2
  require 'patches/sql_patches'
3
+ require 'patches/net_patches'
3
4
 
4
- if defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i == 3
5
+ if defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i >= 3
5
6
  require 'mini_profiler_rails/railtie'
6
7
  end
@@ -1,17 +1,17 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "rack-mini-profiler"
3
- s.version = "0.1.18"
3
+ s.version = "0.1.23"
4
4
  s.summary = "Profiles loading speed for rack applications."
5
- s.authors = ["Aleks Totic","Sam Saffron", "Robin Ward"]
6
- s.description = "Page loading speed displayed on every page. Optimize while you develop, performance is a feature."
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."
7
7
  s.email = "sam.saffron@gmail.com"
8
8
  s.homepage = "http://miniprofiler.com"
9
9
  s.files = [
10
10
  'rack-mini-profiler.gemspec',
11
- ].concat( Dir.glob('lib/**/*').reject {|f| File.directory?(f) || f =~ /~$/ } )
11
+ ].concat( Dir.glob('Ruby/lib/**/*').reject {|f| File.directory?(f) || f =~ /~$/ } )
12
12
  s.extra_rdoc_files = [
13
- "README.md",
14
- "CHANGELOG"
13
+ "Ruby/README.md",
14
+ "Ruby/CHANGELOG"
15
15
  ]
16
16
  s.add_runtime_dependency 'rack', '>= 1.1.3'
17
17
  if RUBY_VERSION < "1.9"
@@ -21,4 +21,6 @@ Gem::Specification.new do |s|
21
21
  s.add_development_dependency 'rake'
22
22
  s.add_development_dependency 'rack-test'
23
23
  s.add_development_dependency 'activerecord', '~> 3.0'
24
+
25
+ s.require_paths = ["Ruby/lib"]
24
26
  end
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.18
4
+ version: 0.1.23
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-09-07 00:00:00.000000000 Z
14
+ date: 2012-11-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rack
@@ -77,52 +77,57 @@ 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
- - README.md
87
- - CHANGELOG
86
+ - Ruby/README.md
87
+ - Ruby/CHANGELOG
88
88
  files:
89
89
  - rack-mini-profiler.gemspec
90
- - lib/mini_profiler/sql_timer_struct.rb
91
- - lib/mini_profiler/request_timer_struct.rb
92
- - lib/mini_profiler/timer_struct.rb
93
- - lib/mini_profiler/page_timer_struct.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/client_timer_struct.rb
99
- - lib/mini_profiler/profiler.rb
100
- - lib/mini_profiler/storage/memory_store.rb
101
- - lib/mini_profiler/storage/file_store.rb
102
- - lib/mini_profiler/storage/redis_store.rb
103
- - lib/mini_profiler/storage/abstract_store.rb
104
- - lib/rack-mini-profiler.rb
105
- - lib/html/jquery.1.7.1.js
106
- - lib/html/includes.tmpl
107
- - lib/html/share.html
108
- - lib/html/includes.less
109
- - lib/html/list.css
110
- - lib/html/includes.js
111
- - lib/html/jquery.tmpl.js
112
- - lib/html/list.tmpl
113
- - lib/html/profile_handler.js
114
- - lib/html/includes.css
115
- - lib/html/list.js
116
- - lib/mini_profiler_rails/railtie.rb
117
- - lib/patches/sql_patches.rb
118
- - README.md
119
- - CHANGELOG
90
+ - Ruby/lib/mini_profiler/version.rb
91
+ - Ruby/lib/mini_profiler/sql_timer_struct.rb
92
+ - Ruby/lib/mini_profiler/request_timer_struct.rb
93
+ - Ruby/lib/mini_profiler/timer_struct.rb
94
+ - Ruby/lib/mini_profiler/page_timer_struct.rb
95
+ - Ruby/lib/mini_profiler/client_settings.rb
96
+ - Ruby/lib/mini_profiler/context.rb
97
+ - Ruby/lib/mini_profiler/config.rb
98
+ - Ruby/lib/mini_profiler/profiling_methods.rb
99
+ - Ruby/lib/mini_profiler/gc_profiler.rb
100
+ - Ruby/lib/mini_profiler/client_timer_struct.rb
101
+ - Ruby/lib/mini_profiler/profiler.rb
102
+ - Ruby/lib/mini_profiler/storage/memory_store.rb
103
+ - Ruby/lib/mini_profiler/storage/file_store.rb
104
+ - Ruby/lib/mini_profiler/storage/redis_store.rb
105
+ - Ruby/lib/mini_profiler/storage/abstract_store.rb
106
+ - Ruby/lib/mini_profiler/storage/memcache_store.rb
107
+ - Ruby/lib/mini_profiler/custom_timer_struct.rb
108
+ - Ruby/lib/rack-mini-profiler.rb
109
+ - Ruby/lib/html/jquery.1.7.1.js
110
+ - Ruby/lib/html/includes.tmpl
111
+ - Ruby/lib/html/share.html
112
+ - Ruby/lib/html/includes.less
113
+ - Ruby/lib/html/list.css
114
+ - Ruby/lib/html/includes.js
115
+ - Ruby/lib/html/jquery.tmpl.js
116
+ - Ruby/lib/html/list.tmpl
117
+ - Ruby/lib/html/profile_handler.js
118
+ - Ruby/lib/html/includes.css
119
+ - Ruby/lib/html/list.js
120
+ - Ruby/lib/mini_profiler_rails/railtie.rb
121
+ - Ruby/lib/patches/sql_patches.rb
122
+ - Ruby/lib/patches/net_patches.rb
123
+ - Ruby/README.md
124
+ - Ruby/CHANGELOG
120
125
  homepage: http://miniprofiler.com
121
126
  licenses: []
122
127
  post_install_message:
123
128
  rdoc_options: []
124
129
  require_paths:
125
- - lib
130
+ - Ruby/lib
126
131
  required_ruby_version: !ruby/object:Gem::Requirement
127
132
  none: false
128
133
  requirements:
@@ -131,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
136
  version: '0'
132
137
  segments:
133
138
  - 0
134
- hash: -322245347
139
+ hash: -387077425
135
140
  required_rubygems_version: !ruby/object:Gem::Requirement
136
141
  none: false
137
142
  requirements:
@@ -140,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
145
  version: '0'
141
146
  segments:
142
147
  - 0
143
- hash: -322245347
148
+ hash: -387077425
144
149
  requirements: []
145
150
  rubyforge_project:
146
151
  rubygems_version: 1.8.24