2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss, Heikki Levanto
14 #include "../isamc/isamd-p.h"
16 struct inv_stat_info {
23 int no_isam_entries[9];
27 int isam_occurrences[20];
31 #define SINGLETON_TYPE 8 /* the type to use for singletons that */
32 /* have no block and no block type */
34 static int inv_stat_handle (char *name, const char *info, int pos,
39 struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
42 stat_info->no_dict_entries++;
43 stat_info->no_dict_bytes += strlen(name);
45 assert (*info == sizeof(ISAMS_P));
46 memcpy (&isam_p, info+1, sizeof(ISAMS_P));
54 pp = isams_pp_open (stat_info->isams, isam_p);
55 occur = isams_pp_num (pp);
56 while (isams_pp_read(pp, &key))
58 //printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
61 assert (occurx == occur);
62 stat_info->no_isam_entries[0] += occur;
70 ispt = is_position (stat_info->isam, isam_p);
71 occur = is_numkeys (ispt);
80 pp = isc_pp_open (stat_info->isamc, isam_p);
81 occur = isc_pp_num (pp);
82 while (isc_pp_read(pp, &key))
84 //printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
87 assert (occurx == occur);
88 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
97 pp = isamd_pp_open (stat_info->isamd, isam_p);
99 occur = isamd_pp_num (pp);
100 while (isamd_pp_read(pp, &key))
103 if ( pp->is->method->debug >8 )
104 logf (LOG_LOG,"sysno=%d seqno=%d (%x/%x) oc=%d/%d ofs=%d ",
105 key.sysno, key.seqno,
106 key.sysno, key.seqno,
107 occur,occurx, pp->offset);
109 if ( pp->is->method->debug >7 )
110 logf(LOG_LOG,"item %d=%d:%d says %d keys, counted %d",
111 isam_p, isamd_type(isam_p), isamd_block(isam_p),
114 logf(LOG_LOG,"Count error!!! read %d, counted %d", occur, occurx);
115 assert (occurx == occur);
116 if ( is_singleton(isam_p) )
117 stat_info->no_isam_entries[SINGLETON_TYPE] += occur;
119 stat_info->no_isam_entries[isamd_type(isam_p)] += occur;
123 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
125 ++(stat_info->isam_occurrences[i]);
129 void inv_prstat (BFiles bfs)
141 int after = 1000000000;
142 struct inv_stat_info stat_info;
143 char term_dict[2*IT_MAX_WORD+2];
151 dict = dict_open (bfs, FNAME_DICT, 100, 0, 0);
154 logf (LOG_FATAL, "dict_open fail");
157 if (res_get_match (common_resource, "isam", "s", ISAM_DEFAULT))
159 struct ISAMS_M_s isams_m;
160 isams = isams_open (bfs, FNAME_ISAMS, 0,
161 key_isams_m(common_resource, &isams_m));
164 logf (LOG_FATAL, "isams_open fail");
169 else if (res_get_match (common_resource, "isam", "i", ISAM_DEFAULT))
171 isam = is_open (bfs, FNAME_ISAM, key_compare, 0,
172 sizeof(struct it_key), common_resource);
175 logf (LOG_FATAL, "is_open fail");
179 else if (res_get_match (common_resource, "isam", "d", ISAM_DEFAULT))
181 struct ISAMD_M_s isamd_m;
182 isamd = isamd_open (bfs, FNAME_ISAMD, 0,
183 key_isamd_m(common_resource,&isamd_m));
186 logf (LOG_FATAL, "isamd_open fail");
190 else if (res_get_match (common_resource, "isam", "c", ISAM_DEFAULT))
192 struct ISAMC_M_s isamc_m;
193 isamc = isc_open (bfs, FNAME_ISAMC, 0,
194 key_isamc_m (common_resource, &isamc_m));
197 logf (LOG_FATAL, "isc_open fail");
202 records = rec_open (bfs, 0, 0);
204 for (i = 0; i<=SINGLETON_TYPE; i++)
205 stat_info.no_isam_entries[i] = 0;
206 stat_info.no_dict_entries = 0;
207 stat_info.no_dict_bytes = 0;
208 stat_info.isams = isams;
210 stat_info.isam = isam;
211 stat_info.isamc = isamc;
212 stat_info.isamd = isamd;
214 stat_info.isam_bounds[0] = 1;
215 stat_info.isam_bounds[1] = 2;
216 stat_info.isam_bounds[2] = 3;
217 stat_info.isam_bounds[3] = 6;
218 stat_info.isam_bounds[4] = 10;
219 stat_info.isam_bounds[5] = 20;
220 stat_info.isam_bounds[6] = 30;
221 stat_info.isam_bounds[7] = 50;
222 stat_info.isam_bounds[8] = 100;
223 stat_info.isam_bounds[9] = 200;
224 stat_info.isam_bounds[10] = 5000;
225 stat_info.isam_bounds[11] = 10000;
226 stat_info.isam_bounds[12] = 20000;
227 stat_info.isam_bounds[13] = 50000;
228 stat_info.isam_bounds[14] = 100000;
229 stat_info.isam_bounds[15] = 200000;
230 stat_info.isam_bounds[16] = 500000;
231 stat_info.isam_bounds[17] = 1000000;
232 stat_info.isam_bounds[18] = 0;
234 for (i = 0; i<20; i++)
235 stat_info.isam_occurrences[i] = 0;
237 dict_scan (dict, term_dict, &before, &after, &stat_info, inv_stat_handle);
242 fprintf (stderr, " Blocks Occur Size KB Bytes/Entry\n");
243 for (i = 0; isc_block_used (isamc, i) >= 0; i++)
245 fprintf (stderr, " %8d %8d", isc_block_used (isamc, i),
246 stat_info.no_isam_entries[i]);
248 if (stat_info.no_isam_entries[i])
249 fprintf (stderr, " %8d %f",
250 (int) ((1023.0 + (double) isc_block_used(isamc, i) *
251 isc_block_size(isamc,i))/1024),
252 ((double) isc_block_used(isamc, i) *
253 isc_block_size(isamc,i))/
254 stat_info.no_isam_entries[i]);
255 fprintf (stderr, "\n");
260 fprintf (stderr, " Blocks Occur KB Bytes/Entry\n");
261 if (isamd->method->debug >0)
262 logf(LOG_LOG," Blocks Occur KB Bytes/Entry");
263 for (i = 0; i<=SINGLETON_TYPE; i++)
265 blocks= isamd_block_used(isamd,i);
266 size= isamd_block_size(isamd,i);
267 count=stat_info.no_isam_entries[i];
268 if (i==SINGLETON_TYPE)
270 if (stat_info.no_isam_entries[i])
272 fprintf (stderr, "%c %7d %7d %7d %5.2f\n",
273 (i==SINGLETON_TYPE)?('z'):('A'+i),
276 (int) ((1023.0 + (double) blocks * size)/1024),
277 ((double) blocks * size)/count);
278 if (isamd->method->debug >0)
279 logf(LOG_LOG, "%c %7d %7d %7d %5.2f",
280 (i==SINGLETON_TYPE)?('z'):('A'+i),
283 (int) ((1023.0 + (double) blocks * size)/1024),
284 ((double) blocks * size)/count);
288 if ( (isamd) && (isamd->method->debug>0))
289 fprintf (stderr, "\n%d words using %d bytes\n",
290 stat_info.no_dict_entries, stat_info.no_dict_bytes);
292 fprintf (stderr, " Occurrences Words\n");
294 for (i = 0; stat_info.isam_bounds[i]; i++)
296 int here = stat_info.isam_bounds[i];
297 fprintf (stderr, "%7d-%-7d %7d\n",
298 prev, here, stat_info.isam_occurrences[i]);
301 fprintf (stderr, "%7d- %7d\n",
302 prev, stat_info.isam_occurrences[i]);
303 rec_close (&records);
317 xmalloc_trav("unfreed"); /*! while hunting memory leaks */
323 * $Log: invstat.c,v $
324 * Revision 1.19 1999-11-30 13:48:03 adam
325 * Improved installation. Updated for inclusion of YAZ header files.
327 * Revision 1.18 1999/10/06 11:46:36 heikki
328 * mproved statistics on isam-d
330 * Revision 1.17 1999/08/20 08:28:37 heikki
333 * Revision 1.16 1999/08/18 08:38:22 heikki
334 * Memory leak hunting
336 * Revision 1.15 1999/08/18 08:34:53 heikki
339 * Revision 1.14 1999/07/14 10:59:26 adam
340 * Changed functions isc_getmethod, isams_getmethod.
341 * Improved fatal error handling (such as missing EXPLAIN schema).
343 * Revision 1.13 1999/07/08 14:23:27 heikki
344 * Fixed a bug in isamh_pp_read and cleaned up a bit
346 * Revision 1.12 1999/07/06 12:28:04 adam
347 * Updated record index structure. Format includes version ID. Compression
348 * algorithm ID is stored for each record block.
350 * Revision 1.11 1999/05/15 14:36:38 adam
351 * Updated dictionary. Implemented "compression" of dictionary.
353 * Revision 1.10 1999/05/12 13:08:06 adam
354 * First version of ISAMS.
356 * Revision 1.9 1999/02/12 13:29:23 adam
357 * Implemented position-flag for registers.
359 * Revision 1.8 1999/02/02 14:50:53 adam
360 * Updated WIN32 code specific sections. Changed header.
362 * Revision 1.7 1998/03/13 15:30:50 adam
363 * New functions isc_block_used and isc_block_size. Fixed 'leak'
364 * in isc_alloc_block.
366 * Revision 1.6 1998/03/06 13:54:02 adam
367 * Fixed two nasty bugs in isc_merge.
369 * Revision 1.5 1997/09/17 12:19:13 adam
370 * Zebra version corresponds to YAZ version 1.4.
371 * Changed Zebra server so that it doesn't depend on global common_resource.
373 * Revision 1.4 1996/11/08 11:10:21 adam
374 * Buffers used during file match got bigger.
375 * Compressed ISAM support everywhere.
376 * Bug fixes regarding masking characters in queries.
377 * Redesigned Regexp-2 queries.
379 * Revision 1.3 1996/06/04 10:18:58 adam
380 * Minor changes - removed include of ctype.h.
382 * Revision 1.2 1996/05/22 08:25:56 adam
385 * Revision 1.1 1996/05/14 14:04:34 adam
386 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT