2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss, Heikki Levanto
13 #include "../isamc/isamd-p.h"
15 struct inv_stat_info {
17 int no_isam_entries[9];
21 int isam_occurrences[20];
23 int isamb_levels[10][5];
30 #define SINGLETON_TYPE 8 /* the type to use for singletons that */
31 /* have no block and no block type */
33 static void print_dict_item (ZebraMaps zm, const char *s, int count,
34 int firstsys, int firstseq, int lastsys, int lastseq )
37 char keybuf[IT_MAX_WORD+1];
39 const char *from = s + 2;
43 const char *res = zebra_maps_output (zm, reg_type, &from);
51 /* yaz_log (LOG_LOG, "%s", keybuf); */
52 printf("%10d %s %d.%d - %d.%d\n",count, keybuf,
53 firstsys,firstseq, lastsys,lastseq);
56 static int inv_stat_handle (char *name, const char *info, int pos,
61 struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
68 stat_info->no_dict_entries++;
69 stat_info->no_dict_bytes += strlen(name);
71 assert (*info == sizeof(ISAMS_P));
72 memcpy (&isam_p, info+1, sizeof(ISAMS_P));
75 if (stat_info->zh->reg->isams)
81 pp = isams_pp_open (stat_info->zh->reg->isams, isam_p);
82 occur = isams_pp_num (pp);
83 while (isams_pp_read(pp, &key))
85 stat_info->cksum = stat_info->cksum * 65509 +
86 key.sysno + 11 * key.seqno;
96 assert (occurx == occur);
97 stat_info->no_isam_entries[0] += occur;
100 if (stat_info->zh->reg->isam)
104 ispt = is_position (stat_info->zh->reg->isam, isam_p);
105 occur = is_numkeys (ispt);
106 stat_info->no_isam_entries[is_type(isam_p)] += occur;
109 if (stat_info->zh->reg->isamc)
115 pp = isc_pp_open (stat_info->zh->reg->isamc, isam_p);
116 occur = isc_pp_num (pp);
117 while (isc_pp_read(pp, &key))
119 stat_info->cksum = stat_info->cksum * 65509 +
120 key.sysno + 11 * key.seqno;
130 assert (occurx == occur);
131 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
134 if (stat_info->zh->reg->isamd)
140 pp = isamd_pp_open (stat_info->zh->reg->isamd, isam_p);
142 occur = isamd_pp_num (pp);
143 while (isamd_pp_read(pp, &key))
145 stat_info->cksum = stat_info->cksum * 65509 +
146 key.sysno + 11 * key.seqno;
155 if ( pp->is->method->debug >8 )
156 logf (LOG_LOG,"sysno=%d seqno=%d (%x/%x) oc=%d/%d ofs=%d ",
157 key.sysno, key.seqno,
158 key.sysno, key.seqno,
159 occur,occurx, pp->offset);
161 if ( pp->is->method->debug >7 )
162 logf(LOG_LOG,"item %d=%d:%d says %d keys, counted %d",
163 isam_p, isamd_type(isam_p), isamd_block(isam_p),
166 logf(LOG_LOG,"Count error!!! read %d, counted %d", occur, occurx);
167 assert (occurx == occur);
168 if ( is_singleton(isam_p) )
169 stat_info->no_isam_entries[SINGLETON_TYPE] += occur;
171 stat_info->no_isam_entries[isamd_type(isam_p)] += occur;
174 if (stat_info->zh->reg->isamb)
178 int cat = isam_p & 3;
183 pp = isamb_pp_open_x(stat_info->zh->reg->isamb, isam_p, &level);
185 while (isamb_pp_read(pp, &key))
187 stat_info->cksum = stat_info->cksum * 65509 +
188 key.sysno + 11 * key.seqno;
198 isamb_pp_close_x (pp, &size, &blocks);
199 stat_info->isamb_blocks[cat] += blocks;
200 stat_info->isamb_sizes[cat] += size;
203 stat_info->isamb_levels[cat][level] ++;
204 stat_info->no_isam_entries[cat] += occur;
207 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
209 ++(stat_info->isam_occurrences[i]);
210 if (stat_info->dumpwords)
211 print_dict_item(stat_info->zh->reg->zebra_maps, name, occur,
212 firstsys,firstseq, lastsys, lastseq);
216 void zebra_register_statistics (ZebraHandle zh, int dumpdict)
224 int after = 1000000000;
225 struct inv_stat_info stat_info;
226 char term_dict[2*IT_MAX_WORD+2];
228 if (zebra_begin_read (zh))
232 stat_info.dumpwords=dumpdict;
237 for (i = 0; i<=SINGLETON_TYPE; i++)
238 stat_info.no_isam_entries[i] = 0;
239 stat_info.no_dict_entries = 0;
240 stat_info.no_dict_bytes = 0;
241 stat_info.isam_bounds[0] = 1;
242 stat_info.isam_bounds[1] = 2;
243 stat_info.isam_bounds[2] = 3;
244 stat_info.isam_bounds[3] = 6;
245 stat_info.isam_bounds[4] = 10;
246 stat_info.isam_bounds[5] = 20;
247 stat_info.isam_bounds[6] = 30;
248 stat_info.isam_bounds[7] = 50;
249 stat_info.isam_bounds[8] = 100;
250 stat_info.isam_bounds[9] = 200;
251 stat_info.isam_bounds[10] = 5000;
252 stat_info.isam_bounds[11] = 10000;
253 stat_info.isam_bounds[12] = 20000;
254 stat_info.isam_bounds[13] = 50000;
255 stat_info.isam_bounds[14] = 100000;
256 stat_info.isam_bounds[15] = 200000;
257 stat_info.isam_bounds[16] = 500000;
258 stat_info.isam_bounds[17] = 1000000;
259 stat_info.isam_bounds[18] = 0;
263 for (i = 0; i<20; i++)
264 stat_info.isam_occurrences[i] = 0;
266 for (i = 0; i<10; i++)
269 for (j = 0; j<5; j++)
270 stat_info.isamb_levels[i][j] = 0;
271 stat_info.isamb_sizes[i] = 0;
272 stat_info.isamb_blocks[i] = 0;
275 dict_scan (zh->reg->dict, term_dict, &before, &after, &stat_info,
280 fprintf (stdout, " Blocks Occur Size KB Bytes/Entry\n");
281 for (i = 0; isc_block_used (zh->reg->isamc, i) >= 0; i++)
283 fprintf (stdout, " %8d %8d", isc_block_used (zh->reg->isamc, i),
284 stat_info.no_isam_entries[i]);
286 if (stat_info.no_isam_entries[i])
287 fprintf (stdout, " %8d %f",
288 (int) ((1023.0 + (double)
289 isc_block_used(zh->reg->isamc, i) *
290 isc_block_size(zh->reg->isamc,i))/1024),
291 ((double) isc_block_used(zh->reg->isamc, i) *
292 isc_block_size(zh->reg->isamc,i))/
293 stat_info.no_isam_entries[i]);
294 fprintf (stdout, "\n");
299 fprintf (stdout, " Blocks Occur KB Bytes/Entry\n");
300 if (zh->reg->isamd->method->debug >0)
301 logf(LOG_LOG," Blocks Occur KB Bytes/Entry");
302 for (i = 0; i<=SINGLETON_TYPE; i++)
304 blocks= isamd_block_used(zh->reg->isamd,i);
305 size= isamd_block_size(zh->reg->isamd,i);
306 count=stat_info.no_isam_entries[i];
307 if (i==SINGLETON_TYPE)
309 if (stat_info.no_isam_entries[i])
311 fprintf (stdout, "%c %7d %7d %7d %5.2f\n",
312 (i==SINGLETON_TYPE)?('z'):('A'+i),
315 (int) ((1023.0 + (double) blocks * size)/1024),
316 ((double) blocks * size)/count);
317 if (zh->reg->isamd->method->debug >0)
318 logf(LOG_LOG, "%c %7d %7d %7d %5.2f",
319 (i==SINGLETON_TYPE)?('z'):('A'+i),
322 (int) ((1023.0 + (double) blocks * size)/1024),
323 ((double) blocks * size)/count);
327 if ( (zh->reg->isamd) && (zh->reg->isamd->method->debug>0))
328 fprintf (stdout, "\n%d words using %d bytes\n",
329 stat_info.no_dict_entries, stat_info.no_dict_bytes);
333 for (i = 0; i<4; i++)
336 int bsize = isamb_block_info(zh->reg->isamb, i);
339 fprintf (stdout, "Category %d\n", i);
340 fprintf (stdout, "Block size %d\n", bsize);
341 fprintf (stdout, "Blocks: %d\n", stat_info.isamb_blocks[i]);
342 fprintf (stdout, "Size: %d\n", stat_info.isamb_sizes[i]);
343 fprintf (stdout, "Entries: %d\n", stat_info.no_isam_entries[i]);
344 fprintf (stdout, "Total %d\n", stat_info.isamb_blocks[i]*
346 for (j = 0; j<5; j++)
347 if (stat_info.isamb_levels[i][j])
348 fprintf (stdout, "Level%d %d\n", j,
349 stat_info.isamb_levels[i][j]);
350 fprintf (stdout, "\n");
353 fprintf (stdout, "Checksum %08lX\n", stat_info.cksum);
355 fprintf (stdout, "Distinct words %d\n", stat_info.no_dict_entries);
357 for (i = 0; i<9; i++)
358 occur += stat_info.no_isam_entries[i];
359 fprintf (stdout, "Word pos %d\n", occur);
360 fprintf (stdout, " Occurrences Words\n");
362 for (i = 0; stat_info.isam_bounds[i]; i++)
364 int here = stat_info.isam_bounds[i];
365 fprintf (stdout, "%7d-%-7d %7d\n",
366 prev, here, stat_info.isam_occurrences[i]);
369 fprintf (stdout, "%7d- %7d\n",
370 prev, stat_info.isam_occurrences[i]);
371 xmalloc_trav("unfreed"); /*! while hunting memory leaks */
378 * $Log: invstat.c,v $
379 * Revision 1.31 2002-07-11 16:16:00 heikki
380 * Fixed a bug in isamd, failed to store a single key when its bits
381 * did not fit into a singleton.
383 * Revision 1.30 2002/07/11 13:03:01 heikki
384 * Added dumpdict command line option to dump the
385 * dictionary before doing the usual stats
387 * Revision 1.29 2002/06/19 10:29:17 adam
388 * align block sizes for isam sys. Better plot for test
390 * Revision 1.28 2002/04/30 19:31:09 adam
391 * isamb delete; more statistics
393 * Revision 1.27 2002/04/30 08:28:37 adam
394 * isamb fixes for pp_read. Statistics
396 * Revision 1.26 2002/04/29 18:03:46 adam
397 * More isamb statistics
399 * Revision 1.25 2002/04/26 08:44:47 adam
400 * Index statistics working again
402 * Revision 1.24 2002/04/05 08:46:26 adam
403 * Zebra with full functionality
405 * Revision 1.23 2002/04/04 14:14:13 adam
406 * Multiple registers (alpha early)
408 * Revision 1.22 2002/02/20 17:30:01 adam
409 * Work on new API. Locking system re-implemented
411 * Revision 1.21 2000/07/13 10:14:20 heikki
412 * Removed compiler warnings when making zebra
414 * Revision 1.20 1999/12/01 13:30:30 adam
415 * Updated configure for Zmbol/Zebra dependent settings.
417 * Revision 1.19 1999/11/30 13:48:03 adam
418 * Improved installation. Updated for inclusion of YAZ header files.
420 * Revision 1.18 1999/10/06 11:46:36 heikki
421 * mproved statistics on isam-d
423 * Revision 1.17 1999/08/20 08:28:37 heikki
426 * Revision 1.16 1999/08/18 08:38:22 heikki
427 * Memory leak hunting
429 * Revision 1.15 1999/08/18 08:34:53 heikki
432 * Revision 1.14 1999/07/14 10:59:26 adam
433 * Changed functions isc_getmethod, isams_getmethod.
434 * Improved fatal error handling (such as missing EXPLAIN schema).
436 * Revision 1.13 1999/07/08 14:23:27 heikki
437 * Fixed a bug in isamh_pp_read and cleaned up a bit
439 * Revision 1.12 1999/07/06 12:28:04 adam
440 * Updated record index structure. Format includes version ID. Compression
441 * algorithm ID is stored for each record block.
443 * Revision 1.11 1999/05/15 14:36:38 adam
444 * Updated dictionary. Implemented "compression" of dictionary.
446 * Revision 1.10 1999/05/12 13:08:06 adam
447 * First version of ISAMS.
449 * Revision 1.9 1999/02/12 13:29:23 adam
450 * Implemented position-flag for registers.
452 * Revision 1.8 1999/02/02 14:50:53 adam
453 * Updated WIN32 code specific sections. Changed header.
455 * Revision 1.7 1998/03/13 15:30:50 adam
456 * New functions isc_block_used and isc_block_size. Fixed 'leak'
457 * in isc_alloc_block.
459 * Revision 1.6 1998/03/06 13:54:02 adam
460 * Fixed two nasty bugs in isc_merge.
462 * Revision 1.5 1997/09/17 12:19:13 adam
463 * Zebra version corresponds to YAZ version 1.4.
464 * Changed Zebra server so that it doesn't depend on global common_resource.
466 * Revision 1.4 1996/11/08 11:10:21 adam
467 * Buffers used during file match got bigger.
468 * Compressed ISAM support everywhere.
469 * Bug fixes regarding masking characters in queries.
470 * Redesigned Regexp-2 queries.
472 * Revision 1.3 1996/06/04 10:18:58 adam
473 * Minor changes - removed include of ctype.h.
475 * Revision 1.2 1996/05/22 08:25:56 adam
478 * Revision 1.1 1996/05/14 14:04:34 adam
479 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT