Fossil SCM
Improve the readability of large sizes on the "stat" webpage.
Commit
701c8e68c6a036340869c0dc51d34c3fe73bf5c7
Parent
82f56632705e3d9…
1 file changed
+23
-4
+23
-4
| --- src/stat.c | ||
| +++ src/stat.c | ||
| @@ -19,10 +19,29 @@ | ||
| 19 | 19 | ** |
| 20 | 20 | */ |
| 21 | 21 | #include <string.h> |
| 22 | 22 | #include "config.h" |
| 23 | 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 | +} | |
| 24 | 43 | |
| 25 | 44 | /* |
| 26 | 45 | ** WEBPAGE: stat |
| 27 | 46 | ** |
| 28 | 47 | ** Show statistics and global information about the repository. |
| @@ -40,12 +59,12 @@ | ||
| 40 | 59 | brief = P("brief")!=0; |
| 41 | 60 | style_header("Repository Statistics"); |
| 42 | 61 | @ <table class="label-value"> |
| 43 | 62 | @ <tr><th>Repository Size:</th><td> |
| 44 | 63 | 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) | |
| 47 | 66 | @ </td></tr> |
| 48 | 67 | if( !brief ){ |
| 49 | 68 | @ <tr><th>Number Of Artifacts:</th><td> |
| 50 | 69 | n = db_int(0, "SELECT count(*) FROM blob"); |
| 51 | 70 | m = db_int(0, "SELECT count(*) FROM delta"); |
| @@ -60,12 +79,12 @@ | ||
| 60 | 79 | db_step(&q); |
| 61 | 80 | t = db_column_int64(&q, 0); |
| 62 | 81 | szAvg = db_column_int(&q, 1); |
| 63 | 82 | szMax = db_column_int(&q, 2); |
| 64 | 83 | 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 | |
| 67 | 86 | @ </td></tr> |
| 68 | 87 | @ <tr><th>Compression Ratio:</th><td> |
| 69 | 88 | if( t/fsize < 5 ){ |
| 70 | 89 | b = 10; |
| 71 | 90 | fsize /= 10; |
| 72 | 91 |
| --- 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 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 Of 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 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 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 Of 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 Ratio:</th><td> |
| 88 | if( t/fsize < 5 ){ |
| 89 | b = 10; |
| 90 | fsize /= 10; |
| 91 |