2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss, Heikki Levanto
15 #include "../isamc/isamd-p.h"
19 struct inv_stat_info {
26 int no_isam_entries[9];
30 int isam_occurrences[20];
34 #define SINGLETON_TYPE 8 /* the type to use for singletons that */
35 /* have no block and no block type */
37 static int inv_stat_handle (char *name, const char *info, int pos,
42 struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
45 stat_info->no_dict_entries++;
46 stat_info->no_dict_bytes += strlen(name);
48 assert (*info == sizeof(ISAMS_P));
49 memcpy (&isam_p, info+1, sizeof(ISAMS_P));
57 pp = isams_pp_open (stat_info->isams, isam_p);
58 occur = isams_pp_num (pp);
59 while (isams_pp_read(pp, &key))
61 //printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
64 assert (occurx == occur);
65 stat_info->no_isam_entries[0] += occur;
73 ispt = is_position (stat_info->isam, isam_p);
74 occur = is_numkeys (ispt);
83 pp = isc_pp_open (stat_info->isamc, isam_p);
84 occur = isc_pp_num (pp);
85 while (isc_pp_read(pp, &key))
87 //printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
90 assert (occurx == occur);
91 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
100 pp = isamd_pp_open (stat_info->isamd, isam_p);
102 occur = isamd_pp_num (pp);
103 while (isamd_pp_read(pp, &key))
106 if ( pp->is->method->debug >8 )
107 logf (LOG_LOG,"sysno=%d seqno=%d (%x/%x) oc=%d/%d ofs=%d ",
108 key.sysno, key.seqno,
109 key.sysno, key.seqno,
110 occur,occurx, pp->offset);
112 if ( pp->is->method->debug >7 )
113 logf(LOG_LOG,"item %d=%d:%d says %d keys, counted %d",
114 isam_p, isamd_type(isam_p), isamd_block(isam_p),
117 logf(LOG_LOG,"Count error!!! read %d, counted %d", occur, occurx);
118 assert (occurx == occur);
119 if ( is_singleton(isam_p) )
120 stat_info->no_isam_entries[SINGLETON_TYPE] += occur;
122 stat_info->no_isam_entries[isamd_type(isam_p)] += occur;
126 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
128 ++(stat_info->isam_occurrences[i]);
132 void inv_prstat (ZebraHandle zh)
134 BFiles bfs = zh->service->bfs;
148 int after = 1000000000;
149 struct inv_stat_info stat_info;
150 char term_dict[2*IT_MAX_WORD+2];
155 dict = dict_open (bfs, FNAME_DICT, 100, 0, 0);
158 logf (LOG_FATAL, "dict_open fail");
161 if (res_get_match (zh->service->res, "isam", "s", ISAM_DEFAULT))
163 struct ISAMS_M_s isams_m;
164 isams = isams_open (bfs, FNAME_ISAMS, 0,
165 key_isams_m(zh->service->res, &isams_m));
168 logf (LOG_FATAL, "isams_open fail");
173 else if (res_get_match (zh->service->res, "isam", "i", ISAM_DEFAULT))
175 isam = is_open (bfs, FNAME_ISAM, key_compare, 0,
176 sizeof(struct it_key), zh->service->res);
179 logf (LOG_FATAL, "is_open fail");
183 else if (res_get_match (zh->service->res, "isam", "d", ISAM_DEFAULT))
185 struct ISAMD_M_s isamd_m;
186 isamd = isamd_open (bfs, FNAME_ISAMD, 0,
187 key_isamd_m(zh->service->res,&isamd_m));
190 logf (LOG_FATAL, "isamd_open fail");
194 else if (res_get_match (zh->service->res, "isam", "c", ISAM_DEFAULT))
196 struct ISAMC_M_s isamc_m;
197 isamc = isc_open (bfs, FNAME_ISAMC, 0,
198 key_isamc_m (zh->service->res, &isamc_m));
201 logf (LOG_FATAL, "isc_open fail");
206 records = rec_open (bfs, 0, 0);
208 for (i = 0; i<=SINGLETON_TYPE; i++)
209 stat_info.no_isam_entries[i] = 0;
210 stat_info.no_dict_entries = 0;
211 stat_info.no_dict_bytes = 0;
212 stat_info.isams = isams;
214 stat_info.isam = isam;
215 stat_info.isamc = isamc;
216 stat_info.isamd = isamd;
218 stat_info.isam_bounds[0] = 1;
219 stat_info.isam_bounds[1] = 2;
220 stat_info.isam_bounds[2] = 3;
221 stat_info.isam_bounds[3] = 6;
222 stat_info.isam_bounds[4] = 10;
223 stat_info.isam_bounds[5] = 20;
224 stat_info.isam_bounds[6] = 30;
225 stat_info.isam_bounds[7] = 50;
226 stat_info.isam_bounds[8] = 100;
227 stat_info.isam_bounds[9] = 200;
228 stat_info.isam_bounds[10] = 5000;
229 stat_info.isam_bounds[11] = 10000;
230 stat_info.isam_bounds[12] = 20000;
231 stat_info.isam_bounds[13] = 50000;
232 stat_info.isam_bounds[14] = 100000;
233 stat_info.isam_bounds[15] = 200000;
234 stat_info.isam_bounds[16] = 500000;
235 stat_info.isam_bounds[17] = 1000000;
236 stat_info.isam_bounds[18] = 0;
238 for (i = 0; i<20; i++)
239 stat_info.isam_occurrences[i] = 0;
241 dict_scan (dict, term_dict, &before, &after, &stat_info, inv_stat_handle);
246 fprintf (stderr, " Blocks Occur Size KB Bytes/Entry\n");
247 for (i = 0; isc_block_used (isamc, i) >= 0; i++)
249 fprintf (stderr, " %8d %8d", isc_block_used (isamc, i),
250 stat_info.no_isam_entries[i]);
252 if (stat_info.no_isam_entries[i])
253 fprintf (stderr, " %8d %f",
254 (int) ((1023.0 + (double) isc_block_used(isamc, i) *
255 isc_block_size(isamc,i))/1024),
256 ((double) isc_block_used(isamc, i) *
257 isc_block_size(isamc,i))/
258 stat_info.no_isam_entries[i]);
259 fprintf (stderr, "\n");
264 fprintf (stderr, " Blocks Occur KB Bytes/Entry\n");
265 if (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(isamd,i);
270 size= isamd_block_size(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 (stderr, "%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 (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 ( (isamd) && (isamd->method->debug>0))
293 fprintf (stderr, "\n%d words using %d bytes\n",
294 stat_info.no_dict_entries, stat_info.no_dict_bytes);
296 fprintf (stderr, " Occurrences Words\n");
298 for (i = 0; stat_info.isam_bounds[i]; i++)
300 int here = stat_info.isam_bounds[i];
301 fprintf (stderr, "%7d-%-7d %7d\n",
302 prev, here, stat_info.isam_occurrences[i]);
305 fprintf (stderr, "%7d- %7d\n",
306 prev, stat_info.isam_occurrences[i]);
307 rec_close (&records);
321 xmalloc_trav("unfreed"); /*! while hunting memory leaks */
327 * $Log: invstat.c,v $
328 * Revision 1.22 2002-02-20 17:30:01 adam
329 * Work on new API. Locking system re-implemented
331 * Revision 1.21 2000/07/13 10:14:20 heikki
332 * Removed compiler warnings when making zebra
334 * Revision 1.20 1999/12/01 13:30:30 adam
335 * Updated configure for Zmbol/Zebra dependent settings.
337 * Revision 1.19 1999/11/30 13:48:03 adam
338 * Improved installation. Updated for inclusion of YAZ header files.
340 * Revision 1.18 1999/10/06 11:46:36 heikki
341 * mproved statistics on isam-d
343 * Revision 1.17 1999/08/20 08:28:37 heikki
346 * Revision 1.16 1999/08/18 08:38:22 heikki
347 * Memory leak hunting
349 * Revision 1.15 1999/08/18 08:34:53 heikki
352 * Revision 1.14 1999/07/14 10:59:26 adam
353 * Changed functions isc_getmethod, isams_getmethod.
354 * Improved fatal error handling (such as missing EXPLAIN schema).
356 * Revision 1.13 1999/07/08 14:23:27 heikki
357 * Fixed a bug in isamh_pp_read and cleaned up a bit
359 * Revision 1.12 1999/07/06 12:28:04 adam
360 * Updated record index structure. Format includes version ID. Compression
361 * algorithm ID is stored for each record block.
363 * Revision 1.11 1999/05/15 14:36:38 adam
364 * Updated dictionary. Implemented "compression" of dictionary.
366 * Revision 1.10 1999/05/12 13:08:06 adam
367 * First version of ISAMS.
369 * Revision 1.9 1999/02/12 13:29:23 adam
370 * Implemented position-flag for registers.
372 * Revision 1.8 1999/02/02 14:50:53 adam
373 * Updated WIN32 code specific sections. Changed header.
375 * Revision 1.7 1998/03/13 15:30:50 adam
376 * New functions isc_block_used and isc_block_size. Fixed 'leak'
377 * in isc_alloc_block.
379 * Revision 1.6 1998/03/06 13:54:02 adam
380 * Fixed two nasty bugs in isc_merge.
382 * Revision 1.5 1997/09/17 12:19:13 adam
383 * Zebra version corresponds to YAZ version 1.4.
384 * Changed Zebra server so that it doesn't depend on global common_resource.
386 * Revision 1.4 1996/11/08 11:10:21 adam
387 * Buffers used during file match got bigger.
388 * Compressed ISAM support everywhere.
389 * Bug fixes regarding masking characters in queries.
390 * Redesigned Regexp-2 queries.
392 * Revision 1.3 1996/06/04 10:18:58 adam
393 * Minor changes - removed include of ctype.h.
395 * Revision 1.2 1996/05/22 08:25:56 adam
398 * Revision 1.1 1996/05/14 14:04:34 adam
399 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT