File: ruby-prof-check-trace

package info (click to toggle)
ruby-prof 0.16.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,680 kB
  • ctags: 972
  • sloc: ruby: 4,552; ansic: 1,888; makefile: 6
file content (45 lines) | stat: -rwxr-xr-x 1,156 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env ruby

stacks = Hash.new{|h,k| h[k] = Hash.new{|h,k| h[k] = []}}
i = 0
File.open(ARGV[0]).each_line do |l|
  i += 1
  unless l =~ /^(\d+):(\d+): *\d+ms *([^ ]+) *(.*): *(\d+) *(.+)$/
    next if l =~/^ *$/
    puts "line doesn't match: #{l}"
    next
  end
  details = $1.to_i, $2.to_i, $3, $4, $5.to_i, $6
  thread, fiber, event, file, line, method = *details
  # puts method
  stack = stacks[thread][fiber]
  case event
  when 'call', 'c-call'
    stack << method
  when 'return', 'c-return'
    last_method = stack.pop
    if last_method != method
      puts "LINE #{i}: return event without call: #{method}"
      puts "STACK: #{stack.inspect}"
      if stack.find(method)
        puts "fixing stack"
        while (popped = stack.pop) && (popped != method)
          puts "popped #{popped}"
        end
      else
        raise "stack unfixable"
      end
      # stack << last_method
    end
  when 'line'
    last_method = stack[-1]
    if last_method != method
      unless stack.find(method)
        raise "LINE #{i}: line event without call: #{method}"
      end
    end
  else
    puts "unkown event"
  end
end
puts stacks.inspect