2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss, Heikki Levanto
15 #include "../isamc/isamd-p.h"
18 struct inv_stat_info {
25 int no_isam_entries[9];
29 int isam_occurrences[20];
33 #define SINGLETON_TYPE 8 /* the type to use for singletons that */
34 /* have no block and no block type */
36 static int inv_stat_handle (char *name, const char *info, int pos,
41 struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
44 stat_info->no_dict_entries++;
45 stat_info->no_dict_bytes += strlen(name);
47 assert (*info == sizeof(ISAMS_P));
48 memcpy (&isam_p, info+1, sizeof(ISAMS_P));
56 pp = isams_pp_open (stat_info->isams, isam_p);
57 occur = isams_pp_num (pp);
58 while (isams_pp_read(pp, &key))
60 //printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
63 assert (occurx == occur);
64 stat_info->no_isam_entries[0] += occur;
72 ispt = is_position (stat_info->isam, isam_p);
73 occur = is_numkeys (ispt);
82 pp = isc_pp_open (stat_info->isamc, isam_p);
83 occur = isc_pp_num (pp);
84 while (isc_pp_read(pp, &key))
86 //printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
89 assert (occurx == occur);
90 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
99 pp = isamd_pp_open (stat_info->isamd, isam_p);
101 occur = isamd_pp_num (pp);
102 while (isamd_pp_read(pp, &key))
105 if ( pp->is->method->debug >8 )
106 logf (LOG_LOG,"sysno=%d seqno=%d (%x/%x) oc=%d/%d ofs=%d ",
107 key.sysno, key.seqno,
108 key.sysno, key.seqno,
109 occur,occurx, pp->offset);
111 if ( pp->is->method->debug >7 )
112 logf(LOG_LOG,"item %d=%d:%d says %d keys, counted %d",
113 isam_p, isamd_type(isam_p), isamd_block(isam_p),
116 logf(LOG_LOG,"Count error!!! read %d, counted %d", occur, occurx);
117 assert (occurx == occur);
118 if ( is_singleton(isam_p) )
119 stat_info->no_isam_entries[SINGLETON_TYPE] += occur;
121 stat_info->no_isam_entries[isamd_type(isam_p)] += occur;
125 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
127 ++(stat_info->isam_occurrences[i]);
131 void inv_prstat (BFiles bfs)
146 int after = 1000000000;
147 struct inv_stat_info stat_info;
148 char term_dict[2*IT_MAX_WORD+2];
153 dict = dict_open (bfs, FNAME_DICT, 100, 0, 0);
156 logf (LOG_FATAL, "dict_open fail");
159 if (res_get_match (common_resource, "isam", "s", ISAM_DEFAULT))
161 struct ISAMS_M_s isams_m;
162 isams = isams_open (bfs, FNAME_ISAMS, 0,
163 key_isams_m(common_resource, &isams_m));
166 logf (LOG_FATAL, "isams_open fail");
171 else if (res_get_match (common_resource, "isam", "i", ISAM_DEFAULT))
173 isam = is_open (bfs, FNAME_ISAM, key_compare, 0,
174 sizeof(struct it_key), common_resource);
177 logf (LOG_FATAL, "is_open fail");
181 else if (res_get_match (common_resource, "isam", "d", ISAM_DEFAULT))
183 struct ISAMD_M_s isamd_m;
184 isamd = isamd_open (bfs, FNAME_ISAMD, 0,
185 key_isamd_m(common_resource,&isamd_m));
188 logf (LOG_FATAL, "isamd_open fail");
192 else if (res_get_match (common_resource, "isam", "c", ISAM_DEFAULT))
194 struct ISAMC_M_s isamc_m;
195 isamc = isc_open (bfs, FNAME_ISAMC, 0,
196 key_isamc_m (common_resource, &isamc_m));
199 logf (LOG_FATAL, "isc_open fail");
204 records = rec_open (bfs, 0, 0);
206 for (i = 0; i<=SINGLETON_TYPE; i++)
207 stat_info.no_isam_entries[i] = 0;
208 stat_info.no_dict_entries = 0;
209 stat_info.no_dict_bytes = 0;
210 stat_info.isams = isams;
212 stat_info.isam = isam;
213 stat_info.isamc = isamc;
214 stat_info.isamd = isamd;
216 stat_info.isam_bounds[0] = 1;
217 stat_info.isam_bounds[1] = 2;
218 stat_info.isam_bounds[2] = 3;
219 stat_info.isam_bounds[3] = 6;
220 stat_info.isam_bounds[4] = 10;
221 stat_info.isam_bounds[5] = 20;
222 stat_info.isam_bounds[6] = 30;
223 stat_info.isam_bounds[7] = 50;
224 stat_info.isam_bounds[8] = 100;
225 stat_info.isam_bounds[9] = 200;
226 stat_info.isam_bounds[10] = 5000;
227 stat_info.isam_bounds[11] = 10000;
228 stat_info.isam_bounds[12] = 20000;
229 stat_info.isam_bounds[13] = 50000;
230 stat_info.isam_bounds[14] = 100000;
231 stat_info.isam_bounds[15] = 200000;
232 stat_info.isam_bounds[16] = 500000;
233 stat_info.isam_bounds[17] = 1000000;
234 stat_info.isam_bounds[18] = 0;
236 for (i = 0; i<20; i++)
237 stat_info.isam_occurrences[i] = 0;
239 dict_scan (dict, term_dict, &before, &after, &stat_info, inv_stat_handle);
244 fprintf (stderr, " Blocks Occur Size KB Bytes/Entry\n");
245 for (i = 0; isc_block_used (isamc, i) >= 0; i++)
247 fprintf (stderr, " %8d %8d", isc_block_used (isamc, i),
248 stat_info.no_isam_entries[i]);
250 if (stat_info.no_isam_entries[i])
251 fprintf (stderr, " %8d %f",
252 (int) ((1023.0 + (double) isc_block_used(isamc, i) *
253 isc_block_size(isamc,i))/1024),
254 ((double) isc_block_used(isamc, i) *
255 isc_block_size(isamc,i))/
256 stat_info.no_isam_entries[i]);
257 fprintf (stderr, "\n");
262 fprintf (stderr, " Blocks Occur KB Bytes/Entry\n");
263 if (isamd->method->debug >0)
264 logf(LOG_LOG," Blocks Occur KB Bytes/Entry");
265 for (i = 0; i<=SINGLETON_TYPE; i++)
267 blocks= isamd_block_used(isamd,i);
268 size= isamd_block_size(isamd,i);
269 count=stat_info.no_isam_entries[i];
270 if (i==SINGLETON_TYPE)
272 if (stat_info.no_isam_entries[i])
274 fprintf (stderr, "%c %7d %7d %7d %5.2f\n",
275 (i==SINGLETON_TYPE)?('z'):('A'+i),
278 (int) ((1023.0 + (double) blocks * size)/1024),
279 ((double) blocks * size)/count);
280 if (isamd->method->debug >0)
281 logf(LOG_LOG, "%c %7d %7d %7d %5.2f",
282 (i==SINGLETON_TYPE)?('z'):('A'+i),
285 (int) ((1023.0 + (double) blocks * size)/1024),
286 ((double) blocks * size)/count);
290 if ( (isamd) && (isamd->method->debug>0))
291 fprintf (stderr, "\n%d words using %d bytes\n",
292 stat_info.no_dict_entries, stat_info.no_dict_bytes);
294 fprintf (stderr, " Occurrences Words\n");
296 for (i = 0; stat_info.isam_bounds[i]; i++)
298 int here = stat_info.isam_bounds[i];
299 fprintf (stderr, "%7d-%-7d %7d\n",
300 prev, here, stat_info.isam_occurrences[i]);
303 fprintf (stderr, "%7d- %7d\n",
304 prev, stat_info.isam_occurrences[i]);
305 rec_close (&records);
319 xmalloc_trav("unfreed"); /*! while hunting memory leaks */
325 * $Log: invstat.c,v $
326 * Revision 1.21 2000-07-13 10:14:20 heikki
327 * Removed compiler warnings when making zebra
329 * Revision 1.20 1999/12/01 13:30:30 adam
330 * Updated configure for Zmbol/Zebra dependent settings.
332 * Revision 1.19 1999/11/30 13:48:03 adam
333 * Improved installation. Updated for inclusion of YAZ header files.
335 * Revision 1.18 1999/10/06 11:46:36 heikki
336 * mproved statistics on isam-d
338 * Revision 1.17 1999/08/20 08:28:37 heikki
341 * Revision 1.16 1999/08/18 08:38:22 heikki
342 * Memory leak hunting
344 * Revision 1.15 1999/08/18 08:34:53 heikki
347 * Revision 1.14 1999/07/14 10:59:26 adam
348 * Changed functions isc_getmethod, isams_getmethod.
349 * Improved fatal error handling (such as missing EXPLAIN schema).
351 * Revision 1.13 1999/07/08 14:23:27 heikki
352 * Fixed a bug in isamh_pp_read and cleaned up a bit
354 * Revision 1.12 1999/07/06 12:28:04 adam
355 * Updated record index structure. Format includes version ID. Compression
356 * algorithm ID is stored for each record block.
358 * Revision 1.11 1999/05/15 14:36:38 adam
359 * Updated dictionary. Implemented "compression" of dictionary.
361 * Revision 1.10 1999/05/12 13:08:06 adam
362 * First version of ISAMS.
364 * Revision 1.9 1999/02/12 13:29:23 adam
365 * Implemented position-flag for registers.
367 * Revision 1.8 1999/02/02 14:50:53 adam
368 * Updated WIN32 code specific sections. Changed header.
370 * Revision 1.7 1998/03/13 15:30:50 adam
371 * New functions isc_block_used and isc_block_size. Fixed 'leak'
372 * in isc_alloc_block.
374 * Revision 1.6 1998/03/06 13:54:02 adam
375 * Fixed two nasty bugs in isc_merge.
377 * Revision 1.5 1997/09/17 12:19:13 adam
378 * Zebra version corresponds to YAZ version 1.4.
379 * Changed Zebra server so that it doesn't depend on global common_resource.
381 * Revision 1.4 1996/11/08 11:10:21 adam
382 * Buffers used during file match got bigger.
383 * Compressed ISAM support everywhere.
384 * Bug fixes regarding masking characters in queries.
385 * Redesigned Regexp-2 queries.
387 * Revision 1.3 1996/06/04 10:18:58 adam
388 * Minor changes - removed include of ctype.h.
390 * Revision 1.2 1996/05/22 08:25:56 adam
393 * Revision 1.1 1996/05/14 14:04:34 adam
394 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT