2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss, Heikki Levanto
14 #include "../isamc/isamh-p.h"
16 struct inv_stat_info {
21 int no_isam_entries[8];
25 int isam_occurrences[20];
29 static int inv_stat_handle (char *name, const char *info, int pos,
34 struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
37 stat_info->no_dict_entries++;
38 stat_info->no_dict_bytes += strlen(name);
40 assert (*info == sizeof(ISAM_P));
41 memcpy (&isam_p, info+1, sizeof(ISAM_P));
48 ispt = is_position (stat_info->isam, isam_p);
49 occur = is_numkeys (ispt);
58 pp = isc_pp_open (stat_info->isamc, isam_p);
59 occur = isc_pp_num (pp);
60 while (isc_pp_read(pp, &key))
62 printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
65 assert (occurx == occur);
66 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
75 pp = isamh_pp_open (stat_info->isamh, isam_p);
77 occur = isamh_pp_num (pp);
78 // printf (" opening item %d=%d:%d \n",
79 // isam_p, isamh_type(isam_p),isamh_block(isam_p));
80 while (isamh_pp_read(pp, &key))
83 logf (LOG_LOG,"sysno=%d seqno=%d (%x/%x) oc=%d/%d ofs=%d ",
86 occur,occurx, pp->offset);
89 logf(LOG_LOG,"Count error!!! read %d, counted %d", occur, occurx);
90 assert (occurx == occur);
91 stat_info->no_isam_entries[isamh_type(isam_p)] += occur;
100 pp = isams_pp_open (stat_info->isams, isam_p);
101 occur = isams_pp_num (pp);
102 while (isams_pp_read(pp, &key))
104 //printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
107 assert (occurx == occur);
108 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
112 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
114 ++(stat_info->isam_occurrences[i]);
118 void inv_prstat (BFiles bfs)
128 int after = 1000000000;
129 struct inv_stat_info stat_info;
130 char term_dict[2*IT_MAX_WORD+2];
135 dict = dict_open (bfs, FNAME_DICT, 100, 0, 0);
138 logf (LOG_FATAL, "dict_open fail");
141 if (res_get_match (common_resource, "isam", "i", NULL))
143 isam = is_open (bfs, FNAME_ISAM, key_compare, 0,
144 sizeof(struct it_key), common_resource);
147 logf (LOG_FATAL, "is_open fail");
151 else if (res_get_match (common_resource, "isam", "s", NULL))
153 isams = isams_open (bfs, FNAME_ISAMS, 0, key_isams_m(common_resource));
156 logf (LOG_FATAL, "isams_open fail");
160 else if (res_get_match (common_resource, "isam", "h", NULL))
162 isamh = isamh_open (bfs, FNAME_ISAMH, 0, key_isamh_m(common_resource));
165 logf (LOG_FATAL, "isamh_open fail");
171 isamc = isc_open (bfs, FNAME_ISAMC, 0, key_isamc_m (common_resource));
174 logf (LOG_FATAL, "isc_open fail");
178 records = rec_open (bfs, 0, 0);
180 for (i = 0; i<8; i++)
181 stat_info.no_isam_entries[i] = 0;
182 stat_info.no_dict_entries = 0;
183 stat_info.no_dict_bytes = 0;
184 stat_info.isam = isam;
185 stat_info.isamc = isamc;
186 stat_info.isams = isams;
187 stat_info.isamh = isamh;
188 stat_info.isam_bounds[0] = 1;
189 stat_info.isam_bounds[1] = 2;
190 stat_info.isam_bounds[2] = 3;
191 stat_info.isam_bounds[3] = 6;
192 stat_info.isam_bounds[4] = 10;
193 stat_info.isam_bounds[5] = 20;
194 stat_info.isam_bounds[6] = 30;
195 stat_info.isam_bounds[7] = 50;
196 stat_info.isam_bounds[8] = 100;
197 stat_info.isam_bounds[9] = 200;
198 stat_info.isam_bounds[10] = 5000;
199 stat_info.isam_bounds[11] = 10000;
200 stat_info.isam_bounds[12] = 20000;
201 stat_info.isam_bounds[13] = 50000;
202 stat_info.isam_bounds[14] = 100000;
203 stat_info.isam_bounds[15] = 200000;
204 stat_info.isam_bounds[16] = 500000;
205 stat_info.isam_bounds[17] = 1000000;
206 stat_info.isam_bounds[18] = 0;
208 for (i = 0; i<20; i++)
209 stat_info.isam_occurrences[i] = 0;
211 dict_scan (dict, term_dict, &before, &after, &stat_info, inv_stat_handle);
215 fprintf (stderr, " Blocks Occur Size KB Bytes/Entry\n");
216 for (i = 0; isc_block_used (isamc, i) >= 0; i++)
218 fprintf (stderr, " %8d %8d", isc_block_used (isamc, i),
219 stat_info.no_isam_entries[i]);
221 if (stat_info.no_isam_entries[i])
222 fprintf (stderr, " %8d %f",
223 (int) ((1023.0 + (double) isc_block_used(isamc, i) *
224 isc_block_size(isamc,i))/1024),
225 ((double) isc_block_used(isamc, i) *
226 isc_block_size(isamc,i))/
227 stat_info.no_isam_entries[i]);
228 fprintf (stderr, "\n");
232 fprintf (stderr, "\n%d words using %d bytes\n",
233 stat_info.no_dict_entries, stat_info.no_dict_bytes);
234 fprintf (stderr, " Occurrences Words\n");
236 for (i = 0; stat_info.isam_bounds[i]; i++)
238 int here = stat_info.isam_bounds[i];
239 fprintf (stderr, "%7d-%-7d %7d\n",
240 prev, here, stat_info.isam_occurrences[i]);
243 fprintf (stderr, "%7d- %7d\n",
244 prev, stat_info.isam_occurrences[i]);
246 rec_close (&records);
263 * $Log: invstat.c,v $
264 * Revision 1.13 1999-07-08 14:23:27 heikki
265 * Fixed a bug in isamh_pp_read and cleaned up a bit
267 * Revision 1.12 1999/07/06 12:28:04 adam
268 * Updated record index structure. Format includes version ID. Compression
269 * algorithm ID is stored for each record block.
271 * Revision 1.11 1999/05/15 14:36:38 adam
272 * Updated dictionary. Implemented "compression" of dictionary.
274 * Revision 1.10 1999/05/12 13:08:06 adam
275 * First version of ISAMS.
277 * Revision 1.9 1999/02/12 13:29:23 adam
278 * Implemented position-flag for registers.
280 * Revision 1.8 1999/02/02 14:50:53 adam
281 * Updated WIN32 code specific sections. Changed header.
283 * Revision 1.7 1998/03/13 15:30:50 adam
284 * New functions isc_block_used and isc_block_size. Fixed 'leak'
285 * in isc_alloc_block.
287 * Revision 1.6 1998/03/06 13:54:02 adam
288 * Fixed two nasty bugs in isc_merge.
290 * Revision 1.5 1997/09/17 12:19:13 adam
291 * Zebra version corresponds to YAZ version 1.4.
292 * Changed Zebra server so that it doesn't depend on global common_resource.
294 * Revision 1.4 1996/11/08 11:10:21 adam
295 * Buffers used during file match got bigger.
296 * Compressed ISAM support everywhere.
297 * Bug fixes regarding masking characters in queries.
298 * Redesigned Regexp-2 queries.
300 * Revision 1.3 1996/06/04 10:18:58 adam
301 * Minor changes - removed include of ctype.h.
303 * Revision 1.2 1996/05/22 08:25:56 adam
306 * Revision 1.1 1996/05/14 14:04:34 adam
307 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT