Top Level Namespace

Defined Under Namespace

Classes: String

Instance Method Summary collapse

Instance Method Details

#format(obj) ⇒ Object



97
98
99
100
101
102
103
104
# File 'lib/straces.rb', line 97

def format(obj)
  [
    obj[:time].round(4).to_s.ljust(6, "0"),
    obj[:timing].round(6).to_s.ljust(8, "0"),
    obj[:call].ljust(16),
    obj[:middle],
  ].join(" ")
end

#process(lines, syscalls_ignored, syscalls_focused) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/straces.rb', line 76

def process(lines, syscalls_ignored, syscalls_focused)
  last_obj = {
    time: 0.0
  }

  objs = lines.map do |line|
    obj = strace_parse(line)
    next unless obj

    if syscalls_focused.length > 0
      next unless syscalls_focused.include? obj[:call]
    end
    next if syscalls_ignored.include? obj[:call]

    obj[:time] = obj[:timing] + last_obj[:time]
    last_obj = obj
    obj
  end
  objs.compact
end

#strace_parse(line) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/straces.rb', line 40

def strace_parse(line)
  return nil if line.end_with? "<unfinished ...>"
  return nil if line.end_with? "resumed>)      = ?"
  return nil if line.end_with? "+++ exited with 0 +++"
  # accept4(3,
  return nil if line.end_with? ", "
  return nil if line.end_with? "<detached ...>"

  p line if ENV['STRACES_DEBUG'] == "yes"

  matcher = line.match /^(?<pid>\d*)\s?(?<time>\d\d:\d\d:\d\d\.?\d*)?\s?(?<interrupted>\<\.\.\.)?(?<call>[^\(]+)(?<middle>.*)?\<(?<timing>\d+\.\d+)\>$/

  #63796 11:18:12 clock_gettime(CLOCK_MONOTONIC, {tv_sec=27510, tv_nsec=693534954}) = 0 <0.000108>
  #63796 11:18:12 <... clock_gettime resumed> {tv_sec=27510, tv_nsec=648632454}) = 0 <0.000356>

  call, middle = if matcher[:interrupted]
    syscall, rest = matcher[:call].split(" ")
    [syscall, rest]
  else
    [matcher[:call], matcher[:middle]]
  end

  timing = Float matcher[:timing] rescue 0.0

  if matcher
    {
      pid: matcher[:pid],
      call: call,
      middle: middle,
      timing: timing
    }
  else
    nil
  end
end