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 if (!stat_info->zh->reg->isamd)
73 assert (*info == sizeof(ISAMS_P));
74 memcpy (&isam_p, info+1, sizeof(ISAMS_P));
77 if (stat_info->zh->reg->isams)
83 pp = isams_pp_open (stat_info->zh->reg->isams, isam_p);
84 occur = isams_pp_num (pp);
85 while (isams_pp_read(pp, &key))
87 stat_info->cksum = stat_info->cksum * 65509 +
88 key.sysno + 11 * key.seqno;
98 assert (occurx == occur);
99 stat_info->no_isam_entries[0] += occur;
102 if (stat_info->zh->reg->isam)
106 ispt = is_position (stat_info->zh->reg->isam, isam_p);
107 occur = is_numkeys (ispt);
108 stat_info->no_isam_entries[is_type(isam_p)] += occur;
111 if (stat_info->zh->reg->isamc)
117 pp = isc_pp_open (stat_info->zh->reg->isamc, isam_p);
118 occur = isc_pp_num (pp);
119 while (isc_pp_read(pp, &key))
121 stat_info->cksum = stat_info->cksum * 65509 +
122 key.sysno + 11 * key.seqno;
132 assert (occurx == occur);
133 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
136 if (stat_info->zh->reg->isamd)
141 /* printf("[%d: %d %d %d %d %d %d] ", */
142 /* info[0], info[1], info[2], info[3], info[4], info[5], info[7]);*/
143 pp = isamd_pp_open (stat_info->zh->reg->isamd, info+1, info[0]);
145 occur = isamd_pp_num (pp);
146 while (isamd_pp_read(pp, &key))
148 stat_info->cksum = stat_info->cksum * 65509 +
149 key.sysno + 11 * key.seqno;
151 /* printf("%d.%d ", key.sysno, key.seqno); */ /*!*/
159 if ( pp->is->method->debug >8 )
160 logf (LOG_LOG,"sysno=%d seqno=%d (%x/%x) oc=%d/%d ofs=%d ",
161 key.sysno, key.seqno,
162 key.sysno, key.seqno,
163 occur,occurx, pp->offset);
165 /* printf("\n"); */ /*!*/
167 if ( pp->is->method->debug >7 )
168 logf(LOG_LOG,"item %d=%d:%d says %d keys, counted %d",
169 isam_p, isamd_type(isam_p), isamd_block(isam_p),
173 logf(LOG_LOG,"Count error!!! read %d, counted %d", occur, occurx);
174 assert (occurx == occur);
178 stat_info->no_isam_entries[i] += occur;
181 if (stat_info->zh->reg->isamb)
185 int cat = isam_p & 3;
190 pp = isamb_pp_open_x(stat_info->zh->reg->isamb, isam_p, &level);
192 while (isamb_pp_read(pp, &key))
194 stat_info->cksum = stat_info->cksum * 65509 +
195 key.sysno + 11 * key.seqno;
205 isamb_pp_close_x (pp, &size, &blocks);
206 stat_info->isamb_blocks[cat] += blocks;
207 stat_info->isamb_sizes[cat] += size;
210 stat_info->isamb_levels[cat][level] ++;
211 stat_info->no_isam_entries[cat] += occur;
214 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
216 ++(stat_info->isam_occurrences[i]);
217 if (stat_info->dumpwords)
218 print_dict_item(stat_info->zh->reg->zebra_maps, name, occur,
219 firstsys,firstseq, lastsys, lastseq);
223 void zebra_register_statistics (ZebraHandle zh, int dumpdict)
231 int after = 1000000000;
232 struct inv_stat_info stat_info;
233 char term_dict[2*IT_MAX_WORD+2];
235 if (zebra_begin_read (zh))
239 stat_info.dumpwords=dumpdict;
244 for (i = 0; i<=SINGLETON_TYPE; i++)
245 stat_info.no_isam_entries[i] = 0;
246 stat_info.no_dict_entries = 0;
247 stat_info.no_dict_bytes = 0;
248 stat_info.isam_bounds[0] = 1;
249 stat_info.isam_bounds[1] = 2;
250 stat_info.isam_bounds[2] = 3;
251 stat_info.isam_bounds[3] = 6;
252 stat_info.isam_bounds[4] = 10;
253 stat_info.isam_bounds[5] = 20;
254 stat_info.isam_bounds[6] = 30;
255 stat_info.isam_bounds[7] = 50;
256 stat_info.isam_bounds[8] = 100;
257 stat_info.isam_bounds[9] = 200;
258 stat_info.isam_bounds[10] = 5000;
259 stat_info.isam_bounds[11] = 10000;
260 stat_info.isam_bounds[12] = 20000;
261 stat_info.isam_bounds[13] = 50000;
262 stat_info.isam_bounds[14] = 100000;
263 stat_info.isam_bounds[15] = 200000;
264 stat_info.isam_bounds[16] = 500000;
265 stat_info.isam_bounds[17] = 1000000;
266 stat_info.isam_bounds[18] = 0;
270 for (i = 0; i<20; i++)
271 stat_info.isam_occurrences[i] = 0;
273 for (i = 0; i<10; i++)
276 for (j = 0; j<5; j++)
277 stat_info.isamb_levels[i][j] = 0;
278 stat_info.isamb_sizes[i] = 0;
279 stat_info.isamb_blocks[i] = 0;
282 dict_scan (zh->reg->dict, term_dict, &before, &after, &stat_info,
287 fprintf (stdout, " Blocks Occur Size KB Bytes/Entry\n");
288 for (i = 0; isc_block_used (zh->reg->isamc, i) >= 0; i++)
290 fprintf (stdout, " %8d %8d", isc_block_used (zh->reg->isamc, i),
291 stat_info.no_isam_entries[i]);
293 if (stat_info.no_isam_entries[i])
294 fprintf (stdout, " %8d %f",
295 (int) ((1023.0 + (double)
296 isc_block_used(zh->reg->isamc, i) *
297 isc_block_size(zh->reg->isamc,i))/1024),
298 ((double) isc_block_used(zh->reg->isamc, i) *
299 isc_block_size(zh->reg->isamc,i))/
300 stat_info.no_isam_entries[i]);
301 fprintf (stdout, "\n");
306 fprintf (stdout, " Blocks Occur KB Bytes/Entry\n");
307 if (zh->reg->isamd->method->debug >0)
308 logf(LOG_LOG," Blocks Occur KB Bytes/Entry");
309 for (i = 0; i<=SINGLETON_TYPE; i++)
311 blocks= isamd_block_used(zh->reg->isamd,i);
312 size= isamd_block_size(zh->reg->isamd,i);
313 count=stat_info.no_isam_entries[i];
314 if (i==SINGLETON_TYPE)
316 if (stat_info.no_isam_entries[i])
318 fprintf (stdout, "%c %7d %7d %7d %5.2f\n",
319 (i==SINGLETON_TYPE)?('z'):('A'+i),
322 (int) ((1023.0 + (double) blocks * size)/1024),
323 ((double) blocks * size)/count);
324 if (zh->reg->isamd->method->debug >0)
325 logf(LOG_LOG, "%c %7d %7d %7d %5.2f",
326 (i==SINGLETON_TYPE)?('z'):('A'+i),
329 (int) ((1023.0 + (double) blocks * size)/1024),
330 ((double) blocks * size)/count);
334 if ( (zh->reg->isamd) && (zh->reg->isamd->method->debug>0))
335 fprintf (stdout, "\n%d words using %d bytes\n",
336 stat_info.no_dict_entries, stat_info.no_dict_bytes);
340 for (i = 0; i<4; i++)
343 int bsize = isamb_block_info(zh->reg->isamb, i);
346 fprintf (stdout, "Category %d\n", i);
347 fprintf (stdout, "Block size %d\n", bsize);
348 fprintf (stdout, "Blocks: %d\n", stat_info.isamb_blocks[i]);
349 fprintf (stdout, "Size: %d\n", stat_info.isamb_sizes[i]);
350 fprintf (stdout, "Entries: %d\n", stat_info.no_isam_entries[i]);
351 fprintf (stdout, "Total %d\n", stat_info.isamb_blocks[i]*
353 for (j = 0; j<5; j++)
354 if (stat_info.isamb_levels[i][j])
355 fprintf (stdout, "Level%d %d\n", j,
356 stat_info.isamb_levels[i][j]);
357 fprintf (stdout, "\n");
360 fprintf (stdout, "Checksum %08lX\n", stat_info.cksum);
362 fprintf (stdout, "Distinct words %d\n", stat_info.no_dict_entries);
364 for (i = 0; i<9; i++)
365 occur += stat_info.no_isam_entries[i];
366 fprintf (stdout, "Word pos %d\n", occur);
367 fprintf (stdout, " Occurrences Words\n");
369 for (i = 0; stat_info.isam_bounds[i]; i++)
371 int here = stat_info.isam_bounds[i];
372 fprintf (stdout, "%7d-%-7d %7d\n",
373 prev, here, stat_info.isam_occurrences[i]);
376 fprintf (stdout, "%7d- %7d\n",
377 prev, stat_info.isam_occurrences[i]);
378 xmalloc_trav("unfreed"); /*! while hunting memory leaks */
385 * $Log: invstat.c,v $
386 * Revision 1.32 2002-07-12 18:12:22 heikki
387 * Isam-D now stores small entries directly in the dictionary.
388 * Needs more tuning and cleaning...
390 * Revision 1.31 2002/07/11 16:16:00 heikki
391 * Fixed a bug in isamd, failed to store a single key when its bits
392 * did not fit into a singleton.
394 * Revision 1.30 2002/07/11 13:03:01 heikki
395 * Added dumpdict command line option to dump the
396 * dictionary before doing the usual stats
398 * Revision 1.29 2002/06/19 10:29:17 adam
399 * align block sizes for isam sys. Better plot for test
401 * Revision 1.28 2002/04/30 19:31:09 adam
402 * isamb delete; more statistics
404 * Revision 1.27 2002/04/30 08:28:37 adam
405 * isamb fixes for pp_read. Statistics
407 * Revision 1.26 2002/04/29 18:03:46 adam
408 * More isamb statistics
410 * Revision 1.25 2002/04/26 08:44:47 adam
411 * Index statistics working again
413 * Revision 1.24 2002/04/05 08:46:26 adam
414 * Zebra with full functionality
416 * Revision 1.23 2002/04/04 14:14:13 adam
417 * Multiple registers (alpha early)
419 * Revision 1.22 2002/02/20 17:30:01 adam
420 * Work on new API. Locking system re-implemented
422 * Revision 1.21 2000/07/13 10:14:20 heikki
423 * Removed compiler warnings when making zebra
425 * Revision 1.20 1999/12/01 13:30:30 adam
426 * Updated configure for Zmbol/Zebra dependent settings.
428 * Revision 1.19 1999/11/30 13:48:03 adam
429 * Improved installation. Updated for inclusion of YAZ header files.
431 * Revision 1.18 1999/10/06 11:46:36 heikki
432 * mproved statistics on isam-d
434 * Revision 1.17 1999/08/20 08:28:37 heikki
437 * Revision 1.16 1999/08/18 08:38:22 heikki
438 * Memory leak hunting
440 * Revision 1.15 1999/08/18 08:34:53 heikki
443 * Revision 1.14 1999/07/14 10:59:26 adam
444 * Changed functions isc_getmethod, isams_getmethod.
445 * Improved fatal error handling (such as missing EXPLAIN schema).
447 * Revision 1.13 1999/07/08 14:23:27 heikki
448 * Fixed a bug in isamh_pp_read and cleaned up a bit
450 * Revision 1.12 1999/07/06 12:28:04 adam
451 * Updated record index structure. Format includes version ID. Compression
452 * algorithm ID is stored for each record block.
454 * Revision 1.11 1999/05/15 14:36:38 adam
455 * Updated dictionary. Implemented "compression" of dictionary.
457 * Revision 1.10 1999/05/12 13:08:06 adam
458 * First version of ISAMS.
460 * Revision 1.9 1999/02/12 13:29:23 adam
461 * Implemented position-flag for registers.
463 * Revision 1.8 1999/02/02 14:50:53 adam
464 * Updated WIN32 code specific sections. Changed header.
466 * Revision 1.7 1998/03/13 15:30:50 adam
467 * New functions isc_block_used and isc_block_size. Fixed 'leak'
468 * in isc_alloc_block.
470 * Revision 1.6 1998/03/06 13:54:02 adam
471 * Fixed two nasty bugs in isc_merge.
473 * Revision 1.5 1997/09/17 12:19:13 adam
474 * Zebra version corresponds to YAZ version 1.4.
475 * Changed Zebra server so that it doesn't depend on global common_resource.
477 * Revision 1.4 1996/11/08 11:10:21 adam
478 * Buffers used during file match got bigger.
479 * Compressed ISAM support everywhere.
480 * Bug fixes regarding masking characters in queries.
481 * Redesigned Regexp-2 queries.
483 * Revision 1.3 1996/06/04 10:18:58 adam
484 * Minor changes - removed include of ctype.h.
486 * Revision 1.2 1996/05/22 08:25:56 adam
489 * Revision 1.1 1996/05/14 14:04:34 adam
490 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT