Class: StraceLog::ParsedCall

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

Constant Summary collapse

ESCAPES =
[ /x[\da-f][\da-f]/i, /n/, /t/, /r/, /\\/, /"/, /\d+/]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ ParsedCall

Returns a new instance of ParsedCall.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/strace_log.rb', line 12

def initialize(line)
  @size = nil
  if /^(?:(\d\d:\d\d:\d\d|\d+)(?:\.(\d+))? )?[+-]{3}.*[+-]{3}$/ =~ line
    @mesg = line
  else
    s = StringScanner.new(line)
    s.scan(/^(?:(\d\d:\d\d:\d\d|\d+)(?:\.(\d+))? )?([\w\d]+)\(/)
    @time = s[1]
    @usec = s[2]
    @func = s[3]
    @args = scan_items(s,/\s*\)\s*/)
    s.scan(/\s*= ([^=<>\s]+(?:<[^<>]*>)?)(?:\s+([^<>]+))?(?: <([\d.]+)>)?$/)
    @ret  = s[1]
    @mesg = s[2]
    @elap = s[3]
  end
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



29
30
31
# File 'lib/strace_log.rb', line 29

def args
  @args
end

#elapObject (readonly)

Returns the value of attribute elap.



29
30
31
# File 'lib/strace_log.rb', line 29

def elap
  @elap
end

#funcObject (readonly)

Returns the value of attribute func.



29
30
31
# File 'lib/strace_log.rb', line 29

def func
  @func
end

#mesgObject (readonly)

Returns the value of attribute mesg.



29
30
31
# File 'lib/strace_log.rb', line 29

def mesg
  @mesg
end

#retObject (readonly)

Returns the value of attribute ret.



29
30
31
# File 'lib/strace_log.rb', line 29

def ret
  @ret
end

#sizeObject (readonly)

Returns the value of attribute size.



29
30
31
# File 'lib/strace_log.rb', line 29

def size
  @size
end

#timeObject (readonly)

Returns the value of attribute time.



29
30
31
# File 'lib/strace_log.rb', line 29

def time
  @time
end

#usecObject (readonly)

Returns the value of attribute usec.



29
30
31
# File 'lib/strace_log.rb', line 29

def usec
  @usec
end

Instance Method Details

#scan_brace(s) ⇒ Object



73
74
75
# File 'lib/strace_log.rb', line 73

def scan_brace(s)
  s.scan(/\s*{\s*/) && '{'+scan_items(s,/\s*}\s*/).join(',')+'}'
end

#scan_bracket(s) ⇒ Object



69
70
71
# File 'lib/strace_log.rb', line 69

def scan_bracket(s)
  s.scan(/\s*\[\s*/) && '['+scan_items(s,/\s*\]\s*/).join(',')+']'
end

#scan_items(s, close) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/strace_log.rb', line 31

def scan_items(s,close)
  args = []
  i = 0
  while !s.scan(close)
    x = scan_string(s) || scan_bracket(s) ||
      scan_brace(s) || scan_method(s) || scan_other(s)
    if x.nil?
      raise "match error: args=#{args.inspect} post_match=#{s.post_match}"
    end
    (args[i] ||= "") << x
    if s.scan(/\s*,\s*/)
      i += 1
    end
  end
  args
end

#scan_method(s) ⇒ Object



77
78
79
80
81
82
# File 'lib/strace_log.rb', line 77

def scan_method(s)
  if s.scan(/([^"\\,{}()\[\]]+)\(/)
    meth = s[1]
    meth+'('+scan_items(s,/\s*\)\s*/).join(',')+')'
  end
end

#scan_other(s) ⇒ Object



84
85
86
# File 'lib/strace_log.rb', line 84

def scan_other(s)
  s.scan(/[^"\\,{}()\[\]]+/)
end

#scan_string(s) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/strace_log.rb', line 48

def scan_string(s)
  return nil if s.scan(/\s*"/).nil?
  arg = ""
  while !s.scan(/"/)
    if s.scan(/\\/)
      ESCAPES.each do |re|
        if x = s.scan(re)
          arg << eval('"\\'+x+'"')
          break
        end
      end
    elsif x = s.scan(/[^\\"]+/)
      arg << x
    end
  end
  if x = s.scan(/\.+/)
    arg << x
  end
  arg
end

#set_sizeObject



88
89
90
91
92
93
# File 'lib/strace_log.rb', line 88

def set_size
  sz = @ret.to_i
  if sz >= 0
    @size = sz
  end
end