2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.10 1999-05-12 13:08:06 adam
8 * First version of ISAMS.
10 * Revision 1.9 1999/02/12 13:29:23 adam
11 * Implemented position-flag for registers.
13 * Revision 1.8 1999/02/02 14:50:53 adam
14 * Updated WIN32 code specific sections. Changed header.
16 * Revision 1.7 1998/03/13 15:30:50 adam
17 * New functions isc_block_used and isc_block_size. Fixed 'leak'
20 * Revision 1.6 1998/03/06 13:54:02 adam
21 * Fixed two nasty bugs in isc_merge.
23 * Revision 1.5 1997/09/17 12:19:13 adam
24 * Zebra version corresponds to YAZ version 1.4.
25 * Changed Zebra server so that it doesn't depend on global common_resource.
27 * Revision 1.4 1996/11/08 11:10:21 adam
28 * Buffers used during file match got bigger.
29 * Compressed ISAM support everywhere.
30 * Bug fixes regarding masking characters in queries.
31 * Redesigned Regexp-2 queries.
33 * Revision 1.3 1996/06/04 10:18:58 adam
34 * Minor changes - removed include of ctype.h.
36 * Revision 1.2 1996/05/22 08:25:56 adam
39 * Revision 1.1 1996/05/14 14:04:34 adam
40 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
51 struct inv_stat_info {
55 int no_isam_entries[8];
59 int isam_occurrences[20];
63 static int inv_stat_handle (char *name, const char *info, int pos,
68 struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
71 stat_info->no_dict_entries++;
72 stat_info->no_dict_bytes += strlen(name);
74 assert (*info == sizeof(ISAM_P));
75 memcpy (&isam_p, info+1, sizeof(ISAM_P));
82 ispt = is_position (stat_info->isam, isam_p);
83 occur = is_numkeys (ispt);
92 pp = isc_pp_open (stat_info->isamc, isam_p);
93 occur = isc_pp_num (pp);
94 while (isc_pp_read(pp, &key))
96 printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
99 assert (occurx == occur);
100 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
103 if (stat_info->isams)
109 pp = isams_pp_open (stat_info->isams, isam_p);
110 occur = isams_pp_num (pp);
111 while (isams_pp_read(pp, &key))
113 printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
116 assert (occurx == occur);
117 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
121 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
123 ++(stat_info->isam_occurrences[i]);
127 void inv_prstat (BFiles bfs)
136 int after = 1000000000;
137 struct inv_stat_info stat_info;
138 char term_dict[2*IT_MAX_WORD+2];
143 dict = dict_open (bfs, FNAME_DICT, 100, 0);
146 logf (LOG_FATAL, "dict_open fail");
149 if (res_get_match (common_resource, "isam", "i", NULL))
151 isam = is_open (bfs, FNAME_ISAM, key_compare, 0,
152 sizeof(struct it_key), common_resource);
155 logf (LOG_FATAL, "is_open fail");
159 else if (res_get_match (common_resource, "isam", "s", NULL))
161 isams = isams_open (bfs, FNAME_ISAMS, 0, key_isams_m(common_resource));
164 logf (LOG_FATAL, "isams_open fail");
170 isamc = isc_open (bfs, FNAME_ISAMC, 0, key_isamc_m (common_resource));
173 logf (LOG_FATAL, "isc_open fail");
177 records = rec_open (bfs, 0);
179 for (i = 0; i<8; i++)
180 stat_info.no_isam_entries[i] = 0;
181 stat_info.no_dict_entries = 0;
182 stat_info.no_dict_bytes = 0;
183 stat_info.isam = isam;
184 stat_info.isamc = isamc;
185 stat_info.isams = isams;
186 stat_info.isam_bounds[0] = 1;
187 stat_info.isam_bounds[1] = 2;
188 stat_info.isam_bounds[2] = 3;
189 stat_info.isam_bounds[3] = 6;
190 stat_info.isam_bounds[4] = 10;
191 stat_info.isam_bounds[5] = 20;
192 stat_info.isam_bounds[6] = 30;
193 stat_info.isam_bounds[7] = 50;
194 stat_info.isam_bounds[8] = 100;
195 stat_info.isam_bounds[9] = 200;
196 stat_info.isam_bounds[10] = 5000;
197 stat_info.isam_bounds[11] = 10000;
198 stat_info.isam_bounds[12] = 20000;
199 stat_info.isam_bounds[13] = 50000;
200 stat_info.isam_bounds[14] = 100000;
201 stat_info.isam_bounds[15] = 200000;
202 stat_info.isam_bounds[16] = 500000;
203 stat_info.isam_bounds[17] = 1000000;
204 stat_info.isam_bounds[18] = 0;
206 for (i = 0; i<20; i++)
207 stat_info.isam_occurrences[i] = 0;
209 dict_scan (dict, term_dict, &before, &after, &stat_info, inv_stat_handle);
213 fprintf (stderr, " Blocks Occur Size KB Bytes/Entry\n");
214 for (i = 0; isc_block_used (isamc, i) >= 0; i++)
216 fprintf (stderr, " %8d %8d", isc_block_used (isamc, i),
217 stat_info.no_isam_entries[i]);
219 if (stat_info.no_isam_entries[i])
220 fprintf (stderr, " %8d %f",
221 (int) ((1023.0 + (double) isc_block_used(isamc, i) *
222 isc_block_size(isamc,i))/1024),
223 ((double) isc_block_used(isamc, i) *
224 isc_block_size(isamc,i))/
225 stat_info.no_isam_entries[i]);
226 fprintf (stderr, "\n");
230 fprintf (stderr, "\n%d words using %d bytes\n",
231 stat_info.no_dict_entries, stat_info.no_dict_bytes);
232 fprintf (stderr, " Occurrences Words\n");
234 for (i = 0; stat_info.isam_bounds[i]; i++)
236 int here = stat_info.isam_bounds[i];
237 fprintf (stderr, "%7d-%-7d %7d\n",
238 prev, here, stat_info.isam_occurrences[i]);
241 fprintf (stderr, "%7d- %7d\n",
242 prev, stat_info.isam_occurrences[i]);
244 rec_close (&records);