/ Check-in [030013ff]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the stack_usage.tcl script for analyzing the output of objdump on the amalgamation and estimating the sizes of stack frames on each function.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:030013ff0c7af5f146a64f9ede31297ff003e0c4
User & Date: drh 2012-09-18 14:00:54
Context
2012-09-18
17:08
Enhancements to the comments on sqlite3FindInIndex(). No code changes. check-in: b1a4c394 user: drh tags: trunk
14:00
Add the stack_usage.tcl script for analyzing the output of objdump on the amalgamation and estimating the sizes of stack frames on each function. check-in: 030013ff user: drh tags: trunk
13:20
Update the vdbe-compress.tcl script so that it accepts variable declarations inside of #ifdef...#endif. This enhancement is needed due to the change of check-in [39866c0ede5d6ef4]. check-in: e7db056a user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Added tool/stack_usage.tcl.

            1  +#!/usr/bin/tclsh
            2  +#
            3  +# Parse the output of 
            4  +#
            5  +#         objdump -d sqlite3.o
            6  +#
            7  +# for x64 and generate a report showing:
            8  +#
            9  +#    (1)  Stack used by each function
           10  +#    (2)  Recursion paths and their aggregate stack depth
           11  +#
           12  +set getStack 0
           13  +while {![eof stdin]} {
           14  +  set line [gets stdin]
           15  +  if {[regexp {^[0-9a-f]+ <([^>]+)>:\s*$} $line all procname]} {
           16  +    set curfunc $procname
           17  +    set root($curfunc) 1
           18  +    set calls($curfunc) {}
           19  +    set calledby($curfunc) {}
           20  +    set recursive($curfunc) {}
           21  +    set stkdepth($curfunc) 0
           22  +    set getStack 1
           23  +    continue
           24  +  }
           25  +  if {[regexp {callq? +[0-9a-z]+ <([^>]+)>} $line all other]} {
           26  +    set key [list $curfunc $other]
           27  +    set callpair($key) 1
           28  +    unset -nocomplain root($curfunc)
           29  +    continue
           30  +  }
           31  +  if {[regexp {sub +\$(0x[0-9a-z]+),%[er]sp} $line all xdepth]} {
           32  +    if {$getStack} {
           33  +      scan $xdepth %x depth
           34  +      set stkdepth($curfunc) $depth
           35  +      set getStack 0
           36  +    }
           37  +    continue
           38  +  }
           39  +}
           40  +
           41  +puts "****************** Stack Usage By Function ********************"
           42  +set sdlist {}
           43  +foreach f [array names stkdepth] {
           44  +  lappend sdlist [list $stkdepth($f) $f]
           45  +}
           46  +foreach sd [lsort -integer -decr -index 0 $sdlist] {
           47  +  foreach {depth fname} $sd break
           48  +  puts [format {%6d %s} $depth $fname]
           49  +}
           50  +
           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
           56  +}
           57  +proc all_descendents {root} {
           58  +  global calls recursive
           59  +  set todo($root) $root
           60  +  set go 1
           61  +  while {$go} {
           62  +    set go 0
           63  +    foreach f [array names todo] {
           64  +      set path $todo($f)
           65  +      unset todo($f)
           66  +      if {![info exists calls($f)]} continue
           67  +      foreach x $calls($f) {
           68  +        if {$x==$root} {
           69  +          lappend recursive($root) [concat $path $root]
           70  +        } elseif {![info exists d($x)]} {
           71  +          set go 1
           72  +          set todo($x) [concat $path $x]
           73  +          set d($x) 1
           74  +        }
           75  +      }
           76  +    }
           77  +  }
           78  +  return [array names d]
           79  +}
           80  +set pathlist {}
           81  +foreach f [array names recursive] {
           82  +  all_descendents $f
           83  +  foreach m $recursive($f) {
           84  +    set depth 0
           85  +    foreach b [lrange $m 0 end-1] {
           86  +      set depth [expr {$depth+$stkdepth($b)}]
           87  +    }
           88  +    lappend pathlist [list $depth $m]
           89  +  }
           90  +}
           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)"
           97  +  }
           98  +}