2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss, Heikki Levanto
14 #include "../isamc/isamh-p.h"
15 #include "../isamc/isamd-p.h"
17 struct inv_stat_info {
23 int no_isam_entries[8];
27 int isam_occurrences[20];
31 static int inv_stat_handle (char *name, const char *info, int pos,
36 struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
39 stat_info->no_dict_entries++;
40 stat_info->no_dict_bytes += strlen(name);
42 assert (*info == sizeof(ISAM_P));
43 memcpy (&isam_p, info+1, sizeof(ISAM_P));
50 ispt = is_position (stat_info->isam, isam_p);
51 occur = is_numkeys (ispt);
60 pp = isc_pp_open (stat_info->isamc, isam_p);
61 occur = isc_pp_num (pp);
62 while (isc_pp_read(pp, &key))
64 //printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
67 assert (occurx == occur);
68 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
77 pp = isamh_pp_open (stat_info->isamh, isam_p);
79 occur = isamh_pp_num (pp);
80 // printf (" opening item %d=%d:%d \n",
81 // isam_p, isamh_type(isam_p),isamh_block(isam_p));
82 while (isamh_pp_read(pp, &key))
85 //logf (LOG_LOG,"sysno=%d seqno=%d (%x/%x) oc=%d/%d ofs=%d ",
86 // key.sysno, key.seqno,
87 // key.sysno, key.seqno,
88 // occur,occurx, pp->offset);
90 if (occurx != occur) {
91 logf(LOG_LOG,"Count error!!! read %d, counted %d", occur, occurx);
92 //isamh_pp_dump(stat_info->isamh, isam_p);
94 stat_info->no_isam_entries[isamh_type(isam_p)] += occur;
103 pp = isamd_pp_open (stat_info->isamd, isam_p);
105 occur = isamd_pp_num (pp);
106 while (isamd_pp_read(pp, &key))
109 if ( pp->is->method->debug >8 )
110 logf (LOG_LOG,"sysno=%d seqno=%d (%x/%x) oc=%d/%d ofs=%d ",
111 key.sysno, key.seqno,
112 key.sysno, key.seqno,
113 occur,occurx, pp->offset);
115 if ( pp->is->method->debug >7 )
116 logf(LOG_LOG,"item %d=%d:%d says %d keys, counted %d",
117 isam_p, isamd_type(isam_p), isamd_block(isam_p),
120 logf(LOG_LOG,"Count error!!! read %d, counted %d", occur, occurx);
121 assert (occurx == occur);
122 stat_info->no_isam_entries[isamd_type(isam_p)] += occur;
125 if (stat_info->isams)
131 pp = isams_pp_open (stat_info->isams, isam_p);
132 occur = isams_pp_num (pp);
133 while (isams_pp_read(pp, &key))
135 //printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
138 assert (occurx == occur);
139 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
143 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
145 ++(stat_info->isam_occurrences[i]);
149 void inv_prstat (BFiles bfs)
160 int after = 1000000000;
161 struct inv_stat_info stat_info;
162 char term_dict[2*IT_MAX_WORD+2];
167 dict = dict_open (bfs, FNAME_DICT, 100, 0, 0);
170 logf (LOG_FATAL, "dict_open fail");
173 if (res_get_match (common_resource, "isam", "i", NULL))
175 isam = is_open (bfs, FNAME_ISAM, key_compare, 0,
176 sizeof(struct it_key), common_resource);
179 logf (LOG_FATAL, "is_open fail");
183 else if (res_get_match (common_resource, "isam", "s", NULL))
185 struct ISAMS_M_s isams_m;
186 isams = isams_open (bfs, FNAME_ISAMS, 0,
187 key_isams_m(common_resource, &isams_m));
190 logf (LOG_FATAL, "isams_open fail");
194 else if (res_get_match (common_resource, "isam", "h", NULL))
196 isamh = isamh_open (bfs, FNAME_ISAMH, 0, key_isamh_m(common_resource));
199 logf (LOG_FATAL, "isamh_open fail");
203 else if (res_get_match (common_resource, "isam", "d", NULL))
205 struct ISAMD_M_s isamd_m;
206 isamd = isamd_open (bfs, FNAME_ISAMD, 0,
207 key_isamd_m(common_resource,&isamd_m));
210 logf (LOG_FATAL, "isamd_open fail");
216 struct ISAMC_M_s isamc_m;
217 isamc = isc_open (bfs, FNAME_ISAMC, 0,
218 key_isamc_m (common_resource, &isamc_m));
221 logf (LOG_FATAL, "isc_open fail");
225 records = rec_open (bfs, 0, 0);
227 for (i = 0; i<8; i++)
228 stat_info.no_isam_entries[i] = 0;
229 stat_info.no_dict_entries = 0;
230 stat_info.no_dict_bytes = 0;
231 stat_info.isam = isam;
232 stat_info.isamc = isamc;
233 stat_info.isams = isams;
234 stat_info.isamh = isamh;
235 stat_info.isamd = isamd;
236 stat_info.isam_bounds[0] = 1;
237 stat_info.isam_bounds[1] = 2;
238 stat_info.isam_bounds[2] = 3;
239 stat_info.isam_bounds[3] = 6;
240 stat_info.isam_bounds[4] = 10;
241 stat_info.isam_bounds[5] = 20;
242 stat_info.isam_bounds[6] = 30;
243 stat_info.isam_bounds[7] = 50;
244 stat_info.isam_bounds[8] = 100;
245 stat_info.isam_bounds[9] = 200;
246 stat_info.isam_bounds[10] = 5000;
247 stat_info.isam_bounds[11] = 10000;
248 stat_info.isam_bounds[12] = 20000;
249 stat_info.isam_bounds[13] = 50000;
250 stat_info.isam_bounds[14] = 100000;
251 stat_info.isam_bounds[15] = 200000;
252 stat_info.isam_bounds[16] = 500000;
253 stat_info.isam_bounds[17] = 1000000;
254 stat_info.isam_bounds[18] = 0;
256 for (i = 0; i<20; i++)
257 stat_info.isam_occurrences[i] = 0;
259 dict_scan (dict, term_dict, &before, &after, &stat_info, inv_stat_handle);
263 fprintf (stderr, " Blocks Occur Size KB Bytes/Entry\n");
264 for (i = 0; isc_block_used (isamc, i) >= 0; i++)
266 fprintf (stderr, " %8d %8d", isc_block_used (isamc, i),
267 stat_info.no_isam_entries[i]);
269 if (stat_info.no_isam_entries[i])
270 fprintf (stderr, " %8d %f",
271 (int) ((1023.0 + (double) isc_block_used(isamc, i) *
272 isc_block_size(isamc,i))/1024),
273 ((double) isc_block_used(isamc, i) *
274 isc_block_size(isamc,i))/
275 stat_info.no_isam_entries[i]);
276 fprintf (stderr, "\n");
280 fprintf (stderr, "\n%d words using %d bytes\n",
281 stat_info.no_dict_entries, stat_info.no_dict_bytes);
282 fprintf (stderr, " Occurrences Words\n");
284 for (i = 0; stat_info.isam_bounds[i]; i++)
286 int here = stat_info.isam_bounds[i];
287 fprintf (stderr, "%7d-%-7d %7d\n",
288 prev, here, stat_info.isam_occurrences[i]);
291 fprintf (stderr, "%7d- %7d\n",
292 prev, stat_info.isam_occurrences[i]);
294 rec_close (&records);
308 xmalloc_trav("unfreed"); /*! while hunting memory leaks */
314 * $Log: invstat.c,v $
315 * Revision 1.17 1999-08-20 08:28:37 heikki
318 * Revision 1.16 1999/08/18 08:38:22 heikki
319 * Memory leak hunting
321 * Revision 1.15 1999/08/18 08:34:53 heikki
324 * Revision 1.14 1999/07/14 10:59:26 adam
325 * Changed functions isc_getmethod, isams_getmethod.
326 * Improved fatal error handling (such as missing EXPLAIN schema).
328 * Revision 1.13 1999/07/08 14:23:27 heikki
329 * Fixed a bug in isamh_pp_read and cleaned up a bit
331 * Revision 1.12 1999/07/06 12:28:04 adam
332 * Updated record index structure. Format includes version ID. Compression
333 * algorithm ID is stored for each record block.
335 * Revision 1.11 1999/05/15 14:36:38 adam
336 * Updated dictionary. Implemented "compression" of dictionary.
338 * Revision 1.10 1999/05/12 13:08:06 adam
339 * First version of ISAMS.
341 * Revision 1.9 1999/02/12 13:29:23 adam
342 * Implemented position-flag for registers.
344 * Revision 1.8 1999/02/02 14:50:53 adam
345 * Updated WIN32 code specific sections. Changed header.
347 * Revision 1.7 1998/03/13 15:30:50 adam
348 * New functions isc_block_used and isc_block_size. Fixed 'leak'
349 * in isc_alloc_block.
351 * Revision 1.6 1998/03/06 13:54:02 adam
352 * Fixed two nasty bugs in isc_merge.
354 * Revision 1.5 1997/09/17 12:19:13 adam
355 * Zebra version corresponds to YAZ version 1.4.
356 * Changed Zebra server so that it doesn't depend on global common_resource.
358 * Revision 1.4 1996/11/08 11:10:21 adam
359 * Buffers used during file match got bigger.
360 * Compressed ISAM support everywhere.
361 * Bug fixes regarding masking characters in queries.
362 * Redesigned Regexp-2 queries.
364 * Revision 1.3 1996/06/04 10:18:58 adam
365 * Minor changes - removed include of ctype.h.
367 * Revision 1.2 1996/05/22 08:25:56 adam
370 * Revision 1.1 1996/05/14 14:04:34 adam
371 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT