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 +5 -5
- data/lib/tracing/version.rb +1 -1
- data/lib/tracing.rb +126 -124
- data/tracing.gemspec +5 -6
- metadata +9 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1d9bee81e1e7dfdc4d5fd0631a608f7755d5d41354ac769d43608c4f32a1229c
|
4
|
+
data.tar.gz: f53406967209b0b91f15400bfb9a044159ed5049662c824c06171371156830b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6998f8a70dc488d6d4463cd071ca23b642e1c9716fa44fd286fd2fb99484392702fb1a026afaca8a13d70be4c24de2c2b5b56a583db754a3705b127529c9d46
|
7
|
+
data.tar.gz: 53e69bb7fbf5ebc75e30b4fbd478567e786862fef7b6922c624c178cf4cf5b6e89a53a133f77d0f6e75534a860abfc1d3f113ca1a29dbcc47bd851de7ea9af7f
|
data/lib/tracing/version.rb
CHANGED
data/lib/tracing.rb
CHANGED
@@ -56,24 +56,24 @@ module Tracing
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def reinitialize
|
59
|
-
@indent = 0
|
59
|
+
@indent = 0 # Current nesting level of enabled trace blocks
|
60
60
|
@nested = false # Set when a block enables all enclosed tracing
|
61
|
-
@available = {}
|
62
|
-
@delayed = nil
|
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
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
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
|
-
|
95
|
-
|
96
|
-
|
94
|
+
@keys[s] = true
|
95
|
+
setup_help if s == :help
|
96
|
+
setup_flame if s == :flame
|
97
97
|
else
|
98
|
-
|
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
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
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
|
-
|
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
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
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
|
-
|
144
|
-
|
143
|
+
require 'ruby-trace '
|
144
|
+
Debugger.start # (:post_mortem => true) # Some Ruby versions crash on post-mortem debugging
|
145
145
|
rescue LoadError
|
146
|
-
|
146
|
+
# Ok, no debugger, tough luck.
|
147
147
|
end
|
148
148
|
|
149
149
|
if trace :trap
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
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
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
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
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
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.
|
183
|
+
$stderr.puts(errors.inspect)
|
183
184
|
end
|
184
185
|
|
185
186
|
def setup_firstaid
|
186
187
|
if trace :firstaid
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
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
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
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
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
@available[key] ||= key
|
265
|
-
if @nested ||
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
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
|
-
|
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 "
|
34
|
-
spec.add_development_dependency "
|
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
|
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.
|
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
|
-
|
117
|
-
|
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: []
|