2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss, Heikki Levanto
14 #include "../isamc/isamh-p.h"
15 #include "../isamc/isamd-p.h"
17 struct inv_stat_info {
23 int no_isam_entries[8];
27 int isam_occurrences[20];
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(ISAM_P));
43 memcpy (&isam_p, info+1, sizeof(ISAM_P));
50 ispt = is_position (stat_info->isam, isam_p);
51 occur = is_numkeys (ispt);
60 pp = isc_pp_open (stat_info->isamc, isam_p);
61 occur = isc_pp_num (pp);
62 while (isc_pp_read(pp, &key))
64 printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
67 assert (occurx == occur);
68 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
77 pp = isamh_pp_open (stat_info->isamh, isam_p);
79 occur = isamh_pp_num (pp);
80 // printf (" opening item %d=%d:%d \n",
81 // isam_p, isamh_type(isam_p),isamh_block(isam_p));
82 while (isamh_pp_read(pp, &key))
85 logf (LOG_LOG,"sysno=%d seqno=%d (%x/%x) oc=%d/%d ofs=%d ",
88 occur,occurx, pp->offset);
91 logf(LOG_LOG,"Count error!!! read %d, counted %d", occur, occurx);
92 assert (occurx == occur);
93 stat_info->no_isam_entries[isamh_type(isam_p)] += occur;
102 pp = isamd_pp_open (stat_info->isamd, isam_p);
104 occur = isamd_pp_num (pp);
105 // printf (" opening item %d=%d:%d \n",
106 // isam_p, isamh_type(isam_p),isamh_block(isam_p));
107 while (isamd_pp_read(pp, &key))
110 logf (LOG_LOG,"sysno=%d seqno=%d (%x/%x) oc=%d/%d ofs=%d ",
111 key.sysno, key.seqno,
112 key.sysno, key.seqno,
113 occur,occurx, pp->offset);
116 logf(LOG_LOG,"Count error!!! read %d, counted %d", occur, occurx);
117 assert (occurx == occur);
118 stat_info->no_isam_entries[isamd_type(isam_p)] += occur;
121 if (stat_info->isams)
127 pp = isams_pp_open (stat_info->isams, isam_p);
128 occur = isams_pp_num (pp);
129 while (isams_pp_read(pp, &key))
131 //printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
134 assert (occurx == occur);
135 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
139 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
141 ++(stat_info->isam_occurrences[i]);
145 void inv_prstat (BFiles bfs)
156 int after = 1000000000;
157 struct inv_stat_info stat_info;
158 char term_dict[2*IT_MAX_WORD+2];
163 dict = dict_open (bfs, FNAME_DICT, 100, 0, 0);
166 logf (LOG_FATAL, "dict_open fail");
169 if (res_get_match (common_resource, "isam", "i", NULL))
171 isam = is_open (bfs, FNAME_ISAM, key_compare, 0,
172 sizeof(struct it_key), common_resource);
175 logf (LOG_FATAL, "is_open fail");
179 else if (res_get_match (common_resource, "isam", "s", NULL))
181 struct ISAMS_M_s isams_m;
182 isams = isams_open (bfs, FNAME_ISAMS, 0,
183 key_isams_m(common_resource, &isams_m));
186 logf (LOG_FATAL, "isams_open fail");
190 else if (res_get_match (common_resource, "isam", "h", NULL))
192 isamh = isamh_open (bfs, FNAME_ISAMH, 0, key_isamh_m(common_resource));
195 logf (LOG_FATAL, "isamh_open fail");
199 else if (res_get_match (common_resource, "isam", "d", NULL))
201 struct ISAMD_M_s isamd_m;
202 isamd = isamd_open (bfs, FNAME_ISAMD, 0,
203 key_isamd_m(common_resource,&isamd_m));
206 logf (LOG_FATAL, "isamd_open fail");
212 struct ISAMC_M_s isamc_m;
213 isamc = isc_open (bfs, FNAME_ISAMC, 0,
214 key_isamc_m (common_resource, &isamc_m));
217 logf (LOG_FATAL, "isc_open fail");
221 records = rec_open (bfs, 0, 0);
223 for (i = 0; i<8; i++)
224 stat_info.no_isam_entries[i] = 0;
225 stat_info.no_dict_entries = 0;
226 stat_info.no_dict_bytes = 0;
227 stat_info.isam = isam;
228 stat_info.isamc = isamc;
229 stat_info.isams = isams;
230 stat_info.isamh = isamh;
231 stat_info.isamd = isamd;
232 stat_info.isam_bounds[0] = 1;
233 stat_info.isam_bounds[1] = 2;
234 stat_info.isam_bounds[2] = 3;
235 stat_info.isam_bounds[3] = 6;
236 stat_info.isam_bounds[4] = 10;
237 stat_info.isam_bounds[5] = 20;
238 stat_info.isam_bounds[6] = 30;
239 stat_info.isam_bounds[7] = 50;
240 stat_info.isam_bounds[8] = 100;
241 stat_info.isam_bounds[9] = 200;
242 stat_info.isam_bounds[10] = 5000;
243 stat_info.isam_bounds[11] = 10000;
244 stat_info.isam_bounds[12] = 20000;
245 stat_info.isam_bounds[13] = 50000;
246 stat_info.isam_bounds[14] = 100000;
247 stat_info.isam_bounds[15] = 200000;
248 stat_info.isam_bounds[16] = 500000;
249 stat_info.isam_bounds[17] = 1000000;
250 stat_info.isam_bounds[18] = 0;
252 for (i = 0; i<20; i++)
253 stat_info.isam_occurrences[i] = 0;
255 dict_scan (dict, term_dict, &before, &after, &stat_info, inv_stat_handle);
259 fprintf (stderr, " Blocks Occur Size KB Bytes/Entry\n");
260 for (i = 0; isc_block_used (isamc, i) >= 0; i++)
262 fprintf (stderr, " %8d %8d", isc_block_used (isamc, i),
263 stat_info.no_isam_entries[i]);
265 if (stat_info.no_isam_entries[i])
266 fprintf (stderr, " %8d %f",
267 (int) ((1023.0 + (double) isc_block_used(isamc, i) *
268 isc_block_size(isamc,i))/1024),
269 ((double) isc_block_used(isamc, i) *
270 isc_block_size(isamc,i))/
271 stat_info.no_isam_entries[i]);
272 fprintf (stderr, "\n");
276 fprintf (stderr, "\n%d words using %d bytes\n",
277 stat_info.no_dict_entries, stat_info.no_dict_bytes);
278 fprintf (stderr, " Occurrences Words\n");
280 for (i = 0; stat_info.isam_bounds[i]; i++)
282 int here = stat_info.isam_bounds[i];
283 fprintf (stderr, "%7d-%-7d %7d\n",
284 prev, here, stat_info.isam_occurrences[i]);
287 fprintf (stderr, "%7d- %7d\n",
288 prev, stat_info.isam_occurrences[i]);
290 rec_close (&records);
304 xmalloc_trav("unfreed"); /*! while hunting memory leaks */
310 * $Log: invstat.c,v $
311 * Revision 1.16 1999-08-18 08:38:22 heikki
312 * Memory leak hunting
314 * Revision 1.15 1999/08/18 08:34:53 heikki
317 * Revision 1.14 1999/07/14 10:59:26 adam
318 * Changed functions isc_getmethod, isams_getmethod.
319 * Improved fatal error handling (such as missing EXPLAIN schema).
321 * Revision 1.13 1999/07/08 14:23:27 heikki
322 * Fixed a bug in isamh_pp_read and cleaned up a bit
324 * Revision 1.12 1999/07/06 12:28:04 adam
325 * Updated record index structure. Format includes version ID. Compression
326 * algorithm ID is stored for each record block.
328 * Revision 1.11 1999/05/15 14:36:38 adam
329 * Updated dictionary. Implemented "compression" of dictionary.
331 * Revision 1.10 1999/05/12 13:08:06 adam
332 * First version of ISAMS.
334 * Revision 1.9 1999/02/12 13:29:23 adam
335 * Implemented position-flag for registers.
337 * Revision 1.8 1999/02/02 14:50:53 adam
338 * Updated WIN32 code specific sections. Changed header.
340 * Revision 1.7 1998/03/13 15:30:50 adam
341 * New functions isc_block_used and isc_block_size. Fixed 'leak'
342 * in isc_alloc_block.
344 * Revision 1.6 1998/03/06 13:54:02 adam
345 * Fixed two nasty bugs in isc_merge.
347 * Revision 1.5 1997/09/17 12:19:13 adam
348 * Zebra version corresponds to YAZ version 1.4.
349 * Changed Zebra server so that it doesn't depend on global common_resource.
351 * Revision 1.4 1996/11/08 11:10:21 adam
352 * Buffers used during file match got bigger.
353 * Compressed ISAM support everywhere.
354 * Bug fixes regarding masking characters in queries.
355 * Redesigned Regexp-2 queries.
357 * Revision 1.3 1996/06/04 10:18:58 adam
358 * Minor changes - removed include of ctype.h.
360 * Revision 1.2 1996/05/22 08:25:56 adam
363 * Revision 1.1 1996/05/14 14:04:34 adam
364 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT