tracing 2.0.6 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9739a647135bf8bcc92c1409cea96320adb82ac2
4
- data.tar.gz: 7937518cbb1c5d0ca60e6e0c4c88d62389d4cca8
2
+ SHA256:
3
+ metadata.gz: 1d9bee81e1e7dfdc4d5fd0631a608f7755d5d41354ac769d43608c4f32a1229c
4
+ data.tar.gz: f53406967209b0b91f15400bfb9a044159ed5049662c824c06171371156830b7
5
5
  SHA512:
6
- metadata.gz: 23f0502f771d20479eb25621b4a5570a9566a5a9b80a8a7ea4fda8f628d87d1f9b9831ff81b17e909af8781f582c774ebfe2cd80c7011d2fd06baa67a5b54bf3
7
- data.tar.gz: 151a604da4a65877a69f895b23856f06a5a1ae384101a28f02c1853fb95661dea9275e29ba735eb3ad3502570eadf86817e3a4aa1fd02ae57d4b074eef653f59
6
+ metadata.gz: a6998f8a70dc488d6d4463cd071ca23b642e1c9716fa44fd286fd2fb99484392702fb1a026afaca8a13d70be4c24de2c2b5b56a583db754a3705b127529c9d46
7
+ data.tar.gz: 53e69bb7fbf5ebc75e30b4fbd478567e786862fef7b6922c624c178cf4cf5b6e89a53a133f77d0f6e75534a860abfc1d3f113ca1a29dbcc47bd851de7ea9af7f
@@ -1,3 +1,3 @@
1
1
  module Tracing
2
- VERSION = "2.0.6"
2
+ VERSION = "2.0.9"
3
3
  end
data/lib/tracing.rb CHANGED
@@ -56,24 +56,24 @@ module Tracing
56
56
  end
57
57
 
58
58
  def reinitialize
59
- @indent = 0 # Current nesting level of enabled trace blocks
59
+ @indent = 0 # Current nesting level of enabled trace blocks
60
60
  @nested = false # Set when a block enables all enclosed tracing
61
- @available = {} # Hash of available trace keys, accumulated during the run
62
- @delayed = nil # A delayed message, emitted only if the enclosed block emits tracing
61
+ @available = {} # Hash of available trace keys, accumulated during the run
62
+ @delayed = nil # A delayed message, emitted only if the enclosed block emits tracing
63
63
 
64
64
  @keys = {}
65
65
  if (e = ENV["TRACE"])
66
- e.split(/[^_a-zA-Z0-9]/).each{|k| enable(k) }
66
+ e.split(/[^_a-zA-Z0-9]/).each{|k| enable(k) }
67
67
  end
68
68
  end
69
69
 
70
70
  def trace(*args, &block)
71
71
  begin
72
- old_indent, old_nested, old_delayed, enabled = @indent, @nested, @delayed, show(*args)
73
- # This monstrosity reduces the steps when single-stepping:
74
- block ? yield : (args.size == 0 ? self : enabled)
72
+ old_indent, old_nested, old_delayed, enabled = @indent, @nested, @delayed, show(*args)
73
+ # This monstrosity reduces the steps when single-stepping:
74
+ block ? yield : (args.size == 0 ? self : enabled)
75
75
  ensure
76
- @indent, @nested, @delayed = old_indent, old_nested, old_delayed
76
+ @indent, @nested, @delayed = old_indent, old_nested, old_delayed
77
77
  end
78
78
  end
79
79
 
@@ -91,11 +91,11 @@ module Tracing
91
91
 
92
92
  def enable key
93
93
  if !key.empty? && !@keys[s = key.to_sym]
94
- @keys[s] = true
95
- setup_help if s == :help
96
- setup_flame if s == :flame
94
+ @keys[s] = true
95
+ setup_help if s == :help
96
+ setup_flame if s == :flame
97
97
  else
98
- true
98
+ true
99
99
  end
100
100
  end
101
101
 
@@ -105,19 +105,19 @@ module Tracing
105
105
 
106
106
  def toggle key
107
107
  if !key.empty?
108
- if enabled?(key)
109
- disable(key)
110
- false
111
- else
112
- enable(key)
113
- true
114
- end
108
+ if enabled?(key)
109
+ disable(key)
110
+ false
111
+ else
112
+ enable(key)
113
+ true
114
+ end
115
115
  end
116
116
  end
117
117
 
118
118
  def setup_help
119
119
  at_exit {
120
- $stderr.puts "---\nTracing keys available: #{@available.keys.map{|s| s.to_s}.sort*", "}"
120
+ $stderr.puts "---\nTracing keys available: #{@available.keys.map{|s| s.to_s}.sort*", "}"
121
121
  }
122
122
  end
123
123
 
@@ -126,85 +126,87 @@ module Tracing
126
126
  require 'ruby-prof-flamegraph'
127
127
  profile_result = RubyProf.start
128
128
  at_exit {
129
- profile_result2 = RubyProf.stop
130
- printer = RubyProf::FlameGraphPrinter.new(profile_result2)
131
- data_file = "/tmp/flamedata_#{Process.pid}.txt"
132
- svg_file = "/tmp/flamedata_#{Process.pid}.svg"
133
- flamegraph = File.dirname(__FILE__)+"/flamegraph.pl"
134
- File.popen("tee #{data_file} | perl #{flamegraph} --countname=ms --width=4800 > #{svg_file}", "w") { |f|
135
- printer.print(f, {})
136
- }
137
- STDERR.puts("Flame graph dumped to file:///#{svg_file}")
129
+ profile_result2 = RubyProf.stop
130
+ printer = RubyProf::FlameGraphPrinter.new(profile_result2)
131
+ data_file = "/tmp/flamedata_#{Process.pid}.txt"
132
+ svg_file = "/tmp/flamedata_#{Process.pid}.svg"
133
+ flamegraph = File.dirname(__FILE__)+"/flamegraph.pl"
134
+ File.popen("tee #{data_file} | perl #{flamegraph} --countname=ms --width=4800 > #{svg_file}", "w") { |f|
135
+ printer.print(f, {})
136
+ }
137
+ STDERR.puts("Flame graph dumped to file:///#{svg_file}")
138
138
  }
139
139
  end
140
140
 
141
141
  def setup_debugger
142
142
  begin
143
- require 'ruby-trace '
144
- Debugger.start # (:post_mortem => true) # Some Ruby versions crash on post-mortem debugging
143
+ require 'ruby-trace '
144
+ Debugger.start # (:post_mortem => true) # Some Ruby versions crash on post-mortem debugging
145
145
  rescue LoadError
146
- # Ok, no debugger, tough luck.
146
+ # Ok, no debugger, tough luck.
147
147
  end
148
148
 
149
149
  if trace :trap
150
- trap('SIGINT') do
151
- puts "Stopped at:\n\t"+caller*"\n\t"
152
- debugger
153
- true # Stopped on SIGINT
154
- end
150
+ trap('SIGINT') do
151
+ puts "Stopped at:\n\t"+caller*"\n\t"
152
+ debugger
153
+ true # Stopped on SIGINT
154
+ end
155
155
  end
156
156
 
157
157
  errors = []
158
158
  (
159
- [ENV["DEBUG_PREFERENCE"]].compact +
160
- [
161
- 'byebug',
162
- 'pry',
163
- 'debugger',
164
- 'ruby-trace '
165
- ]
159
+ [ENV["DEBUG_PREFERENCE"]].compact +
160
+ [
161
+ 'debug',
162
+ 'byebug',
163
+ 'pry',
164
+ 'debugger',
165
+ 'ruby-trace '
166
+ ]
166
167
  ).each do |debugger|
167
- begin
168
- require debugger
169
- if debugger == 'byebug'
170
- Kernel.class_eval do
171
- alias_method :debugger, :byebug
172
- end
173
- end
174
- ::Debugger.start if (const_get(::Debugger) rescue nil)
175
- return
176
- rescue LoadError => e
177
- errors << e
178
- end
168
+ begin
169
+ require debugger
170
+ if debugger == 'byebug'
171
+ Kernel.class_eval do
172
+ alias_method :debugger, :byebug
173
+ end
174
+ end
175
+ ::Debugger.start if (const_get(::Debugger) rescue nil)
176
+ return
177
+ rescue LoadError => e
178
+ errors << e
179
+ end
179
180
  end
180
181
 
181
182
  # Report when we couldn't load any debugger
182
- $stderr.p errors
183
+ $stderr.puts(errors.inspect)
183
184
  end
184
185
 
185
186
  def setup_firstaid
186
187
  if trace :firstaid
187
- puts "Preparing first aid kit"
188
- ::Exception.class_eval do
189
- alias_method :firstaid_initialize, :initialize
190
-
191
- def initialize *args, &b
192
- send(:firstaid_initialize, *args, &b)
193
- # Array#flatten calls to_ary, ignore it when it comes from Gem Specifications:
194
- return if NoMethodError === self && message =~ /^undefined method `to_ary' for \#<Gem::Specification/
195
-
196
- # LoadErrors are not hard to diagnose, and polyglot uses them
197
- return if LoadError === self
198
-
199
- # The Array() method calls to_ary and/or to_a before making a new array, ignore that:
200
- clr = caller
201
- return if NoMethodError === self && clr.detect{|frame| frame =~ /in `Array'/}
202
-
203
- puts "Stopped due to #{self.class}: #{message} at "+clr*"\n\t"
204
- debugger
205
- true # Stopped in Exception constructor
206
- end
207
- end
188
+ puts "Preparing first aid kit"
189
+ ::Exception.class_eval do
190
+ alias_method :firstaid_initialize, :initialize
191
+
192
+ def initialize *args, &b
193
+ send(:firstaid_initialize, *args, &b)
194
+ # Array#flatten calls to_ary, ignore it when it comes from Gem Specifications:
195
+ return if NoMethodError === self && message =~ /^undefined method `to_ary' for \#<Gem::Specification/
196
+
197
+ # LoadErrors are not hard to diagnose, and polyglot uses them
198
+ return if LoadError === self
199
+ return if self.message =~ /uninitialized constant Mini[Tt]est/ # From RSpec usually
200
+
201
+ # The Array() method calls to_ary and/or to_a before making a new array, ignore that:
202
+ clr = caller
203
+ return if NoMethodError === self && clr.detect{|frame| frame =~ /in `Array'/}
204
+
205
+ puts "Stopped due to #{self.class}: #{message} at "+clr*"\n\t"
206
+ debugger
207
+ true # Stopped in Exception constructor
208
+ end
209
+ end
208
210
  end
209
211
  end
210
212
 
@@ -217,24 +219,24 @@ module Tracing
217
219
 
218
220
  # Emit the message if enabled or a parent is:
219
221
  if enabled_prefix && args.size > 0
220
- message =
221
- "\##{enabled_prefix} " +
222
- ' '*@indent +
223
- args.
224
- map{|a| a.respond_to?(:call) ? a.call : a}.
225
- join(' ')
226
-
227
- if @delay
228
- @delayed = [@delayed, message].compact*"\n" # Arrange to display this message later, if necessary
229
- @delay = false
230
- else
231
- if @delayed
232
- display key, @delayed # Display a delayed message, then the current one
233
- @delayed = nil
234
- @delay = false
235
- end
236
- display key, message
237
- end
222
+ message =
223
+ "\##{enabled_prefix} " +
224
+ ' '*@indent +
225
+ args.
226
+ map{|a| a.respond_to?(:call) ? a.call : a}.
227
+ join(' ')
228
+
229
+ if @delay
230
+ @delayed = [@delayed, message].compact*"\n" # Arrange to display this message later, if necessary
231
+ @delay = false
232
+ else
233
+ if @delayed
234
+ display key, @delayed # Display a delayed message, then the current one
235
+ @delayed = nil
236
+ @delay = false
237
+ end
238
+ display key, message
239
+ end
238
240
  end
239
241
  @indent += (enabled_prefix ? 1 : 0)
240
242
  !!enabled_prefix
@@ -245,33 +247,33 @@ module Tracing
245
247
  # Figure out whether this trace is enabled (itself or by :all), if it nests, and if we should print the key:
246
248
  @delay = false
247
249
  key =
248
- if Symbol === args[0]
249
- control = args.shift
250
- case s = control.to_s
251
- when /!\Z/ # Enable all nested trace calls
252
- nested = true
253
- s.sub(/!\Z/, '').to_sym
254
- when /\?\Z/ # Delay this message until a nested active trace
255
- @delay = true
256
- s.sub(/\?\Z/, '').to_sym
257
- else
258
- control
259
- end
260
- else
261
- :all
262
- end
263
-
264
- @available[key] ||= key # Remember that this trace was requested, for help
265
- if @nested || # This trace is enabled because it's in a nested block
266
- @keys[key] || # This trace is enabled in its own right
267
- @keys[:all] # This trace is enabled because all are
268
- if @keys[:keys] || @keys[:all] # Use a formatting prefix?
269
- enabled_prefix = " %-15s"%key
270
- @keys[key] = enabled_prefix if @keys[key] == true # Save the formatting prefix
271
- else
272
- enabled_prefix = ''
273
- end
274
- @nested ||= nested # Activate nesting, if requested
250
+ if Symbol === args[0]
251
+ control = args.shift
252
+ case s = control.to_s
253
+ when /!\Z/ # Enable all nested trace calls
254
+ nested = true
255
+ s.sub(/!\Z/, '').to_sym
256
+ when /\?\Z/ # Delay this message until a nested active trace
257
+ @delay = true
258
+ s.sub(/\?\Z/, '').to_sym
259
+ else
260
+ control
261
+ end
262
+ else
263
+ :all
264
+ end
265
+
266
+ @available[key] ||= key # Remember that this trace was requested, for help
267
+ if @nested || # This trace is enabled because it's in a nested block
268
+ @keys[key] || # This trace is enabled in its own right
269
+ @keys[:all] # This trace is enabled because all are
270
+ if @keys[:keys] || @keys[:all] # Use a formatting prefix?
271
+ enabled_prefix = " %-15s"%key
272
+ @keys[key] = enabled_prefix if @keys[key] == true # Save the formatting prefix
273
+ else
274
+ enabled_prefix = ''
275
+ end
276
+ @nested ||= nested # Activate nesting, if requested
275
277
  end
276
278
 
277
279
  [key, enabled_prefix]
@@ -286,7 +288,7 @@ class Object
286
288
  begin
287
289
  # This monstrosity reduces the steps when single-stepping:
288
290
  tracer = (Tracing.tracer ||= Tracing::Tracer.new) and
289
- (old_indent, old_nested, old_delayed, enabled = tracer.indent, tracer.nested, tracer.delayed, tracer.show(*args))
291
+ (old_indent, old_nested, old_delayed, enabled = tracer.indent, tracer.nested, tracer.delayed, tracer.show(*args))
290
292
 
291
293
  block ? yield : (args.size == 0 ? tracer : enabled)
292
294
  ensure
data/tracing.gemspec CHANGED
@@ -30,13 +30,12 @@ debugging.
30
30
  ]
31
31
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
32
 
33
- spec.add_development_dependency "bundler", ">= 1.10", "~> 1.10.6"
34
- spec.add_development_dependency "rake", "~> 10.0"
35
- spec.add_development_dependency "rspec", "~> 3.3"
33
+ spec.add_development_dependency "rake", ">= 10.0"
34
+ spec.add_development_dependency "rspec", ">= 3.3"
36
35
 
37
- spec.add_runtime_dependency(%q<ruby-debug>, ["~> 0"]) if RUBY_VERSION < "1.9"
38
- spec.add_runtime_dependency(%q<debugger>, ["~> 1"]) if RUBY_VERSION =~ /^1\.9/ or RUBY_VERSION =~ /^2\.0/
39
- spec.add_runtime_dependency(%q<byebug>, ["~> 1"]) if RUBY_VERSION =~ /^2\.1/
36
+ # spec.add_runtime_dependency(%q<ruby-debug>, ["~> 0"]) if RUBY_VERSION < "1.9"
37
+ # spec.add_runtime_dependency(%q<debugger>, ["~> 1"]) if RUBY_VERSION =~ /^1\.9/ or RUBY_VERSION =~ /^2\.0/
38
+ # spec.add_runtime_dependency(%q<byebug>) if RUBY_VERSION =~ /^2\.[1-9]/
40
39
  # spec.add_development_dependency(%q<pry>, ["~> 0"]) # rbx, jruby
41
40
  end
42
41
 
metadata CHANGED
@@ -1,77 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tracing
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clifford Heath
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
11
  date: 2015-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '1.10'
20
- - - "~>"
21
- - !ruby/object:Gem::Version
22
- version: 1.10.6
23
- type: :development
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: '1.10'
30
- - - "~>"
31
- - !ruby/object:Gem::Version
32
- version: 1.10.6
33
13
  - !ruby/object:Gem::Dependency
34
14
  name: rake
35
15
  requirement: !ruby/object:Gem::Requirement
36
16
  requirements:
37
- - - "~>"
17
+ - - ">="
38
18
  - !ruby/object:Gem::Version
39
19
  version: '10.0'
40
20
  type: :development
41
21
  prerelease: false
42
22
  version_requirements: !ruby/object:Gem::Requirement
43
23
  requirements:
44
- - - "~>"
24
+ - - ">="
45
25
  - !ruby/object:Gem::Version
46
26
  version: '10.0'
47
27
  - !ruby/object:Gem::Dependency
48
28
  name: rspec
49
29
  requirement: !ruby/object:Gem::Requirement
50
30
  requirements:
51
- - - "~>"
31
+ - - ">="
52
32
  - !ruby/object:Gem::Version
53
33
  version: '3.3'
54
34
  type: :development
55
35
  prerelease: false
56
36
  version_requirements: !ruby/object:Gem::Requirement
57
37
  requirements:
58
- - - "~>"
38
+ - - ">="
59
39
  - !ruby/object:Gem::Version
60
40
  version: '3.3'
61
- - !ruby/object:Gem::Dependency
62
- name: byebug
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - "~>"
66
- - !ruby/object:Gem::Version
67
- version: '1'
68
- type: :runtime
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: '1'
75
41
  description: |2
76
42
 
77
43
  Enable tracing by setting the TRACE environment variable to a list of the
@@ -98,7 +64,7 @@ homepage: https://github.com/cjheath/tracing
98
64
  licenses:
99
65
  - MIT
100
66
  metadata: {}
101
- post_install_message:
67
+ post_install_message:
102
68
  rdoc_options: []
103
69
  require_paths:
104
70
  - lib
@@ -113,9 +79,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
79
  - !ruby/object:Gem::Version
114
80
  version: '0'
115
81
  requirements: []
116
- rubyforge_project:
117
- rubygems_version: 2.2.2
118
- signing_key:
82
+ rubygems_version: 3.2.22
83
+ signing_key:
119
84
  specification_version: 4
120
85
  summary: A nested tracing API for user defined trace classes
121
86
  test_files: []