Class: StraceLog::IOCounter
- Inherits:
-
Object
- Object
- StraceLog::IOCounter
- Defined in:
- lib/strace_log.rb
Instance Attribute Summary collapse
-
#fail ⇒ Object
readonly
Returns the value of attribute fail.
-
#ok ⇒ Object
readonly
Returns the value of attribute ok.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#rename ⇒ Object
readonly
Returns the value of attribute rename.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #add(h, func, c) ⇒ Object
- #count(fc) ⇒ Object
- #count_size(fc) ⇒ Object
-
#initialize(path) ⇒ IOCounter
constructor
A new instance of IOCounter.
- #print ⇒ Object
- #rename_as(newpath) ⇒ Object
Constructor Details
#initialize(path) ⇒ IOCounter
Returns a new instance of IOCounter.
88 89 90 91 92 93 94 95 |
# File 'lib/strace_log.rb', line 88 def initialize(path) @path = path @ok = {} @fail = {} @size = {} @time = {} @rename = [] end |
Instance Attribute Details
#fail ⇒ Object (readonly)
Returns the value of attribute fail.
96 97 98 |
# File 'lib/strace_log.rb', line 96 def fail @fail end |
#ok ⇒ Object (readonly)
Returns the value of attribute ok.
96 97 98 |
# File 'lib/strace_log.rb', line 96 def ok @ok end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
96 97 98 |
# File 'lib/strace_log.rb', line 96 def path @path end |
#rename ⇒ Object (readonly)
Returns the value of attribute rename.
96 97 98 |
# File 'lib/strace_log.rb', line 96 def rename @rename end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
96 97 98 |
# File 'lib/strace_log.rb', line 96 def size @size end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
96 97 98 |
# File 'lib/strace_log.rb', line 96 def time @time end |
Instance Method Details
#add(h, func, c) ⇒ Object
98 99 100 |
# File 'lib/strace_log.rb', line 98 def add(h,func,c) h[func] = (h[func] || 0) + c end |
#count(fc) ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/strace_log.rb', line 102 def count(fc) if fc.ret == "-1" add(@fail, fc.func, 1) else add(@ok, fc.func, 1) end add(@time, fc.func, fc.elap.to_f) if fc.elap end |
#count_size(fc) ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/strace_log.rb', line 111 def count_size(fc) sz = fc.ret.to_i if sz >= 0 add(@size, fc.func, sz) end count(fc) end |
#print ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/strace_log.rb', line 124 def print Kernel.print @path+":\n" if !@ok.empty? keys = @ok.keys.sort Kernel.print " ok={"+keys.map{|k| "#{k}:#{@ok[k]}"}.join(", ")+"}\n" end if !@fail.empty? keys = @fail.keys.sort Kernel.print " fail={"+keys.map{|k| "#{k}:#{@fail[k]}"}.join(", ")+"}\n" end if !@size.empty? keys = @size.keys.sort Kernel.print " size={"+keys.map{|k| "#{k}:#{@size[k]}"}.join(", ")+"}\n" end if !@time.empty? keys = @time.keys.sort Kernel.print " time={"+keys.map{|k| "#{k}:#{@time[k]}"}.join(", ")+"}\n" end if !@rename.empty? Kernel.print " rename={#{@rename.join(', ')}}\n" end puts end |
#rename_as(newpath) ⇒ Object
119 120 121 122 |
# File 'lib/strace_log.rb', line 119 def rename_as(newpath) @rename << @path @path = newpath end |