Space analyzer: Format integer results as integers. Also fix the calculation of average-fanout. (CVS 2304)

FossilOrigin-Name: 52e473b94694cd0991257427d57515ecef93c780
This commit is contained in:
danielk1977 2005-02-01 10:36:40 +00:00
parent a38432df12
commit 24c9253c43
3 changed files with 43 additions and 24 deletions

View File

@ -1,5 +1,5 @@
C Have\sdebugging\scode\shandle\ssqliteMalloc(n)\swhere\sn<0\sin\sthe\ssame\sway\sas\sproduction.\s(CVS\s2303)
D 2005-02-01T10:35:07
C Space\sanalyzer:\sFormat\sinteger\sresults\sas\sintegers.\sAlso\sfix\sthe\scalculation\sof\saverage-fanout.\s(CVS\s2304)
D 2005-02-01T10:36:40
F Makefile.in ffd81f5e926d40b457071b4de8d7c1fa18f39b5a
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
@ -223,7 +223,7 @@ F tool/report1.txt 9eae07f26a8fc53889b45fc833a66a33daa22816
F tool/showdb.c 3559eac5a3b46e9b558d50856946b25e77633236
F tool/showjournal.c ec3b171be148656827c4949fbfb8ab4370822f87
F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b
F tool/spaceanal.tcl 102d6dcb9deaba272d98c0dcdd15baaeb75b6926
F tool/spaceanal.tcl 184f5e590ccadb0b3d05e252c4e867c214e7ecd2
F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F www/arch.fig d5f9752a4dbf242e9cfffffd3f5762b6c63b3bcf
@ -272,7 +272,7 @@ F www/tclsqlite.tcl e73f8f8e5f20e8277619433f7970060ab01088fc
F www/vdbe.tcl 095f106d93875c94b47367384ebc870517431618
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
F www/whentouse.tcl 3e522a06ad41992023c80ca29a048ae2331ca5bd
P a3d12726bb7bce72b8266236800c07f22ac5212f
R b57b166e1928ebe0d59a6327104a41fd
P ab85e1d01299e383bda1834664370f04b13634b6
R bcce933ac3e6dcc6ca757b454ac92b4e
U danielk1977
Z 12bc5af8e1b73a495f7666b7272f68e3
Z 6799ad8200d711d5582a4cc34901f770

View File

@ -1 +1 @@
ab85e1d01299e383bda1834664370f04b13634b6
52e473b94694cd0991257427d57515ecef93c780

View File

@ -55,6 +55,11 @@ set tabledef\
);}
mem eval $tabledef
proc integerify {real} {
return [expr int($real)]
}
mem function int integerify
# Quote a string for use in an SQL query. Examples:
#
# [quote {hello world}] == {'hello world'}
@ -379,6 +384,11 @@ proc percent {num denom {of {}}} {
}
}
proc divide {num denom} {
if {$denom==0} {return 0.0}
return [format %.2f [expr double($num)/double($denom)]]
}
# Generate a subreport that covers some subset of the database.
# the $where clause determines which subset to analyze.
#
@ -395,18 +405,18 @@ proc subreport {title where} {
#
mem eval "
SELECT
sum(nentry) AS nentry,
sum(leaf_entries) AS nleaf,
sum(payload) AS payload,
sum(ovfl_payload) AS ovfl_payload,
int(sum(nentry)) AS nentry,
int(sum(leaf_entries)) AS nleaf,
int(sum(payload)) AS payload,
int(sum(ovfl_payload)) AS ovfl_payload,
max(mx_payload) AS mx_payload,
sum(ovfl_cnt) as ovfl_cnt,
sum(leaf_pages) AS leaf_pages,
sum(int_pages) AS int_pages,
sum(ovfl_pages) AS ovfl_pages,
sum(leaf_unused) AS leaf_unused,
sum(int_unused) AS int_unused,
sum(ovfl_unused) AS ovfl_unused
int(sum(ovfl_cnt)) as ovfl_cnt,
int(sum(leaf_pages)) AS leaf_pages,
int(sum(int_pages)) AS int_pages,
int(sum(ovfl_pages)) AS ovfl_pages,
int(sum(leaf_unused)) AS leaf_unused,
int(sum(int_unused)) AS int_unused,
int(sum(ovfl_unused)) AS ovfl_unused
FROM space_used WHERE $where" {} {}
# Output the sub-report title, nicely decorated with * characters.
@ -434,11 +444,20 @@ proc subreport {title where} {
set storage [expr {$total_pages*$pageSize}]
set payload_percent [percent $payload $storage {of storage consumed}]
set total_unused [expr {$ovfl_unused+$int_unused+$leaf_unused}]
set avg_payload [expr {$nleaf>0?$payload/$nleaf:0}]
set avg_unused [expr {$nleaf>0?$total_unused/$nleaf:0}]
set avg_payload [divide $payload $nleaf]
set avg_unused [divide $total_unused $nleaf]
if {$int_pages>0} {
# TODO: Is this formula correct?
set avg_fanout [format %.2f [expr double($nentry-$nleaf)/$int_pages]]
set nTab [mem eval "
SELECT count(*) FROM (
SELECT DISTINCT tblname FROM space_used WHERE $where AND is_index=0
)
"]
set avg_fanout [mem eval "
SELECT (sum(leaf_pages+int_pages)-$nTab)/sum(int_pages) FROM space_used
WHERE $where AND is_index = 0
"]
set avg_fanout [format %.2f $avg_fanout]
}
set ovfl_cnt_percent [percent $ovfl_cnt $nleaf {of all entries}]
@ -536,7 +555,7 @@ set av_pgcnt [autovacuum_overhead $file_pgcnt $pageSize]
set av_percent [percent $av_pgcnt $file_pgcnt]
set sql {SELECT sum(leaf_pages+int_pages+ovfl_pages) FROM space_used}
set inuse_pgcnt [expr [mem eval $sql]]
set inuse_pgcnt [expr int([mem eval $sql])]
set inuse_percent [percent $inuse_pgcnt $file_pgcnt]
set free_pgcnt [expr $file_pgcnt-$inuse_pgcnt-$av_pgcnt]
@ -553,7 +572,7 @@ set nautoindex [db eval $sql]
set nmanindex [expr {$nindex-$nautoindex}]
# set total_payload [mem eval "SELECT sum(payload) FROM space_used"]
set user_payload [mem one {SELECT sum(payload) FROM space_used
set user_payload [mem one {SELECT int(sum(payload)) FROM space_used
WHERE NOT is_index AND name NOT LIKE 'sqlite_master'}]
set user_percent [percent $user_payload $file_bytes]
@ -582,7 +601,7 @@ puts ""
puts "*** Page counts for all tables with their indices ********************"
puts ""
mem eval {SELECT tblname, count(*) AS cnt,
sum(int_pages+leaf_pages+ovfl_pages) AS size
int(sum(int_pages+leaf_pages+ovfl_pages)) AS size
FROM space_used GROUP BY tblname ORDER BY size DESC, tblname} {} {
statline [string toupper $tblname] $size [percent $size $file_pgcnt]
}