rbtrace 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/rbtrace +81 -76
- data/rbtrace.gemspec +1 -1
- metadata +3 -3
data/bin/rbtrace
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'rubygems'
|
3
3
|
require 'ffi'
|
4
|
+
require 'trollop'
|
4
5
|
|
5
6
|
module FFI::LastError
|
6
7
|
def self.exception
|
@@ -195,6 +196,7 @@ class RBTracer
|
|
195
196
|
# Returns nothing.
|
196
197
|
def detach
|
197
198
|
send_cmd('detach')
|
199
|
+
puts
|
198
200
|
end
|
199
201
|
|
200
202
|
# Process events from the traced process.
|
@@ -357,31 +359,28 @@ class RBTracer
|
|
357
359
|
STDERR.puts "error on: #{line}"
|
358
360
|
raise e
|
359
361
|
end
|
360
|
-
end
|
361
|
-
|
362
|
-
if __FILE__ == $0
|
363
|
-
require 'trollop'
|
364
362
|
|
365
|
-
|
366
|
-
|
363
|
+
def self.run
|
364
|
+
opts = Trollop.options do
|
365
|
+
version <<-EOS
|
367
366
|
rbtrace: like strace, but for ruby code
|
368
|
-
version 0.2.
|
367
|
+
version 0.2.1
|
369
368
|
(c) 2011 Aman Gupta (tmm1)
|
370
369
|
http://github.com/tmm1/rbtrace
|
371
370
|
EOS
|
372
371
|
|
373
|
-
|
372
|
+
banner <<-EOS
|
374
373
|
rbtrace shows you method calls happening inside another ruby process in real time.
|
375
374
|
|
376
|
-
to use, simply `require "rbtrace"` in your ruby app.
|
375
|
+
to use rbtrace, simply `require "rbtrace"` in your ruby app.
|
377
376
|
|
378
377
|
Usage:
|
379
378
|
|
380
379
|
rbtrace -p <PID> # trace the given process
|
381
380
|
rbtrace -o <FILE> # write output to file
|
382
381
|
rbtrace -t # show method call start time
|
383
|
-
rbtrace -
|
384
|
-
rbtrace -
|
382
|
+
rbtrace -n # hide duration of each method call
|
383
|
+
rbtrace -r 3 # use 3 spaces to nest method calls
|
385
384
|
|
386
385
|
Tracers:
|
387
386
|
|
@@ -405,81 +404,87 @@ Trace Expressions:
|
|
405
404
|
method(self.attr) # value of arbitrary ruby expression
|
406
405
|
method(__source__) # source file/line of callsite
|
407
406
|
|
407
|
+
|
408
408
|
All Options:\n
|
409
409
|
|
410
410
|
EOS
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
:
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
:
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
411
|
+
opt :pid,
|
412
|
+
"pid of the ruby process to trace",
|
413
|
+
:type => :int,
|
414
|
+
:short => '-p'
|
415
|
+
|
416
|
+
opt :firehose,
|
417
|
+
"show all method calls",
|
418
|
+
:short => '-f'
|
419
|
+
|
420
|
+
opt :slow,
|
421
|
+
"watch for method calls slower than 250 milliseconds",
|
422
|
+
:default => 250,
|
423
|
+
:short => '-s'
|
424
|
+
|
425
|
+
opt :methods,
|
426
|
+
"method(s) to trace (valid formats: sleep String#gsub Process.pid Kernel# Dir.)",
|
427
|
+
:type => :strings,
|
428
|
+
:short => '-m'
|
429
|
+
|
430
|
+
opt :start_time,
|
431
|
+
"show start time for each method call",
|
432
|
+
:short => '-t'
|
433
|
+
|
434
|
+
opt :no_duration,
|
435
|
+
"hide time spent in each method call",
|
436
|
+
:default => false,
|
437
|
+
:short => '-n'
|
438
|
+
|
439
|
+
opt :output,
|
440
|
+
"write trace to filename",
|
441
|
+
:type => String,
|
442
|
+
:short => '-o'
|
443
|
+
|
444
|
+
opt :prefix,
|
445
|
+
"prefix nested method calls with N spaces",
|
446
|
+
:default => 1,
|
447
|
+
:short => '-r'
|
448
|
+
end
|
444
449
|
|
445
|
-
|
446
|
-
|
450
|
+
RBTracer.check_msgmnb
|
451
|
+
RBTracer.cleanup_queues
|
447
452
|
|
448
|
-
begin
|
449
453
|
begin
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
+
begin
|
455
|
+
tracer = RBTracer.new(opts[:pid])
|
456
|
+
rescue ArgumentError => e
|
457
|
+
Trollop.die :pid, "invalid (#{e.message})"
|
458
|
+
end
|
454
459
|
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
460
|
+
if opts[:slow_given]
|
461
|
+
tracer.watch(opts[:slow])
|
462
|
+
elsif opts[:firehose]
|
463
|
+
tracer.firehose
|
464
|
+
elsif methods = opts[:methods]
|
465
|
+
tracer.add(methods)
|
466
|
+
end
|
462
467
|
|
463
|
-
|
464
|
-
|
465
|
-
|
468
|
+
if out = opts[:output]
|
469
|
+
tracer.out = File.open(out,'w')
|
470
|
+
end
|
466
471
|
|
467
|
-
|
468
|
-
|
469
|
-
|
472
|
+
tracer.prefix = ' ' * opts[:prefix]
|
473
|
+
tracer.show_duration = !opts[:no_duration]
|
474
|
+
tracer.show_time = opts[:start_time]
|
470
475
|
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
if tracer
|
482
|
-
STDERR.puts "*** detached from process #{tracer.pid}"
|
476
|
+
begin
|
477
|
+
STDERR.puts "*** attached to process #{tracer.pid}"
|
478
|
+
tracer.recv_loop
|
479
|
+
rescue Interrupt
|
480
|
+
end
|
481
|
+
ensure
|
482
|
+
if tracer
|
483
|
+
tracer.detach
|
484
|
+
STDERR.puts "*** detached from process #{tracer.pid}"
|
485
|
+
end
|
483
486
|
end
|
484
487
|
end
|
485
488
|
end
|
489
|
+
|
490
|
+
RBTracer.run
|
data/rbtrace.gemspec
CHANGED
metadata
CHANGED