time_bandits 0.0.7 → 0.0.8
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.
- data/README.rdoc +2 -4
- data/README_RAILS2.rdoc +98 -0
- data/init.rb +12 -0
- data/lib/time_bandits.rb +6 -2
- data/lib/time_bandits/monkey_patches/action_controller_rails2.rb +129 -0
- data/lib/time_bandits/monkey_patches/active_record_rails2.rb +86 -0
- data/lib/time_bandits/time_consumers/database_rails2.rb +53 -0
- data/lib/time_bandits/time_consumers/garbage_collection.rb +8 -3
- data/lib/time_bandits/time_consumers/jmx.rb +7 -5
- data/lib/time_bandits/version.rb +1 -1
- data/rails/init.rb +1 -0
- data/time_bandits.gemspec +3 -3
- metadata +29 -7
data/README.rdoc
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
== About
|
|
4
4
|
|
|
5
|
-
Time Bandits is a plugin which enhances Rails' controller/view/db benchmark logging.
|
|
5
|
+
Time Bandits is a gem plugin for Rails which enhances Rails' controller/view/db benchmark logging.
|
|
6
6
|
|
|
7
7
|
== Usage
|
|
8
8
|
|
|
@@ -81,9 +81,7 @@ rewrite, hence we changed the name.
|
|
|
81
81
|
|
|
82
82
|
== License
|
|
83
83
|
|
|
84
|
-
Copyright (c) 2009,2011 Stefan Kaes <skaes@railsexpress.de>
|
|
85
|
-
|
|
86
|
-
Some portions Copyright (c) 2008 tylerkovacs
|
|
84
|
+
Copyright (c) 2009, 2011 Stefan Kaes <skaes@railsexpress.de>
|
|
87
85
|
|
|
88
86
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
89
87
|
a copy of this software and associated documentation files (the
|
data/README_RAILS2.rdoc
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
= Time Bandits
|
|
2
|
+
|
|
3
|
+
== About
|
|
4
|
+
|
|
5
|
+
Time Bandits is a plugin which enhances Rails' controller/view/db benchmark logging.
|
|
6
|
+
|
|
7
|
+
== Usage
|
|
8
|
+
|
|
9
|
+
Without configuration, the standard Rails 'Completed line' will change
|
|
10
|
+
from its default format
|
|
11
|
+
|
|
12
|
+
Completed in 56ms (View: 28, DB: 5) | 200 OK [http://127.0.0.1/jobs/info]
|
|
13
|
+
|
|
14
|
+
to:
|
|
15
|
+
|
|
16
|
+
Completed in 56.278ms (View: 28.488, DB: 5.111(2,0)) | 200 OK [http://127.0.0.1/jobs/info]
|
|
17
|
+
|
|
18
|
+
Here "DB: 5.111(2,0)" means that 2 DB queries were executed and there were 0 SQL query cache hits.
|
|
19
|
+
|
|
20
|
+
However, non-trivial applications also rather often use external services, which consume time that adds
|
|
21
|
+
to your total response time, and sometimes these external services are not under your control. In these
|
|
22
|
+
cases, it's very helpful to have an entry in your log file that records the time spent in the exterrnal
|
|
23
|
+
service (so that you can prove that it wasn't your rails app that slowed down during your slashdotting,
|
|
24
|
+
for example ;-).
|
|
25
|
+
|
|
26
|
+
Additional TimeConsumers can be added to the log using the "Timebandits.add" method.
|
|
27
|
+
|
|
28
|
+
Example:
|
|
29
|
+
|
|
30
|
+
TimeBandits.add TimeBandits::TimeConsumers::Memcached
|
|
31
|
+
TimeBandits.add TimeBandits::TimeConsumers::GarbageCollection.instance if GC.respond_to? :enable_stats
|
|
32
|
+
|
|
33
|
+
Here we've added two additional consumers, which are already provided with the plugin. (Note that GC
|
|
34
|
+
information requires a patched ruby, (e.g. http://github.com/skaes/matzruby, branch ruby187pl202patched
|
|
35
|
+
or Ruby Enterprise Edition).
|
|
36
|
+
|
|
37
|
+
With these two new time consumers, the log line changes to
|
|
38
|
+
|
|
39
|
+
Completed in 680.378ms (View: 28.488, DB: 5.111(2,0), MC: 5.382(6r,0m), GC: 120.100(1), HP: 0(2000000,546468,18682541,934967)) | 200 OK [http://127.0.0.1/jobs/info]
|
|
40
|
+
|
|
41
|
+
"MC: 5.382(6r,0m)" means that 6 memcache reads were performed and all keys were found in the cache (0 misses).
|
|
42
|
+
|
|
43
|
+
"GC: 120.100(1)" tells us that 1 garbage collection was triggered during the request, taking 120.100 milliseconds.
|
|
44
|
+
|
|
45
|
+
"HP: 0(2000000,546468,18682541,934967)" shows statistics on heap usage. The format is g(s,a,m,l), where
|
|
46
|
+
|
|
47
|
+
g: heap growth during the request (#slots)
|
|
48
|
+
s: size of the heap after request processing was completed (#slots)
|
|
49
|
+
a: number of object allocations during the request (#slots)
|
|
50
|
+
m: number of bytes allocated by the ruby x_malloc call (#bytes)
|
|
51
|
+
l: live data set size after last GC (#slots)
|
|
52
|
+
|
|
53
|
+
It's pretty easy to write additional time consumers; please refer to the source code.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
== Prerequisites
|
|
57
|
+
|
|
58
|
+
Rails 2.3.2, 2.3.3 or 2.3.4 The plugin will raise an error if you try
|
|
59
|
+
to use it with a different version.
|
|
60
|
+
|
|
61
|
+
A ruby with the railsbench GC patches applied, if you want to include
|
|
62
|
+
GC and heap size information in the completed line. This is very
|
|
63
|
+
useful, especially if you want to analyze your rails logs using logjam
|
|
64
|
+
(see http://github.com/alpinegizmo/logjam/).
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
== History
|
|
68
|
+
|
|
69
|
+
This plugin started from the code of the 'custom_benchmark' plugin
|
|
70
|
+
written by tylerkovacs. However, we changed so much of the code that
|
|
71
|
+
is is practically a full rewrite, hence we changed the name.
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
== License
|
|
75
|
+
|
|
76
|
+
Copyright (c) 2009 Stefan Kaes <skaes@railsexpress.de>
|
|
77
|
+
|
|
78
|
+
Some portions Copyright (c) 2008 tylerkovacs
|
|
79
|
+
|
|
80
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
81
|
+
a copy of this software and associated documentation files (the
|
|
82
|
+
"Software"), to deal in the Software without restriction, including
|
|
83
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
84
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
85
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
86
|
+
the following conditions:
|
|
87
|
+
|
|
88
|
+
The above copyright notice and this permission notice shall be
|
|
89
|
+
included in all copies or substantial portions of the Software.
|
|
90
|
+
|
|
91
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
92
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
93
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
94
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
95
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
96
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
97
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
98
|
+
|
data/init.rb
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# this file gets only loaded for rails2
|
|
2
|
+
require 'time_bandits'
|
|
3
|
+
require 'time_bandits/monkey_patches/active_record_rails2'
|
|
4
|
+
require 'time_bandits/monkey_patches/action_controller_rails2'
|
|
5
|
+
|
|
6
|
+
ActionController::Base.send :include, ActionController::TimeBanditry
|
|
7
|
+
|
|
8
|
+
TimeBandits::TimeConsumers::GarbageCollection.heap_dumps_enabled = %w(production development).include?(RAILS_ENV)
|
|
9
|
+
|
|
10
|
+
# TimeBandits.add TimeBandits::TimeConsumers::Memcached if defined?(Memcached)
|
|
11
|
+
# TimeBandits.add TimeBandits::TimeConsumers::GarbageCollection.instance if GC.respond_to? :enable_stats
|
|
12
|
+
# TimeBandits.add TimeBandits::TimeConsumers::JMX.instance if defined? JRUBY_VERSION
|
data/lib/time_bandits.rb
CHANGED
|
@@ -3,14 +3,18 @@ require 'active_support/core_ext'
|
|
|
3
3
|
module TimeBandits
|
|
4
4
|
|
|
5
5
|
module TimeConsumers
|
|
6
|
-
|
|
6
|
+
if defined?(Rails) && Rails::VERSION::STRING < "3.0"
|
|
7
|
+
autoload :Database, 'time_bandits/time_consumers/database_rails2'
|
|
8
|
+
else
|
|
9
|
+
autoload :Database, 'time_bandits/time_consumers/database'
|
|
10
|
+
end
|
|
7
11
|
autoload :GarbageCollection, 'time_bandits/time_consumers/garbage_collection'
|
|
8
12
|
autoload :JMX, 'time_bandits/time_consumers/jmx'
|
|
9
13
|
autoload :MemCache, 'time_bandits/time_consumers/mem_cache'
|
|
10
14
|
autoload :Memcached, 'time_bandits/time_consumers/memcached'
|
|
11
15
|
end
|
|
12
16
|
|
|
13
|
-
require 'time_bandits/railtie' if defined?(Rails)
|
|
17
|
+
require 'time_bandits/railtie' if defined?(Rails) && Rails::VERSION::STRING >= "3.0"
|
|
14
18
|
|
|
15
19
|
mattr_accessor :time_bandits
|
|
16
20
|
self.time_bandits = []
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# =========================================================================================================
|
|
2
|
+
# IMPORTANT: the plugin changes the ActionController#process method chain
|
|
3
|
+
#
|
|
4
|
+
# the original rails stack looks like this:
|
|
5
|
+
#
|
|
6
|
+
# ApplicationController#process_with_unload_user
|
|
7
|
+
# ActionController::SessionManagement#process_with_session_management_support
|
|
8
|
+
# ActionController::Filters#process_with_filters
|
|
9
|
+
# ActionController::Base#process
|
|
10
|
+
# ActionController::Caching::SqlCache#perform_action_with_caching
|
|
11
|
+
# ActionController::Rescue#perform_action_with_rescue
|
|
12
|
+
# *** ActionController::Benchmarking#perform_action_with_benchmark ***
|
|
13
|
+
# ActionController::Filters#perform_action_with_filters (==> this runs the filters)
|
|
14
|
+
# ActionController::Base#perform_action (==> run the action and eventually call render)
|
|
15
|
+
# ActionController::Benchmarking#render_with_benchmark (==> this is where the rendering time gets computed)
|
|
16
|
+
# ActionController::Base::render
|
|
17
|
+
#
|
|
18
|
+
# with the plugin installed, the stack looks like this:
|
|
19
|
+
#
|
|
20
|
+
# ApplicationController#process_with_unload_user
|
|
21
|
+
# ActionController::SessionManagement#process_with_session_management_support
|
|
22
|
+
# ActionController::Filters#process_with_filters
|
|
23
|
+
# ActionController::Base#process
|
|
24
|
+
# *** ActionController::Benchmarking#perform_action_with_time_bandits *** <=========== !!!!
|
|
25
|
+
# ActionController::Caching::SqlCache#perform_action_with_caching
|
|
26
|
+
# ActionController::Rescue#perform_action_with_rescue
|
|
27
|
+
# ActionController::Filters#perform_action_with_filters (==> this runs the filters)
|
|
28
|
+
# ActionController::Base#perform_action (==> run the action and eventually call render)
|
|
29
|
+
# ActionController::Benchmarking#render_with_benchmark (==> this is where the rendering time gets computed)
|
|
30
|
+
# ActionController::Base::render
|
|
31
|
+
# =========================================================================================================
|
|
32
|
+
|
|
33
|
+
module ActionController #:nodoc:
|
|
34
|
+
module TimeBanditry #:nodoc:
|
|
35
|
+
def self.included(base)
|
|
36
|
+
base.class_eval do
|
|
37
|
+
alias_method_chain :perform_action, :time_bandits
|
|
38
|
+
alias_method_chain :rescue_action, :time_bandits
|
|
39
|
+
|
|
40
|
+
# if timebandits are used, the default benchmarking is
|
|
41
|
+
# disabled. As alias_method_chain is unfriendly to extensions,
|
|
42
|
+
# this is done by skipping perform_action_with_benchmarks by
|
|
43
|
+
# calling perform_action_without_benchmarks at the appropriate
|
|
44
|
+
# place.
|
|
45
|
+
def perform_action_without_rescue
|
|
46
|
+
perform_action_without_benchmark
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
alias_method :render, :render_with_benchmark
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
TimeBandits.add TimeBandits::TimeConsumers::Database.instance
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def render_with_benchmark(options = nil, extra_options = {}, &block)
|
|
56
|
+
if logger
|
|
57
|
+
before_rendering = TimeBandits.consumed
|
|
58
|
+
|
|
59
|
+
render_output = nil
|
|
60
|
+
@view_runtime = Benchmark::realtime { render_output = render_without_benchmark(options, extra_options, &block) }
|
|
61
|
+
|
|
62
|
+
other_time_consumed_during_rendering = TimeBandits.consumed - before_rendering
|
|
63
|
+
@view_runtime -= other_time_consumed_during_rendering
|
|
64
|
+
|
|
65
|
+
render_output
|
|
66
|
+
else
|
|
67
|
+
render_without_benchmark(options, extra_options, &block)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def perform_action_with_time_bandits
|
|
72
|
+
if logger
|
|
73
|
+
TimeBandits.reset
|
|
74
|
+
|
|
75
|
+
seconds = [ Benchmark::measure{ perform_action_without_time_bandits }.real, 0.0001 ].max
|
|
76
|
+
|
|
77
|
+
log_message = "Completed in #{sprintf("%.3f", seconds * 1000)}ms"
|
|
78
|
+
|
|
79
|
+
log_message << " ("
|
|
80
|
+
log_message << view_runtime
|
|
81
|
+
TimeBandits.time_bandits.each do |bandit|
|
|
82
|
+
log_message << ", #{bandit.runtime}"
|
|
83
|
+
end
|
|
84
|
+
log_message << ")"
|
|
85
|
+
|
|
86
|
+
log_message << " | #{response.status}"
|
|
87
|
+
log_message << " [#{complete_request_uri rescue "unknown"}]"
|
|
88
|
+
|
|
89
|
+
logger.info(log_message)
|
|
90
|
+
response.headers["X-Runtime"] = "#{sprintf("%.0f", seconds * 1000)}ms"
|
|
91
|
+
else
|
|
92
|
+
perform_action_without_time_bandits
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def rescue_action_with_time_bandits(exception)
|
|
97
|
+
# HACK!
|
|
98
|
+
if logger && !caller.any?{|c| c =~ /perform_action_without_time_bandits/ }
|
|
99
|
+
TimeBandits.reset
|
|
100
|
+
|
|
101
|
+
seconds = [ Benchmark::measure{ rescue_action_without_time_bandits(exception) }.real, 0.0001 ].max
|
|
102
|
+
|
|
103
|
+
log_message = "Completed in #{sprintf("%.3f", seconds * 1000)}ms"
|
|
104
|
+
|
|
105
|
+
log_message << " ("
|
|
106
|
+
log_message << view_runtime
|
|
107
|
+
TimeBandits.time_bandits.each do |bandit|
|
|
108
|
+
log_message << ", #{bandit.runtime}"
|
|
109
|
+
end
|
|
110
|
+
log_message << ")"
|
|
111
|
+
|
|
112
|
+
log_message << " | #{response.status}"
|
|
113
|
+
log_message << " [#{complete_request_uri rescue "unknown"}]"
|
|
114
|
+
|
|
115
|
+
logger.info(log_message)
|
|
116
|
+
response.headers["X-Runtime"] = "#{sprintf("%.0f", seconds * 1000)}ms"
|
|
117
|
+
else
|
|
118
|
+
rescue_action_without_time_bandits(exception)
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
private
|
|
123
|
+
|
|
124
|
+
def view_runtime
|
|
125
|
+
"View: %.3f" % ((@view_runtime||0) * 1000)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
end
|
|
129
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# this file monkey patches class ActiveRecord::ConnectionAdapters::AbstractAdapter
|
|
2
|
+
# and the module module ActiveRecord::ConnectionAdapters::QueryCache
|
|
3
|
+
# to count the number of sql statements being executed.
|
|
4
|
+
# it needs to be adapted to each new rails version
|
|
5
|
+
|
|
6
|
+
raise "AR abstract adapter monkey patch for custom benchmarking is not compatible with your rails version" unless
|
|
7
|
+
%w(2.3.2 2.3.3 2.3.4 2.3.8 2.3.9 2.3.10).include?(Rails::VERSION::STRING)
|
|
8
|
+
|
|
9
|
+
module ActiveRecord
|
|
10
|
+
module ConnectionAdapters
|
|
11
|
+
class ConnectionPool
|
|
12
|
+
attr_reader :connections
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class AbstractAdapter
|
|
16
|
+
attr_accessor :call_count, :query_cache_hits
|
|
17
|
+
|
|
18
|
+
def initialize(connection, logger = nil) #:nodoc:
|
|
19
|
+
@connection, @logger = connection, logger
|
|
20
|
+
@runtime = 0
|
|
21
|
+
@call_count = 0
|
|
22
|
+
@last_verification = 0
|
|
23
|
+
@query_cache_enabled = false
|
|
24
|
+
@query_cache_hits = 0
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def reset_call_count
|
|
28
|
+
calls = @call_count
|
|
29
|
+
@call_count = 0
|
|
30
|
+
calls
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def reset_query_cache_hits
|
|
34
|
+
hits = @query_cache_hits
|
|
35
|
+
@query_cache_hits = 0
|
|
36
|
+
hits
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
protected
|
|
40
|
+
def log(sql, name)
|
|
41
|
+
if block_given?
|
|
42
|
+
result = nil
|
|
43
|
+
seconds = Benchmark.realtime { result = yield }
|
|
44
|
+
@runtime += seconds
|
|
45
|
+
@call_count += 1
|
|
46
|
+
log_info(sql, name, seconds * 1000)
|
|
47
|
+
result
|
|
48
|
+
else
|
|
49
|
+
log_info(sql, name, 0)
|
|
50
|
+
nil
|
|
51
|
+
end
|
|
52
|
+
rescue Exception => e
|
|
53
|
+
# Log message and raise exception.
|
|
54
|
+
# Set last_verification to 0, so that connection gets verified
|
|
55
|
+
# upon reentering the request loop
|
|
56
|
+
@last_verification = 0
|
|
57
|
+
message = "#{e.class.name}: #{e.message}: #{sql}"
|
|
58
|
+
log_info(message, name, 0)
|
|
59
|
+
raise ActiveRecord::StatementInvalid, message
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
module QueryCache
|
|
64
|
+
private
|
|
65
|
+
def cache_sql(sql)
|
|
66
|
+
result =
|
|
67
|
+
if @query_cache.has_key?(sql)
|
|
68
|
+
@query_cache_hits += 1
|
|
69
|
+
log_info(sql, "CACHE", 0.0)
|
|
70
|
+
@query_cache[sql]
|
|
71
|
+
else
|
|
72
|
+
@query_cache[sql] = yield
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
if Array === result
|
|
76
|
+
result.collect { |row| row.dup }
|
|
77
|
+
else
|
|
78
|
+
result.duplicable? ? result.dup : result
|
|
79
|
+
end
|
|
80
|
+
rescue TypeError
|
|
81
|
+
result
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Database time consumer for Rails2. You need to add it via
|
|
2
|
+
#
|
|
3
|
+
# TimeBandits.add TimeBandits::TimeConsumers::Database.instance
|
|
4
|
+
#
|
|
5
|
+
|
|
6
|
+
module TimeBandits
|
|
7
|
+
module TimeConsumers
|
|
8
|
+
# provide a time consumer interface to ActiveRecord for perform_action_with_benchmark and render_with_benchmark
|
|
9
|
+
class Database
|
|
10
|
+
def initialize
|
|
11
|
+
@consumed = 0.0
|
|
12
|
+
@call_count = 0
|
|
13
|
+
@query_cache_hits = 0
|
|
14
|
+
end
|
|
15
|
+
private :initialize
|
|
16
|
+
|
|
17
|
+
def self.instance
|
|
18
|
+
@instance ||= new
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def reset
|
|
22
|
+
reset_stats
|
|
23
|
+
@call_count = 0
|
|
24
|
+
@consumed = 0.0
|
|
25
|
+
@query_cache_hits = 0
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def consumed
|
|
29
|
+
hits, calls, time = reset_stats
|
|
30
|
+
@query_cache_hits += hits
|
|
31
|
+
@call_count += calls
|
|
32
|
+
@consumed += time
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def runtime
|
|
36
|
+
sprintf "DB: %.3f(%d,%d)", @consumed * 1000, @call_count, @query_cache_hits
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
def all_connections
|
|
41
|
+
ActiveRecord::Base.connection_handler.connection_pools.values.map{|pool| pool.connections}.flatten
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def reset_stats
|
|
45
|
+
connections = all_connections
|
|
46
|
+
hits = connections.map{|c| c.reset_query_cache_hits}.sum
|
|
47
|
+
calls = connections.map{|c| c.reset_call_count}.sum
|
|
48
|
+
time = connections.map{|c| c.reset_runtime}.sum
|
|
49
|
+
[hits, calls, time]
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -72,14 +72,19 @@ module TimeBandits
|
|
|
72
72
|
end
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
+
if defined?(Rails) && Rails::VERSION::STRING >= "3.0"
|
|
76
|
+
GCFORMAT = "GC: %.3f(%d) | HP: %d(%d,%d,%d,%d)"
|
|
77
|
+
else
|
|
78
|
+
GCFORMAT= "GC: %.3f(%d), HP: %d(%d,%d,%d,%d)"
|
|
79
|
+
end
|
|
80
|
+
|
|
75
81
|
def runtime
|
|
76
82
|
heap_slots = GC.heap_slots
|
|
77
83
|
heap_growth = self.heap_growth
|
|
78
84
|
allocated_objects = self.allocated_objects
|
|
79
85
|
allocated_size = self.allocated_size
|
|
80
|
-
GCHacks.heap_dump if heap_growth > 0 && @@heap_dumps_enabled
|
|
81
|
-
|
|
82
|
-
[consumed_gc_time * 1000, collections, heap_growth, heap_slots, allocated_objects, allocated_size, live_data_set_size]
|
|
86
|
+
GCHacks.heap_dump if heap_growth > 0 && @@heap_dumps_enabled && defined?(GCHacks)
|
|
87
|
+
GCFORMAT % [consumed_gc_time * 1000, collections, heap_growth, heap_slots, allocated_objects, allocated_size, live_data_set_size]
|
|
83
88
|
end
|
|
84
89
|
|
|
85
90
|
else
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# a time consumer implementation for jruby, using
|
|
1
|
+
# a time consumer implementation for jruby, using jmx
|
|
2
2
|
#
|
|
3
3
|
# the gc counts and times reported are summed over all the garbage collectors
|
|
4
4
|
# heap_growth reflects changes in the committed size of the java heap
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
# allocated_size reflects changes in the active (used) part of the java heap
|
|
7
7
|
# java non-heap memory is not reported
|
|
8
8
|
|
|
9
|
+
require 'jmx' if defined? JRUBY_VERSION
|
|
10
|
+
|
|
9
11
|
module TimeBandits
|
|
10
12
|
module TimeConsumers
|
|
11
13
|
class JMX
|
|
@@ -28,7 +30,7 @@ module TimeBandits
|
|
|
28
30
|
def gc_time
|
|
29
31
|
@collectors.to_array.map {|gc| @server[gc].collection_time}.sum
|
|
30
32
|
end
|
|
31
|
-
|
|
33
|
+
|
|
32
34
|
def gc_collections
|
|
33
35
|
@collectors.to_array.map {|gc| @server[gc].collection_count}.sum
|
|
34
36
|
end
|
|
@@ -36,7 +38,7 @@ module TimeBandits
|
|
|
36
38
|
def heap_size
|
|
37
39
|
@memory_bean.heap_memory_usage.committed
|
|
38
40
|
end
|
|
39
|
-
|
|
41
|
+
|
|
40
42
|
def heap_usage
|
|
41
43
|
@memory_bean.heap_memory_usage.used
|
|
42
44
|
end
|
|
@@ -47,7 +49,7 @@ module TimeBandits
|
|
|
47
49
|
@heap_committed = heap_size
|
|
48
50
|
@heap_used = heap_usage
|
|
49
51
|
end
|
|
50
|
-
|
|
52
|
+
|
|
51
53
|
def collections_delta
|
|
52
54
|
gc_collections - @collections
|
|
53
55
|
end
|
|
@@ -63,7 +65,7 @@ module TimeBandits
|
|
|
63
65
|
def usage_growth
|
|
64
66
|
heap_usage - @heap_used
|
|
65
67
|
end
|
|
66
|
-
|
|
68
|
+
|
|
67
69
|
def allocated_objects
|
|
68
70
|
0
|
|
69
71
|
end
|
data/lib/time_bandits/version.rb
CHANGED
data/rails/init.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require File.expand_path('../../init.rb', __FILE__)
|
data/time_bandits.gemspec
CHANGED
|
@@ -8,15 +8,15 @@ Gem::Specification.new do |s|
|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
|
9
9
|
s.authors = ["Stefan Kaes"]
|
|
10
10
|
s.email = ["skaes@railsexpress.de"]
|
|
11
|
-
s.homepage = "https://github.com/skaes/time_bandits/
|
|
11
|
+
s.homepage = "https://github.com/skaes/time_bandits/"
|
|
12
12
|
s.summary = "Custom performance logging for Rails"
|
|
13
|
-
s.description = "Rails
|
|
13
|
+
s.description = "Rails Completed Line on Steroids"
|
|
14
14
|
|
|
15
15
|
s.files = `git ls-files`.split("\n")
|
|
16
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
17
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
18
18
|
s.require_paths = ["lib"]
|
|
19
19
|
|
|
20
|
-
s.add_runtime_dependency("activesupport", ["
|
|
20
|
+
s.add_runtime_dependency("activesupport", [">= 2.3.2"])
|
|
21
21
|
end
|
|
22
22
|
|
metadata
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: time_bandits
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 15
|
|
4
5
|
prerelease:
|
|
5
|
-
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 0
|
|
9
|
+
- 8
|
|
10
|
+
version: 0.0.8
|
|
6
11
|
platform: ruby
|
|
7
12
|
authors:
|
|
8
13
|
- Stefan Kaes
|
|
@@ -10,7 +15,7 @@ autorequire:
|
|
|
10
15
|
bindir: bin
|
|
11
16
|
cert_chain: []
|
|
12
17
|
|
|
13
|
-
date: 2011-
|
|
18
|
+
date: 2011-08-06 00:00:00 +02:00
|
|
14
19
|
default_executable:
|
|
15
20
|
dependencies:
|
|
16
21
|
- !ruby/object:Gem::Dependency
|
|
@@ -19,12 +24,17 @@ dependencies:
|
|
|
19
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
|
20
25
|
none: false
|
|
21
26
|
requirements:
|
|
22
|
-
- -
|
|
27
|
+
- - ">="
|
|
23
28
|
- !ruby/object:Gem::Version
|
|
24
|
-
|
|
29
|
+
hash: 7
|
|
30
|
+
segments:
|
|
31
|
+
- 2
|
|
32
|
+
- 3
|
|
33
|
+
- 2
|
|
34
|
+
version: 2.3.2
|
|
25
35
|
type: :runtime
|
|
26
36
|
version_requirements: *id001
|
|
27
|
-
description: Rails
|
|
37
|
+
description: Rails Completed Line on Steroids
|
|
28
38
|
email:
|
|
29
39
|
- skaes@railsexpress.de
|
|
30
40
|
executables: []
|
|
@@ -37,24 +47,30 @@ files:
|
|
|
37
47
|
- .gitignore
|
|
38
48
|
- Gemfile
|
|
39
49
|
- README.rdoc
|
|
50
|
+
- README_RAILS2.rdoc
|
|
40
51
|
- Rakefile
|
|
41
52
|
- TODO
|
|
53
|
+
- init.rb
|
|
42
54
|
- lib/time_bandits.rb
|
|
43
55
|
- lib/time_bandits/monkey_patches/action_controller.rb
|
|
56
|
+
- lib/time_bandits/monkey_patches/action_controller_rails2.rb
|
|
44
57
|
- lib/time_bandits/monkey_patches/active_record.rb
|
|
58
|
+
- lib/time_bandits/monkey_patches/active_record_rails2.rb
|
|
45
59
|
- lib/time_bandits/monkey_patches/memcache-client.rb
|
|
46
60
|
- lib/time_bandits/monkey_patches/memcached.rb
|
|
47
61
|
- lib/time_bandits/monkey_patches/rails_rack_logger.rb
|
|
48
62
|
- lib/time_bandits/railtie.rb
|
|
49
63
|
- lib/time_bandits/time_consumers/database.rb
|
|
64
|
+
- lib/time_bandits/time_consumers/database_rails2.rb
|
|
50
65
|
- lib/time_bandits/time_consumers/garbage_collection.rb
|
|
51
66
|
- lib/time_bandits/time_consumers/jmx.rb
|
|
52
67
|
- lib/time_bandits/time_consumers/mem_cache.rb
|
|
53
68
|
- lib/time_bandits/time_consumers/memcached.rb
|
|
54
69
|
- lib/time_bandits/version.rb
|
|
70
|
+
- rails/init.rb
|
|
55
71
|
- time_bandits.gemspec
|
|
56
72
|
has_rdoc: true
|
|
57
|
-
homepage: https://github.com/skaes/time_bandits/
|
|
73
|
+
homepage: https://github.com/skaes/time_bandits/
|
|
58
74
|
licenses: []
|
|
59
75
|
|
|
60
76
|
post_install_message:
|
|
@@ -67,17 +83,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
67
83
|
requirements:
|
|
68
84
|
- - ">="
|
|
69
85
|
- !ruby/object:Gem::Version
|
|
86
|
+
hash: 3
|
|
87
|
+
segments:
|
|
88
|
+
- 0
|
|
70
89
|
version: "0"
|
|
71
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
91
|
none: false
|
|
73
92
|
requirements:
|
|
74
93
|
- - ">="
|
|
75
94
|
- !ruby/object:Gem::Version
|
|
95
|
+
hash: 3
|
|
96
|
+
segments:
|
|
97
|
+
- 0
|
|
76
98
|
version: "0"
|
|
77
99
|
requirements: []
|
|
78
100
|
|
|
79
101
|
rubyforge_project:
|
|
80
|
-
rubygems_version: 1.
|
|
102
|
+
rubygems_version: 1.6.2
|
|
81
103
|
signing_key:
|
|
82
104
|
specification_version: 3
|
|
83
105
|
summary: Custom performance logging for Rails
|