Artifact 0523d46255501dad8ee2aea70ddb105732bf339c:
File
src/stat.c
part of check-in
[cf84ce2d8c]
- Fix a typo on the "stat" page.
by
drh on
2008-05-07 23:56:28.
0000: 2f 2a 0a 2a 2a 20 43 6f 70 79 72 69 67 68 74 20 /*.** Copyright
0010: 28 63 29 20 32 30 30 37 20 44 2e 20 52 69 63 68 (c) 2007 D. Rich
0020: 61 72 64 20 48 69 70 70 0a 2a 2a 0a 2a 2a 20 54 ard Hipp.**.** T
0030: 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 66 his program is f
0040: 72 65 65 20 73 6f 66 74 77 61 72 65 3b 20 79 6f ree software; yo
0050: 75 20 63 61 6e 20 72 65 64 69 73 74 72 69 62 75 u can redistribu
0060: 74 65 20 69 74 20 61 6e 64 2f 6f 72 0a 2a 2a 20 te it and/or.**
0070: 6d 6f 64 69 66 79 20 69 74 20 75 6e 64 65 72 20 modify it under
0080: 74 68 65 20 74 65 72 6d 73 20 6f 66 20 74 68 65 the terms of the
0090: 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 62 GNU General Pub
00a0: 6c 69 63 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 76 lic.** License v
00b0: 65 72 73 69 6f 6e 20 32 20 61 73 20 70 75 62 6c ersion 2 as publ
00c0: 69 73 68 65 64 20 62 79 20 74 68 65 20 46 72 65 ished by the Fre
00d0: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64 e Software Found
00e0: 61 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 69 ation..**.** Thi
00f0: 73 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69 73 s program is dis
0100: 74 72 69 62 75 74 65 64 20 69 6e 20 74 68 65 20 tributed in the
0110: 68 6f 70 65 20 74 68 61 74 20 69 74 20 77 69 6c hope that it wil
0120: 6c 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a 20 l be useful,.**
0130: 62 75 74 20 57 49 54 48 4f 55 54 20 41 4e 59 20 but WITHOUT ANY
0140: 57 41 52 52 41 4e 54 59 3b 20 77 69 74 68 6f 75 WARRANTY; withou
0150: 74 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c 69 t even the impli
0160: 65 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a 2a ed warranty of.*
0170: 2a 20 4d 45 52 43 48 41 4e 54 41 42 49 4c 49 54 * MERCHANTABILIT
0180: 59 20 6f 72 20 46 49 54 4e 45 53 53 20 46 4f 52 Y or FITNESS FOR
0190: 20 41 20 50 41 52 54 49 43 55 4c 41 52 20 50 55 A PARTICULAR PU
01a0: 52 50 4f 53 45 2e 20 20 53 65 65 20 74 68 65 20 RPOSE. See the
01b0: 47 4e 55 0a 2a 2a 20 47 65 6e 65 72 61 6c 20 50 GNU.** General P
01c0: 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 66 6f ublic License fo
01d0: 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73 2e 0a r more details..
01e0: 2a 2a 20 0a 2a 2a 20 59 6f 75 20 73 68 6f 75 6c ** .** You shoul
01f0: 64 20 68 61 76 65 20 72 65 63 65 69 76 65 64 20 d have received
0200: 61 20 63 6f 70 79 20 6f 66 20 74 68 65 20 47 4e a copy of the GN
0210: 55 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69 63 U General Public
0220: 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 61 6c 6f 6e .** License alon
0230: 67 20 77 69 74 68 20 74 68 69 73 20 6c 69 62 72 g with this libr
0240: 61 72 79 3b 20 69 66 20 6e 6f 74 2c 20 77 72 69 ary; if not, wri
0250: 74 65 20 74 6f 20 74 68 65 0a 2a 2a 20 46 72 65 te to the.** Fre
0260: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64 e Software Found
0270: 61 74 69 6f 6e 2c 20 49 6e 63 2e 2c 20 35 39 20 ation, Inc., 59
0280: 54 65 6d 70 6c 65 20 50 6c 61 63 65 20 2d 20 53 Temple Place - S
0290: 75 69 74 65 20 33 33 30 2c 0a 2a 2a 20 42 6f 73 uite 330,.** Bos
02a0: 74 6f 6e 2c 20 4d 41 20 20 30 32 31 31 31 2d 31 ton, MA 02111-1
02b0: 33 30 37 2c 20 55 53 41 2e 0a 2a 2a 0a 2a 2a 20 307, USA..**.**
02c0: 41 75 74 68 6f 72 20 63 6f 6e 74 61 63 74 20 69 Author contact i
02d0: 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20 nformation:.**
02e0: 20 64 72 68 40 68 77 61 63 69 2e 63 6f 6d 0a 2a drh@hwaci.com.*
02f0: 2a 20 20 20 68 74 74 70 3a 2f 2f 77 77 77 2e 68 * http://www.h
0300: 77 61 63 69 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a waci.com/drh/.**
0310: 0a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a .***************
0320: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0330: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0340: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0350: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0360: 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 66 69 6c 65 .**.** This file
0370: 20 63 6f 6e 74 61 69 6e 73 20 63 6f 64 65 20 74 contains code t
0380: 6f 20 69 6d 70 6c 65 6d 65 6e 74 20 74 68 65 20 o implement the
0390: 73 74 61 74 20 77 65 62 20 70 61 67 65 0a 2a 2a stat web page.**
03a0: 0a 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 .*/.#include <st
03b0: 72 69 6e 67 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 ring.h>.#include
03c0: 20 22 63 6f 6e 66 69 67 2e 68 22 0a 23 69 6e 63 "config.h".#inc
03d0: 6c 75 64 65 20 22 73 74 61 74 2e 68 22 0a 0a 2f lude "stat.h"../
03e0: 2a 0a 2a 2a 20 57 45 42 50 41 47 45 3a 20 73 74 *.** WEBPAGE: st
03f0: 61 74 0a 2a 2a 0a 2a 2a 20 53 68 6f 77 20 73 74 at.**.** Show st
0400: 61 74 69 73 74 69 63 73 20 61 6e 64 20 67 6c 6f atistics and glo
0410: 62 61 6c 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 bal information
0420: 61 62 6f 75 74 20 74 68 65 20 72 65 70 6f 73 69 about the reposi
0430: 74 6f 72 79 2e 0a 2a 2f 0a 76 6f 69 64 20 73 74 tory..*/.void st
0440: 61 74 5f 70 61 67 65 28 76 6f 69 64 29 7b 0a 20 at_page(void){.
0450: 20 69 36 34 20 74 3b 0a 20 20 69 6e 74 20 6e 2c i64 t;. int n,
0460: 20 6d 2c 20 66 73 69 7a 65 3b 0a 20 20 63 68 61 m, fsize;. cha
0470: 72 20 7a 42 75 66 5b 31 30 30 5d 3b 0a 20 20 6c r zBuf[100];. l
0480: 6f 67 69 6e 5f 63 68 65 63 6b 5f 63 72 65 64 65 ogin_check_crede
0490: 6e 74 69 61 6c 73 28 29 3b 0a 20 20 69 66 28 20 ntials();. if(
04a0: 21 67 2e 6f 6b 52 65 61 64 20 29 7b 20 6c 6f 67 !g.okRead ){ log
04b0: 69 6e 5f 6e 65 65 64 65 64 28 29 3b 20 72 65 74 in_needed(); ret
04c0: 75 72 6e 3b 20 7d 0a 20 20 73 74 79 6c 65 5f 68 urn; }. style_h
04d0: 65 61 64 65 72 28 22 52 65 70 6f 73 69 74 6f 72 eader("Repositor
04e0: 79 20 53 74 61 74 69 73 74 69 63 73 22 29 3b 0a y Statistics");.
04f0: 20 20 40 20 3c 70 3e 3c 74 61 62 6c 65 20 63 6c @ <p><table cl
0500: 61 73 73 3d 22 6c 61 62 65 6c 2d 76 61 6c 75 65 ass="label-value
0510: 22 3e 0a 20 20 40 20 3c 74 72 3e 3c 74 68 3e 52 ">. @ <tr><th>R
0520: 65 70 6f 73 69 74 6f 72 79 26 6e 62 73 70 3b 53 epository S
0530: 69 7a 65 3a 3c 2f 74 68 3e 3c 74 64 3e 0a 20 20 ize:</th><td>.
0540: 66 73 69 7a 65 20 3d 20 66 69 6c 65 5f 73 69 7a fsize = file_siz
0550: 65 28 67 2e 7a 52 65 70 6f 73 69 74 6f 72 79 4e e(g.zRepositoryN
0560: 61 6d 65 29 3b 0a 20 20 40 20 25 64 28 66 73 69 ame);. @ %d(fsi
0570: 7a 65 29 20 62 79 74 65 73 0a 20 20 40 20 3c 2f ze) bytes. @ </
0580: 74 64 3e 3c 2f 74 72 3e 0a 20 20 40 20 3c 74 72 td></tr>. @ <tr
0590: 3e 3c 74 68 3e 4e 75 6d 62 65 72 26 6e 62 73 70 ><th>Number 
05a0: 3b 4f 66 26 6e 62 73 70 3b 41 72 74 69 66 61 63 ;Of Artifac
05b0: 74 73 3a 3c 2f 74 68 3e 3c 74 64 3e 0a 20 20 6e ts:</th><td>. n
05c0: 20 3d 20 64 62 5f 69 6e 74 28 30 2c 20 22 53 45 = db_int(0, "SE
05d0: 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 LECT count(*) FR
05e0: 4f 4d 20 62 6c 6f 62 22 29 3b 0a 20 20 6d 20 3d OM blob");. m =
05f0: 20 64 62 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45 db_int(0, "SELE
0600: 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d CT count(*) FROM
0610: 20 64 65 6c 74 61 22 29 3b 0a 20 20 40 20 25 64 delta");. @ %d
0620: 28 6e 2d 6d 29 20 63 6f 6d 70 6c 65 74 65 2c 20 (n-m) complete,
0630: 25 64 28 6d 29 20 64 65 6c 74 61 73 2c 20 25 64 %d(m) deltas, %d
0640: 28 6e 29 20 74 6f 74 61 6c 0a 20 20 40 20 3c 2f (n) total. @ </
0650: 74 64 3e 3c 2f 74 72 3e 0a 20 20 69 66 28 20 6e td></tr>. if( n
0660: 3e 30 20 29 7b 0a 20 20 20 20 69 6e 74 20 61 2c >0 ){. int a,
0670: 20 62 3b 0a 20 20 20 20 40 20 3c 74 72 3e 3c 74 b;. @ <tr><t
0680: 68 3e 55 6e 63 6f 6d 70 72 65 73 73 65 64 26 6e h>Uncompressed&n
0690: 62 73 70 3b 41 72 74 69 66 61 63 74 26 6e 62 73 bsp;Artifact&nbs
06a0: 70 3b 53 69 7a 65 3a 3c 2f 74 68 3e 3c 74 64 3e p;Size:</th><td>
06b0: 0a 20 20 20 20 74 20 3d 20 64 62 5f 69 6e 74 36 . t = db_int6
06c0: 34 28 30 2c 20 22 53 45 4c 45 43 54 20 74 6f 74 4(0, "SELECT tot
06d0: 61 6c 28 73 69 7a 65 29 20 46 52 4f 4d 20 62 6c al(size) FROM bl
06e0: 6f 62 20 57 48 45 52 45 20 73 69 7a 65 3e 30 22 ob WHERE size>0"
06f0: 29 3b 0a 20 20 20 20 73 71 6c 69 74 65 33 5f 73 );. sqlite3_s
0700: 6e 70 72 69 6e 74 66 28 73 69 7a 65 6f 66 28 7a nprintf(sizeof(z
0710: 42 75 66 29 2c 20 7a 42 75 66 2c 20 22 25 6c 6c Buf), zBuf, "%ll
0720: 64 22 2c 20 74 29 3b 0a 20 20 20 20 40 20 25 64 d", t);. @ %d
0730: 28 28 69 6e 74 29 28 28 28 64 6f 75 62 6c 65 29 ((int)(((double)
0740: 74 29 2f 28 64 6f 75 62 6c 65 29 6e 29 29 20 62 t)/(double)n)) b
0750: 79 74 65 73 20 61 76 65 72 61 67 65 2c 20 25 73 ytes average, %s
0760: 28 7a 42 75 66 29 20 62 79 74 65 73 20 74 6f 74 (zBuf) bytes tot
0770: 61 6c 0a 20 20 20 20 40 20 3c 2f 74 64 3e 3c 2f al. @ </td></
0780: 74 72 3e 0a 20 20 20 20 40 20 3c 74 72 3e 3c 74 tr>. @ <tr><t
0790: 68 3e 43 6f 6d 70 72 65 73 73 69 6f 6e 26 6e 62 h>Compression&nb
07a0: 73 70 3b 52 61 74 69 6f 3a 3c 2f 74 68 3e 3c 74 sp;Ratio:</th><t
07b0: 64 3e 0a 20 20 20 20 69 66 28 20 74 2f 66 73 69 d>. if( t/fsi
07c0: 7a 65 20 3c 20 35 20 29 7b 0a 20 20 20 20 20 20 ze < 5 ){.
07d0: 62 20 3d 20 31 30 3b 0a 20 20 20 20 20 20 66 73 b = 10;. fs
07e0: 69 7a 65 20 2f 3d 20 31 30 3b 0a 20 20 20 20 7d ize /= 10;. }
07f0: 65 6c 73 65 7b 0a 20 20 20 20 20 20 62 20 3d 20 else{. b =
0800: 31 3b 0a 20 20 20 20 7d 0a 20 20 20 20 61 20 3d 1;. }. a =
0810: 20 74 2f 66 73 69 7a 65 3b 0a 20 20 20 20 40 20 t/fsize;. @
0820: 25 64 28 61 29 3a 25 64 28 62 29 0a 20 20 20 20 %d(a):%d(b).
0830: 40 20 3c 2f 74 64 3e 3c 2f 74 72 3e 0a 20 20 7d @ </td></tr>. }
0840: 0a 20 20 40 20 3c 74 72 3e 3c 74 68 3e 4e 75 6d . @ <tr><th>Num
0850: 62 65 72 26 6e 62 73 70 3b 4f 66 26 6e 62 73 70 ber Of 
0860: 3b 42 61 73 65 6c 69 6e 65 73 3a 3c 2f 74 68 3e ;Baselines:</th>
0870: 3c 74 64 3e 0a 20 20 6e 20 3d 20 64 62 5f 69 6e <td>. n = db_in
0880: 74 28 30 2c 20 22 53 45 4c 45 43 54 20 63 6f 75 t(0, "SELECT cou
0890: 6e 74 28 64 69 73 74 69 6e 63 74 20 6d 69 64 29 nt(distinct mid)
08a0: 20 46 52 4f 4d 20 6d 6c 69 6e 6b 22 29 3b 0a 20 FROM mlink");.
08b0: 20 40 20 25 64 28 6e 29 0a 20 20 40 20 3c 2f 74 @ %d(n). @ </t
08c0: 64 3e 3c 2f 74 72 3e 0a 20 20 40 20 3c 74 72 3e d></tr>. @ <tr>
08d0: 3c 74 68 3e 4e 75 6d 62 65 72 26 6e 62 73 70 3b <th>Number
08e0: 4f 66 26 6e 62 73 70 3b 46 69 6c 65 73 3a 3c 2f Of Files:</
08f0: 74 68 3e 3c 74 64 3e 0a 20 20 6e 20 3d 20 64 62 th><td>. n = db
0900: 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45 43 54 20 _int(0, "SELECT
0910: 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 66 69 count(*) FROM fi
0920: 6c 65 6e 61 6d 65 22 29 3b 0a 20 20 40 20 25 64 lename");. @ %d
0930: 28 6e 29 0a 20 20 40 20 3c 2f 74 64 3e 3c 2f 74 (n). @ </td></t
0940: 72 3e 0a 20 20 40 20 3c 74 72 3e 3c 74 68 3e 4e r>. @ <tr><th>N
0950: 75 6d 62 65 72 26 6e 62 73 70 3b 4f 66 26 6e 62 umber Of&nb
0960: 73 70 3b 57 69 6b 69 26 6e 62 73 70 3b 50 61 67 sp;Wiki Pag
0970: 65 73 3a 3c 2f 74 68 3e 3c 74 64 3e 0a 20 20 6e es:</th><td>. n
0980: 20 3d 20 64 62 5f 69 6e 74 28 30 2c 20 22 53 45 = db_int(0, "SE
0990: 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 LECT count(*) FR
09a0: 4f 4d 20 74 61 67 20 57 48 45 52 45 20 2b 74 61 OM tag WHERE +ta
09b0: 67 6e 61 6d 65 20 47 4c 4f 42 20 27 77 69 6b 69 gname GLOB 'wiki
09c0: 2d 2a 27 22 29 3b 0a 20 20 40 20 25 64 28 6e 29 -*'");. @ %d(n)
09d0: 0a 20 20 40 20 3c 2f 74 64 3e 3c 2f 74 72 3e 0a . @ </td></tr>.
09e0: 20 20 40 20 3c 74 72 3e 3c 74 68 3e 4e 75 6d 62 @ <tr><th>Numb
09f0: 65 72 26 6e 62 73 70 3b 4f 66 26 6e 62 73 70 3b er Of
0a00: 54 69 63 6b 65 74 73 3a 3c 2f 74 68 3e 3c 74 64 Tickets:</th><td
0a10: 3e 0a 20 20 6e 20 3d 20 64 62 5f 69 6e 74 28 30 >. n = db_int(0
0a20: 2c 20 22 53 45 4c 45 43 54 20 63 6f 75 6e 74 28 , "SELECT count(
0a30: 2a 29 20 46 52 4f 4d 20 74 61 67 20 57 48 45 52 *) FROM tag WHER
0a40: 45 20 2b 74 61 67 6e 61 6d 65 20 47 4c 4f 42 20 E +tagname GLOB
0a50: 27 74 69 63 6b 65 74 2d 2a 27 22 29 3b 0a 20 20 'ticket-*'");.
0a60: 40 20 25 64 28 6e 29 0a 20 20 40 20 3c 2f 74 64 @ %d(n). @ </td
0a70: 3e 3c 2f 74 72 3e 0a 20 20 40 20 3c 74 72 3e 3c ></tr>. @ <tr><
0a80: 74 68 3e 44 75 72 61 74 69 6f 6e 26 6e 62 73 70 th>Duration 
0a90: 3b 4f 66 26 6e 62 73 70 3b 50 72 6f 6a 65 63 74 ;Of Project
0aa0: 3a 3c 2f 74 68 3e 3c 74 64 3e 0a 20 20 6e 20 3d :</th><td>. n =
0ab0: 20 64 62 5f 69 6e 74 28 30 2c 20 22 53 45 4c 45 db_int(0, "SELE
0ac0: 43 54 20 6a 75 6c 69 61 6e 64 61 79 28 27 6e 6f CT julianday('no
0ad0: 77 27 29 20 2d 20 28 53 45 4c 45 43 54 20 6d 69 w') - (SELECT mi
0ae0: 6e 28 6d 74 69 6d 65 29 20 46 52 4f 4d 20 65 76 n(mtime) FROM ev
0af0: 65 6e 74 29 22 29 3b 0a 20 20 40 20 25 64 28 6e ent)");. @ %d(n
0b00: 29 20 64 61 79 73 0a 20 20 40 20 3c 2f 74 64 3e ) days. @ </td>
0b10: 3c 2f 74 72 3e 0a 20 20 40 20 3c 74 72 3e 3c 74 </tr>. @ <tr><t
0b20: 68 3e 50 72 6f 6a 65 63 74 26 6e 62 73 70 3b 49 h>Project I
0b30: 44 3a 3c 2f 74 68 3e 3c 74 64 3e 0a 20 20 40 20 D:</th><td>. @
0b40: 25 68 28 64 62 5f 67 65 74 28 22 70 72 6f 6a 65 %h(db_get("proje
0b50: 63 74 2d 63 6f 64 65 22 2c 22 22 29 29 0a 20 20 ct-code","")).
0b60: 40 20 3c 2f 74 64 3e 3c 2f 74 72 3e 0a 20 20 40 @ </td></tr>. @
0b70: 20 3c 74 72 3e 3c 74 68 3e 53 65 72 76 65 72 26 <tr><th>Server&
0b80: 6e 62 73 70 3b 49 44 3a 3c 2f 74 68 3e 3c 74 64 nbsp;ID:</th><td
0b90: 3e 0a 20 20 40 20 25 68 28 64 62 5f 67 65 74 28 >. @ %h(db_get(
0ba0: 22 73 65 72 76 65 72 2d 63 6f 64 65 22 2c 22 22 "server-code",""
0bb0: 29 29 0a 20 20 40 20 3c 2f 74 64 3e 3c 2f 74 72 )). @ </td></tr
0bc0: 3e 0a 20 20 40 20 3c 2f 74 61 62 6c 65 3e 3c 2f >. @ </table></
0bd0: 70 3e 0a 20 20 73 74 79 6c 65 5f 66 6f 6f 74 65 p>. style_foote
0be0: 72 28 29 3b 0a 7d 0a r();.}.