Fossil SCM

Improve the readability of large sizes on the "stat" webpage.

drh 2012-04-02 01:14 trunk
Commit 701c8e68c6a036340869c0dc51d34c3fe73bf5c7
1 file changed +23 -4
+23 -4
--- src/stat.c
+++ src/stat.c
@@ -19,10 +19,29 @@
1919
**
2020
*/
2121
#include <string.h>
2222
#include "config.h"
2323
#include "stat.h"
24
+
25
+/*
26
+** For a sufficiently large integer, provide an alternative
27
+** representation as MB or GB or TB.
28
+*/
29
+static void bigSizeName(int nOut, char *zOut, sqlite3_int64 v){
30
+ if( v<100000 ){
31
+ sqlite3_snprintf(nOut, zOut, "%lld bytes", v);
32
+ }else if( v<1000000000 ){
33
+ sqlite3_snprintf(nOut, zOut, "%lld bytes (%.1fMB)",
34
+ (double)v/1000000.0, v);
35
+ }else if( v<1000000000000 ){
36
+ sqlite3_snprintf(nOut, zOut, "%lld bytes (%.1fGB)",
37
+ (double)v/1000000000.0, v);
38
+ }else{
39
+ sqlite3_snprintf(nOut, zOut, "%lld bytes (%.1fTB)",
40
+ (double)v/1000000000000.0, v);
41
+ }
42
+}
2443
2544
/*
2645
** WEBPAGE: stat
2746
**
2847
** Show statistics and global information about the repository.
@@ -40,12 +59,12 @@
4059
brief = P("brief")!=0;
4160
style_header("Repository Statistics");
4261
@ <table class="label-value">
4362
@ <tr><th>Repository&nbsp;Size:</th><td>
4463
fsize = file_size(g.zRepositoryName);
45
- sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", fsize);
46
- @ %s(zBuf) bytes
64
+ bigSizeName(sizeof(zBuf), zBuf, fsize);
65
+ @ %s(zBuf)
4766
@ </td></tr>
4867
if( !brief ){
4968
@ <tr><th>Number&nbsp;Of&nbsp;Artifacts:</th><td>
5069
n = db_int(0, "SELECT count(*) FROM blob");
5170
m = db_int(0, "SELECT count(*) FROM delta");
@@ -60,12 +79,12 @@
6079
db_step(&q);
6180
t = db_column_int64(&q, 0);
6281
szAvg = db_column_int(&q, 1);
6382
szMax = db_column_int(&q, 2);
6483
db_finalize(&q);
65
- sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", t);
66
- @ %d(szAvg) bytes average, %d(szMax) bytes max, %s(zBuf) bytes total
84
+ bigSizeName(sizeof(zBuf), zBuf, t);
85
+ @ %d(szAvg) bytes average, %d(szMax) bytes max, %s(zBuf) total
6786
@ </td></tr>
6887
@ <tr><th>Compression&nbsp;Ratio:</th><td>
6988
if( t/fsize < 5 ){
7089
b = 10;
7190
fsize /= 10;
7291
--- src/stat.c
+++ src/stat.c
@@ -19,10 +19,29 @@
19 **
20 */
21 #include <string.h>
22 #include "config.h"
23 #include "stat.h"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
25 /*
26 ** WEBPAGE: stat
27 **
28 ** Show statistics and global information about the repository.
@@ -40,12 +59,12 @@
40 brief = P("brief")!=0;
41 style_header("Repository Statistics");
42 @ <table class="label-value">
43 @ <tr><th>Repository&nbsp;Size:</th><td>
44 fsize = file_size(g.zRepositoryName);
45 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", fsize);
46 @ %s(zBuf) bytes
47 @ </td></tr>
48 if( !brief ){
49 @ <tr><th>Number&nbsp;Of&nbsp;Artifacts:</th><td>
50 n = db_int(0, "SELECT count(*) FROM blob");
51 m = db_int(0, "SELECT count(*) FROM delta");
@@ -60,12 +79,12 @@
60 db_step(&q);
61 t = db_column_int64(&q, 0);
62 szAvg = db_column_int(&q, 1);
63 szMax = db_column_int(&q, 2);
64 db_finalize(&q);
65 sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", t);
66 @ %d(szAvg) bytes average, %d(szMax) bytes max, %s(zBuf) bytes total
67 @ </td></tr>
68 @ <tr><th>Compression&nbsp;Ratio:</th><td>
69 if( t/fsize < 5 ){
70 b = 10;
71 fsize /= 10;
72
--- src/stat.c
+++ src/stat.c
@@ -19,10 +19,29 @@
19 **
20 */
21 #include <string.h>
22 #include "config.h"
23 #include "stat.h"
24
25 /*
26 ** For a sufficiently large integer, provide an alternative
27 ** representation as MB or GB or TB.
28 */
29 static void bigSizeName(int nOut, char *zOut, sqlite3_int64 v){
30 if( v<100000 ){
31 sqlite3_snprintf(nOut, zOut, "%lld bytes", v);
32 }else if( v<1000000000 ){
33 sqlite3_snprintf(nOut, zOut, "%lld bytes (%.1fMB)",
34 (double)v/1000000.0, v);
35 }else if( v<1000000000000 ){
36 sqlite3_snprintf(nOut, zOut, "%lld bytes (%.1fGB)",
37 (double)v/1000000000.0, v);
38 }else{
39 sqlite3_snprintf(nOut, zOut, "%lld bytes (%.1fTB)",
40 (double)v/1000000000000.0, v);
41 }
42 }
43
44 /*
45 ** WEBPAGE: stat
46 **
47 ** Show statistics and global information about the repository.
@@ -40,12 +59,12 @@
59 brief = P("brief")!=0;
60 style_header("Repository Statistics");
61 @ <table class="label-value">
62 @ <tr><th>Repository&nbsp;Size:</th><td>
63 fsize = file_size(g.zRepositoryName);
64 bigSizeName(sizeof(zBuf), zBuf, fsize);
65 @ %s(zBuf)
66 @ </td></tr>
67 if( !brief ){
68 @ <tr><th>Number&nbsp;Of&nbsp;Artifacts:</th><td>
69 n = db_int(0, "SELECT count(*) FROM blob");
70 m = db_int(0, "SELECT count(*) FROM delta");
@@ -60,12 +79,12 @@
79 db_step(&q);
80 t = db_column_int64(&q, 0);
81 szAvg = db_column_int(&q, 1);
82 szMax = db_column_int(&q, 2);
83 db_finalize(&q);
84 bigSizeName(sizeof(zBuf), zBuf, t);
85 @ %d(szAvg) bytes average, %d(szMax) bytes max, %s(zBuf) total
86 @ </td></tr>
87 @ <tr><th>Compression&nbsp;Ratio:</th><td>
88 if( t/fsize < 5 ){
89 b = 10;
90 fsize /= 10;
91

Keyboard Shortcuts

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