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];
29 #define SINGLETON_TYPE 8 /* the type to use for singletons that */
30 /* have no block and no block type */
32 static int inv_stat_handle (char *name, const char *info, int pos,
37 struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
40 stat_info->no_dict_entries++;
41 stat_info->no_dict_bytes += strlen(name);
43 assert (*info == sizeof(ISAMS_P));
44 memcpy (&isam_p, info+1, sizeof(ISAMS_P));
46 if (stat_info->zh->reg->isams)
52 pp = isams_pp_open (stat_info->zh->reg->isams, isam_p);
53 occur = isams_pp_num (pp);
54 while (isams_pp_read(pp, &key))
56 //printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
59 assert (occurx == occur);
60 stat_info->no_isam_entries[0] += occur;
63 if (stat_info->zh->reg->isam)
67 ispt = is_position (stat_info->zh->reg->isam, isam_p);
68 occur = is_numkeys (ispt);
71 if (stat_info->zh->reg->isamc)
77 pp = isc_pp_open (stat_info->zh->reg->isamc, isam_p);
78 occur = isc_pp_num (pp);
79 while (isc_pp_read(pp, &key))
81 //printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
84 assert (occurx == occur);
85 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
88 if (stat_info->zh->reg->isamd)
94 pp = isamd_pp_open (stat_info->zh->reg->isamd, isam_p);
96 occur = isamd_pp_num (pp);
97 while (isamd_pp_read(pp, &key))
100 if ( pp->is->method->debug >8 )
101 logf (LOG_LOG,"sysno=%d seqno=%d (%x/%x) oc=%d/%d ofs=%d ",
102 key.sysno, key.seqno,
103 key.sysno, key.seqno,
104 occur,occurx, pp->offset);
106 if ( pp->is->method->debug >7 )
107 logf(LOG_LOG,"item %d=%d:%d says %d keys, counted %d",
108 isam_p, isamd_type(isam_p), isamd_block(isam_p),
111 logf(LOG_LOG,"Count error!!! read %d, counted %d", occur, occurx);
112 assert (occurx == occur);
113 if ( is_singleton(isam_p) )
114 stat_info->no_isam_entries[SINGLETON_TYPE] += occur;
116 stat_info->no_isam_entries[isamd_type(isam_p)] += occur;
119 if (stat_info->zh->reg->isamb)
123 int cat = isam_p & 3;
128 pp = isamb_pp_open_x(stat_info->zh->reg->isamb, isam_p, &level);
129 while (isamb_pp_read(pp, &key))
131 isamb_pp_close_x (pp, &size, &blocks);
132 stat_info->isamb_no[cat]++;
133 stat_info->isamb_levels[cat] += level;
134 stat_info->isamb_blocks[cat] += blocks;
135 stat_info->isamb_sizes[cat] += size;
138 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
140 ++(stat_info->isam_occurrences[i]);
144 void zebra_register_statistics (ZebraHandle zh)
151 int after = 1000000000;
152 struct inv_stat_info stat_info;
153 char term_dict[2*IT_MAX_WORD+2];
155 if (zebra_begin_read (zh))
163 for (i = 0; i<=SINGLETON_TYPE; i++)
164 stat_info.no_isam_entries[i] = 0;
165 stat_info.no_dict_entries = 0;
166 stat_info.no_dict_bytes = 0;
167 stat_info.isam_bounds[0] = 1;
168 stat_info.isam_bounds[1] = 2;
169 stat_info.isam_bounds[2] = 3;
170 stat_info.isam_bounds[3] = 6;
171 stat_info.isam_bounds[4] = 10;
172 stat_info.isam_bounds[5] = 20;
173 stat_info.isam_bounds[6] = 30;
174 stat_info.isam_bounds[7] = 50;
175 stat_info.isam_bounds[8] = 100;
176 stat_info.isam_bounds[9] = 200;
177 stat_info.isam_bounds[10] = 5000;
178 stat_info.isam_bounds[11] = 10000;
179 stat_info.isam_bounds[12] = 20000;
180 stat_info.isam_bounds[13] = 50000;
181 stat_info.isam_bounds[14] = 100000;
182 stat_info.isam_bounds[15] = 200000;
183 stat_info.isam_bounds[16] = 500000;
184 stat_info.isam_bounds[17] = 1000000;
185 stat_info.isam_bounds[18] = 0;
187 for (i = 0; i<20; i++)
188 stat_info.isam_occurrences[i] = 0;
190 for (i = 0; i<10; i++)
192 stat_info.isamb_levels[i] = 0;
193 stat_info.isamb_sizes[i] = 0;
194 stat_info.isamb_blocks[i] = 0;
195 stat_info.isamb_no[i] = 0;
198 dict_scan (zh->reg->dict, term_dict, &before, &after, &stat_info,
203 fprintf (stderr, " Blocks Occur Size KB Bytes/Entry\n");
204 for (i = 0; isc_block_used (zh->reg->isamc, i) >= 0; i++)
206 fprintf (stderr, " %8d %8d", isc_block_used (zh->reg->isamc, i),
207 stat_info.no_isam_entries[i]);
209 if (stat_info.no_isam_entries[i])
210 fprintf (stderr, " %8d %f",
211 (int) ((1023.0 + (double)
212 isc_block_used(zh->reg->isamc, i) *
213 isc_block_size(zh->reg->isamc,i))/1024),
214 ((double) isc_block_used(zh->reg->isamc, i) *
215 isc_block_size(zh->reg->isamc,i))/
216 stat_info.no_isam_entries[i]);
217 fprintf (stderr, "\n");
222 fprintf (stderr, " Blocks Occur KB Bytes/Entry\n");
223 if (zh->reg->isamd->method->debug >0)
224 logf(LOG_LOG," Blocks Occur KB Bytes/Entry");
225 for (i = 0; i<=SINGLETON_TYPE; i++)
227 blocks= isamd_block_used(zh->reg->isamd,i);
228 size= isamd_block_size(zh->reg->isamd,i);
229 count=stat_info.no_isam_entries[i];
230 if (i==SINGLETON_TYPE)
232 if (stat_info.no_isam_entries[i])
234 fprintf (stderr, "%c %7d %7d %7d %5.2f\n",
235 (i==SINGLETON_TYPE)?('z'):('A'+i),
238 (int) ((1023.0 + (double) blocks * size)/1024),
239 ((double) blocks * size)/count);
240 if (zh->reg->isamd->method->debug >0)
241 logf(LOG_LOG, "%c %7d %7d %7d %5.2f",
242 (i==SINGLETON_TYPE)?('z'):('A'+i),
245 (int) ((1023.0 + (double) blocks * size)/1024),
246 ((double) blocks * size)/count);
250 if ( (zh->reg->isamd) && (zh->reg->isamd->method->debug>0))
251 fprintf (stderr, "\n%d words using %d bytes\n",
252 stat_info.no_dict_entries, stat_info.no_dict_bytes);
256 for (i = 0; i<4; i++)
258 int bsize = isamb_block_info(zh->reg->isamb, i);
261 fprintf (stderr, "Category %d\n", i);
262 fprintf (stderr, "Block size %d\n", bsize);
263 fprintf (stderr, "Lists: %d\n", stat_info.isamb_no[i]);
264 fprintf (stderr, "Blocks: %d\n", stat_info.isamb_blocks[i]);
265 fprintf (stderr, "Size: %d\n", stat_info.isamb_sizes[i]);
266 fprintf (stderr, "Total %d\n", stat_info.isamb_blocks[i]*
271 fprintf (stderr, " Occurrences Words\n");
273 for (i = 0; stat_info.isam_bounds[i]; i++)
275 int here = stat_info.isam_bounds[i];
276 fprintf (stderr, "%7d-%-7d %7d\n",
277 prev, here, stat_info.isam_occurrences[i]);
280 fprintf (stderr, "%7d- %7d\n",
281 prev, stat_info.isam_occurrences[i]);
282 xmalloc_trav("unfreed"); /*! while hunting memory leaks */
289 * $Log: invstat.c,v $
290 * Revision 1.26 2002-04-29 18:03:46 adam
291 * More isamb statistics
293 * Revision 1.25 2002/04/26 08:44:47 adam
294 * Index statistics working again
296 * Revision 1.24 2002/04/05 08:46:26 adam
297 * Zebra with full functionality
299 * Revision 1.23 2002/04/04 14:14:13 adam
300 * Multiple registers (alpha early)
302 * Revision 1.22 2002/02/20 17:30:01 adam
303 * Work on new API. Locking system re-implemented
305 * Revision 1.21 2000/07/13 10:14:20 heikki
306 * Removed compiler warnings when making zebra
308 * Revision 1.20 1999/12/01 13:30:30 adam
309 * Updated configure for Zmbol/Zebra dependent settings.
311 * Revision 1.19 1999/11/30 13:48:03 adam
312 * Improved installation. Updated for inclusion of YAZ header files.
314 * Revision 1.18 1999/10/06 11:46:36 heikki
315 * mproved statistics on isam-d
317 * Revision 1.17 1999/08/20 08:28:37 heikki
320 * Revision 1.16 1999/08/18 08:38:22 heikki
321 * Memory leak hunting
323 * Revision 1.15 1999/08/18 08:34:53 heikki
326 * Revision 1.14 1999/07/14 10:59:26 adam
327 * Changed functions isc_getmethod, isams_getmethod.
328 * Improved fatal error handling (such as missing EXPLAIN schema).
330 * Revision 1.13 1999/07/08 14:23:27 heikki
331 * Fixed a bug in isamh_pp_read and cleaned up a bit
333 * Revision 1.12 1999/07/06 12:28:04 adam
334 * Updated record index structure. Format includes version ID. Compression
335 * algorithm ID is stored for each record block.
337 * Revision 1.11 1999/05/15 14:36:38 adam
338 * Updated dictionary. Implemented "compression" of dictionary.
340 * Revision 1.10 1999/05/12 13:08:06 adam
341 * First version of ISAMS.
343 * Revision 1.9 1999/02/12 13:29:23 adam
344 * Implemented position-flag for registers.
346 * Revision 1.8 1999/02/02 14:50:53 adam
347 * Updated WIN32 code specific sections. Changed header.
349 * Revision 1.7 1998/03/13 15:30:50 adam
350 * New functions isc_block_used and isc_block_size. Fixed 'leak'
351 * in isc_alloc_block.
353 * Revision 1.6 1998/03/06 13:54:02 adam
354 * Fixed two nasty bugs in isc_merge.
356 * Revision 1.5 1997/09/17 12:19:13 adam
357 * Zebra version corresponds to YAZ version 1.4.
358 * Changed Zebra server so that it doesn't depend on global common_resource.
360 * Revision 1.4 1996/11/08 11:10:21 adam
361 * Buffers used during file match got bigger.
362 * Compressed ISAM support everywhere.
363 * Bug fixes regarding masking characters in queries.
364 * Redesigned Regexp-2 queries.
366 * Revision 1.3 1996/06/04 10:18:58 adam
367 * Minor changes - removed include of ctype.h.
369 * Revision 1.2 1996/05/22 08:25:56 adam
372 * Revision 1.1 1996/05/14 14:04:34 adam
373 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT