7 # for x64 and generate a report showing:
9 # (1) Stack used by each function
10 # (2) Recursion paths and their aggregate stack depth
13 while {![eof stdin
]} {
15 if {[regexp {^
[0-9a-f
]+ <([^
>]+)>:\s
*$} $line all procname
]} {
18 set calls
($curfunc) {}
19 set calledby
($curfunc) {}
20 set recursive
($curfunc) {}
21 set stkdepth
($curfunc) 0
25 if {[regexp {callq?
+[0-9a-z
]+ <([^
>]+)>} $line all other
]} {
26 set key
[list $curfunc $other]
28 unset -nocomplain root
($curfunc)
31 if {[regexp {sub
+\$(0x
[0-9a-z
]+),%[er
]sp
} $line all xdepth
]} {
34 set stkdepth
($curfunc) $depth
41 puts "****************** Stack Usage By Function ********************"
43 foreach f
[array names stkdepth
] {
44 lappend sdlist
[list $stkdepth($f) $f]
46 foreach sd
[lsort -integer -decr -index 0 $sdlist] {
47 foreach {depth fname
} $sd break
48 puts [format {%6d
%s
} $depth $fname]
51 puts "****************** Stack Usage By Recursion *******************"
52 foreach key
[array names callpair
] {
53 foreach {from to
} $key break
54 lappend calls
($from) $to
55 # lappend calledby($to) $from
57 proc all_descendents
{root
} {
58 global calls recursive
63 foreach f
[array names todo
] {
66 if {![info exists calls
($f)]} continue
67 foreach x
$calls($f) {
69 lappend recursive
($root) [concat $path $root]
70 } elseif
{![info exists d
($x)]} {
72 set todo
($x) [concat $path $x]
78 return [array names d
]
81 foreach f
[array names recursive
] {
83 foreach m
$recursive($f) {
85 foreach b
[lrange $m 0 end-1
] {
86 set depth
[expr {$depth+$stkdepth($b)}]
88 lappend pathlist
[list $depth $m]
91 foreach path
[lsort -integer -decr -index 0 $pathlist] {
92 foreach {depth m
} $path break
93 set first
[lindex $m 0]
94 puts [format {%6d
%s
%d
} $depth $first $stkdepth($first)]
95 foreach b
[lrange $m 1 end
] {
96 puts " $b $stkdepth($b)"