Class: ProcView
- Inherits:
-
Object
- Object
- ProcView
- Defined in:
- lib/procview.rb,
lib/procview/version.rb
Constant Summary collapse
- STRACE =
%w{ /usr/bin/env strace -f -T -e desc,network,file }- LSOF =
%w{ /usr/bin/env lsof }- VERSION =
'0.6.1'
Instance Attribute Summary collapse
-
#calls ⇒ Object
readonly
Returns the value of attribute calls.
-
#debug ⇒ Object
writeonly
Sets the attribute debug.
-
#hmap ⇒ Object
readonly
Returns the value of attribute hmap.
-
#iomap ⇒ Object
readonly
Returns the value of attribute iomap.
-
#resume ⇒ Object
readonly
Returns the value of attribute resume.
-
#sigmap ⇒ Object
readonly
Returns the value of attribute sigmap.
-
#unk ⇒ Object
readonly
Returns the value of attribute unk.
Instance Method Summary collapse
- #checklsof ⇒ Object
- #checkstrace ⇒ Object
- #digest(line) ⇒ Object
-
#initialize(quiet = false) ⇒ ProcView
constructor
A new instance of ProcView.
- #load(io) ⇒ Object
- #setupstdio ⇒ Object
Constructor Details
#initialize(quiet = false) ⇒ ProcView
Returns a new instance of ProcView.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/procview.rb', line 18 def initialize quiet=false @calls = Hash.new {|h,k| h[k] = [0,0.0]} @unk = [] @hmap = Hash.new{|h,k| @unk.push k; h[k] = "h#{k}".to_sym;} # current handle map @quiet = quiet @iomap = Hash.new(0.0) @sigmap = Hash.new(0) @resume = [] @debug = nil end |
Instance Attribute Details
#calls ⇒ Object (readonly)
Returns the value of attribute calls.
15 16 17 |
# File 'lib/procview.rb', line 15 def calls @calls end |
#debug=(value) ⇒ Object (writeonly)
Sets the attribute debug
16 17 18 |
# File 'lib/procview.rb', line 16 def debug=(value) @debug = value end |
#hmap ⇒ Object (readonly)
Returns the value of attribute hmap.
15 16 17 |
# File 'lib/procview.rb', line 15 def hmap @hmap end |
#iomap ⇒ Object (readonly)
Returns the value of attribute iomap.
15 16 17 |
# File 'lib/procview.rb', line 15 def iomap @iomap end |
#resume ⇒ Object (readonly)
Returns the value of attribute resume.
15 16 17 |
# File 'lib/procview.rb', line 15 def resume @resume end |
#sigmap ⇒ Object (readonly)
Returns the value of attribute sigmap.
15 16 17 |
# File 'lib/procview.rb', line 15 def sigmap @sigmap end |
#unk ⇒ Object (readonly)
Returns the value of attribute unk.
15 16 17 |
# File 'lib/procview.rb', line 15 def unk @unk end |
Instance Method Details
#checklsof ⇒ Object
29 30 31 32 33 34 |
# File 'lib/procview.rb', line 29 def checklsof lsof = `#{(ProcView::LSOF+%w{ -v 2>&1 }).join(' ')}` /\s+revision:\s+(?<rev>[.\d]+)\s+/ =~ lsof raise "'lsof' not found! Check that it is installed and on your PATH" if rev.nil? STDERR.puts "Using lsof #{rev}" unless @quiet end |
#checkstrace ⇒ Object
36 37 38 39 40 41 |
# File 'lib/procview.rb', line 36 def checkstrace strace = `#{(ProcView::STRACE+%w{ -V 2>&1 }).join(' ')}` /^strace\s+--\s+version\s+(?<rev>[.\d]+)$/ =~ strace raise "'strace' not found! Check that it is installed and on your PATH" if rev.nil? STDERR.puts "Using strace #{rev}" unless @quiet end |
#digest(line) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/procview.rb', line 69 def digest line pid = (line.slice! /^(\d+)\s+/) ? $~[1].to_i: 0 case line when /^TIME\s+/ puts "TRACED on #{$'}" when /^REQUEST\s+/ puts $' when /^LSOF/ fields = line.split /\s+/ unless fields.size > 9 STDERR.print "Too few fields" unless @quiet return 1 end handle = fields[4].chop.to_i @hmap[handle] = fields[9..-1].join(' ') when /^(?<call>\w+) \((?<args>.*)\)\s+=\s+(?<rc>-?\d+)\s* (?<ret>.*)\s* <(?<duration>.*)>$ /x return handleCall($1.to_sym, $2, $3.to_i, $4, $5.to_f) when /<unfinished ...>/ @resume.push $` when /<... (\w+) resumed>/ call = $1.to_sym rest = $'.chomp prev = @resume.find_index {|f| f =~ /^#{call}/} unless prev STDERR.print "Failed to find resumable call" unless @quiet return 1 end first = @resume.delete_at(prev) return digest (first+rest) when /^---\s*(\w+)\s*/ signal = $1.to_sym @sigmap[signal] += 1 else STDERR.print "Unknown" unless @quiet return 1 end return 0 end |
#load(io) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/procview.rb', line 49 def load io badLines = 0 while line = io.gets @debug.puts line if @debug begin if digest(line) > 0 puts ": #{line}" unless @quiet badLines += 1 end rescue StandardError => e STDERR.puts "#{e.message} (#{e.backtrace[0]}): #{line}" unless @quiet badLines += 1 end end unless @quiet STDERR.puts "WARNING: Unknown handles: #{@unk.join(', ')}" if @unk.size > 0 STDERR.puts "WARNING: #{badLines} bad lines" if badLines > 0 end end |
#setupstdio ⇒ Object
43 44 45 46 47 |
# File 'lib/procview.rb', line 43 def setupstdio @hmap[0] = :stdin @hmap[1] = :stdout @hmap[2] = :stderr end |