Class: StraceLog::Stat

Inherits:
Object
  • Object
show all
Defined in:
lib/strace_log.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStat

Returns a new instance of Stat.



152
153
154
155
156
# File 'lib/strace_log.rb', line 152

def initialize
  @stat = {}
  @count = {}
  @spent = {}
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



158
159
160
# File 'lib/strace_log.rb', line 158

def count
  @count
end

#spentObject (readonly)

Returns the value of attribute spent.



158
159
160
# File 'lib/strace_log.rb', line 158

def spent
  @spent
end

#statObject (readonly)

Returns the value of attribute stat.



158
159
160
# File 'lib/strace_log.rb', line 158

def stat
  @stat
end

Instance Method Details

#count_fd(fd, pc) ⇒ Object



221
222
223
224
# File 'lib/strace_log.rb', line 221

def count_fd(fd,pc)
  path = @fd2path[fd]
  count_path(path,pc)
end

#count_path(path, pc) ⇒ Object



226
227
228
# File 'lib/strace_log.rb', line 226

def count_path(path,pc)
  io_counter(path).count(pc)
end

#count_size(path, pc) ⇒ Object



230
231
232
# File 'lib/strace_log.rb', line 230

def count_size(path,pc)
  io_counter(path).count_size(pc)
end

#io_counter(path) ⇒ Object



234
235
236
# File 'lib/strace_log.rb', line 234

def io_counter(path)
  @stat[path] ||= IOCounter.new(path)
end

#parse(a) ⇒ Object



160
161
162
163
164
165
# File 'lib/strace_log.rb', line 160

def parse(a)
  @fd2path = ["stdin", "stdout", "stderr"]
  a.each do |line|
    stat_call( ParsedCall.new(line) )
  end
end


248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/strace_log.rb', line 248

def print
  Kernel.print "count={\n"
  @count.each do |m,c|
    Kernel.print " #{m}: #{c},\n"
  end
  Kernel.print "}\n\n"
  Kernel.print "time={\n"
  @spent.each do |m,t|
    Kernel.print " #{m}: #{t},\n"
  end
  Kernel.print "}\n\n"
  files = @stat.keys.select{|x| x.class==String}.sort
  files.each do |fn|
    @stat[fn].print
  end
end

#rename(pc) ⇒ Object



238
239
240
241
242
243
244
245
246
# File 'lib/strace_log.rb', line 238

def rename(pc)
  if pc.ret != "-1"
    oldpath = pc.args[0]
    newpath = pc.args[1]
    ioc = @stat[newpath] = @stat[oldpath]
    ioc.rename_as(newpath)
    @stat.delete(oldpath)
  end
end

#stat_call(pc) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/strace_log.rb', line 167

def stat_call(pc)
  m = pc.func
  return if m.nil?
  @count[m] = (@count[m] || 0) + 1
  @spent[m] = (@spent[m] || 0) + pc.elap.to_f if pc.elap

  case m

  when /^(open|execve|l?stat|(read|un)?link|getc?wd|access|mkdir|mknod|chmod|chown)$/
    path = pc.args[0]
    count_path(path,pc)
    if m=="open" && pc.ret != "-1"
      fd = pc.ret.to_i
      @fd2path[fd] = path
    end

  when /^(readv?|writev?)$/
    path = @fd2path[pc.args[0].to_i]
    count_size(path,pc)

  when /^(fstat|fchmod|[fl]chown|lseek|ioctl|fcntl|getdents|sendto|recvmsg|close)$/
    fd = pc.args[0].to_i
    count_fd(fd,pc)
    if m=="close" && pc.ret != "-1"
      @fd2path[fd] = nil
    end

  when /^rename$/
    path = pc.args[0]
    count_path(path,pc)
    rename(pc)

  when /^dup[23]?$/
    fd = pc.args[0].to_i
    count_fd(fd,pc)
    if pc.ret != "-1"
      fd = pc.ret.to_i
      @fd2path[fd] = path
    end

  when /^mmap$/
    fd = pc.args[4].to_i
    if fd >= 0
      count_fd(fd,pc)
    end

  when /^connect$/
    fd = pc.args[0].to_i
    @fd2path[fd] = path = pc.args[1]
    count_path(path,pc)

  end
end