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 {
20 int no_isam_entries[9];
24 int isam_occurrences[20];
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));
51 pp = isams_pp_open (stat_info->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;
66 ispt = is_position (stat_info->isam, isam_p);
67 occur = is_numkeys (ispt);
76 pp = isc_pp_open (stat_info->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;
93 pp = isamd_pp_open (stat_info->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 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
120 ++(stat_info->isam_occurrences[i]);
124 void inv_prstat (ZebraHandle zh)
139 int after = 1000000000;
140 struct inv_stat_info stat_info;
141 char term_dict[2*IT_MAX_WORD+2];
143 if (!res || !zh->reg)
151 dict = dict_open (bfs, FNAME_DICT, 100, 0, 0);
154 logf (LOG_FATAL, "dict_open fail");
157 if (res_get_match (res, "isam", "s", ISAM_DEFAULT))
159 struct ISAMS_M_s isams_m;
160 isams = isams_open (bfs, FNAME_ISAMS, 0,
161 key_isams_m(res, &isams_m));
164 logf (LOG_FATAL, "isams_open fail");
168 else if (res_get_match (res, "isam", "i", ISAM_DEFAULT))
170 isam = is_open (bfs, FNAME_ISAM, key_compare, 0,
171 sizeof(struct it_key), res);
174 logf (LOG_FATAL, "is_open fail");
178 else if (res_get_match (res, "isam", "d", ISAM_DEFAULT))
180 struct ISAMD_M_s isamd_m;
181 isamd = isamd_open (bfs, FNAME_ISAMD, 0,
182 key_isamd_m(res,&isamd_m));
185 logf (LOG_FATAL, "isamd_open fail");
189 else if (res_get_match (res, "isam", "c", ISAM_DEFAULT))
191 struct ISAMC_M_s isamc_m;
192 isamc = isc_open (bfs, FNAME_ISAMC, 0,
193 key_isamc_m (res, &isamc_m));
196 logf (LOG_FATAL, "isc_open fail");
200 records = rec_open (bfs, 0, 0);
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.isams = isams;
207 stat_info.isam = isam;
208 stat_info.isamc = isamc;
209 stat_info.isamd = isamd;
210 stat_info.isam_bounds[0] = 1;
211 stat_info.isam_bounds[1] = 2;
212 stat_info.isam_bounds[2] = 3;
213 stat_info.isam_bounds[3] = 6;
214 stat_info.isam_bounds[4] = 10;
215 stat_info.isam_bounds[5] = 20;
216 stat_info.isam_bounds[6] = 30;
217 stat_info.isam_bounds[7] = 50;
218 stat_info.isam_bounds[8] = 100;
219 stat_info.isam_bounds[9] = 200;
220 stat_info.isam_bounds[10] = 5000;
221 stat_info.isam_bounds[11] = 10000;
222 stat_info.isam_bounds[12] = 20000;
223 stat_info.isam_bounds[13] = 50000;
224 stat_info.isam_bounds[14] = 100000;
225 stat_info.isam_bounds[15] = 200000;
226 stat_info.isam_bounds[16] = 500000;
227 stat_info.isam_bounds[17] = 1000000;
228 stat_info.isam_bounds[18] = 0;
230 for (i = 0; i<20; i++)
231 stat_info.isam_occurrences[i] = 0;
233 dict_scan (dict, term_dict, &before, &after, &stat_info, inv_stat_handle);
237 fprintf (stderr, " Blocks Occur Size KB Bytes/Entry\n");
238 for (i = 0; isc_block_used (isamc, i) >= 0; i++)
240 fprintf (stderr, " %8d %8d", isc_block_used (isamc, i),
241 stat_info.no_isam_entries[i]);
243 if (stat_info.no_isam_entries[i])
244 fprintf (stderr, " %8d %f",
245 (int) ((1023.0 + (double) isc_block_used(isamc, i) *
246 isc_block_size(isamc,i))/1024),
247 ((double) isc_block_used(isamc, i) *
248 isc_block_size(isamc,i))/
249 stat_info.no_isam_entries[i]);
250 fprintf (stderr, "\n");
255 fprintf (stderr, " Blocks Occur KB Bytes/Entry\n");
256 if (isamd->method->debug >0)
257 logf(LOG_LOG," Blocks Occur KB Bytes/Entry");
258 for (i = 0; i<=SINGLETON_TYPE; i++)
260 blocks= isamd_block_used(isamd,i);
261 size= isamd_block_size(isamd,i);
262 count=stat_info.no_isam_entries[i];
263 if (i==SINGLETON_TYPE)
265 if (stat_info.no_isam_entries[i])
267 fprintf (stderr, "%c %7d %7d %7d %5.2f\n",
268 (i==SINGLETON_TYPE)?('z'):('A'+i),
271 (int) ((1023.0 + (double) blocks * size)/1024),
272 ((double) blocks * size)/count);
273 if (isamd->method->debug >0)
274 logf(LOG_LOG, "%c %7d %7d %7d %5.2f",
275 (i==SINGLETON_TYPE)?('z'):('A'+i),
278 (int) ((1023.0 + (double) blocks * size)/1024),
279 ((double) blocks * size)/count);
283 if ( (isamd) && (isamd->method->debug>0))
284 fprintf (stderr, "\n%d words using %d bytes\n",
285 stat_info.no_dict_entries, stat_info.no_dict_bytes);
286 fprintf (stderr, " Occurrences Words\n");
288 for (i = 0; stat_info.isam_bounds[i]; i++)
290 int here = stat_info.isam_bounds[i];
291 fprintf (stderr, "%7d-%-7d %7d\n",
292 prev, here, stat_info.isam_occurrences[i]);
295 fprintf (stderr, "%7d- %7d\n",
296 prev, stat_info.isam_occurrences[i]);
297 rec_close (&records);
308 xmalloc_trav("unfreed"); /*! while hunting memory leaks */
314 * $Log: invstat.c,v $
315 * Revision 1.24 2002-04-05 08:46:26 adam
316 * Zebra with full functionality
318 * Revision 1.23 2002/04/04 14:14:13 adam
319 * Multiple registers (alpha early)
321 * Revision 1.22 2002/02/20 17:30:01 adam
322 * Work on new API. Locking system re-implemented
324 * Revision 1.21 2000/07/13 10:14:20 heikki
325 * Removed compiler warnings when making zebra
327 * Revision 1.20 1999/12/01 13:30:30 adam
328 * Updated configure for Zmbol/Zebra dependent settings.
330 * Revision 1.19 1999/11/30 13:48:03 adam
331 * Improved installation. Updated for inclusion of YAZ header files.
333 * Revision 1.18 1999/10/06 11:46:36 heikki
334 * mproved statistics on isam-d
336 * Revision 1.17 1999/08/20 08:28:37 heikki
339 * Revision 1.16 1999/08/18 08:38:22 heikki
340 * Memory leak hunting
342 * Revision 1.15 1999/08/18 08:34:53 heikki
345 * Revision 1.14 1999/07/14 10:59:26 adam
346 * Changed functions isc_getmethod, isams_getmethod.
347 * Improved fatal error handling (such as missing EXPLAIN schema).
349 * Revision 1.13 1999/07/08 14:23:27 heikki
350 * Fixed a bug in isamh_pp_read and cleaned up a bit
352 * Revision 1.12 1999/07/06 12:28:04 adam
353 * Updated record index structure. Format includes version ID. Compression
354 * algorithm ID is stored for each record block.
356 * Revision 1.11 1999/05/15 14:36:38 adam
357 * Updated dictionary. Implemented "compression" of dictionary.
359 * Revision 1.10 1999/05/12 13:08:06 adam
360 * First version of ISAMS.
362 * Revision 1.9 1999/02/12 13:29:23 adam
363 * Implemented position-flag for registers.
365 * Revision 1.8 1999/02/02 14:50:53 adam
366 * Updated WIN32 code specific sections. Changed header.
368 * Revision 1.7 1998/03/13 15:30:50 adam
369 * New functions isc_block_used and isc_block_size. Fixed 'leak'
370 * in isc_alloc_block.
372 * Revision 1.6 1998/03/06 13:54:02 adam
373 * Fixed two nasty bugs in isc_merge.
375 * Revision 1.5 1997/09/17 12:19:13 adam
376 * Zebra version corresponds to YAZ version 1.4.
377 * Changed Zebra server so that it doesn't depend on global common_resource.
379 * Revision 1.4 1996/11/08 11:10:21 adam
380 * Buffers used during file match got bigger.
381 * Compressed ISAM support everywhere.
382 * Bug fixes regarding masking characters in queries.
383 * Redesigned Regexp-2 queries.
385 * Revision 1.3 1996/06/04 10:18:58 adam
386 * Minor changes - removed include of ctype.h.
388 * Revision 1.2 1996/05/22 08:25:56 adam
391 * Revision 1.1 1996/05/14 14:04:34 adam
392 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT