2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss, Heikki Levanto
14 #include "../isamc/isamd-p.h"
17 struct inv_stat_info {
24 int no_isam_entries[9];
28 int isam_occurrences[20];
32 #define SINGLETON_TYPE 8 /* the type to use for singletons that */
33 /* have no block and no block type */
35 static int inv_stat_handle (char *name, const char *info, int pos,
40 struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
43 stat_info->no_dict_entries++;
44 stat_info->no_dict_bytes += strlen(name);
46 assert (*info == sizeof(ISAMS_P));
47 memcpy (&isam_p, info+1, sizeof(ISAMS_P));
55 pp = isams_pp_open (stat_info->isams, isam_p);
56 occur = isams_pp_num (pp);
57 while (isams_pp_read(pp, &key))
59 //printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
62 assert (occurx == occur);
63 stat_info->no_isam_entries[0] += occur;
71 ispt = is_position (stat_info->isam, isam_p);
72 occur = is_numkeys (ispt);
81 pp = isc_pp_open (stat_info->isamc, isam_p);
82 occur = isc_pp_num (pp);
83 while (isc_pp_read(pp, &key))
85 //printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
88 assert (occurx == occur);
89 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
98 pp = isamd_pp_open (stat_info->isamd, isam_p);
100 occur = isamd_pp_num (pp);
101 while (isamd_pp_read(pp, &key))
104 if ( pp->is->method->debug >8 )
105 logf (LOG_LOG,"sysno=%d seqno=%d (%x/%x) oc=%d/%d ofs=%d ",
106 key.sysno, key.seqno,
107 key.sysno, key.seqno,
108 occur,occurx, pp->offset);
110 if ( pp->is->method->debug >7 )
111 logf(LOG_LOG,"item %d=%d:%d says %d keys, counted %d",
112 isam_p, isamd_type(isam_p), isamd_block(isam_p),
115 logf(LOG_LOG,"Count error!!! read %d, counted %d", occur, occurx);
116 assert (occurx == occur);
117 if ( is_singleton(isam_p) )
118 stat_info->no_isam_entries[SINGLETON_TYPE] += occur;
120 stat_info->no_isam_entries[isamd_type(isam_p)] += occur;
124 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
126 ++(stat_info->isam_occurrences[i]);
130 void inv_prstat (ZebraHandle zh)
147 int after = 1000000000;
148 struct inv_stat_info stat_info;
149 char term_dict[2*IT_MAX_WORD+2];
151 if (!res || !zh->reg)
159 dict = dict_open (bfs, FNAME_DICT, 100, 0, 0);
162 logf (LOG_FATAL, "dict_open fail");
165 if (res_get_match (res, "isam", "s", ISAM_DEFAULT))
167 struct ISAMS_M_s isams_m;
168 isams = isams_open (bfs, FNAME_ISAMS, 0,
169 key_isams_m(res, &isams_m));
172 logf (LOG_FATAL, "isams_open fail");
177 else if (res_get_match (res, "isam", "i", ISAM_DEFAULT))
179 isam = is_open (bfs, FNAME_ISAM, key_compare, 0,
180 sizeof(struct it_key), res);
183 logf (LOG_FATAL, "is_open fail");
187 else if (res_get_match (res, "isam", "d", ISAM_DEFAULT))
189 struct ISAMD_M_s isamd_m;
190 isamd = isamd_open (bfs, FNAME_ISAMD, 0,
191 key_isamd_m(res,&isamd_m));
194 logf (LOG_FATAL, "isamd_open fail");
198 else if (res_get_match (res, "isam", "c", ISAM_DEFAULT))
200 struct ISAMC_M_s isamc_m;
201 isamc = isc_open (bfs, FNAME_ISAMC, 0,
202 key_isamc_m (res, &isamc_m));
205 logf (LOG_FATAL, "isc_open fail");
210 records = rec_open (bfs, 0, 0);
212 for (i = 0; i<=SINGLETON_TYPE; i++)
213 stat_info.no_isam_entries[i] = 0;
214 stat_info.no_dict_entries = 0;
215 stat_info.no_dict_bytes = 0;
216 stat_info.isams = isams;
218 stat_info.isam = isam;
219 stat_info.isamc = isamc;
220 stat_info.isamd = isamd;
222 stat_info.isam_bounds[0] = 1;
223 stat_info.isam_bounds[1] = 2;
224 stat_info.isam_bounds[2] = 3;
225 stat_info.isam_bounds[3] = 6;
226 stat_info.isam_bounds[4] = 10;
227 stat_info.isam_bounds[5] = 20;
228 stat_info.isam_bounds[6] = 30;
229 stat_info.isam_bounds[7] = 50;
230 stat_info.isam_bounds[8] = 100;
231 stat_info.isam_bounds[9] = 200;
232 stat_info.isam_bounds[10] = 5000;
233 stat_info.isam_bounds[11] = 10000;
234 stat_info.isam_bounds[12] = 20000;
235 stat_info.isam_bounds[13] = 50000;
236 stat_info.isam_bounds[14] = 100000;
237 stat_info.isam_bounds[15] = 200000;
238 stat_info.isam_bounds[16] = 500000;
239 stat_info.isam_bounds[17] = 1000000;
240 stat_info.isam_bounds[18] = 0;
242 for (i = 0; i<20; i++)
243 stat_info.isam_occurrences[i] = 0;
245 dict_scan (dict, term_dict, &before, &after, &stat_info, inv_stat_handle);
250 fprintf (stderr, " Blocks Occur Size KB Bytes/Entry\n");
251 for (i = 0; isc_block_used (isamc, i) >= 0; i++)
253 fprintf (stderr, " %8d %8d", isc_block_used (isamc, i),
254 stat_info.no_isam_entries[i]);
256 if (stat_info.no_isam_entries[i])
257 fprintf (stderr, " %8d %f",
258 (int) ((1023.0 + (double) isc_block_used(isamc, i) *
259 isc_block_size(isamc,i))/1024),
260 ((double) isc_block_used(isamc, i) *
261 isc_block_size(isamc,i))/
262 stat_info.no_isam_entries[i]);
263 fprintf (stderr, "\n");
268 fprintf (stderr, " Blocks Occur KB Bytes/Entry\n");
269 if (isamd->method->debug >0)
270 logf(LOG_LOG," Blocks Occur KB Bytes/Entry");
271 for (i = 0; i<=SINGLETON_TYPE; i++)
273 blocks= isamd_block_used(isamd,i);
274 size= isamd_block_size(isamd,i);
275 count=stat_info.no_isam_entries[i];
276 if (i==SINGLETON_TYPE)
278 if (stat_info.no_isam_entries[i])
280 fprintf (stderr, "%c %7d %7d %7d %5.2f\n",
281 (i==SINGLETON_TYPE)?('z'):('A'+i),
284 (int) ((1023.0 + (double) blocks * size)/1024),
285 ((double) blocks * size)/count);
286 if (isamd->method->debug >0)
287 logf(LOG_LOG, "%c %7d %7d %7d %5.2f",
288 (i==SINGLETON_TYPE)?('z'):('A'+i),
291 (int) ((1023.0 + (double) blocks * size)/1024),
292 ((double) blocks * size)/count);
296 if ( (isamd) && (isamd->method->debug>0))
297 fprintf (stderr, "\n%d words using %d bytes\n",
298 stat_info.no_dict_entries, stat_info.no_dict_bytes);
300 fprintf (stderr, " Occurrences Words\n");
302 for (i = 0; stat_info.isam_bounds[i]; i++)
304 int here = stat_info.isam_bounds[i];
305 fprintf (stderr, "%7d-%-7d %7d\n",
306 prev, here, stat_info.isam_occurrences[i]);
309 fprintf (stderr, "%7d- %7d\n",
310 prev, stat_info.isam_occurrences[i]);
311 rec_close (&records);
325 xmalloc_trav("unfreed"); /*! while hunting memory leaks */
331 * $Log: invstat.c,v $
332 * Revision 1.23 2002-04-04 14:14:13 adam
333 * Multiple registers (alpha early)
335 * Revision 1.22 2002/02/20 17:30:01 adam
336 * Work on new API. Locking system re-implemented
338 * Revision 1.21 2000/07/13 10:14:20 heikki
339 * Removed compiler warnings when making zebra
341 * Revision 1.20 1999/12/01 13:30:30 adam
342 * Updated configure for Zmbol/Zebra dependent settings.
344 * Revision 1.19 1999/11/30 13:48:03 adam
345 * Improved installation. Updated for inclusion of YAZ header files.
347 * Revision 1.18 1999/10/06 11:46:36 heikki
348 * mproved statistics on isam-d
350 * Revision 1.17 1999/08/20 08:28:37 heikki
353 * Revision 1.16 1999/08/18 08:38:22 heikki
354 * Memory leak hunting
356 * Revision 1.15 1999/08/18 08:34:53 heikki
359 * Revision 1.14 1999/07/14 10:59:26 adam
360 * Changed functions isc_getmethod, isams_getmethod.
361 * Improved fatal error handling (such as missing EXPLAIN schema).
363 * Revision 1.13 1999/07/08 14:23:27 heikki
364 * Fixed a bug in isamh_pp_read and cleaned up a bit
366 * Revision 1.12 1999/07/06 12:28:04 adam
367 * Updated record index structure. Format includes version ID. Compression
368 * algorithm ID is stored for each record block.
370 * Revision 1.11 1999/05/15 14:36:38 adam
371 * Updated dictionary. Implemented "compression" of dictionary.
373 * Revision 1.10 1999/05/12 13:08:06 adam
374 * First version of ISAMS.
376 * Revision 1.9 1999/02/12 13:29:23 adam
377 * Implemented position-flag for registers.
379 * Revision 1.8 1999/02/02 14:50:53 adam
380 * Updated WIN32 code specific sections. Changed header.
382 * Revision 1.7 1998/03/13 15:30:50 adam
383 * New functions isc_block_used and isc_block_size. Fixed 'leak'
384 * in isc_alloc_block.
386 * Revision 1.6 1998/03/06 13:54:02 adam
387 * Fixed two nasty bugs in isc_merge.
389 * Revision 1.5 1997/09/17 12:19:13 adam
390 * Zebra version corresponds to YAZ version 1.4.
391 * Changed Zebra server so that it doesn't depend on global common_resource.
393 * Revision 1.4 1996/11/08 11:10:21 adam
394 * Buffers used during file match got bigger.
395 * Compressed ISAM support everywhere.
396 * Bug fixes regarding masking characters in queries.
397 * Redesigned Regexp-2 queries.
399 * Revision 1.3 1996/06/04 10:18:58 adam
400 * Minor changes - removed include of ctype.h.
402 * Revision 1.2 1996/05/22 08:25:56 adam
405 * Revision 1.1 1996/05/14 14:04:34 adam
406 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT