Class: StraceLog::ParsedCall
- Inherits:
-
Object
- Object
- StraceLog::ParsedCall
- Defined in:
- lib/strace_log.rb
Constant Summary collapse
- ESCAPES =
[ /x[\da-f][\da-f]/i, /n/, /t/, /r/, /\\/, /"/, /\d+/]
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#elap ⇒ Object
readonly
Returns the value of attribute elap.
-
#func ⇒ Object
readonly
Returns the value of attribute func.
-
#mesg ⇒ Object
readonly
Returns the value of attribute mesg.
-
#ret ⇒ Object
readonly
Returns the value of attribute ret.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#usec ⇒ Object
readonly
Returns the value of attribute usec.
Instance Method Summary collapse
-
#initialize(line) ⇒ ParsedCall
constructor
A new instance of ParsedCall.
- #scan_brace(s) ⇒ Object
- #scan_bracket(s) ⇒ Object
- #scan_items(s, close) ⇒ Object
- #scan_method(s) ⇒ Object
- #scan_other(s) ⇒ Object
- #scan_string(s) ⇒ Object
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
#args ⇒ Object (readonly)
Returns the value of attribute args.
26 27 28 |
# File 'lib/strace_log.rb', line 26 def args @args end |
#elap ⇒ Object (readonly)
Returns the value of attribute elap.
26 27 28 |
# File 'lib/strace_log.rb', line 26 def elap @elap end |
#func ⇒ Object (readonly)
Returns the value of attribute func.
26 27 28 |
# File 'lib/strace_log.rb', line 26 def func @func end |
#mesg ⇒ Object (readonly)
Returns the value of attribute mesg.
26 27 28 |
# File 'lib/strace_log.rb', line 26 def mesg @mesg end |
#ret ⇒ Object (readonly)
Returns the value of attribute ret.
26 27 28 |
# File 'lib/strace_log.rb', line 26 def ret @ret end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
26 27 28 |
# File 'lib/strace_log.rb', line 26 def time @time end |
#usec ⇒ Object (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 |