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 )
36 char keybuf[IT_MAX_WORD+1];
38 const char *from = s + 2;
42 const char *res = zebra_maps_output (zm, reg_type, &from);
50 /* yaz_log (LOG_LOG, "%s", keybuf); */
51 printf("%10d %s\n",count, keybuf);
54 static int inv_stat_handle (char *name, const char *info, int pos,
59 struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
62 stat_info->no_dict_entries++;
63 stat_info->no_dict_bytes += strlen(name);
65 assert (*info == sizeof(ISAMS_P));
66 memcpy (&isam_p, info+1, sizeof(ISAMS_P));
69 if (stat_info->zh->reg->isams)
75 pp = isams_pp_open (stat_info->zh->reg->isams, isam_p);
76 occur = isams_pp_num (pp);
77 while (isams_pp_read(pp, &key))
79 stat_info->cksum = stat_info->cksum * 65509 +
80 key.sysno + 11 * key.seqno;
83 assert (occurx == occur);
84 stat_info->no_isam_entries[0] += occur;
87 if (stat_info->zh->reg->isam)
91 ispt = is_position (stat_info->zh->reg->isam, isam_p);
92 occur = is_numkeys (ispt);
93 stat_info->no_isam_entries[is_type(isam_p)] += occur;
96 if (stat_info->zh->reg->isamc)
102 pp = isc_pp_open (stat_info->zh->reg->isamc, isam_p);
103 occur = isc_pp_num (pp);
104 while (isc_pp_read(pp, &key))
106 stat_info->cksum = stat_info->cksum * 65509 +
107 key.sysno + 11 * key.seqno;
110 assert (occurx == occur);
111 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
114 if (stat_info->zh->reg->isamd)
120 pp = isamd_pp_open (stat_info->zh->reg->isamd, isam_p);
122 occur = isamd_pp_num (pp);
123 while (isamd_pp_read(pp, &key))
125 stat_info->cksum = stat_info->cksum * 65509 +
126 key.sysno + 11 * key.seqno;
128 if ( pp->is->method->debug >8 )
129 logf (LOG_LOG,"sysno=%d seqno=%d (%x/%x) oc=%d/%d ofs=%d ",
130 key.sysno, key.seqno,
131 key.sysno, key.seqno,
132 occur,occurx, pp->offset);
134 if ( pp->is->method->debug >7 )
135 logf(LOG_LOG,"item %d=%d:%d says %d keys, counted %d",
136 isam_p, isamd_type(isam_p), isamd_block(isam_p),
139 logf(LOG_LOG,"Count error!!! read %d, counted %d", occur, occurx);
140 assert (occurx == occur);
141 if ( is_singleton(isam_p) )
142 stat_info->no_isam_entries[SINGLETON_TYPE] += occur;
144 stat_info->no_isam_entries[isamd_type(isam_p)] += occur;
147 if (stat_info->zh->reg->isamb)
151 int cat = isam_p & 3;
156 pp = isamb_pp_open_x(stat_info->zh->reg->isamb, isam_p, &level);
158 while (isamb_pp_read(pp, &key))
160 stat_info->cksum = stat_info->cksum * 65509 +
161 key.sysno + 11 * key.seqno;
164 isamb_pp_close_x (pp, &size, &blocks);
165 stat_info->isamb_blocks[cat] += blocks;
166 stat_info->isamb_sizes[cat] += size;
169 stat_info->isamb_levels[cat][level] ++;
170 stat_info->no_isam_entries[cat] += occur;
173 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
175 ++(stat_info->isam_occurrences[i]);
176 if (stat_info->dumpwords)
177 print_dict_item(stat_info->zh->reg->zebra_maps, name, occur);
181 void zebra_register_statistics (ZebraHandle zh, int dumpdict)
189 int after = 1000000000;
190 struct inv_stat_info stat_info;
191 char term_dict[2*IT_MAX_WORD+2];
193 if (zebra_begin_read (zh))
197 stat_info.dumpwords=dumpdict;
202 for (i = 0; i<=SINGLETON_TYPE; i++)
203 stat_info.no_isam_entries[i] = 0;
204 stat_info.no_dict_entries = 0;
205 stat_info.no_dict_bytes = 0;
206 stat_info.isam_bounds[0] = 1;
207 stat_info.isam_bounds[1] = 2;
208 stat_info.isam_bounds[2] = 3;
209 stat_info.isam_bounds[3] = 6;
210 stat_info.isam_bounds[4] = 10;
211 stat_info.isam_bounds[5] = 20;
212 stat_info.isam_bounds[6] = 30;
213 stat_info.isam_bounds[7] = 50;
214 stat_info.isam_bounds[8] = 100;
215 stat_info.isam_bounds[9] = 200;
216 stat_info.isam_bounds[10] = 5000;
217 stat_info.isam_bounds[11] = 10000;
218 stat_info.isam_bounds[12] = 20000;
219 stat_info.isam_bounds[13] = 50000;
220 stat_info.isam_bounds[14] = 100000;
221 stat_info.isam_bounds[15] = 200000;
222 stat_info.isam_bounds[16] = 500000;
223 stat_info.isam_bounds[17] = 1000000;
224 stat_info.isam_bounds[18] = 0;
228 for (i = 0; i<20; i++)
229 stat_info.isam_occurrences[i] = 0;
231 for (i = 0; i<10; i++)
234 for (j = 0; j<5; j++)
235 stat_info.isamb_levels[i][j] = 0;
236 stat_info.isamb_sizes[i] = 0;
237 stat_info.isamb_blocks[i] = 0;
240 dict_scan (zh->reg->dict, term_dict, &before, &after, &stat_info,
245 fprintf (stdout, " Blocks Occur Size KB Bytes/Entry\n");
246 for (i = 0; isc_block_used (zh->reg->isamc, i) >= 0; i++)
248 fprintf (stdout, " %8d %8d", isc_block_used (zh->reg->isamc, i),
249 stat_info.no_isam_entries[i]);
251 if (stat_info.no_isam_entries[i])
252 fprintf (stdout, " %8d %f",
253 (int) ((1023.0 + (double)
254 isc_block_used(zh->reg->isamc, i) *
255 isc_block_size(zh->reg->isamc,i))/1024),
256 ((double) isc_block_used(zh->reg->isamc, i) *
257 isc_block_size(zh->reg->isamc,i))/
258 stat_info.no_isam_entries[i]);
259 fprintf (stdout, "\n");
264 fprintf (stdout, " Blocks Occur KB Bytes/Entry\n");
265 if (zh->reg->isamd->method->debug >0)
266 logf(LOG_LOG," Blocks Occur KB Bytes/Entry");
267 for (i = 0; i<=SINGLETON_TYPE; i++)
269 blocks= isamd_block_used(zh->reg->isamd,i);
270 size= isamd_block_size(zh->reg->isamd,i);
271 count=stat_info.no_isam_entries[i];
272 if (i==SINGLETON_TYPE)
274 if (stat_info.no_isam_entries[i])
276 fprintf (stdout, "%c %7d %7d %7d %5.2f\n",
277 (i==SINGLETON_TYPE)?('z'):('A'+i),
280 (int) ((1023.0 + (double) blocks * size)/1024),
281 ((double) blocks * size)/count);
282 if (zh->reg->isamd->method->debug >0)
283 logf(LOG_LOG, "%c %7d %7d %7d %5.2f",
284 (i==SINGLETON_TYPE)?('z'):('A'+i),
287 (int) ((1023.0 + (double) blocks * size)/1024),
288 ((double) blocks * size)/count);
292 if ( (zh->reg->isamd) && (zh->reg->isamd->method->debug>0))
293 fprintf (stdout, "\n%d words using %d bytes\n",
294 stat_info.no_dict_entries, stat_info.no_dict_bytes);
298 for (i = 0; i<4; i++)
301 int bsize = isamb_block_info(zh->reg->isamb, i);
304 fprintf (stdout, "Category %d\n", i);
305 fprintf (stdout, "Block size %d\n", bsize);
306 fprintf (stdout, "Blocks: %d\n", stat_info.isamb_blocks[i]);
307 fprintf (stdout, "Size: %d\n", stat_info.isamb_sizes[i]);
308 fprintf (stdout, "Entries: %d\n", stat_info.no_isam_entries[i]);
309 fprintf (stdout, "Total %d\n", stat_info.isamb_blocks[i]*
311 for (j = 0; j<5; j++)
312 if (stat_info.isamb_levels[i][j])
313 fprintf (stdout, "Level%d %d\n", j,
314 stat_info.isamb_levels[i][j]);
315 fprintf (stdout, "\n");
318 fprintf (stdout, "Checksum %08lX\n", stat_info.cksum);
320 fprintf (stdout, "Distinct words %d\n", stat_info.no_dict_entries);
322 for (i = 0; i<9; i++)
323 occur += stat_info.no_isam_entries[i];
324 fprintf (stdout, "Word pos %d\n", occur);
325 fprintf (stdout, " Occurrences Words\n");
327 for (i = 0; stat_info.isam_bounds[i]; i++)
329 int here = stat_info.isam_bounds[i];
330 fprintf (stdout, "%7d-%-7d %7d\n",
331 prev, here, stat_info.isam_occurrences[i]);
334 fprintf (stdout, "%7d- %7d\n",
335 prev, stat_info.isam_occurrences[i]);
336 xmalloc_trav("unfreed"); /*! while hunting memory leaks */
343 * $Log: invstat.c,v $
344 * Revision 1.30 2002-07-11 13:03:01 heikki
345 * Added dumpdict command line option to dump the
346 * dictionary before doing the usual stats
348 * Revision 1.29 2002/06/19 10:29:17 adam
349 * align block sizes for isam sys. Better plot for test
351 * Revision 1.28 2002/04/30 19:31:09 adam
352 * isamb delete; more statistics
354 * Revision 1.27 2002/04/30 08:28:37 adam
355 * isamb fixes for pp_read. Statistics
357 * Revision 1.26 2002/04/29 18:03:46 adam
358 * More isamb statistics
360 * Revision 1.25 2002/04/26 08:44:47 adam
361 * Index statistics working again
363 * Revision 1.24 2002/04/05 08:46:26 adam
364 * Zebra with full functionality
366 * Revision 1.23 2002/04/04 14:14:13 adam
367 * Multiple registers (alpha early)
369 * Revision 1.22 2002/02/20 17:30:01 adam
370 * Work on new API. Locking system re-implemented
372 * Revision 1.21 2000/07/13 10:14:20 heikki
373 * Removed compiler warnings when making zebra
375 * Revision 1.20 1999/12/01 13:30:30 adam
376 * Updated configure for Zmbol/Zebra dependent settings.
378 * Revision 1.19 1999/11/30 13:48:03 adam
379 * Improved installation. Updated for inclusion of YAZ header files.
381 * Revision 1.18 1999/10/06 11:46:36 heikki
382 * mproved statistics on isam-d
384 * Revision 1.17 1999/08/20 08:28:37 heikki
387 * Revision 1.16 1999/08/18 08:38:22 heikki
388 * Memory leak hunting
390 * Revision 1.15 1999/08/18 08:34:53 heikki
393 * Revision 1.14 1999/07/14 10:59:26 adam
394 * Changed functions isc_getmethod, isams_getmethod.
395 * Improved fatal error handling (such as missing EXPLAIN schema).
397 * Revision 1.13 1999/07/08 14:23:27 heikki
398 * Fixed a bug in isamh_pp_read and cleaned up a bit
400 * Revision 1.12 1999/07/06 12:28:04 adam
401 * Updated record index structure. Format includes version ID. Compression
402 * algorithm ID is stored for each record block.
404 * Revision 1.11 1999/05/15 14:36:38 adam
405 * Updated dictionary. Implemented "compression" of dictionary.
407 * Revision 1.10 1999/05/12 13:08:06 adam
408 * First version of ISAMS.
410 * Revision 1.9 1999/02/12 13:29:23 adam
411 * Implemented position-flag for registers.
413 * Revision 1.8 1999/02/02 14:50:53 adam
414 * Updated WIN32 code specific sections. Changed header.
416 * Revision 1.7 1998/03/13 15:30:50 adam
417 * New functions isc_block_used and isc_block_size. Fixed 'leak'
418 * in isc_alloc_block.
420 * Revision 1.6 1998/03/06 13:54:02 adam
421 * Fixed two nasty bugs in isc_merge.
423 * Revision 1.5 1997/09/17 12:19:13 adam
424 * Zebra version corresponds to YAZ version 1.4.
425 * Changed Zebra server so that it doesn't depend on global common_resource.
427 * Revision 1.4 1996/11/08 11:10:21 adam
428 * Buffers used during file match got bigger.
429 * Compressed ISAM support everywhere.
430 * Bug fixes regarding masking characters in queries.
431 * Redesigned Regexp-2 queries.
433 * Revision 1.3 1996/06/04 10:18:58 adam
434 * Minor changes - removed include of ctype.h.
436 * Revision 1.2 1996/05/22 08:25:56 adam
439 * Revision 1.1 1996/05/14 14:04:34 adam
440 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT