1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-27 20:41:58 +03:00

Update the space-analyzer tool to support auto-vacuum databases. (CVS 2080)

FossilOrigin-Name: 1cb8086612c7dec170da0910cf0cbe4e48c417f8
This commit is contained in:
danielk1977
2004-11-08 16:15:09 +00:00
parent 8f5a31b50f
commit 16254450f4
3 changed files with 100 additions and 34 deletions

View File

@ -1,5 +1,5 @@
C A\sfew\smore\sauto-vacuum\stests.\s(CVS\s2079) C Update\sthe\sspace-analyzer\stool\sto\ssupport\sauto-vacuum\sdatabases.\s(CVS\s2080)
D 2004-11-08T12:32:50 D 2004-11-08T16:15:09
F Makefile.in c4d2416860f472a1e3393714d0372074197565df F Makefile.in c4d2416860f472a1e3393714d0372074197565df
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1 F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
@ -210,7 +210,7 @@ F tool/report1.txt 9eae07f26a8fc53889b45fc833a66a33daa22816
F tool/showdb.c 3559eac5a3b46e9b558d50856946b25e77633236 F tool/showdb.c 3559eac5a3b46e9b558d50856946b25e77633236
F tool/showjournal.c ec3b171be148656827c4949fbfb8ab4370822f87 F tool/showjournal.c ec3b171be148656827c4949fbfb8ab4370822f87
F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b
F tool/spaceanal.tcl c8c39c466fbbc01dab10fc6c4a816db3c8168ab3 F tool/spaceanal.tcl a1ba7f05762dfad4c987b75cab6b317823319aa5
F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355 F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F www/arch.fig d5f9752a4dbf242e9cfffffd3f5762b6c63b3bcf F www/arch.fig d5f9752a4dbf242e9cfffffd3f5762b6c63b3bcf
@ -254,7 +254,7 @@ F www/tclsqlite.tcl 560ecd6a916b320e59f2917317398f3d59b7cc25
F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
F www/whentouse.tcl fdacb0ba2d39831e8a6240d05a490026ad4c4e4c F www/whentouse.tcl fdacb0ba2d39831e8a6240d05a490026ad4c4e4c
P 9d7cd1f732ba6f9d69fc30100a4608b74f212b76 P 9d4a60bbd67704ff3a9503678db94498dc700ccc
R 332706045c880050ac7896f172870779 R 8cf6f260fdfd53f2e09339439b8556c2
U danielk1977 U danielk1977
Z e559ccf849c343b03d2edaffd64c8f69 Z 02ec250981012ecec875e37f4f347117

View File

@ -1 +1 @@
9d4a60bbd67704ff3a9503678db94498dc700ccc 1cb8086612c7dec170da0910cf0cbe4e48c417f8

View File

@ -5,7 +5,7 @@
# Get the name of the database to analyze # Get the name of the database to analyze
# #
set argv $argv0 #set argv $argv0
if {[llength $argv]!=1} { if {[llength $argv]!=1} {
puts stderr "Usage: $argv0 database-name" puts stderr "Usage: $argv0 database-name"
exit 1 exit 1
@ -322,42 +322,103 @@ proc subreport {title where} {
return 1 return 1
} }
# Calculate the overhead in pages caused by auto-vacuum.
#
# This procedure calculates and returns the number of pages used by the
# auto-vacuum 'pointer-map'. If the database does not support auto-vacuum,
# then 0 is returned. The two arguments are the size of the database file in
# bytes and the page size used by the database (also in bytes).
proc autovacuum_overhead {filePages pageSize} {
# Read the value of meta 4. If non-zero, then the database supports
# auto-vacuum. It would be possible to use "PRAGMA auto_vacuum" instead,
# but that would not work if the SQLITE_OMIT_PRAGMA macro was defined
# when the library was built.
set meta4 [lindex [btree_get_meta $::DB] 4]
# If the database is not an auto-vacuum database or the file consists
# of one page only then there is no overhead for auto-vacuum. Return zero.
if {0==$meta4 || $filePages==1} {
return 0
}
# The number of entries on each pointer map page. The layout of the
# database file is one pointer-map page, followed by $ptrsPerPage other
# pages, followed by a pointer-map page etc. The first pointer-map page
# is the second page of the file overall.
set ptrsPerPage [expr double($pageSize/5)]
# Return the number of pointer map pages in the database.
return [expr int(ceil( ($filePages-1.0)/($ptrsPerPage+1.0) ))]
}
# Output summary statistics: # Output summary statistics:
# #
puts "/** Disk-Space Utilization Report For $file_to_analyze" puts "/** Disk-Space Utilization Report For $file_to_analyze"
puts "*** As of [clock format [clock seconds] -format {%Y-%b-%d %H:%M:%S}]" puts "*** As of [clock format [clock seconds] -format {%Y-%b-%d %H:%M:%S}]"
puts "" puts ""
statline {Page size in bytes} $pageSize
set fsize [file size $file_to_analyze] # Variables:
set file_pgcnt [expr {$fsize/$pageSize}] #
set usedcnt [mem eval \ # pageSize: Size of each page in bytes.
{SELECT sum(leaf_pages+int_pages+ovfl_pages) FROM space_used}] # file_bytes: File size in bytes.
set freecnt [expr {$file_pgcnt-$usedcnt}] # file_pgcnt: Number of pages in the file.
set freecnt2 [lindex [btree_get_meta $DB] 0] # file_pgcnt2: Number of pages in the file (calculated).
statline {Pages in the whole file (measured)} $file_pgcnt # av_pgcnt: Pages consumed by the auto-vacuum pointer-map.
set file_pgcnt2 [expr {$usedcnt+$freecnt2}] # av_percent: Percentage of the file consumed by auto-vacuum pointer-map.
statline {Pages in the whole file (calculated)} $file_pgcnt2 # inuse_pgcnt: Data pages in the file.
statline {Pages that store data} $usedcnt [percent $usedcnt $file_pgcnt] # inuse_percent: Percentage of pages used to store data.
statline {Pages on the freelist (per header)}\ # free_pgcnt: Free pages calculated as (<total pages> - <in-use pages>)
$freecnt2 [percent $freecnt2 $file_pgcnt] # free_pgcnt2: Free pages in the file according to the file header.
statline {Pages on the freelist (calculated)}\ # free_percent: Percentage of file consumed by free pages (calculated).
$freecnt [percent $freecnt $file_pgcnt] # free_percent2: Percentage of file consumed by free pages (header).
# ntable: Number of tables in the db.
# nindex: Number of indices in the db.
# nautoindex: Number of indices created automatically.
# nmanindex: Number of indices created manually.
# user_payload:
set file_bytes [file size $file_to_analyze]
set file_pgcnt [expr {$file_bytes/$pageSize}]
set av_pgcnt [autovacuum_overhead $file_pgcnt $pageSize]
set av_percent [percent $av_pgcnt $file_pgcnt]
set q {SELECT sum(leaf_pages+int_pages+ovfl_pages) FROM space_used}
set inuse_pgcnt [expr [mem eval $q]]
set inuse_percent [percent $inuse_pgcnt $file_pgcnt]
set free_pgcnt [expr $file_pgcnt-$inuse_pgcnt-$av_pgcnt]
set free_percent [percent $free_pgcnt $file_pgcnt]
set free_pgcnt2 [lindex [btree_get_meta $DB] 0]
set free_percent2 [percent $free_pgcnt2 $file_pgcnt]
set file_pgcnt2 [expr {$inuse_pgcnt+$free_pgcnt2+$av_pgcnt}]
set ntable [db eval {SELECT count(*)+1 FROM sqlite_master WHERE type='table'}] set ntable [db eval {SELECT count(*)+1 FROM sqlite_master WHERE type='table'}]
statline {Number of tables in the database} $ntable
set nindex [db eval {SELECT count(*) FROM sqlite_master WHERE type='index'}] set nindex [db eval {SELECT count(*) FROM sqlite_master WHERE type='index'}]
set autoindex [db eval {SELECT count(*) FROM sqlite_master set q {SELECT count(*) FROM sqlite_master WHERE name LIKE 'sqlite_autoindex%'}
WHERE type='index' AND name LIKE '(% autoindex %)'}] set nautoindex [db eval $q]
set manindex [expr {$nindex-$autoindex}] set nmanindex [expr {$nindex-$nautoindex}]
statline {Number of indices} $nindex
statline {Number of named indices} $manindex # set total_payload [mem eval "SELECT sum(payload) FROM space_used"]
statline {Automatically generated indices} $autoindex
set total_payload [mem eval "SELECT sum(payload) FROM space_used"]
statline "Size of the file in bytes" $fsize
set user_payload [mem one {SELECT sum(payload) FROM space_used set user_payload [mem one {SELECT sum(payload) FROM space_used
WHERE NOT is_index AND name NOT LIKE 'sqlite_master'}] WHERE NOT is_index AND name NOT LIKE 'sqlite_master'}]
statline "Bytes of user payload stored" $user_payload \ set user_payload_percent [percent $user_payload $file_bytes]
[percent $user_payload $fsize]
statline {Page size in bytes} $pageSize
statline {Pages in the whole file (measured)} $file_pgcnt
statline {Pages in the whole file (calculated)} $file_pgcnt2
statline {Pages that store data} $inuse_pgcnt $inuse_percent
statline {Pages on the freelist (per header)} $free_pgcnt2 $free_percent2
statline {Pages on the freelist (calculated)} $free_pgcnt $free_percent
statline {Pages of auto-vacuum overhead} $av_pgcnt $av_percent
statline {Number of tables in the database} $ntable
statline {Number of indices} $nindex
statline {Number of named indices} $nmanindex
statline {Automatically generated indices} $nautoindex
statline {Size of the file in bytes} $file_bytes
statline {Bytes of user payload stored} $user_payload $user_payload_percent
# Output table rankings # Output table rankings
# #
@ -422,6 +483,11 @@ Pages on the freelist
future use. The percentage at the right is the number of freelist pages future use. The percentage at the right is the number of freelist pages
divided by the total number of pages in the file. divided by the total number of pages in the file.
Pages of auto-vacuum overhead
The number of pages that store data used by the database to facilitate
auto-vacuum. This is zero for databases that do not support auto-vacuum.
Number of tables in the database Number of tables in the database
The number of tables in the database, including the SQLITE_MASTER table The number of tables in the database, including the SQLITE_MASTER table