:-) (CVS 1711)
FossilOrigin-Name: 0529c979fd17995aff82e21b91b5cc833f23d8ef
This commit is contained in:
parent
2702114089
commit
d9e5075ff6
11
manifest
11
manifest
@ -1,5 +1,5 @@
|
||||
C :-)\s(CVS\s179)
|
||||
D 2001-01-21T00:58:08
|
||||
C :-)\s(CVS\s1711)
|
||||
D 2001-01-21T22:03:30
|
||||
F COPYRIGHT 74a8a6531a42e124df07ab5599aad63870fa0bd4
|
||||
F Makefile.in 7efa81e2985b45ba73db27d55b70cc927f5abfd7
|
||||
F README 51f6a4e7408b34afa5bc1c0485f61b6a4efb6958
|
||||
@ -62,6 +62,7 @@ F test/update.test 62f6ce99ff31756aab0ca832ff6d34c5a87b6250
|
||||
F test/vacuum.test 2127748ff4ddb409212efbb6d9fb9c469ea1b49c
|
||||
F test/where.test bbab5a308055fb6087dc23d600b4ad2b72797397
|
||||
F tool/gdbmdump.c 529e67c78d920606ba196326ea55b57b75fcc82b
|
||||
F tool/gdbmstat.c 56a9033531e5f5a48413f6ec436d5fb0341632c1
|
||||
F tool/lemon.c b13a31798574af881753d38f4da7d505929259c3
|
||||
F tool/lempar.c a1eec94d6eacc12332368660ec65f3b248853833
|
||||
F tool/memleak.awk a0a11dd84bf4582acc81c3c61271021ae49b3f15
|
||||
@ -82,7 +83,7 @@ F www/opcode.tcl cb3a1abf8b7b9be9f3a228d097d6bf8b742c2b6f
|
||||
F www/sqlite.tcl cb0d23d8f061a80543928755ec7775da6e4f362f
|
||||
F www/tclsqlite.tcl 06f81c401f79a04f2c5ebfb97e7c176225c0aef2
|
||||
F www/vdbe.tcl 0c8aaa529dd216ccbf7daaabd80985e413d5f9ad
|
||||
P 1662063dfb0925bd439e3e2e49bff82705e20fd0
|
||||
R fd78a6c47a1cf484ff41084553feb3d7
|
||||
P d5f2a668978c0d108045237f19b0a7efa07678f2
|
||||
R 1dea96afaac1107dc23974be6b858cb9
|
||||
U drh
|
||||
Z d0449f87f2ca7d65ae84190b1471dad1
|
||||
Z 7168eb4919f6604238c3251129477d38
|
||||
|
@ -1 +1 @@
|
||||
d5f2a668978c0d108045237f19b0a7efa07678f2
|
||||
0529c979fd17995aff82e21b91b5cc833f23d8ef
|
144
tool/gdbmstat.c
Normal file
144
tool/gdbmstat.c
Normal file
@ -0,0 +1,144 @@
|
||||
/*
|
||||
** Copyright (c) 1999, 2000 D. Richard Hipp
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or
|
||||
** modify it under the terms of the GNU General Public
|
||||
** License as published by the Free Software Foundation; either
|
||||
** version 2 of the License, or (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
** General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public
|
||||
** License along with this library; if not, write to the
|
||||
** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
** Boston, MA 02111-1307, USA.
|
||||
**
|
||||
** Author contact information:
|
||||
** drh@hwaci.com
|
||||
** http://www.hwaci.com/drh/
|
||||
**
|
||||
*************************************************************************
|
||||
** A utility print statistics about the content of a GDBM database.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <gdbm.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static int bins[] = {
|
||||
4, 8, 12, 16, 24,
|
||||
32, 40, 48, 56, 64,
|
||||
80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256,
|
||||
288, 320, 352, 384, 416, 448, 480, 512, 1024, 2048, 4096, 8192,
|
||||
16384, 32768, 65536,
|
||||
};
|
||||
#define NBIN (sizeof(bins)/sizeof(bins[0])+1)
|
||||
|
||||
static int gAllSize[NBIN];
|
||||
static int gCount;
|
||||
static int gTotal;
|
||||
static int gMax;
|
||||
static int gKey;
|
||||
static int gMaxKey;
|
||||
|
||||
static int gdbm_stat(char *zFilename){
|
||||
GDBM_FILE p;
|
||||
datum data, key, next;
|
||||
int nEntry = 0;
|
||||
int keyTotal = 0;
|
||||
int dataTotal = 0;
|
||||
int allTotal = 0;
|
||||
int lMax = 0;
|
||||
int keySize[NBIN], dataSize[NBIN], allSize[NBIN];
|
||||
int i, priorSize;
|
||||
|
||||
p = gdbm_open(zFilename, 0, GDBM_READER, 0, 0);
|
||||
if( p==0 ){
|
||||
fprintf(stderr,"can't open file \"%s\"\n", zFilename);
|
||||
return 1;
|
||||
}
|
||||
for(i=0; i<NBIN; i++){
|
||||
keySize[i] = 0;
|
||||
dataSize[i] = 0;
|
||||
allSize[i] = 0;
|
||||
}
|
||||
key = gdbm_firstkey(p);
|
||||
while( key.dptr ){
|
||||
int all;
|
||||
nEntry++;
|
||||
gCount++;
|
||||
keyTotal += key.dsize;
|
||||
for(i=0; i<NBIN-1 && key.dsize>bins[i]; i++){}
|
||||
keySize[i]++;
|
||||
gKey += key.dsize;
|
||||
if( key.dsize>gMaxKey ) gMaxKey = key.dsize;
|
||||
data = gdbm_fetch(p, key);
|
||||
if( data.dptr==0 ) data.dsize = 0;
|
||||
dataTotal += data.dsize;
|
||||
for(i=0; i<NBIN-1 && data.dsize>bins[i]; i++){}
|
||||
dataSize[i]++;
|
||||
all = key.dsize + data.dsize;
|
||||
allTotal += all;
|
||||
gTotal += all;
|
||||
if( all>gMax ) gMax = all;
|
||||
if( all>lMax ) lMax = all;
|
||||
for(i=0; i<NBIN-1 && all>bins[i]; i++){}
|
||||
allSize[i]++;
|
||||
gAllSize[i]++;
|
||||
next = gdbm_nextkey(p, key);
|
||||
free( key.dptr );
|
||||
key = next;
|
||||
}
|
||||
gdbm_close(p);
|
||||
printf("%s:\n", zFilename);
|
||||
printf(" entries: %d\n", nEntry);
|
||||
printf(" keysize: %d (%d per entry)\n",
|
||||
keyTotal, nEntry>0 ? (keyTotal+nEntry-1)/nEntry : 0);
|
||||
printf(" datasize: %d (%d per entry)\n",
|
||||
dataTotal, nEntry>0 ? (dataTotal+nEntry-1)/nEntry : 0);
|
||||
printf(" size: %d (%d per entry)\n",
|
||||
allTotal, nEntry>0 ? (allTotal+nEntry-1)/nEntry : 0);
|
||||
priorSize = 0;
|
||||
for(i=0; i<NBIN-1; i++){
|
||||
if( keySize[i]==0 && dataSize[i]==0 ) continue;
|
||||
printf("%5d..%-5d %7d %7d %7d\n", priorSize, bins[i], keySize[i],
|
||||
dataSize[i], allSize[i]);
|
||||
priorSize = bins[i]+1;
|
||||
}
|
||||
if( keySize[NBIN-1]>0 || dataSize[NBIN-1]>0 ){
|
||||
printf("%5d..%-5d %7d %7d %7d\n", priorSize, lMax,
|
||||
keySize[NBIN-1], dataSize[NBIN-1], allSize[NBIN-1]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
int i, ps, sum;
|
||||
int nErr = 0;
|
||||
for(i=1; i<argc; i++){
|
||||
nErr += gdbm_stat(argv[i]);
|
||||
}
|
||||
printf("*****************************************************************\n");
|
||||
printf("Entries: %d\n", gCount);
|
||||
printf("Size: %d\n", gTotal);
|
||||
printf("Avg Size: %d\n", gCount>0 ? (gTotal + gCount - 1)/gCount : 0);
|
||||
printf("Key Size: %d\n", gKey);
|
||||
printf("Avg Key Size: %d\n", gCount>0 ? (gKey + gCount - 1)/gCount : 0);
|
||||
printf("Max Key Size: %d\n\n", gMaxKey);
|
||||
ps = 0;
|
||||
sum = 0;
|
||||
for(i=0; i<NBIN-1; i++){
|
||||
if( gAllSize[i]==0 ) continue;
|
||||
sum += gAllSize[i];
|
||||
printf("%5d..%-5d %8d %3d%%\n",
|
||||
ps, bins[i], gAllSize[i], sum*100/gCount);
|
||||
ps = bins[i]+1;
|
||||
}
|
||||
if( gAllSize[NBIN-1]>0 ){
|
||||
printf("%5d..%-5d %8d 100%%\n", ps, gMax, gAllSize[NBIN-1]);
|
||||
}
|
||||
return nErr;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user