Class: Procview::Runner
- Inherits:
-
Object
- Object
- Procview::Runner
- Defined in:
- lib/procview/runner.rb
Constant Summary collapse
- FORMAT =
"%7s"
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Runner
constructor
A new instance of Runner.
- #printCalls(pv) ⇒ Object
- #printReport(pv) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(argv) ⇒ Runner
Returns a new instance of Runner.
18 19 20 |
# File 'lib/procview/runner.rb', line 18 def initialize(argv) @opts = Options.new(argv) end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
14 15 16 |
# File 'lib/procview/runner.rb', line 14 def opts @opts end |
Instance Method Details
#printCalls(pv) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/procview/runner.rb', line 134 def printCalls pv puts "Duration by Call Type" pv.calls.keys.sort{|a,b| pv.calls[b][1] <=> pv.calls[a][1]}.each do |k| v = pv.calls[k] printf "#{FORMAT} #{k}: #{v[0]}\n", v[1].to_duration(@opts.digits) end printf "#{FORMAT} Total duration \n\n", totalType.to_duration(@opts.digits) if pv.sigmap.size > 0 puts "Signals" pv.sigmap.keys.sort{|a,b| pv.sigmap[b] <=> pv.sigmap[a]}.each do |k| puts "\t#{k}: #{pv.sigmap[k]}" end end end |
#printReport(pv) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/procview/runner.rb', line 101 def printReport pv ioformat = Array.new(4, FORMAT).join(' ') puts "Duration by Source" printf "#{ioformat} %s\n", 'OTHER', 'WAIT', 'READ', 'WRITE', 'Name' totalSource = Procview::Stats.new pv.iomap.keys.sort{|a,b| pv.iomap[b].sum <=> pv.iomap[a].sum}.each do |k| binned = false @opts.buckets.values.each do |v| binned = k =~ v[0] if binned v[1].add! pv.iomap[k] break end end unless binned printf "#{ioformat} ", *(pv.iomap[k].map{|m|m.to_duration(@opts.digits)}) puts k # as it may contain % end totalSource.add! pv.iomap[k] end @opts.buckets.each do |k,v| name = k.is_a?(Symbol) ? k.to_s: "Sum: #{k}" printf "#{ioformat} #{name}\n", *(v[1].map{|m|m.to_duration(@opts.digits)}) end printf "#{ioformat} Total duration\n", *(totalSource.map{|m|m.to_duration(@opts.digits)}) printf "#{FORMAT} %34s\n", pv.dregs.to_duration(@opts.digits), 'Unassigned' return totalSource.sum end |
#run ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 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 |
# File 'lib/procview/runner.rb', line 22 def run if @opts.debug @opts.debug = File.open("/tmp/procview.debug.#{$$}", "w") $stderr.puts "Writing debug output to file #{@opts.debug.path}" end unless @opts.filename Procview.checklsof @opts.quiet Procview.checkstrace @opts.quiet end pv = Analyzer.new @opts.to_h if @opts.filename file = File.open(@opts.filename, "r") unless file $stderr.puts "Can't open input file #{@opts.filename}" exit 2 end if @opts.raw pv.pwd = FileUtils.pwd pv.inithandles = { 0 => :stdin, 1 => :stdout, 2 => :stderr } end pv.load(file) else fifoname = "/tmp/procview.fifo.#{$$}" res = `mkfifo #{fifoname}` begin cmdargs = Procview::STRACE + [ "-o", fifoname ] if @opts.pid puts "Tracing PID #{@opts.pid} (Ctrl-C to disconnect)" cmdargs += [ "-p", @opts.pid.to_s ] else cmdargs += ARGV end stpid = spawn *cmdargs trap 'INT' do Process.kill("INT", stpid) puts "Sent #{stpid} SIGINT" end if @opts.pid IO.popen(Procview::LSOF + ["-p", @opts.pid.to_s]) do |lsof| while line = lsof.gets fields = line.split /\s+/ next unless fields[3] =~ /(\d+\w|cwd)/ @opts.debug.puts "LSOF #{line}\n" if @opts.debug pv.digest "LSOF #{line}" end end else pv.pwd = FileUtils.pwd pv.inithandles = { 0 => :stdin, 1 => :stdout, 2 => :stderr } end File.open(fifoname, "r") do |fifo| pv.load(fifo) end Process.wait(stpid) ensure FileUtils.rm_f fifoname end end totalBySource = printReport pv totalByCall = pv.calls.values.inject(0.0){|s,v| s + v[1]} unless @opts.quiet $stderr.puts "Warnings (#{pv.warnings.size})\n" if pv.warnings.size > 0 pv.warnings.each { |w| $stderr.puts w } end unless totalByCall.near? totalBySource + pv.dregs, 0.001 puts "WARNING IO and call totals don't add up!" printf "\tDelta %s (The dregs were %s)\n", (totalByCall - totalSource.sum).to_duration(@opts.digits), pv.dregs.to_duration(@opts.digits) end printCalls(pv) if @opts.calls end |