time_bandits 0.7.0 → 0.7.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35f89fba835aab0fa8499beaa01ec8f407d8f91c
4
- data.tar.gz: 89209eb4f594b1365907ee4d0c3f2206595f35af
3
+ metadata.gz: 1c02c0496a8f416f2a02bd4ca1c95d45c5f16d72
4
+ data.tar.gz: fae74e56ca2de98be7cd3baffea5e55c960d795e
5
5
  SHA512:
6
- metadata.gz: 17989ad515a1eae58cae1b6410ad20726852d3e8c12fbdd45c0c1ed3a001ea2b02b1024eb37b72ad4519c8a5015fe41848c00f75cbf29c98d38f703c59937bf4
7
- data.tar.gz: de288045a8ff9f03503485a24b63a138d68e024ff2cbf232cad1ef927e45b19371cf77980243fa2c23283a1559bf7bcf94f74896a153aa5ddc085cd432ea7f39
6
+ metadata.gz: 8667e3d1e7469130c909bdd62b6e28cda05ff499eef7c94cef32967e689405e5e7e4021151c8afb690d1e401886aae58df3d08624eed42f2abea4fc7f9379ee1
7
+ data.tar.gz: 4e44865ab865d5406190c7437323ec2f0f3bd957ccd8296c7293cfe27bca26e5d39bdc5cdf8b017c5fd11f4115846cf62c963674187dd4692c64b7d35cdf35b6
@@ -80,10 +80,13 @@ changed so much of the code that is is practically a full rewrite, hence we chan
80
80
 
81
81
  == Running Tests
82
82
 
83
- In order for the test to run you need a running memcached and redis-server
83
+ In order for the test to run you need a running memcached, redis-server and mysql
84
84
 
85
85
  == Release Notes
86
86
 
87
+ version 0.7.1
88
+ - support measuring sequel gem
89
+
87
90
  version 0.7.0
88
91
  - switched to byebug (debugger does not fully support 2.0 and 2.1 not at all)
89
92
  - adapted garbage collection statistics to work for 2.1
@@ -15,6 +15,7 @@ module TimeBandits
15
15
  autoload :Memcached, 'time_bandits/time_consumers/memcached'
16
16
  autoload :Dalli, 'time_bandits/time_consumers/dalli'
17
17
  autoload :Redis, 'time_bandits/time_consumers/redis'
18
+ autoload :Sequel, 'time_bandits/time_consumers/sequel'
18
19
  end
19
20
 
20
21
  require 'time_bandits/railtie' if defined?(Rails) && Rails::VERSION::STRING >= "3.0"
@@ -44,8 +45,12 @@ module TimeBandits
44
45
  end
45
46
 
46
47
  def self.metrics
47
- metrics = {}
48
- time_bandits.each{|b| metrics.merge! b.metrics}
48
+ metrics = Hash.new(0)
49
+ time_bandits.each do |bandit|
50
+ bandit.metrics.each do |k,v|
51
+ metrics[k] += v
52
+ end
53
+ end
49
54
  metrics
50
55
  end
51
56
 
@@ -0,0 +1,19 @@
1
+ require 'sequel'
2
+
3
+ major, minor, _ = Sequel.version.split('.').map(&:to_i)
4
+ if major < 4 || (major == 4 && minor < 15)
5
+ raise "time_bandits Sequel monkey patch is not compatible with your sequel version"
6
+ end
7
+
8
+ Sequel::Database.class_eval do
9
+ alias :_orig_log_yield :log_yield
10
+
11
+ def log_yield(*args)
12
+ begin
13
+ start = Time.now
14
+ _orig_log_yield(args) { yield if block_given? }
15
+ ensure
16
+ ActiveSupport::Notifications.instrument('duration.sequel', durationInSeconds: Time.now - start)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ # a time consumer implementation for sequel
2
+ # install into application_controller.rb with the line
3
+ #
4
+ # time_bandit TimeBandits::TimeConsumers::Sequel
5
+ #
6
+ require 'time_bandits/monkey_patches/sequel'
7
+
8
+ module TimeBandits
9
+ module TimeConsumers
10
+ class Sequel < BaseConsumer
11
+ prefix :db
12
+ fields :time, :calls
13
+ format "Sequel: %.3fms(%dq)", :time, :calls
14
+
15
+ class Subscriber < ActiveSupport::LogSubscriber
16
+ def duration(event)
17
+ i = Sequel.instance
18
+ i.time += (event.payload[:durationInSeconds] * 1000)
19
+ i.calls += 1
20
+ end
21
+ end
22
+ Subscriber.attach_to(:sequel)
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module TimeBandits
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
@@ -0,0 +1,58 @@
1
+ require_relative '../test_helper'
2
+
3
+ class DuplicateBandits < Test::Unit::TestCase
4
+ class FooConsumer < TimeBandits::TimeConsumers::BaseConsumer
5
+ prefix :simple
6
+ fields :time, :calls
7
+ format "SimpleFoo: %.1fms(%d calls)", :time, :calls
8
+ end
9
+
10
+ class BarConsumer < TimeBandits::TimeConsumers::BaseConsumer
11
+ prefix :simple
12
+ fields :time, :calls
13
+ format "SimpleBar: %.1fms(%d calls)", :time, :calls
14
+ end
15
+
16
+ def setup
17
+ TimeBandits.time_bandits = []
18
+ TimeBandits.add FooConsumer
19
+ TimeBandits.add BarConsumer
20
+ TimeBandits.reset
21
+ end
22
+
23
+ test "nothing measured" do
24
+ assert_equal({
25
+ :simple_time => 0,
26
+ :simple_calls => 0
27
+ }, TimeBandits.metrics)
28
+ end
29
+
30
+ test "only one consumer measured sth (the one)" do
31
+ FooConsumer.instance.calls = 3
32
+ FooConsumer.instance.time = 0.123
33
+ assert_equal({
34
+ :simple_time => 0.123,
35
+ :simple_calls => 3
36
+ }, TimeBandits.metrics)
37
+ end
38
+
39
+ test "only one consumer measured sth (the other)" do
40
+ BarConsumer.instance.calls = 2
41
+ BarConsumer.instance.time = 0.321
42
+ assert_equal({
43
+ :simple_time => 0.321,
44
+ :simple_calls => 2
45
+ }, TimeBandits.metrics)
46
+ end
47
+
48
+ test "both consumer measured sth" do
49
+ FooConsumer.instance.calls = 3
50
+ FooConsumer.instance.time = 0.123
51
+ BarConsumer.instance.calls = 2
52
+ BarConsumer.instance.time = 0.321
53
+ assert_equal({
54
+ :simple_time => 0.444,
55
+ :simple_calls => 5
56
+ }, TimeBandits.metrics)
57
+ end
58
+ end
@@ -0,0 +1,43 @@
1
+ require_relative '../test_helper'
2
+ require 'sequel'
3
+
4
+ class SequelTest < Test::Unit::TestCase
5
+ def setup
6
+ TimeBandits.time_bandits = []
7
+ TimeBandits.add TimeBandits::TimeConsumers::Sequel
8
+ TimeBandits.reset
9
+ end
10
+
11
+ test "getting metrics" do
12
+ nothing_measured = {
13
+ :db_time => 0,
14
+ :db_calls => 0
15
+ }
16
+ assert_equal nothing_measured, metrics
17
+ end
18
+
19
+ test "formatting" do
20
+ bandit.calls = 3
21
+ assert_equal "Sequel: 0.000ms(3q)", TimeBandits.runtime
22
+ end
23
+
24
+ test "metrics" do
25
+ (1..4).each { sequel['SELECT 1'].all }
26
+
27
+ assert_equal 6, metrics[:db_calls] # +2 for set wait_timeout and set SQL_AUTO_IS_NULL=0
28
+ assert 0 < metrics[:db_time]
29
+ assert_equal metrics[:db_time], TimeBandits.consumed
30
+ end
31
+
32
+ def sequel
33
+ @sequel ||= Sequel.connect('mysql2://localhost:3601')
34
+ end
35
+
36
+ def metrics
37
+ TimeBandits.metrics
38
+ end
39
+
40
+ def bandit
41
+ TimeBandits::TimeConsumers::Sequel.instance
42
+ end
43
+ end
@@ -26,6 +26,8 @@ Gem::Specification.new do |s|
26
26
  s.add_development_dependency("dalli")
27
27
  s.add_development_dependency("redis")
28
28
  s.add_development_dependency("memcached")
29
+ s.add_development_dependency("sequel")
30
+ s.add_development_dependency("mysql2")
29
31
  s.add_development_dependency("minitest", '~> 4.7.5')
30
32
  end
31
33
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_bandits
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Kaes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-02 00:00:00.000000000 Z
11
+ date: 2014-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thread_variables
@@ -122,6 +122,34 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: sequel
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: mysql2
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
125
153
  - !ruby/object:Gem::Dependency
126
154
  name: minitest
127
155
  requirement: !ruby/object:Gem::Requirement
@@ -146,7 +174,6 @@ files:
146
174
  - ".gitignore"
147
175
  - Gemfile
148
176
  - README.rdoc
149
- - README_RAILS2.rdoc
150
177
  - Rakefile
151
178
  - TODO
152
179
  - lib/time_bandits.rb
@@ -156,6 +183,7 @@ files:
156
183
  - lib/time_bandits/monkey_patches/memcache-client.rb
157
184
  - lib/time_bandits/monkey_patches/memcached.rb
158
185
  - lib/time_bandits/monkey_patches/redis.rb
186
+ - lib/time_bandits/monkey_patches/sequel.rb
159
187
  - lib/time_bandits/rack/logger.rb
160
188
  - lib/time_bandits/rack/logger40.rb
161
189
  - lib/time_bandits/railtie.rb
@@ -167,15 +195,18 @@ files:
167
195
  - lib/time_bandits/time_consumers/mem_cache.rb
168
196
  - lib/time_bandits/time_consumers/memcached.rb
169
197
  - lib/time_bandits/time_consumers/redis.rb
198
+ - lib/time_bandits/time_consumers/sequel.rb
170
199
  - lib/time_bandits/version.rb
171
200
  - rails/init.rb
172
201
  - test/test_helper.rb
173
202
  - test/unit/active_support_notifications_test.rb
174
203
  - test/unit/base_test.rb
175
204
  - test/unit/dalli_test.rb
205
+ - test/unit/duplicate_bandits.rb
176
206
  - test/unit/gc_consumer_test.rb
177
207
  - test/unit/memcached_test.rb
178
208
  - test/unit/redis_test.rb
209
+ - test/unit/sequel_test.rb
179
210
  - time_bandits.gemspec
180
211
  homepage: https://github.com/skaes/time_bandits/
181
212
  licenses:
@@ -206,6 +237,8 @@ test_files:
206
237
  - test/unit/active_support_notifications_test.rb
207
238
  - test/unit/base_test.rb
208
239
  - test/unit/dalli_test.rb
240
+ - test/unit/duplicate_bandits.rb
209
241
  - test/unit/gc_consumer_test.rb
210
242
  - test/unit/memcached_test.rb
211
243
  - test/unit/redis_test.rb
244
+ - test/unit/sequel_test.rb
@@ -1,98 +0,0 @@
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
-