Fossil SCM
Added new "dbstat" command, mostly analog to the /stat web page, but not called "stat" to avoid breaking any "stat==status" typing habits.
Commit
1dd493231a854cdc77afd04d3a203bcbe4cc5319
Parent
a0dd51e9af4a7a7…
1 file changed
+104
+104
| --- src/stat.c | ||
| +++ src/stat.c | ||
| @@ -137,10 +137,114 @@ | ||
| 137 | 137 | @ </td></tr> |
| 138 | 138 | |
| 139 | 139 | @ </table> |
| 140 | 140 | style_footer(); |
| 141 | 141 | } |
| 142 | + | |
| 143 | +/* | |
| 144 | +** COMMAND: dbstat | |
| 145 | +** | |
| 146 | +** Show statistics and global information about the repository. | |
| 147 | +*/ | |
| 148 | +void dbstat_cmd(void){ | |
| 149 | + i64 t, fsize; | |
| 150 | + int n, m; | |
| 151 | + int szMax, szAvg; | |
| 152 | + const char *zDb; | |
| 153 | + int brief; | |
| 154 | + char zBuf[100]; | |
| 155 | + const int colWidth = -20 /* printf alignment/width for left column */; | |
| 156 | + brief = find_option("brief", "b",0)!=0; | |
| 157 | + db_find_and_open_repository(0,0); | |
| 158 | + fsize = file_size(g.zRepositoryName); | |
| 159 | + bigSizeName(sizeof(zBuf), zBuf, fsize); | |
| 160 | + fossil_print( "%*s%s\n", colWidth, "repository-size:", zBuf ); | |
| 161 | + if( !brief ){ | |
| 162 | + n = db_int(0, "SELECT count(*) FROM blob"); | |
| 163 | + m = db_int(0, "SELECT count(*) FROM delta"); | |
| 164 | + fossil_print("%*s%d (stored as %d full text and %d delta blobs)\n", | |
| 165 | + colWidth, "artifact-count:", | |
| 166 | + n, n-m, m); | |
| 167 | + if( n>0 ){ | |
| 168 | + int a, b; | |
| 169 | + Stmt q; | |
| 170 | + db_prepare(&q, "SELECT total(size), avg(size), max(size)" | |
| 171 | + " FROM blob WHERE size>0"); | |
| 172 | + db_step(&q); | |
| 173 | + t = db_column_int64(&q, 0); | |
| 174 | + szAvg = db_column_int(&q, 1); | |
| 175 | + szMax = db_column_int(&q, 2); | |
| 176 | + db_finalize(&q); | |
| 177 | + bigSizeName(sizeof(zBuf), zBuf, t); | |
| 178 | + fossil_print( "%*s%d bytes average, " | |
| 179 | + "%d bytes max, %s total\n", | |
| 180 | + colWidth, "artifact-sizes:", | |
| 181 | + szAvg, szMax, zBuf); | |
| 182 | + if( t/fsize < 5 ){ | |
| 183 | + b = 10; | |
| 184 | + fsize /= 10; | |
| 185 | + }else{ | |
| 186 | + b = 1; | |
| 187 | + } | |
| 188 | + a = t/fsize; | |
| 189 | + fossil_print("%*s%d:%d\n", colWidth, "compression-ratio:", a, b); | |
| 190 | + } | |
| 191 | + n = db_int(0, "SELECT COUNT(*) FROM event e WHERE e.type='ci'"); | |
| 192 | + fossil_print("%*s%d\n", colWidth, "checkin-count:", n); | |
| 193 | + n = db_int(0, "SELECT count(*) FROM filename /*scan*/"); | |
| 194 | + /* FIXME/TODO: add the change-count-per-type to each event type, | |
| 195 | + ** plus add 'Event' count | |
| 196 | + */ | |
| 197 | +#if 0 | |
| 198 | + m = db_int(0, "SELECT count(distinct mid) FROM mlink /*scan*/"); | |
| 199 | +#endif | |
| 200 | + fossil_print("%*s%d"/* (%d changes) */"\n", colWidth, "file-count:", | |
| 201 | + n/*, m */); | |
| 202 | + n = db_int(0, "SELECT count(*) FROM tag /*scan*/" | |
| 203 | + " WHERE tagname GLOB 'wiki-*'"); | |
| 204 | +#if 0 | |
| 205 | + m = db_int(0, "SELECT COUNT(*) FROM blob b JOIN event e WHERE " | |
| 206 | + "b.rid=e.objid AND e.type='w'"); | |
| 207 | +#endif | |
| 208 | + fossil_print("%*s%d"/* (%d changes) */"\n", colWidth, "wikipage-count:", | |
| 209 | + n/*, m */); | |
| 210 | + n = db_int(0, "SELECT count(*) FROM tag /*scan*/" | |
| 211 | + " WHERE tagname GLOB 'tkt-*'"); | |
| 212 | +#if 0 | |
| 213 | + m = db_int(0, "SELECT COUNT(*) FROM blob b JOIN event e WHERE " | |
| 214 | + "b.rid=e.objid AND e.type='t'"); | |
| 215 | +#endif | |
| 216 | + fossil_print("%*s%d"/* (%d changes)*/"\n", colWidth, "ticket-count:", | |
| 217 | + n/* , m */); | |
| 218 | + } | |
| 219 | + n = db_int(0, "SELECT julianday('now') - (SELECT min(mtime) FROM event)" | |
| 220 | + " + 0.99"); | |
| 221 | + fossil_print("%*s%d days or approximately %.2f years.\n", | |
| 222 | + colWidth, "project-age:", n, n/365.24); | |
| 223 | + fossil_print("%*s%s\n", colWidth, "project-id:", db_get("project-code","")); | |
| 224 | + fossil_print("%*s%s\n", colWidth, "server-id:", db_get("server-code","")); | |
| 225 | + fossil_print("%*s%s %s %s (%s)\n", | |
| 226 | + colWidth, "fossil-version:", | |
| 227 | + RELEASE_VERSION, MANIFEST_DATE, MANIFEST_VERSION, | |
| 228 | + COMPILER_NAME); | |
| 229 | + fossil_print("%*s%.19s [%.10s] (%s)\n", | |
| 230 | + colWidth, "sqlite-version:", | |
| 231 | + SQLITE_SOURCE_ID, &SQLITE_SOURCE_ID[20], | |
| 232 | + SQLITE_VERSION); | |
| 233 | + zDb = db_name("repository"); | |
| 234 | + fossil_print("%*s%d pages, %d bytes/page, %d free pages, " | |
| 235 | + "%s, %s mode\n", | |
| 236 | + colWidth, "database-stats:", | |
| 237 | + db_int(0, "PRAGMA %s.page_count", zDb), | |
| 238 | + db_int(0, "PRAGMA %s.page_size", zDb), | |
| 239 | + db_int(0, "PRAGMA %s.freelist_count", zDb), | |
| 240 | + db_text(0, "PRAGMA %s.encoding", zDb), | |
| 241 | + db_text(0, "PRAGMA %s.journal_mode", zDb)); | |
| 242 | + | |
| 243 | +} | |
| 244 | + | |
| 245 | + | |
| 142 | 246 | |
| 143 | 247 | /* |
| 144 | 248 | ** WEBPAGE: urllist |
| 145 | 249 | ** |
| 146 | 250 | ** Show ways in which this repository has been accessed |
| 147 | 251 |
| --- src/stat.c | |
| +++ src/stat.c | |
| @@ -137,10 +137,114 @@ | |
| 137 | @ </td></tr> |
| 138 | |
| 139 | @ </table> |
| 140 | style_footer(); |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | ** WEBPAGE: urllist |
| 145 | ** |
| 146 | ** Show ways in which this repository has been accessed |
| 147 |
| --- src/stat.c | |
| +++ src/stat.c | |
| @@ -137,10 +137,114 @@ | |
| 137 | @ </td></tr> |
| 138 | |
| 139 | @ </table> |
| 140 | style_footer(); |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | ** COMMAND: dbstat |
| 145 | ** |
| 146 | ** Show statistics and global information about the repository. |
| 147 | */ |
| 148 | void dbstat_cmd(void){ |
| 149 | i64 t, fsize; |
| 150 | int n, m; |
| 151 | int szMax, szAvg; |
| 152 | const char *zDb; |
| 153 | int brief; |
| 154 | char zBuf[100]; |
| 155 | const int colWidth = -20 /* printf alignment/width for left column */; |
| 156 | brief = find_option("brief", "b",0)!=0; |
| 157 | db_find_and_open_repository(0,0); |
| 158 | fsize = file_size(g.zRepositoryName); |
| 159 | bigSizeName(sizeof(zBuf), zBuf, fsize); |
| 160 | fossil_print( "%*s%s\n", colWidth, "repository-size:", zBuf ); |
| 161 | if( !brief ){ |
| 162 | n = db_int(0, "SELECT count(*) FROM blob"); |
| 163 | m = db_int(0, "SELECT count(*) FROM delta"); |
| 164 | fossil_print("%*s%d (stored as %d full text and %d delta blobs)\n", |
| 165 | colWidth, "artifact-count:", |
| 166 | n, n-m, m); |
| 167 | if( n>0 ){ |
| 168 | int a, b; |
| 169 | Stmt q; |
| 170 | db_prepare(&q, "SELECT total(size), avg(size), max(size)" |
| 171 | " FROM blob WHERE size>0"); |
| 172 | db_step(&q); |
| 173 | t = db_column_int64(&q, 0); |
| 174 | szAvg = db_column_int(&q, 1); |
| 175 | szMax = db_column_int(&q, 2); |
| 176 | db_finalize(&q); |
| 177 | bigSizeName(sizeof(zBuf), zBuf, t); |
| 178 | fossil_print( "%*s%d bytes average, " |
| 179 | "%d bytes max, %s total\n", |
| 180 | colWidth, "artifact-sizes:", |
| 181 | szAvg, szMax, zBuf); |
| 182 | if( t/fsize < 5 ){ |
| 183 | b = 10; |
| 184 | fsize /= 10; |
| 185 | }else{ |
| 186 | b = 1; |
| 187 | } |
| 188 | a = t/fsize; |
| 189 | fossil_print("%*s%d:%d\n", colWidth, "compression-ratio:", a, b); |
| 190 | } |
| 191 | n = db_int(0, "SELECT COUNT(*) FROM event e WHERE e.type='ci'"); |
| 192 | fossil_print("%*s%d\n", colWidth, "checkin-count:", n); |
| 193 | n = db_int(0, "SELECT count(*) FROM filename /*scan*/"); |
| 194 | /* FIXME/TODO: add the change-count-per-type to each event type, |
| 195 | ** plus add 'Event' count |
| 196 | */ |
| 197 | #if 0 |
| 198 | m = db_int(0, "SELECT count(distinct mid) FROM mlink /*scan*/"); |
| 199 | #endif |
| 200 | fossil_print("%*s%d"/* (%d changes) */"\n", colWidth, "file-count:", |
| 201 | n/*, m */); |
| 202 | n = db_int(0, "SELECT count(*) FROM tag /*scan*/" |
| 203 | " WHERE tagname GLOB 'wiki-*'"); |
| 204 | #if 0 |
| 205 | m = db_int(0, "SELECT COUNT(*) FROM blob b JOIN event e WHERE " |
| 206 | "b.rid=e.objid AND e.type='w'"); |
| 207 | #endif |
| 208 | fossil_print("%*s%d"/* (%d changes) */"\n", colWidth, "wikipage-count:", |
| 209 | n/*, m */); |
| 210 | n = db_int(0, "SELECT count(*) FROM tag /*scan*/" |
| 211 | " WHERE tagname GLOB 'tkt-*'"); |
| 212 | #if 0 |
| 213 | m = db_int(0, "SELECT COUNT(*) FROM blob b JOIN event e WHERE " |
| 214 | "b.rid=e.objid AND e.type='t'"); |
| 215 | #endif |
| 216 | fossil_print("%*s%d"/* (%d changes)*/"\n", colWidth, "ticket-count:", |
| 217 | n/* , m */); |
| 218 | } |
| 219 | n = db_int(0, "SELECT julianday('now') - (SELECT min(mtime) FROM event)" |
| 220 | " + 0.99"); |
| 221 | fossil_print("%*s%d days or approximately %.2f years.\n", |
| 222 | colWidth, "project-age:", n, n/365.24); |
| 223 | fossil_print("%*s%s\n", colWidth, "project-id:", db_get("project-code","")); |
| 224 | fossil_print("%*s%s\n", colWidth, "server-id:", db_get("server-code","")); |
| 225 | fossil_print("%*s%s %s %s (%s)\n", |
| 226 | colWidth, "fossil-version:", |
| 227 | RELEASE_VERSION, MANIFEST_DATE, MANIFEST_VERSION, |
| 228 | COMPILER_NAME); |
| 229 | fossil_print("%*s%.19s [%.10s] (%s)\n", |
| 230 | colWidth, "sqlite-version:", |
| 231 | SQLITE_SOURCE_ID, &SQLITE_SOURCE_ID[20], |
| 232 | SQLITE_VERSION); |
| 233 | zDb = db_name("repository"); |
| 234 | fossil_print("%*s%d pages, %d bytes/page, %d free pages, " |
| 235 | "%s, %s mode\n", |
| 236 | colWidth, "database-stats:", |
| 237 | db_int(0, "PRAGMA %s.page_count", zDb), |
| 238 | db_int(0, "PRAGMA %s.page_size", zDb), |
| 239 | db_int(0, "PRAGMA %s.freelist_count", zDb), |
| 240 | db_text(0, "PRAGMA %s.encoding", zDb), |
| 241 | db_text(0, "PRAGMA %s.journal_mode", zDb)); |
| 242 | |
| 243 | } |
| 244 | |
| 245 | |
| 246 | |
| 247 | /* |
| 248 | ** WEBPAGE: urllist |
| 249 | ** |
| 250 | ** Show ways in which this repository has been accessed |
| 251 |