Fossil SCM

On the /repo-tabsize page, show the total repository size. And show the size of the local checkout database and its breakdown if run from "fossil ui".

drh 2015-05-09 13:07 trunk
Commit f3c7b3a6b5851d76b16da58ea390a1f7dfa57cc2
1 file changed +52 -2
+52 -2
--- src/stat.c
+++ src/stat.c
@@ -36,10 +36,25 @@
3636
}else{
3737
sqlite3_snprintf(nOut, zOut, "%lld bytes (%.1fGB)",
3838
v, (double)v/1000000000.0);
3939
}
4040
}
41
+
42
+/*
43
+** Return the approximate size as KB, MB, GB, or TB.
44
+*/
45
+void approxSizeName(int nOut, char *zOut, sqlite3_int64 v){
46
+ if( v<1000 ){
47
+ sqlite3_snprintf(nOut, zOut, "%lld bytes", v);
48
+ }else if( v<1000000 ){
49
+ sqlite3_snprintf(nOut, zOut, "%.1fKB", (double)v/1000.0);
50
+ }else if( v<1000000000 ){
51
+ sqlite3_snprintf(nOut, zOut, "%.1fMB", (double)v/1000000.0);
52
+ }else{
53
+ sqlite3_snprintf(nOut, zOut, "%.1fGB", (double)v/1000000000.0);
54
+ }
55
+}
4156
4257
/*
4358
** WEBPAGE: stat
4459
**
4560
** Show statistics and global information about the repository.
@@ -366,10 +381,12 @@
366381
*/
367382
void repo_tabsize_page(void){
368383
Stmt q;
369384
login_check_credentials();
370385
int nPageFree;
386
+ sqlite3_int64 fsize;
387
+ char zBuf[100];
371388
if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
372389
373390
style_header("Repository Table Sizes");
374391
style_adunit_config(ADUNIT_RIGHT_OK);
375392
style_submenu_element("Stat", "Repository Stats", "stat");
@@ -384,17 +401,50 @@
384401
" coalesce((SELECT tabname FROM trans WHERE trans.name=dbx.name),name)"
385402
" FROM dbx"
386403
" GROUP BY 2 ORDER BY 2;",
387404
db_name("repository"), db_name("repository")
388405
);
389
- nPageFree = db_int(0, "PRAGMA freelist_count");
406
+ nPageFree = db_int(0, "PRAGMA \"%w\".freelist_count", db_name("repository"));
390407
if( nPageFree>0 ){
391408
db_multi_exec(
392409
"INSERT INTO piechart(amt,label) VALUES(%d,'freelist')",
393410
nPageFree
394411
);
395412
}
413
+ fsize = file_size(g.zRepositoryName);
414
+ approxSizeName(sizeof(zBuf), zBuf, fsize);
415
+ @ <h2>Repository Size: %s(zBuf)</h2>
396416
@ <center><svg width='800' height='600'>
397417
piechart_render(800,600,PIE_OTHER|PIE_PERCENT);
398
- @ </svg>
418
+ @ </svg></center>
419
+
420
+ if( g.localOpen ){
421
+ db_multi_exec(
422
+ "DROP TABLE temp.dbx;"
423
+ "CREATE VIRTUAL TABLE temp.dbx USING dbstat(%s);"
424
+ "DELETE FROM trans;"
425
+ "INSERT INTO trans(name,tabname)"
426
+ " SELECT name, tbl_name FROM %s.sqlite_master;"
427
+ "DELETE FROM piechart;"
428
+ "INSERT INTO piechart(amt,label)"
429
+ " SELECT count(*), "
430
+ " coalesce((SELECT tabname FROM trans WHERE trans.name=dbx.name),name)"
431
+ " FROM dbx"
432
+ " GROUP BY 2 ORDER BY 2;",
433
+ db_name("localdb"), db_name("localdb")
434
+ );
435
+ nPageFree = db_int(0, "PRAGMA \"%s\".freelist_count", db_name("localdb"));
436
+ if( nPageFree>0 ){
437
+ db_multi_exec(
438
+ "INSERT INTO piechart(amt,label) VALUES(%d,'freelist')",
439
+ nPageFree
440
+ );
441
+ }
442
+ fsize = file_size(g.zLocalDbName);
443
+ approxSizeName(sizeof(zBuf), zBuf, fsize);
444
+ @ <h2>%h(file_tail(g.zLocalDbName)) Size: %s(zBuf)</h2>
445
+ @ <center><svg width='800' height='600'>
446
+ piechart_render(800,600,PIE_OTHER|PIE_PERCENT);
447
+ @ </svg></center>
448
+ }
399449
style_footer();
400450
}
401451
--- src/stat.c
+++ src/stat.c
@@ -36,10 +36,25 @@
36 }else{
37 sqlite3_snprintf(nOut, zOut, "%lld bytes (%.1fGB)",
38 v, (double)v/1000000000.0);
39 }
40 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
42 /*
43 ** WEBPAGE: stat
44 **
45 ** Show statistics and global information about the repository.
@@ -366,10 +381,12 @@
366 */
367 void repo_tabsize_page(void){
368 Stmt q;
369 login_check_credentials();
370 int nPageFree;
 
 
371 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
372
373 style_header("Repository Table Sizes");
374 style_adunit_config(ADUNIT_RIGHT_OK);
375 style_submenu_element("Stat", "Repository Stats", "stat");
@@ -384,17 +401,50 @@
384 " coalesce((SELECT tabname FROM trans WHERE trans.name=dbx.name),name)"
385 " FROM dbx"
386 " GROUP BY 2 ORDER BY 2;",
387 db_name("repository"), db_name("repository")
388 );
389 nPageFree = db_int(0, "PRAGMA freelist_count");
390 if( nPageFree>0 ){
391 db_multi_exec(
392 "INSERT INTO piechart(amt,label) VALUES(%d,'freelist')",
393 nPageFree
394 );
395 }
 
 
 
396 @ <center><svg width='800' height='600'>
397 piechart_render(800,600,PIE_OTHER|PIE_PERCENT);
398 @ </svg>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
399 style_footer();
400 }
401
--- src/stat.c
+++ src/stat.c
@@ -36,10 +36,25 @@
36 }else{
37 sqlite3_snprintf(nOut, zOut, "%lld bytes (%.1fGB)",
38 v, (double)v/1000000000.0);
39 }
40 }
41
42 /*
43 ** Return the approximate size as KB, MB, GB, or TB.
44 */
45 void approxSizeName(int nOut, char *zOut, sqlite3_int64 v){
46 if( v<1000 ){
47 sqlite3_snprintf(nOut, zOut, "%lld bytes", v);
48 }else if( v<1000000 ){
49 sqlite3_snprintf(nOut, zOut, "%.1fKB", (double)v/1000.0);
50 }else if( v<1000000000 ){
51 sqlite3_snprintf(nOut, zOut, "%.1fMB", (double)v/1000000.0);
52 }else{
53 sqlite3_snprintf(nOut, zOut, "%.1fGB", (double)v/1000000000.0);
54 }
55 }
56
57 /*
58 ** WEBPAGE: stat
59 **
60 ** Show statistics and global information about the repository.
@@ -366,10 +381,12 @@
381 */
382 void repo_tabsize_page(void){
383 Stmt q;
384 login_check_credentials();
385 int nPageFree;
386 sqlite3_int64 fsize;
387 char zBuf[100];
388 if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
389
390 style_header("Repository Table Sizes");
391 style_adunit_config(ADUNIT_RIGHT_OK);
392 style_submenu_element("Stat", "Repository Stats", "stat");
@@ -384,17 +401,50 @@
401 " coalesce((SELECT tabname FROM trans WHERE trans.name=dbx.name),name)"
402 " FROM dbx"
403 " GROUP BY 2 ORDER BY 2;",
404 db_name("repository"), db_name("repository")
405 );
406 nPageFree = db_int(0, "PRAGMA \"%w\".freelist_count", db_name("repository"));
407 if( nPageFree>0 ){
408 db_multi_exec(
409 "INSERT INTO piechart(amt,label) VALUES(%d,'freelist')",
410 nPageFree
411 );
412 }
413 fsize = file_size(g.zRepositoryName);
414 approxSizeName(sizeof(zBuf), zBuf, fsize);
415 @ <h2>Repository Size: %s(zBuf)</h2>
416 @ <center><svg width='800' height='600'>
417 piechart_render(800,600,PIE_OTHER|PIE_PERCENT);
418 @ </svg></center>
419
420 if( g.localOpen ){
421 db_multi_exec(
422 "DROP TABLE temp.dbx;"
423 "CREATE VIRTUAL TABLE temp.dbx USING dbstat(%s);"
424 "DELETE FROM trans;"
425 "INSERT INTO trans(name,tabname)"
426 " SELECT name, tbl_name FROM %s.sqlite_master;"
427 "DELETE FROM piechart;"
428 "INSERT INTO piechart(amt,label)"
429 " SELECT count(*), "
430 " coalesce((SELECT tabname FROM trans WHERE trans.name=dbx.name),name)"
431 " FROM dbx"
432 " GROUP BY 2 ORDER BY 2;",
433 db_name("localdb"), db_name("localdb")
434 );
435 nPageFree = db_int(0, "PRAGMA \"%s\".freelist_count", db_name("localdb"));
436 if( nPageFree>0 ){
437 db_multi_exec(
438 "INSERT INTO piechart(amt,label) VALUES(%d,'freelist')",
439 nPageFree
440 );
441 }
442 fsize = file_size(g.zLocalDbName);
443 approxSizeName(sizeof(zBuf), zBuf, fsize);
444 @ <h2>%h(file_tail(g.zLocalDbName)) Size: %s(zBuf)</h2>
445 @ <center><svg width='800' height='600'>
446 piechart_render(800,600,PIE_OTHER|PIE_PERCENT);
447 @ </svg></center>
448 }
449 style_footer();
450 }
451

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button