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.



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

def initialize(line)
  if /^(?:(\d\d:\d\d:\d\d|\d+)(?:\.(\d+))? )?---.*---$/ =~ 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.



26
27
28
# File 'lib/strace_log.rb', line 26

def args
  @args
end

#elapObject (readonly)

Returns the value of attribute elap.



26
27
28
# File 'lib/strace_log.rb', line 26

def elap
  @elap
end

#funcObject (readonly)

Returns the value of attribute func.



26
27
28
# File 'lib/strace_log.rb', line 26

def func
  @func
end

#mesgObject (readonly)

Returns the value of attribute mesg.



26
27
28
# File 'lib/strace_log.rb', line 26

def mesg
  @mesg
end

#retObject (readonly)

Returns the value of attribute ret.



26
27
28
# File 'lib/strace_log.rb', line 26

def ret
  @ret
end

#timeObject (readonly)

Returns the value of attribute time.



26
27
28
# File 'lib/strace_log.rb', line 26

def time
  @time
end

#usecObject (readonly)

Returns the value of attribute usec.



26
27
28
# File 'lib/strace_log.rb', line 26

def usec
  @usec
end

Instance Method Details

#scan_brace(s) ⇒ Object



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

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

#scan_bracket(s) ⇒ Object



66
67
68
# File 'lib/strace_log.rb', line 66

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

#scan_items(s, close) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/strace_log.rb', line 28

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



74
75
76
77
78
79
# File 'lib/strace_log.rb', line 74

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

#scan_other(s) ⇒ Object



81
82
83
# File 'lib/strace_log.rb', line 81

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

#scan_string(s) ⇒ Object



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

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