2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.11 1999-05-15 14:36:38 adam
8 * Updated dictionary. Implemented "compression" of dictionary.
10 * Revision 1.10 1999/05/12 13:08:06 adam
11 * First version of ISAMS.
13 * Revision 1.9 1999/02/12 13:29:23 adam
14 * Implemented position-flag for registers.
16 * Revision 1.8 1999/02/02 14:50:53 adam
17 * Updated WIN32 code specific sections. Changed header.
19 * Revision 1.7 1998/03/13 15:30:50 adam
20 * New functions isc_block_used and isc_block_size. Fixed 'leak'
23 * Revision 1.6 1998/03/06 13:54:02 adam
24 * Fixed two nasty bugs in isc_merge.
26 * Revision 1.5 1997/09/17 12:19:13 adam
27 * Zebra version corresponds to YAZ version 1.4.
28 * Changed Zebra server so that it doesn't depend on global common_resource.
30 * Revision 1.4 1996/11/08 11:10:21 adam
31 * Buffers used during file match got bigger.
32 * Compressed ISAM support everywhere.
33 * Bug fixes regarding masking characters in queries.
34 * Redesigned Regexp-2 queries.
36 * Revision 1.3 1996/06/04 10:18:58 adam
37 * Minor changes - removed include of ctype.h.
39 * Revision 1.2 1996/05/22 08:25:56 adam
42 * Revision 1.1 1996/05/14 14:04:34 adam
43 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
54 struct inv_stat_info {
58 int no_isam_entries[8];
62 int isam_occurrences[20];
66 static int inv_stat_handle (char *name, const char *info, int pos,
71 struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
74 stat_info->no_dict_entries++;
75 stat_info->no_dict_bytes += strlen(name);
77 assert (*info == sizeof(ISAM_P));
78 memcpy (&isam_p, info+1, sizeof(ISAM_P));
85 ispt = is_position (stat_info->isam, isam_p);
86 occur = is_numkeys (ispt);
95 pp = isc_pp_open (stat_info->isamc, isam_p);
96 occur = isc_pp_num (pp);
97 while (isc_pp_read(pp, &key))
99 printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
102 assert (occurx == occur);
103 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
106 if (stat_info->isams)
112 pp = isams_pp_open (stat_info->isams, isam_p);
113 occur = isams_pp_num (pp);
114 while (isams_pp_read(pp, &key))
116 printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
119 assert (occurx == occur);
120 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
124 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
126 ++(stat_info->isam_occurrences[i]);
130 void inv_prstat (BFiles bfs)
139 int after = 1000000000;
140 struct inv_stat_info stat_info;
141 char term_dict[2*IT_MAX_WORD+2];
146 dict = dict_open (bfs, FNAME_DICT, 100, 0, 0);
149 logf (LOG_FATAL, "dict_open fail");
152 if (res_get_match (common_resource, "isam", "i", NULL))
154 isam = is_open (bfs, FNAME_ISAM, key_compare, 0,
155 sizeof(struct it_key), common_resource);
158 logf (LOG_FATAL, "is_open fail");
162 else if (res_get_match (common_resource, "isam", "s", NULL))
164 isams = isams_open (bfs, FNAME_ISAMS, 0, key_isams_m(common_resource));
167 logf (LOG_FATAL, "isams_open fail");
173 isamc = isc_open (bfs, FNAME_ISAMC, 0, key_isamc_m (common_resource));
176 logf (LOG_FATAL, "isc_open fail");
180 records = rec_open (bfs, 0);
182 for (i = 0; i<8; i++)
183 stat_info.no_isam_entries[i] = 0;
184 stat_info.no_dict_entries = 0;
185 stat_info.no_dict_bytes = 0;
186 stat_info.isam = isam;
187 stat_info.isamc = isamc;
188 stat_info.isams = isams;
189 stat_info.isam_bounds[0] = 1;
190 stat_info.isam_bounds[1] = 2;
191 stat_info.isam_bounds[2] = 3;
192 stat_info.isam_bounds[3] = 6;
193 stat_info.isam_bounds[4] = 10;
194 stat_info.isam_bounds[5] = 20;
195 stat_info.isam_bounds[6] = 30;
196 stat_info.isam_bounds[7] = 50;
197 stat_info.isam_bounds[8] = 100;
198 stat_info.isam_bounds[9] = 200;
199 stat_info.isam_bounds[10] = 5000;
200 stat_info.isam_bounds[11] = 10000;
201 stat_info.isam_bounds[12] = 20000;
202 stat_info.isam_bounds[13] = 50000;
203 stat_info.isam_bounds[14] = 100000;
204 stat_info.isam_bounds[15] = 200000;
205 stat_info.isam_bounds[16] = 500000;
206 stat_info.isam_bounds[17] = 1000000;
207 stat_info.isam_bounds[18] = 0;
209 for (i = 0; i<20; i++)
210 stat_info.isam_occurrences[i] = 0;
212 dict_scan (dict, term_dict, &before, &after, &stat_info, inv_stat_handle);
216 fprintf (stderr, " Blocks Occur Size KB Bytes/Entry\n");
217 for (i = 0; isc_block_used (isamc, i) >= 0; i++)
219 fprintf (stderr, " %8d %8d", isc_block_used (isamc, i),
220 stat_info.no_isam_entries[i]);
222 if (stat_info.no_isam_entries[i])
223 fprintf (stderr, " %8d %f",
224 (int) ((1023.0 + (double) isc_block_used(isamc, i) *
225 isc_block_size(isamc,i))/1024),
226 ((double) isc_block_used(isamc, i) *
227 isc_block_size(isamc,i))/
228 stat_info.no_isam_entries[i]);
229 fprintf (stderr, "\n");
233 fprintf (stderr, "\n%d words using %d bytes\n",
234 stat_info.no_dict_entries, stat_info.no_dict_bytes);
235 fprintf (stderr, " Occurrences Words\n");
237 for (i = 0; stat_info.isam_bounds[i]; i++)
239 int here = stat_info.isam_bounds[i];
240 fprintf (stderr, "%7d-%-7d %7d\n",
241 prev, here, stat_info.isam_occurrences[i]);
244 fprintf (stderr, "%7d- %7d\n",
245 prev, stat_info.isam_occurrences[i]);
247 rec_close (&records);