rbtrace 0.2.0 → 0.2.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.
Files changed (3) hide show
  1. data/bin/rbtrace +81 -76
  2. data/rbtrace.gemspec +1 -1
  3. metadata +3 -3
@@ -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
- opts = Trollop.options do
366
- version <<-EOS
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.0
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
- banner <<-EOS
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 -T # show duration of each method call
384
- rbtrace -n 3 # use 3 spaces to nest method calls
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
- opt :pid,
412
- "pid of the ruby process to trace",
413
- :short => '-p',
414
- :type => :int
415
-
416
- opt :firehose,
417
- "show all method calls"
418
-
419
- opt :slow,
420
- "watch for method calls slower than 250 milliseconds",
421
- :default => 250
422
-
423
- opt :methods,
424
- "method(s) to trace (valid formats: sleep String#gsub Process.pid Kernel# Dir.)",
425
- :type => :strings,
426
- :short => '-m'
427
-
428
- opt :start_time,
429
- "show start time for each method call",
430
- :short => '-t'
431
-
432
- opt :no_duration,
433
- "hide time spent in each method call",
434
- :default => false
435
-
436
- opt :output,
437
- "write trace to filename",
438
- :type => String
439
-
440
- opt :prefix,
441
- "prefix nested method calls with N spaces",
442
- :default => 1
443
- end
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
- RBTracer.check_msgmnb
446
- RBTracer.cleanup_queues
450
+ RBTracer.check_msgmnb
451
+ RBTracer.cleanup_queues
447
452
 
448
- begin
449
453
  begin
450
- tracer = RBTracer.new(opts[:pid])
451
- rescue ArgumentError => e
452
- Trollop.die :pid, "invalid (#{e.message})"
453
- end
454
+ begin
455
+ tracer = RBTracer.new(opts[:pid])
456
+ rescue ArgumentError => e
457
+ Trollop.die :pid, "invalid (#{e.message})"
458
+ end
454
459
 
455
- if opts[:slow_given]
456
- tracer.watch(opts[:slow])
457
- elsif opts[:firehose]
458
- tracer.firehose
459
- elsif methods = opts[:methods]
460
- tracer.add(methods)
461
- end
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
- if out = opts[:output]
464
- tracer.out = File.open(out,'w')
465
- end
468
+ if out = opts[:output]
469
+ tracer.out = File.open(out,'w')
470
+ end
466
471
 
467
- tracer.prefix = ' ' * opts[:prefix]
468
- tracer.show_duration = !opts[:no_duration]
469
- tracer.show_time = opts[:start_time]
472
+ tracer.prefix = ' ' * opts[:prefix]
473
+ tracer.show_duration = !opts[:no_duration]
474
+ tracer.show_time = opts[:start_time]
470
475
 
471
- begin
472
- STDERR.puts "*** attached to process #{tracer.pid}"
473
- tracer.recv_loop
474
- rescue Interrupt
475
- end
476
- ensure
477
- if tracer
478
- tracer.detach
479
- end
480
- puts
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rbtrace'
3
- s.version = '0.2.0'
3
+ s.version = '0.2.1'
4
4
  s.homepage = 'http://github.com/tmm1/rbtrace'
5
5
 
6
6
  s.authors = "Aman Gupta"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbtrace
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Aman Gupta