30
30
time = time . to_i
31
31
32
32
case type
33
- when '<' :
34
- # Can only return from inner or same depth level frame
33
+ when '<' :
34
+ # Can only return from inner or same depth level frame
35
35
if not [ d , d - 1 ] . include? depth then
36
36
print "Return from stack depth: " , d ,
37
37
" to depth:" , depth , ", line " ,
41
41
m = mstack . pop
42
42
t = tstack . pop
43
43
44
- # Sanity check
44
+ # Sanity check
45
45
if not m == method then
46
46
print "Method " , method , " not found at depth " ,
47
47
depth , " line " , lines_read , "\n "
48
48
return
49
- end
49
+ end
50
50
51
- # Total time for a method is the time to execute it minus the time to
52
- # invoke all called methods
51
+ # Total time for a method is the time to execute it minus the time to
52
+ # invoke all called methods
53
53
method_time = time - t
54
54
results [ method ] = results . fetch ( method , 0 ) + method_time -
55
- total_time_at_depth . fetch ( depth + 1 , 0 )
55
+ total_time_at_depth . fetch ( depth + 1 , 0 )
56
56
57
- # Sanity check
57
+ # Sanity check
58
58
if method_time - total_time_at_depth . fetch ( depth + 1 , 0 ) < 0 then
59
- print "Time required for method #{ method } (#{ method_time } ) less
59
+ print "Time required for method #{ method } (#{ method_time } ) less
60
60
than time for required for inner frame
61
61
(#{ total_time_at_depth . fetch ( depth + 1 , 0 ) } )! " ,
62
- "Line " , lines_read , "\n "
62
+ "Line " , lines_read , "\n "
63
63
return
64
64
end
65
65
66
- # Total for a frame is the total time of its first level decendant
67
- # plus the time required to execute all methods at the same depth
66
+ # Total for a frame is the total time of its first level decendant
67
+ # plus the time required to execute all methods at the same depth
68
68
total_time_at_depth [ depth ] = method_time -
69
- total_time_at_depth . fetch ( depth + 1 , 0 ) +
69
+ total_time_at_depth . fetch ( depth + 1 , 0 ) +
70
70
total_time_at_depth . fetch ( depth , 0 )
71
71
# Inner stack frame time was used already at this depth,
72
- # delete to avoid reusing
73
- total_time_at_depth . delete ( depth + 1 )
72
+ # delete to avoid reusing
73
+ total_time_at_depth . delete ( depth + 1 )
74
74
75
- # Reset total time for depth 0 after it has been used
76
- # since the statement above never runs at this depth
75
+ # Reset total time for depth 0 after it has been used
76
+ # since the statement above never runs at this depth
77
77
if depth == 0 :
78
78
total_time_at_depth . delete ( depth )
79
79
end
80
- when '>' :
81
- # Can only go into an inner or same depth level frame
80
+ when '>' :
81
+ # Can only go into an inner or same depth level frame
82
82
if not [ d , d + 1 ] . include? depth then
83
83
print "Jump from stack depth: #{ d } to depth: #{ depth } ,
84
84
line #{ lines_read } \n "
94
94
# Print results sorted
95
95
results . sort { |a , b | b [ 1 ] <=>a [ 1 ] } . each { |x |
96
96
print "#{ x [ 0 ] } #{ x [ 1 ] } \n "
97
- }
97
+ }
0 commit comments