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];
25 #define SINGLETON_TYPE 8 /* the type to use for singletons that */
26 /* have no block and no block type */
28 static int inv_stat_handle (char *name, const char *info, int pos,
33 struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
36 stat_info->no_dict_entries++;
37 stat_info->no_dict_bytes += strlen(name);
39 assert (*info == sizeof(ISAMS_P));
40 memcpy (&isam_p, info+1, sizeof(ISAMS_P));
42 if (stat_info->zh->reg->isams)
48 pp = isams_pp_open (stat_info->zh->reg->isams, isam_p);
49 occur = isams_pp_num (pp);
50 while (isams_pp_read(pp, &key))
52 //printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
55 assert (occurx == occur);
56 stat_info->no_isam_entries[0] += occur;
59 if (stat_info->zh->reg->isam)
63 ispt = is_position (stat_info->zh->reg->isam, isam_p);
64 occur = is_numkeys (ispt);
67 if (stat_info->zh->reg->isamc)
73 pp = isc_pp_open (stat_info->zh->reg->isamc, isam_p);
74 occur = isc_pp_num (pp);
75 while (isc_pp_read(pp, &key))
77 //printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
80 assert (occurx == occur);
81 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
84 if (stat_info->zh->reg->isamd)
90 pp = isamd_pp_open (stat_info->zh->reg->isamd, isam_p);
92 occur = isamd_pp_num (pp);
93 while (isamd_pp_read(pp, &key))
96 if ( pp->is->method->debug >8 )
97 logf (LOG_LOG,"sysno=%d seqno=%d (%x/%x) oc=%d/%d ofs=%d ",
100 occur,occurx, pp->offset);
102 if ( pp->is->method->debug >7 )
103 logf(LOG_LOG,"item %d=%d:%d says %d keys, counted %d",
104 isam_p, isamd_type(isam_p), isamd_block(isam_p),
107 logf(LOG_LOG,"Count error!!! read %d, counted %d", occur, occurx);
108 assert (occurx == occur);
109 if ( is_singleton(isam_p) )
110 stat_info->no_isam_entries[SINGLETON_TYPE] += occur;
112 stat_info->no_isam_entries[isamd_type(isam_p)] += occur;
115 if (stat_info->zh->reg->isamb)
120 pp = isamb_pp_open(stat_info->zh->reg->isamb, isam_p);
121 while (isamb_pp_read(pp, &key))
126 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
128 ++(stat_info->isam_occurrences[i]);
132 void zebra_register_statistics (ZebraHandle zh)
139 int after = 1000000000;
140 struct inv_stat_info stat_info;
141 char term_dict[2*IT_MAX_WORD+2];
143 if (zebra_begin_read (zh))
151 for (i = 0; i<=SINGLETON_TYPE; i++)
152 stat_info.no_isam_entries[i] = 0;
153 stat_info.no_dict_entries = 0;
154 stat_info.no_dict_bytes = 0;
155 stat_info.isam_bounds[0] = 1;
156 stat_info.isam_bounds[1] = 2;
157 stat_info.isam_bounds[2] = 3;
158 stat_info.isam_bounds[3] = 6;
159 stat_info.isam_bounds[4] = 10;
160 stat_info.isam_bounds[5] = 20;
161 stat_info.isam_bounds[6] = 30;
162 stat_info.isam_bounds[7] = 50;
163 stat_info.isam_bounds[8] = 100;
164 stat_info.isam_bounds[9] = 200;
165 stat_info.isam_bounds[10] = 5000;
166 stat_info.isam_bounds[11] = 10000;
167 stat_info.isam_bounds[12] = 20000;
168 stat_info.isam_bounds[13] = 50000;
169 stat_info.isam_bounds[14] = 100000;
170 stat_info.isam_bounds[15] = 200000;
171 stat_info.isam_bounds[16] = 500000;
172 stat_info.isam_bounds[17] = 1000000;
173 stat_info.isam_bounds[18] = 0;
175 for (i = 0; i<20; i++)
176 stat_info.isam_occurrences[i] = 0;
178 dict_scan (zh->reg->dict, term_dict, &before, &after, &stat_info,
183 fprintf (stderr, " Blocks Occur Size KB Bytes/Entry\n");
184 for (i = 0; isc_block_used (zh->reg->isamc, i) >= 0; i++)
186 fprintf (stderr, " %8d %8d", isc_block_used (zh->reg->isamc, i),
187 stat_info.no_isam_entries[i]);
189 if (stat_info.no_isam_entries[i])
190 fprintf (stderr, " %8d %f",
191 (int) ((1023.0 + (double)
192 isc_block_used(zh->reg->isamc, i) *
193 isc_block_size(zh->reg->isamc,i))/1024),
194 ((double) isc_block_used(zh->reg->isamc, i) *
195 isc_block_size(zh->reg->isamc,i))/
196 stat_info.no_isam_entries[i]);
197 fprintf (stderr, "\n");
202 fprintf (stderr, " Blocks Occur KB Bytes/Entry\n");
203 if (zh->reg->isamd->method->debug >0)
204 logf(LOG_LOG," Blocks Occur KB Bytes/Entry");
205 for (i = 0; i<=SINGLETON_TYPE; i++)
207 blocks= isamd_block_used(zh->reg->isamd,i);
208 size= isamd_block_size(zh->reg->isamd,i);
209 count=stat_info.no_isam_entries[i];
210 if (i==SINGLETON_TYPE)
212 if (stat_info.no_isam_entries[i])
214 fprintf (stderr, "%c %7d %7d %7d %5.2f\n",
215 (i==SINGLETON_TYPE)?('z'):('A'+i),
218 (int) ((1023.0 + (double) blocks * size)/1024),
219 ((double) blocks * size)/count);
220 if (zh->reg->isamd->method->debug >0)
221 logf(LOG_LOG, "%c %7d %7d %7d %5.2f",
222 (i==SINGLETON_TYPE)?('z'):('A'+i),
225 (int) ((1023.0 + (double) blocks * size)/1024),
226 ((double) blocks * size)/count);
230 if ( (zh->reg->isamd) && (zh->reg->isamd->method->debug>0))
231 fprintf (stderr, "\n%d words using %d bytes\n",
232 stat_info.no_dict_entries, stat_info.no_dict_bytes);
233 fprintf (stderr, " Occurrences Words\n");
235 for (i = 0; stat_info.isam_bounds[i]; i++)
237 int here = stat_info.isam_bounds[i];
238 fprintf (stderr, "%7d-%-7d %7d\n",
239 prev, here, stat_info.isam_occurrences[i]);
242 fprintf (stderr, "%7d- %7d\n",
243 prev, stat_info.isam_occurrences[i]);
244 xmalloc_trav("unfreed"); /*! while hunting memory leaks */
251 * $Log: invstat.c,v $
252 * Revision 1.25 2002-04-26 08:44:47 adam
253 * Index statistics working again
255 * Revision 1.24 2002/04/05 08:46:26 adam
256 * Zebra with full functionality
258 * Revision 1.23 2002/04/04 14:14:13 adam
259 * Multiple registers (alpha early)
261 * Revision 1.22 2002/02/20 17:30:01 adam
262 * Work on new API. Locking system re-implemented
264 * Revision 1.21 2000/07/13 10:14:20 heikki
265 * Removed compiler warnings when making zebra
267 * Revision 1.20 1999/12/01 13:30:30 adam
268 * Updated configure for Zmbol/Zebra dependent settings.
270 * Revision 1.19 1999/11/30 13:48:03 adam
271 * Improved installation. Updated for inclusion of YAZ header files.
273 * Revision 1.18 1999/10/06 11:46:36 heikki
274 * mproved statistics on isam-d
276 * Revision 1.17 1999/08/20 08:28:37 heikki
279 * Revision 1.16 1999/08/18 08:38:22 heikki
280 * Memory leak hunting
282 * Revision 1.15 1999/08/18 08:34:53 heikki
285 * Revision 1.14 1999/07/14 10:59:26 adam
286 * Changed functions isc_getmethod, isams_getmethod.
287 * Improved fatal error handling (such as missing EXPLAIN schema).
289 * Revision 1.13 1999/07/08 14:23:27 heikki
290 * Fixed a bug in isamh_pp_read and cleaned up a bit
292 * Revision 1.12 1999/07/06 12:28:04 adam
293 * Updated record index structure. Format includes version ID. Compression
294 * algorithm ID is stored for each record block.
296 * Revision 1.11 1999/05/15 14:36:38 adam
297 * Updated dictionary. Implemented "compression" of dictionary.
299 * Revision 1.10 1999/05/12 13:08:06 adam
300 * First version of ISAMS.
302 * Revision 1.9 1999/02/12 13:29:23 adam
303 * Implemented position-flag for registers.
305 * Revision 1.8 1999/02/02 14:50:53 adam
306 * Updated WIN32 code specific sections. Changed header.
308 * Revision 1.7 1998/03/13 15:30:50 adam
309 * New functions isc_block_used and isc_block_size. Fixed 'leak'
310 * in isc_alloc_block.
312 * Revision 1.6 1998/03/06 13:54:02 adam
313 * Fixed two nasty bugs in isc_merge.
315 * Revision 1.5 1997/09/17 12:19:13 adam
316 * Zebra version corresponds to YAZ version 1.4.
317 * Changed Zebra server so that it doesn't depend on global common_resource.
319 * Revision 1.4 1996/11/08 11:10:21 adam
320 * Buffers used during file match got bigger.
321 * Compressed ISAM support everywhere.
322 * Bug fixes regarding masking characters in queries.
323 * Redesigned Regexp-2 queries.
325 * Revision 1.3 1996/06/04 10:18:58 adam
326 * Minor changes - removed include of ctype.h.
328 * Revision 1.2 1996/05/22 08:25:56 adam
331 * Revision 1.1 1996/05/14 14:04:34 adam
332 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT