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];
28 #define SINGLETON_TYPE 8 /* the type to use for singletons that */
29 /* have no block and no block type */
31 static int inv_stat_handle (char *name, const char *info, int pos,
36 struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
39 stat_info->no_dict_entries++;
40 stat_info->no_dict_bytes += strlen(name);
42 assert (*info == sizeof(ISAMS_P));
43 memcpy (&isam_p, info+1, sizeof(ISAMS_P));
45 if (stat_info->zh->reg->isams)
51 pp = isams_pp_open (stat_info->zh->reg->isams, isam_p);
52 occur = isams_pp_num (pp);
53 while (isams_pp_read(pp, &key))
55 //printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
58 assert (occurx == occur);
59 stat_info->no_isam_entries[0] += occur;
62 if (stat_info->zh->reg->isam)
66 ispt = is_position (stat_info->zh->reg->isam, isam_p);
67 occur = is_numkeys (ispt);
70 if (stat_info->zh->reg->isamc)
76 pp = isc_pp_open (stat_info->zh->reg->isamc, isam_p);
77 occur = isc_pp_num (pp);
78 while (isc_pp_read(pp, &key))
80 //printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
83 assert (occurx == occur);
84 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
87 if (stat_info->zh->reg->isamd)
93 pp = isamd_pp_open (stat_info->zh->reg->isamd, isam_p);
95 occur = isamd_pp_num (pp);
96 while (isamd_pp_read(pp, &key))
99 if ( pp->is->method->debug >8 )
100 logf (LOG_LOG,"sysno=%d seqno=%d (%x/%x) oc=%d/%d ofs=%d ",
101 key.sysno, key.seqno,
102 key.sysno, key.seqno,
103 occur,occurx, pp->offset);
105 if ( pp->is->method->debug >7 )
106 logf(LOG_LOG,"item %d=%d:%d says %d keys, counted %d",
107 isam_p, isamd_type(isam_p), isamd_block(isam_p),
110 logf(LOG_LOG,"Count error!!! read %d, counted %d", occur, occurx);
111 assert (occurx == occur);
112 if ( is_singleton(isam_p) )
113 stat_info->no_isam_entries[SINGLETON_TYPE] += occur;
115 stat_info->no_isam_entries[isamd_type(isam_p)] += occur;
118 if (stat_info->zh->reg->isamb)
122 int cat = isam_p & 3;
127 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_blocks[cat] += blocks;
133 stat_info->isamb_sizes[cat] += size;
136 stat_info->isamb_levels[cat][level] ++;
139 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
141 ++(stat_info->isam_occurrences[i]);
145 void zebra_register_statistics (ZebraHandle zh)
152 int after = 1000000000;
153 struct inv_stat_info stat_info;
154 char term_dict[2*IT_MAX_WORD+2];
156 if (zebra_begin_read (zh))
164 for (i = 0; i<=SINGLETON_TYPE; i++)
165 stat_info.no_isam_entries[i] = 0;
166 stat_info.no_dict_entries = 0;
167 stat_info.no_dict_bytes = 0;
168 stat_info.isam_bounds[0] = 1;
169 stat_info.isam_bounds[1] = 2;
170 stat_info.isam_bounds[2] = 3;
171 stat_info.isam_bounds[3] = 6;
172 stat_info.isam_bounds[4] = 10;
173 stat_info.isam_bounds[5] = 20;
174 stat_info.isam_bounds[6] = 30;
175 stat_info.isam_bounds[7] = 50;
176 stat_info.isam_bounds[8] = 100;
177 stat_info.isam_bounds[9] = 200;
178 stat_info.isam_bounds[10] = 5000;
179 stat_info.isam_bounds[11] = 10000;
180 stat_info.isam_bounds[12] = 20000;
181 stat_info.isam_bounds[13] = 50000;
182 stat_info.isam_bounds[14] = 100000;
183 stat_info.isam_bounds[15] = 200000;
184 stat_info.isam_bounds[16] = 500000;
185 stat_info.isam_bounds[17] = 1000000;
186 stat_info.isam_bounds[18] = 0;
188 for (i = 0; i<20; i++)
189 stat_info.isam_occurrences[i] = 0;
191 for (i = 0; i<10; i++)
194 for (j = 0; j<5; j++)
195 stat_info.isamb_levels[i][j] = 0;
196 stat_info.isamb_sizes[i] = 0;
197 stat_info.isamb_blocks[i] = 0;
200 dict_scan (zh->reg->dict, term_dict, &before, &after, &stat_info,
205 fprintf (stderr, " Blocks Occur Size KB Bytes/Entry\n");
206 for (i = 0; isc_block_used (zh->reg->isamc, i) >= 0; i++)
208 fprintf (stderr, " %8d %8d", isc_block_used (zh->reg->isamc, i),
209 stat_info.no_isam_entries[i]);
211 if (stat_info.no_isam_entries[i])
212 fprintf (stderr, " %8d %f",
213 (int) ((1023.0 + (double)
214 isc_block_used(zh->reg->isamc, i) *
215 isc_block_size(zh->reg->isamc,i))/1024),
216 ((double) isc_block_used(zh->reg->isamc, i) *
217 isc_block_size(zh->reg->isamc,i))/
218 stat_info.no_isam_entries[i]);
219 fprintf (stderr, "\n");
224 fprintf (stderr, " Blocks Occur KB Bytes/Entry\n");
225 if (zh->reg->isamd->method->debug >0)
226 logf(LOG_LOG," Blocks Occur KB Bytes/Entry");
227 for (i = 0; i<=SINGLETON_TYPE; i++)
229 blocks= isamd_block_used(zh->reg->isamd,i);
230 size= isamd_block_size(zh->reg->isamd,i);
231 count=stat_info.no_isam_entries[i];
232 if (i==SINGLETON_TYPE)
234 if (stat_info.no_isam_entries[i])
236 fprintf (stderr, "%c %7d %7d %7d %5.2f\n",
237 (i==SINGLETON_TYPE)?('z'):('A'+i),
240 (int) ((1023.0 + (double) blocks * size)/1024),
241 ((double) blocks * size)/count);
242 if (zh->reg->isamd->method->debug >0)
243 logf(LOG_LOG, "%c %7d %7d %7d %5.2f",
244 (i==SINGLETON_TYPE)?('z'):('A'+i),
247 (int) ((1023.0 + (double) blocks * size)/1024),
248 ((double) blocks * size)/count);
252 if ( (zh->reg->isamd) && (zh->reg->isamd->method->debug>0))
253 fprintf (stderr, "\n%d words using %d bytes\n",
254 stat_info.no_dict_entries, stat_info.no_dict_bytes);
258 for (i = 0; i<4; i++)
261 int bsize = isamb_block_info(zh->reg->isamb, i);
264 fprintf (stderr, "Category %d\n", i);
265 fprintf (stderr, "Block size %d\n", bsize);
266 fprintf (stderr, "Blocks: %d\n", stat_info.isamb_blocks[i]);
267 fprintf (stderr, "Size: %d\n", stat_info.isamb_sizes[i]);
268 fprintf (stderr, "Total %d\n", stat_info.isamb_blocks[i]*
270 for (j = 0; j<5; j++)
271 if (stat_info.isamb_levels[i][j])
272 fprintf (stderr, "Level%d %d\n", j,
273 stat_info.isamb_levels[i][j]);
277 fprintf (stderr, " Occurrences Words\n");
279 for (i = 0; stat_info.isam_bounds[i]; i++)
281 int here = stat_info.isam_bounds[i];
282 fprintf (stderr, "%7d-%-7d %7d\n",
283 prev, here, stat_info.isam_occurrences[i]);
286 fprintf (stderr, "%7d- %7d\n",
287 prev, stat_info.isam_occurrences[i]);
288 xmalloc_trav("unfreed"); /*! while hunting memory leaks */
295 * $Log: invstat.c,v $
296 * Revision 1.27 2002-04-30 08:28:37 adam
297 * isamb fixes for pp_read. Statistics
299 * Revision 1.26 2002/04/29 18:03:46 adam
300 * More isamb statistics
302 * Revision 1.25 2002/04/26 08:44:47 adam
303 * Index statistics working again
305 * Revision 1.24 2002/04/05 08:46:26 adam
306 * Zebra with full functionality
308 * Revision 1.23 2002/04/04 14:14:13 adam
309 * Multiple registers (alpha early)
311 * Revision 1.22 2002/02/20 17:30:01 adam
312 * Work on new API. Locking system re-implemented
314 * Revision 1.21 2000/07/13 10:14:20 heikki
315 * Removed compiler warnings when making zebra
317 * Revision 1.20 1999/12/01 13:30:30 adam
318 * Updated configure for Zmbol/Zebra dependent settings.
320 * Revision 1.19 1999/11/30 13:48:03 adam
321 * Improved installation. Updated for inclusion of YAZ header files.
323 * Revision 1.18 1999/10/06 11:46:36 heikki
324 * mproved statistics on isam-d
326 * Revision 1.17 1999/08/20 08:28:37 heikki
329 * Revision 1.16 1999/08/18 08:38:22 heikki
330 * Memory leak hunting
332 * Revision 1.15 1999/08/18 08:34:53 heikki
335 * Revision 1.14 1999/07/14 10:59:26 adam
336 * Changed functions isc_getmethod, isams_getmethod.
337 * Improved fatal error handling (such as missing EXPLAIN schema).
339 * Revision 1.13 1999/07/08 14:23:27 heikki
340 * Fixed a bug in isamh_pp_read and cleaned up a bit
342 * Revision 1.12 1999/07/06 12:28:04 adam
343 * Updated record index structure. Format includes version ID. Compression
344 * algorithm ID is stored for each record block.
346 * Revision 1.11 1999/05/15 14:36:38 adam
347 * Updated dictionary. Implemented "compression" of dictionary.
349 * Revision 1.10 1999/05/12 13:08:06 adam
350 * First version of ISAMS.
352 * Revision 1.9 1999/02/12 13:29:23 adam
353 * Implemented position-flag for registers.
355 * Revision 1.8 1999/02/02 14:50:53 adam
356 * Updated WIN32 code specific sections. Changed header.
358 * Revision 1.7 1998/03/13 15:30:50 adam
359 * New functions isc_block_used and isc_block_size. Fixed 'leak'
360 * in isc_alloc_block.
362 * Revision 1.6 1998/03/06 13:54:02 adam
363 * Fixed two nasty bugs in isc_merge.
365 * Revision 1.5 1997/09/17 12:19:13 adam
366 * Zebra version corresponds to YAZ version 1.4.
367 * Changed Zebra server so that it doesn't depend on global common_resource.
369 * Revision 1.4 1996/11/08 11:10:21 adam
370 * Buffers used during file match got bigger.
371 * Compressed ISAM support everywhere.
372 * Bug fixes regarding masking characters in queries.
373 * Redesigned Regexp-2 queries.
375 * Revision 1.3 1996/06/04 10:18:58 adam
376 * Minor changes - removed include of ctype.h.
378 * Revision 1.2 1996/05/22 08:25:56 adam
381 * Revision 1.1 1996/05/14 14:04:34 adam
382 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT