2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss, Heikki Levanto
14 #include "../isamc/isamh-p.h"
16 struct inv_stat_info {
21 int no_isam_entries[8];
25 int isam_occurrences[20];
29 static int inv_stat_handle (char *name, const char *info, int pos,
34 struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
37 stat_info->no_dict_entries++;
38 stat_info->no_dict_bytes += strlen(name);
40 assert (*info == sizeof(ISAM_P));
41 memcpy (&isam_p, info+1, sizeof(ISAM_P));
48 ispt = is_position (stat_info->isam, isam_p);
49 occur = is_numkeys (ispt);
58 pp = isc_pp_open (stat_info->isamc, isam_p);
59 occur = isc_pp_num (pp);
60 while (isc_pp_read(pp, &key))
62 printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
65 assert (occurx == occur);
66 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
75 pp = isamh_pp_open (stat_info->isamh, isam_p);
77 occur = isamh_pp_num (pp);
78 // printf (" opening item %d=%d:%d \n",
79 // isam_p, isamh_type(isam_p),isamh_block(isam_p));
80 while (isamh_pp_read(pp, &key))
83 logf (LOG_LOG,"sysno=%d seqno=%d (%x/%x) oc=%d/%d ofs=%d ",
86 occur,occurx, pp->offset);
89 logf(LOG_LOG,"Count error!!! read %d, counted %d", occur, occurx);
90 assert (occurx == occur);
91 stat_info->no_isam_entries[isamh_type(isam_p)] += occur;
100 pp = isams_pp_open (stat_info->isams, isam_p);
101 occur = isams_pp_num (pp);
102 while (isams_pp_read(pp, &key))
104 //printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
107 assert (occurx == occur);
108 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
112 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
114 ++(stat_info->isam_occurrences[i]);
118 void inv_prstat (BFiles bfs)
128 int after = 1000000000;
129 struct inv_stat_info stat_info;
130 char term_dict[2*IT_MAX_WORD+2];
135 dict = dict_open (bfs, FNAME_DICT, 100, 0, 0);
138 logf (LOG_FATAL, "dict_open fail");
141 if (res_get_match (common_resource, "isam", "i", NULL))
143 isam = is_open (bfs, FNAME_ISAM, key_compare, 0,
144 sizeof(struct it_key), common_resource);
147 logf (LOG_FATAL, "is_open fail");
151 else if (res_get_match (common_resource, "isam", "s", NULL))
153 struct ISAMS_M_s isams_m;
154 isams = isams_open (bfs, FNAME_ISAMS, 0,
155 key_isams_m(common_resource, &isams_m));
158 logf (LOG_FATAL, "isams_open fail");
162 else if (res_get_match (common_resource, "isam", "h", NULL))
164 isamh = isamh_open (bfs, FNAME_ISAMH, 0, key_isamh_m(common_resource));
167 logf (LOG_FATAL, "isamh_open fail");
173 struct ISAMC_M_s isamc_m;
174 isamc = isc_open (bfs, FNAME_ISAMC, 0,
175 key_isamc_m (common_resource, &isamc_m));
178 logf (LOG_FATAL, "isc_open fail");
182 records = rec_open (bfs, 0, 0);
184 for (i = 0; i<8; i++)
185 stat_info.no_isam_entries[i] = 0;
186 stat_info.no_dict_entries = 0;
187 stat_info.no_dict_bytes = 0;
188 stat_info.isam = isam;
189 stat_info.isamc = isamc;
190 stat_info.isams = isams;
191 stat_info.isamh = isamh;
192 stat_info.isam_bounds[0] = 1;
193 stat_info.isam_bounds[1] = 2;
194 stat_info.isam_bounds[2] = 3;
195 stat_info.isam_bounds[3] = 6;
196 stat_info.isam_bounds[4] = 10;
197 stat_info.isam_bounds[5] = 20;
198 stat_info.isam_bounds[6] = 30;
199 stat_info.isam_bounds[7] = 50;
200 stat_info.isam_bounds[8] = 100;
201 stat_info.isam_bounds[9] = 200;
202 stat_info.isam_bounds[10] = 5000;
203 stat_info.isam_bounds[11] = 10000;
204 stat_info.isam_bounds[12] = 20000;
205 stat_info.isam_bounds[13] = 50000;
206 stat_info.isam_bounds[14] = 100000;
207 stat_info.isam_bounds[15] = 200000;
208 stat_info.isam_bounds[16] = 500000;
209 stat_info.isam_bounds[17] = 1000000;
210 stat_info.isam_bounds[18] = 0;
212 for (i = 0; i<20; i++)
213 stat_info.isam_occurrences[i] = 0;
215 dict_scan (dict, term_dict, &before, &after, &stat_info, inv_stat_handle);
219 fprintf (stderr, " Blocks Occur Size KB Bytes/Entry\n");
220 for (i = 0; isc_block_used (isamc, i) >= 0; i++)
222 fprintf (stderr, " %8d %8d", isc_block_used (isamc, i),
223 stat_info.no_isam_entries[i]);
225 if (stat_info.no_isam_entries[i])
226 fprintf (stderr, " %8d %f",
227 (int) ((1023.0 + (double) isc_block_used(isamc, i) *
228 isc_block_size(isamc,i))/1024),
229 ((double) isc_block_used(isamc, i) *
230 isc_block_size(isamc,i))/
231 stat_info.no_isam_entries[i]);
232 fprintf (stderr, "\n");
236 fprintf (stderr, "\n%d words using %d bytes\n",
237 stat_info.no_dict_entries, stat_info.no_dict_bytes);
238 fprintf (stderr, " Occurrences Words\n");
240 for (i = 0; stat_info.isam_bounds[i]; i++)
242 int here = stat_info.isam_bounds[i];
243 fprintf (stderr, "%7d-%-7d %7d\n",
244 prev, here, stat_info.isam_occurrences[i]);
247 fprintf (stderr, "%7d- %7d\n",
248 prev, stat_info.isam_occurrences[i]);
250 rec_close (&records);
267 * $Log: invstat.c,v $
268 * Revision 1.14 1999-07-14 10:59:26 adam
269 * Changed functions isc_getmethod, isams_getmethod.
270 * Improved fatal error handling (such as missing EXPLAIN schema).
272 * Revision 1.13 1999/07/08 14:23:27 heikki
273 * Fixed a bug in isamh_pp_read and cleaned up a bit
275 * Revision 1.12 1999/07/06 12:28:04 adam
276 * Updated record index structure. Format includes version ID. Compression
277 * algorithm ID is stored for each record block.
279 * Revision 1.11 1999/05/15 14:36:38 adam
280 * Updated dictionary. Implemented "compression" of dictionary.
282 * Revision 1.10 1999/05/12 13:08:06 adam
283 * First version of ISAMS.
285 * Revision 1.9 1999/02/12 13:29:23 adam
286 * Implemented position-flag for registers.
288 * Revision 1.8 1999/02/02 14:50:53 adam
289 * Updated WIN32 code specific sections. Changed header.
291 * Revision 1.7 1998/03/13 15:30:50 adam
292 * New functions isc_block_used and isc_block_size. Fixed 'leak'
293 * in isc_alloc_block.
295 * Revision 1.6 1998/03/06 13:54:02 adam
296 * Fixed two nasty bugs in isc_merge.
298 * Revision 1.5 1997/09/17 12:19:13 adam
299 * Zebra version corresponds to YAZ version 1.4.
300 * Changed Zebra server so that it doesn't depend on global common_resource.
302 * Revision 1.4 1996/11/08 11:10:21 adam
303 * Buffers used during file match got bigger.
304 * Compressed ISAM support everywhere.
305 * Bug fixes regarding masking characters in queries.
306 * Redesigned Regexp-2 queries.
308 * Revision 1.3 1996/06/04 10:18:58 adam
309 * Minor changes - removed include of ctype.h.
311 * Revision 1.2 1996/05/22 08:25:56 adam
314 * Revision 1.1 1996/05/14 14:04:34 adam
315 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT