remnant 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,12 @@ require 'remnant/base'
4
4
  require 'remnant/configuration'
5
5
  require 'remnant/discover'
6
6
 
7
+ require 'remnant/gc'
8
+ require 'remnant/gc/base'
9
+ require 'remnant/gc/ree'
10
+
11
+ require 'remnant/filters'
12
+
7
13
  require 'remnant/template'
8
14
  require 'remnant/template/trace'
9
15
  require 'remnant/template/rendering'
@@ -41,9 +41,8 @@ class Remnant
41
41
  Remnant.handler.timing("#{key_prefix}.#{remnant_key}", ms.to_i)
42
42
  end
43
43
 
44
- if Remnant::Database.enabled?
45
- Remnant.handler.timing("#{key_prefix}.db", Remnant::Database.total_time.to_i)
46
- end
44
+ Remnant.handler.timing("#{key_prefix}.gc", Remnant::GC.ms.to_i)
45
+ Remnant.handler.timing("#{key_prefix}.db", Remnant::Database.total_time.to_i)
47
46
 
48
47
  @sample_counter = 0
49
48
  else
@@ -61,7 +60,16 @@ class Remnant
61
60
 
62
61
  Rails.logger.info "#{Remnant.color}#{ms.to_i}ms#{Remnant.color(true)}\t#{key}"
63
62
  end
63
+ Rails.logger.info "#{Remnant.color}#{Remnant::GC.time.to_i}ms (#{Remnant::GC.collections} collections)#{Remnant.color(true)}\tGC"
64
+
65
+ # filters
66
+ Rails.logger.info ""
67
+ Rails.logger.info("#{color(false, true)}----- Filters (%.2fms) -----#{color(true)}" % Remnant::Filters.total_time)
68
+ Remnant::Filters.filters.map do |filter|
69
+ Rails.logger.info("#{color}%.2fms#{color(true)}\t#{filter[:name]} (#{filter[:type]})" % filter[:ms])
70
+ end
64
71
 
72
+ # template captures
65
73
  if Remnant::Template.enabled?
66
74
  Rails.logger.info ""
67
75
  Rails.logger.info "#{color(false, true)}----- Templates -----#{color(true)}"
@@ -70,15 +78,14 @@ class Remnant
70
78
  end
71
79
  end
72
80
 
73
- if Remnant::Database.enabled?
74
- Rails.logger.info ""
75
- Rails.logger.info("#{color(false, true)}---- Database (%.2fms) -----#{color(true)}" % Remnant::Database.total_time)
76
- if Remnant::Database.suppress?
77
- Rails.logger.info "queries suppressed in development mode"
78
- else
79
- Remnant::Database.queries.map do |query|
80
- Rails.logger.info("#{color}%.2fms#{color(true)}\t#{query.sql}" % (query.time * 1000))
81
- end
81
+ # sql captures
82
+ Rails.logger.info ""
83
+ Rails.logger.info("#{color(false, true)}---- Database (%.2fms) -----#{color(true)}" % Remnant::Database.total_time)
84
+ if Remnant::Database.suppress?
85
+ Rails.logger.info "queries suppressed in development mode"
86
+ else
87
+ Remnant::Database.queries.map do |query|
88
+ Rails.logger.info("#{color}%.2fms#{color(true)}\t#{query.sql}" % (query.time * 1000))
82
89
  end
83
90
  end
84
91
 
@@ -92,6 +99,7 @@ class Remnant
92
99
 
93
100
  Remnant::Database.reset
94
101
  Remnant::Template.reset
102
+ Remnant::Filters.reset
95
103
  Remnant::Discover.results.clear
96
104
  end
97
105
  end
@@ -0,0 +1,28 @@
1
+ class Remnant
2
+ class Filters
3
+ module ClassMethods
4
+ def record(filter_type, filter_name, &block)
5
+ start_time = Time.now
6
+ result = block.call
7
+ time = Time.now - start_time
8
+ filters << {:type => filter_type, :name => filter_name, :time => time, :ms => time * 1000}
9
+
10
+ return result
11
+ end
12
+
13
+ def reset
14
+ @total_time = nil
15
+ Thread.current['remnant.filters.set'] = []
16
+ end
17
+
18
+ def filters
19
+ Thread.current['remnant.filters.set'] ||= []
20
+ end
21
+
22
+ def total_time
23
+ @total_time ||= filters.map {|filter| filter[:ms]}.sum
24
+ end
25
+ end
26
+ extend ClassMethods
27
+ end
28
+ end
@@ -0,0 +1,38 @@
1
+ class Remnant
2
+ class GC
3
+ module ClassMethods
4
+ def enable_stats
5
+ _gc.enable_stats
6
+ end
7
+
8
+ def disable_stats
9
+ _gc.disable_stats
10
+ end
11
+
12
+ def clear_stats
13
+ _gc.clear_stats
14
+ end
15
+
16
+ def time
17
+ _gc.time
18
+ end
19
+
20
+ def collections
21
+ _gc.collections
22
+ end
23
+
24
+ def _gc
25
+ Thread.current['remnant.gc'] ||= _gc_implementation
26
+ end
27
+
28
+ def _gc_implementation
29
+ if ::GC.respond_to?(:time) && ::GC.respond_to?(:collections)
30
+ Remnant::GC::Ree
31
+ else
32
+ Remnant::GC::Base
33
+ end
34
+ end
35
+ end
36
+ extend ClassMethods
37
+ end
38
+ end
@@ -0,0 +1,28 @@
1
+ class Remnant
2
+ class GC
3
+ class Base
4
+ module ClassMethods
5
+ def time
6
+ 0
7
+ end
8
+
9
+ def collections
10
+ 0
11
+ end
12
+
13
+ def enable_stats
14
+ true
15
+ end
16
+
17
+ def disable_stats
18
+ true
19
+ end
20
+
21
+ def clear_stats
22
+ true
23
+ end
24
+ end
25
+ extend ClassMethods
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,29 @@
1
+ class Remnant
2
+ class GC
3
+ class Ree
4
+ module ClassMethods
5
+ def time
6
+ # returns time in microseconds so convert to ms
7
+ ::GC.time / 1000
8
+ end
9
+
10
+ def collections
11
+ ::GC.collections
12
+ end
13
+
14
+ def enable_stats
15
+ ::GC.enable_stats
16
+ end
17
+
18
+ def disable_stats
19
+ ::GC.disable_stats
20
+ end
21
+
22
+ def clear_stats
23
+ ::GC.clear_stats
24
+ end
25
+ end
26
+ extend ClassMethods
27
+ end
28
+ end
29
+ end
@@ -33,10 +33,29 @@ class Remnant
33
33
 
34
34
  # hook remnants
35
35
  Remnant::Discover.find('request', ActionController::Dispatcher, :call)
36
- Remnant::Discover.find('filters', ActionController::Filters::BeforeFilter, :call)
37
36
  Remnant::Discover.find('action', ActionController::Base, :perform_action)
38
37
  Remnant::Discover.find('view', ActionController::Base, :render)
39
- Remnant::Discover.find('filters', ActionController::Filters::AfterFilter, :call)
38
+
39
+ #
40
+ # Filter capturing
41
+ #
42
+ [
43
+ ActionController::Filters::BeforeFilter,
44
+ ActionController::Filters::AfterFilter,
45
+ ActionController::Filters::AroundFilter
46
+ ].map do |remnant_constant|
47
+ Remnant::Discover.find_with(remnant_constant) do
48
+ remnant_constant.class_eval do
49
+ def call_with_remnant(*args, &block)
50
+ ::Remnant::Filters.record(self.class.to_s, method.to_s) do
51
+ call_without_remnant(*args, &block)
52
+ end
53
+ end
54
+
55
+ alias_method_chain :call, :remnant
56
+ end
57
+ end
58
+ end
40
59
 
41
60
  #
42
61
  # Template rendering
@@ -75,9 +94,12 @@ class Remnant
75
94
  # last hook into request cycle for sending results
76
95
  ::ActionController::Dispatcher.class_eval do
77
96
  def call_with_remnant_discovery(*args, &block) #:nodoc:
97
+ ::Remnant::GC.enable_stats
78
98
  call_without_remnant_discovery(*args, &block).tap do |status, headers, response|
99
+ ::Remnant::GC.disable_stats
79
100
  begin
80
101
  ::Remnant.collect
102
+ ::Remnant::GC.clear_stats
81
103
  ::Rails.logger.flush if ::Rails.logger.respond_to? :flush
82
104
  rescue Exception => e
83
105
  if defined?(::Flail)
@@ -1,3 +1,3 @@
1
1
  class Remnant
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remnant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-11 00:00:00.000000000 Z
12
+ date: 2013-01-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: statsd-ruby
@@ -143,6 +143,10 @@ files:
143
143
  - lib/remnant/database.rb
144
144
  - lib/remnant/database/query.rb
145
145
  - lib/remnant/discover.rb
146
+ - lib/remnant/filters.rb
147
+ - lib/remnant/gc.rb
148
+ - lib/remnant/gc/base.rb
149
+ - lib/remnant/gc/ree.rb
146
150
  - lib/remnant/rails.rb
147
151
  - lib/remnant/railtie.rb
148
152
  - lib/remnant/template.rb
@@ -176,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
180
  version: '0'
177
181
  requirements: []
178
182
  rubyforge_project: remnant
179
- rubygems_version: 1.8.24
183
+ rubygems_version: 1.8.23
180
184
  signing_key:
181
185
  specification_version: 3
182
186
  summary: Rails statistical discoverer