aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2012-09-18 14:00:54 +0000
committerdrh <drh@noemail.net>2012-09-18 14:00:54 +0000
commitc65714ddf063c14c95f8194f96e1b9ca2147f7ea (patch)
tree70f213a05357595f32921a3d0ee0d38951d23bbb
parent3a949878194e1437f1de8861b2dc1c36e041cc99 (diff)
downloadsqlite-c65714ddf063c14c95f8194f96e1b9ca2147f7ea.tar.gz
sqlite-c65714ddf063c14c95f8194f96e1b9ca2147f7ea.zip
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. FossilOrigin-Name: 030013ff0c7af5f146a64f9ede31297ff003e0c4
-rw-r--r--manifest11
-rw-r--r--manifest.uuid2
-rw-r--r--tool/stack_usage.tcl98
3 files changed, 105 insertions, 6 deletions
diff --git a/manifest b/manifest
index 2a95ccf0d..be30a3c7e 100644
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Update\sthe\svdbe-compress.tcl\sscript\sso\sthat\sit\saccepts\svariable\sdeclarations\ninside\sof\s#ifdef...#endif.\nThis\senhancement\sis\sneeded\sdue\sto\sthe\schange\sof\scheck-in\s[39866c0ede5d6ef4].
-D 2012-09-18T13:20:13.054
+C Add\sthe\sstack_usage.tcl\sscript\sfor\sanalyzing\sthe\soutput\sof\sobjdump\son\sthe\namalgamation\sand\sestimating\sthe\ssizes\sof\sstack\sframes\son\seach\sfunction.
+D 2012-09-18T14:00:54.587
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 5f4f26109f9d80829122e0e09f9cda008fa065fb
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -1006,6 +1006,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c
+F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43
F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d
F tool/symbols.sh fec58532668296d7c7dc48be9c87f75ccdb5814f
F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06
@@ -1013,7 +1014,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
F tool/win/sqlite.vsix 67d8a99aceb56384a81b3f30d6c71743146d2cc9
-P 4c21ee2d26466f83dec525153e2b1506bd956701
-R b047ef3cdc6a088ac63e246ab78c4764
+P e7db056a0d76b2411cadbae077890df189e49414
+R 563f678f5a4a0eeba1c7bc783391bc58
U drh
-Z bfcdd96844256469f85fbd5fa7f23556
+Z 77a009fbade94f20c493a281c0066dcb
diff --git a/manifest.uuid b/manifest.uuid
index e4d7cd2c9..6adf74d6a 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-e7db056a0d76b2411cadbae077890df189e49414 \ No newline at end of file
+030013ff0c7af5f146a64f9ede31297ff003e0c4 \ No newline at end of file
diff --git a/tool/stack_usage.tcl b/tool/stack_usage.tcl
new file mode 100644
index 000000000..b3574f026
--- /dev/null
+++ b/tool/stack_usage.tcl
@@ -0,0 +1,98 @@
+#!/usr/bin/tclsh
+#
+# Parse the output of
+#
+# objdump -d sqlite3.o
+#
+# for x64 and generate a report showing:
+#
+# (1) Stack used by each function
+# (2) Recursion paths and their aggregate stack depth
+#
+set getStack 0
+while {![eof stdin]} {
+ set line [gets stdin]
+ if {[regexp {^[0-9a-f]+ <([^>]+)>:\s*$} $line all procname]} {
+ set curfunc $procname
+ set root($curfunc) 1
+ set calls($curfunc) {}
+ set calledby($curfunc) {}
+ set recursive($curfunc) {}
+ set stkdepth($curfunc) 0
+ set getStack 1
+ continue
+ }
+ if {[regexp {callq? +[0-9a-z]+ <([^>]+)>} $line all other]} {
+ set key [list $curfunc $other]
+ set callpair($key) 1
+ unset -nocomplain root($curfunc)
+ continue
+ }
+ if {[regexp {sub +\$(0x[0-9a-z]+),%[er]sp} $line all xdepth]} {
+ if {$getStack} {
+ scan $xdepth %x depth
+ set stkdepth($curfunc) $depth
+ set getStack 0
+ }
+ continue
+ }
+}
+
+puts "****************** Stack Usage By Function ********************"
+set sdlist {}
+foreach f [array names stkdepth] {
+ lappend sdlist [list $stkdepth($f) $f]
+}
+foreach sd [lsort -integer -decr -index 0 $sdlist] {
+ foreach {depth fname} $sd break
+ puts [format {%6d %s} $depth $fname]
+}
+
+puts "****************** Stack Usage By Recursion *******************"
+foreach key [array names callpair] {
+ foreach {from to} $key break
+ lappend calls($from) $to
+ # lappend calledby($to) $from
+}
+proc all_descendents {root} {
+ global calls recursive
+ set todo($root) $root
+ set go 1
+ while {$go} {
+ set go 0
+ foreach f [array names todo] {
+ set path $todo($f)
+ unset todo($f)
+ if {![info exists calls($f)]} continue
+ foreach x $calls($f) {
+ if {$x==$root} {
+ lappend recursive($root) [concat $path $root]
+ } elseif {![info exists d($x)]} {
+ set go 1
+ set todo($x) [concat $path $x]
+ set d($x) 1
+ }
+ }
+ }
+ }
+ return [array names d]
+}
+set pathlist {}
+foreach f [array names recursive] {
+ all_descendents $f
+ foreach m $recursive($f) {
+ set depth 0
+ foreach b [lrange $m 0 end-1] {
+ set depth [expr {$depth+$stkdepth($b)}]
+ }
+ lappend pathlist [list $depth $m]
+ }
+}
+foreach path [lsort -integer -decr -index 0 $pathlist] {
+ foreach {depth m} $path break
+ set first [lindex $m 0]
+ puts [format {%6d %s %d} $depth $first $stkdepth($first)]
+ foreach b [lrange $m 1 end] {
+ puts " $b $stkdepth($b)"
+ }
+}