time_bandits 0.6.7 → 0.7.0

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: 6bc64382ba7806f658e3f31c2fb51e9309c9373c
4
- data.tar.gz: b943632018760ae71fc694dfeb028b2c2fea7cd0
3
+ metadata.gz: 35f89fba835aab0fa8499beaa01ec8f407d8f91c
4
+ data.tar.gz: 89209eb4f594b1365907ee4d0c3f2206595f35af
5
5
  SHA512:
6
- metadata.gz: b564f1041505ecac8a3b4d117acc0c4933eb38f5a19447492d785406681842c243000ceb5b619eb49dc8a970da5be0bc3cc94102c0ada5c7d09f4e75e3a37ed3
7
- data.tar.gz: 13e485dea31a244973b93e2595e26e6c27cecd8263060334b957daf927bcde0ce5bf57f7b46fad34b1fce0f003d730044194e8252cd255cd6f1f8e91a5dbf124
6
+ metadata.gz: 17989ad515a1eae58cae1b6410ad20726852d3e8c12fbdd45c0c1ed3a001ea2b02b1024eb37b72ad4519c8a5015fe41848c00f75cbf29c98d38f703c59937bf4
7
+ data.tar.gz: de288045a8ff9f03503485a24b63a138d68e024ff2cbf232cad1ef927e45b19371cf77980243fa2c23283a1559bf7bcf94f74896a153aa5ddc085cd432ea7f39
data/README.rdoc CHANGED
@@ -84,9 +84,11 @@ In order for the test to run you need a running memcached and redis-server
84
84
 
85
85
  == Release Notes
86
86
 
87
- version 0.6.1
88
- - switched to byebug (debugger does not full support 2.0 and 2.1 not at all)
87
+ version 0.7.0
88
+ - switched to byebug (debugger does not fully support 2.0 and 2.1 not at all)
89
89
  - adapted garbage collection statistics to work for 2.1
90
+ - improved rails 4.x compatibility
91
+ - GC time consumer now tries to make the most out of an unpatched ruby
90
92
 
91
93
  version 0.6.0
92
94
  - added redis time consumer
@@ -99,14 +101,14 @@ version 0.5.1
99
101
  version 0.5:
100
102
  - has dropped rails 2 support
101
103
  - relies on ActiveSupport::Notifications
102
- - is suposedly thread safe
104
+ - is supposedly thread safe
103
105
  - all measurements are thread local (except GC statistics)
104
106
  - times are all measured in milliseconds internally
105
107
  - added class TimeBandits::TimeConsumers::BaseConsumer to simplify writing custom consumers
106
108
 
107
109
  == License
108
110
 
109
- Copyright (c) 2009-2012 Stefan Kaes <skaes@railsexpress.de>
111
+ Copyright (c) 2009-2014 Stefan Kaes <skaes@railsexpress.de>
110
112
 
111
113
  Permission is hereby granted, free of charge, to any person obtaining
112
114
  a copy of this software and associated documentation files (the
@@ -27,6 +27,12 @@ module TimeBandits
27
27
  end
28
28
  end
29
29
 
30
+ if GC.respond_to?(:time)
31
+ def _get_gc_time; GC.time; end
32
+ else
33
+ def _get_gc_time; 0; end
34
+ end
35
+
30
36
  if GC.respond_to?(:collections)
31
37
  def _get_collections; GC.collections; end
32
38
  elsif GC.respond_to?(:count)
@@ -51,23 +57,28 @@ module TimeBandits
51
57
  def _get_allocated_size; 0; end
52
58
  end
53
59
 
54
- if GC.respond_to? :heap_slots
55
-
56
- def reset
57
- @consumed = GC.time
58
- @collections = _get_collections
59
- @allocated_objects = _get_allocated_objects
60
- @allocated_size = _get_allocated_size
61
- @heap_slots = GC.heap_slots
62
- end
63
-
60
+ if GC.respond_to?(:heap_slots)
61
+ def _get_heap_slots; GC.heap_slots; end
62
+ elsif GC.respond_to?(:stat) && RUBY_VERSION >= "2.1.0"
63
+ def _get_heap_slots; GC.stat(:heap_live_slot) + GC.stat(:heap_free_slot) + GC.stat(:heap_final_slot); end
64
64
  else
65
+ def _get_heap_slots; 0; end
66
+ end
65
67
 
66
- def reset
67
- @consumed = GC.time
68
- @collections = _get_collections
69
- end
68
+ if GC.respond_to?(:heap_slots_live_after_last_gc)
69
+ def live_data_set_size; GC.heap_slots_live_after_last_gc; end
70
+ elsif GC.respond_to?(:stat) && RUBY_VERSION >= "2.1.0"
71
+ def live_data_set_size; GC.stat(:heap_live_slot); end
72
+ else
73
+ def live_data_set_size; 0; end
74
+ end
70
75
 
76
+ def reset
77
+ @consumed = _get_gc_time
78
+ @collections = _get_collections
79
+ @allocated_objects = _get_allocated_objects
80
+ @allocated_size = _get_allocated_size
81
+ @heap_slots = _get_heap_slots
71
82
  end
72
83
 
73
84
  def consumed
@@ -75,70 +86,48 @@ module TimeBandits
75
86
  end
76
87
 
77
88
  def consumed_gc_time # ms
78
- (GC.time - @consumed).to_f / 1000
89
+ (_get_gc_time - @consumed).to_f / 1000
79
90
  end
80
91
 
81
92
  def collections
82
93
  _get_collections - @collections
83
94
  end
84
95
 
85
- if GC.respond_to? :heap_slots
86
-
87
- def allocated_objects
88
- _get_allocated_objects - @allocated_objects
89
- end
90
-
91
- def allocated_size
92
- _get_allocated_size - @allocated_size
93
- end
94
-
95
- def heap_growth
96
- GC.heap_slots - @heap_slots
97
- end
98
-
99
- if GC.respond_to? :heap_slots_live_after_last_gc
100
- def live_data_set_size; GC.heap_slots_live_after_last_gc; end
101
- else
102
- def live_data_set_size; 0; end
103
- end
104
-
105
- GCFORMAT = "GC: %.3f(%d) | HP: %d(%d,%d,%d,%d)"
106
-
107
- def runtime
108
- heap_slots = GC.heap_slots
109
- heap_growth = self.heap_growth
110
- allocated_objects = self.allocated_objects
111
- allocated_size = self.allocated_size
112
- GCHacks.heap_dump if heap_growth > 0 && @@heap_dumps_enabled && defined?(GCHacks)
113
- GCFORMAT % [consumed_gc_time, collections, heap_growth, heap_slots, allocated_objects, allocated_size, live_data_set_size]
114
- end
96
+ def allocated_objects
97
+ _get_allocated_objects - @allocated_objects
98
+ end
115
99
 
116
- def metrics
117
- {
118
- :gc_time => consumed_gc_time,
119
- :gc_calls => collections,
120
- :heap_growth => heap_growth,
121
- :heap_size => GC.heap_slots,
122
- :allocated_objects => allocated_objects,
123
- :allocated_bytes => allocated_size,
124
- :live_data_set_size => live_data_set_size
125
- }
126
- end
100
+ def allocated_size
101
+ _get_allocated_size - @allocated_size
102
+ end
127
103
 
128
- else
104
+ def heap_growth
105
+ _get_heap_slots - @heap_slots
106
+ end
129
107
 
130
- def runtime
131
- "GC: %.3f(%d)" % [consumed_gc_time, collections]
132
- end
108
+ GCFORMAT = "GC: %.3f(%d) | HP: %d(%d,%d,%d,%d)"
133
109
 
134
- def metrics
135
- {
136
- :gc_time => consumed_gc_time,
137
- :gc_calls => collections
138
- }
139
- end
110
+ def runtime
111
+ heap_slots = _get_heap_slots
112
+ heap_growth = self.heap_growth
113
+ allocated_objects = self.allocated_objects
114
+ allocated_size = self.allocated_size
115
+ GCHacks.heap_dump if heap_growth > 0 && @@heap_dumps_enabled && defined?(GCHacks)
116
+ GCFORMAT % [consumed_gc_time, collections, heap_growth, heap_slots, allocated_objects, allocated_size, live_data_set_size]
117
+ end
140
118
 
119
+ def metrics
120
+ {
121
+ :gc_time => consumed_gc_time,
122
+ :gc_calls => collections,
123
+ :heap_growth => heap_growth,
124
+ :heap_size => _get_heap_slots,
125
+ :allocated_objects => allocated_objects,
126
+ :allocated_bytes => allocated_size,
127
+ :live_data_set_size => live_data_set_size
128
+ }
141
129
  end
130
+
142
131
  end
143
132
  end
144
133
  end
@@ -1,3 +1,3 @@
1
1
  module TimeBandits
2
- VERSION = "0.6.7"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -47,12 +47,22 @@ class GCConsumerTest < Test::Unit::TestCase
47
47
  def check_work
48
48
  GC.start
49
49
  m = TimeBandits.metrics
50
- assert 0 < m[:gc_calls]
51
- assert 0 < m[:gc_time]
52
- assert 0 <= m[:heap_growth]
53
- assert 0 < m[:heap_size]
54
- assert 0 < m[:allocated_objects]
55
- assert 0 < m[:allocated_bytes]
56
- assert 0 <= m[:live_data_set_size]
50
+ if GC.respond_to?(:time)
51
+ assert 0 < m[:gc_calls]
52
+ assert 0 < m[:gc_time]
53
+ assert 0 <= m[:heap_growth]
54
+ assert 0 < m[:heap_size]
55
+ assert 0 < m[:allocated_objects]
56
+ assert 0 < m[:allocated_bytes]
57
+ assert 0 <= m[:live_data_set_size]
58
+ else
59
+ assert 0 < m[:gc_calls]
60
+ assert 0 <= m[:gc_time]
61
+ assert 0 <= m[:heap_growth]
62
+ assert 0 < m[:heap_size]
63
+ assert 0 < m[:allocated_objects]
64
+ assert 0 <= m[:allocated_bytes]
65
+ assert 0 < m[:live_data_set_size]
66
+ end
57
67
  end
58
68
  end
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.6.7
4
+ version: 0.7.0
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-05-09 00:00:00.000000000 Z
11
+ date: 2014-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thread_variables