2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.9 1999-02-12 13:29:23 adam
8 * Implemented position-flag for registers.
10 * Revision 1.8 1999/02/02 14:50:53 adam
11 * Updated WIN32 code specific sections. Changed header.
13 * Revision 1.7 1998/03/13 15:30:50 adam
14 * New functions isc_block_used and isc_block_size. Fixed 'leak'
17 * Revision 1.6 1998/03/06 13:54:02 adam
18 * Fixed two nasty bugs in isc_merge.
20 * Revision 1.5 1997/09/17 12:19:13 adam
21 * Zebra version corresponds to YAZ version 1.4.
22 * Changed Zebra server so that it doesn't depend on global common_resource.
24 * Revision 1.4 1996/11/08 11:10:21 adam
25 * Buffers used during file match got bigger.
26 * Compressed ISAM support everywhere.
27 * Bug fixes regarding masking characters in queries.
28 * Redesigned Regexp-2 queries.
30 * Revision 1.3 1996/06/04 10:18:58 adam
31 * Minor changes - removed include of ctype.h.
33 * Revision 1.2 1996/05/22 08:25:56 adam
36 * Revision 1.1 1996/05/14 14:04:34 adam
37 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
48 struct inv_stat_info {
51 int no_isam_entries[8];
55 int isam_occurrences[20];
59 static int inv_stat_handle (char *name, const char *info, int pos,
64 struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
67 stat_info->no_dict_entries++;
68 stat_info->no_dict_bytes += strlen(name);
70 assert (*info == sizeof(ISAM_P));
71 memcpy (&isam_p, info+1, sizeof(ISAM_P));
78 ispt = is_position (stat_info->isam, isam_p);
79 occur = is_numkeys (ispt);
88 pp = isc_pp_open (stat_info->isamc, isam_p);
89 occur = isc_pp_num (pp);
90 while (isc_pp_read(pp, &key))
92 printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
95 assert (occurx == occur);
96 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
100 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
102 ++(stat_info->isam_occurrences[i]);
106 void inv_prstat (BFiles bfs)
114 int after = 1000000000;
115 struct inv_stat_info stat_info;
116 char term_dict[2*IT_MAX_WORD+2];
121 dict = dict_open (bfs, FNAME_DICT, 100, 0);
124 logf (LOG_FATAL, "dict_open fail");
127 if (!res_get_match (common_resource, "isam", "i", NULL))
129 isamc = isc_open (bfs, FNAME_ISAMC, 0, key_isamc_m (common_resource));
132 logf (LOG_FATAL, "isc_open fail");
138 isam = is_open (bfs, FNAME_ISAM, key_compare, 0,
139 sizeof(struct it_key), common_resource);
142 logf (LOG_FATAL, "is_open fail");
146 records = rec_open (bfs, 0);
148 for (i = 0; i<8; i++)
149 stat_info.no_isam_entries[i] = 0;
150 stat_info.no_dict_entries = 0;
151 stat_info.no_dict_bytes = 0;
152 stat_info.isam = isam;
153 stat_info.isamc = isamc;
154 stat_info.isam_bounds[0] = 1;
155 stat_info.isam_bounds[1] = 2;
156 stat_info.isam_bounds[2] = 3;
157 stat_info.isam_bounds[3] = 6;
158 stat_info.isam_bounds[4] = 10;
159 stat_info.isam_bounds[5] = 20;
160 stat_info.isam_bounds[6] = 30;
161 stat_info.isam_bounds[7] = 50;
162 stat_info.isam_bounds[8] = 100;
163 stat_info.isam_bounds[9] = 200;
164 stat_info.isam_bounds[10] = 5000;
165 stat_info.isam_bounds[11] = 10000;
166 stat_info.isam_bounds[12] = 20000;
167 stat_info.isam_bounds[13] = 50000;
168 stat_info.isam_bounds[14] = 100000;
169 stat_info.isam_bounds[15] = 200000;
170 stat_info.isam_bounds[16] = 500000;
171 stat_info.isam_bounds[17] = 1000000;
172 stat_info.isam_bounds[18] = 0;
174 for (i = 0; i<20; i++)
175 stat_info.isam_occurrences[i] = 0;
177 dict_scan (dict, term_dict, &before, &after, &stat_info, inv_stat_handle);
181 fprintf (stderr, " Blocks Occur Size KB Bytes/Entry\n");
182 for (i = 0; isc_block_used (isamc, i) >= 0; i++)
184 fprintf (stderr, " %8d %8d", isc_block_used (isamc, i),
185 stat_info.no_isam_entries[i]);
187 if (stat_info.no_isam_entries[i])
188 fprintf (stderr, " %8d %f",
189 (int) ((1023.0 + (double) isc_block_used(isamc, i) *
190 isc_block_size(isamc,i))/1024),
191 ((double) isc_block_used(isamc, i) *
192 isc_block_size(isamc,i))/
193 stat_info.no_isam_entries[i]);
194 fprintf (stderr, "\n");
198 fprintf (stderr, "\n%d words using %d bytes\n",
199 stat_info.no_dict_entries, stat_info.no_dict_bytes);
200 fprintf (stderr, " Occurrences Words\n");
202 for (i = 0; stat_info.isam_bounds[i]; i++)
204 int here = stat_info.isam_bounds[i];
205 fprintf (stderr, "%7d-%-7d %7d\n",
206 prev, here, stat_info.isam_occurrences[i]);
209 fprintf (stderr, "%7d- %7d\n",
210 prev, stat_info.isam_occurrences[i]);
212 rec_close (&records);