2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.8 1999-02-02 14:50:53 adam
8 * Updated WIN32 code specific sections. Changed header.
10 * Revision 1.7 1998/03/13 15:30:50 adam
11 * New functions isc_block_used and isc_block_size. Fixed 'leak'
14 * Revision 1.6 1998/03/06 13:54:02 adam
15 * Fixed two nasty bugs in isc_merge.
17 * Revision 1.5 1997/09/17 12:19:13 adam
18 * Zebra version corresponds to YAZ version 1.4.
19 * Changed Zebra server so that it doesn't depend on global common_resource.
21 * Revision 1.4 1996/11/08 11:10:21 adam
22 * Buffers used during file match got bigger.
23 * Compressed ISAM support everywhere.
24 * Bug fixes regarding masking characters in queries.
25 * Redesigned Regexp-2 queries.
27 * Revision 1.3 1996/06/04 10:18:58 adam
28 * Minor changes - removed include of ctype.h.
30 * Revision 1.2 1996/05/22 08:25:56 adam
33 * Revision 1.1 1996/05/14 14:04:34 adam
34 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
45 struct inv_stat_info {
48 int no_isam_entries[8];
52 int isam_occurrences[20];
56 static int inv_stat_handle (char *name, const char *info, int pos,
61 struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
64 stat_info->no_dict_entries++;
65 stat_info->no_dict_bytes += strlen(name);
67 assert (*info == sizeof(ISAM_P));
68 memcpy (&isam_p, info+1, sizeof(ISAM_P));
74 ispt = is_position (stat_info->isam, isam_p);
75 occur = is_numkeys (ispt);
84 pp = isc_pp_open (stat_info->isamc, isam_p);
85 occur = isc_pp_num (pp);
86 while (isc_pp_read(pp, buf))
88 assert (occurx == occur);
89 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
93 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
95 ++(stat_info->isam_occurrences[i]);
99 void inv_prstat (BFiles bfs)
107 int after = 1000000000;
108 struct inv_stat_info stat_info;
109 char term_dict[2*IT_MAX_WORD+2];
114 dict = dict_open (bfs, FNAME_DICT, 100, 0);
117 logf (LOG_FATAL, "dict_open fail");
120 if (!res_get_match (common_resource, "isam", "i", NULL))
122 isamc = isc_open (bfs, FNAME_ISAMC, 0, key_isamc_m (common_resource));
125 logf (LOG_FATAL, "isc_open fail");
131 isam = is_open (bfs, FNAME_ISAM, key_compare, 0,
132 sizeof(struct it_key), common_resource);
135 logf (LOG_FATAL, "is_open fail");
139 records = rec_open (bfs, 0);
141 for (i = 0; i<8; i++)
142 stat_info.no_isam_entries[i] = 0;
143 stat_info.no_dict_entries = 0;
144 stat_info.no_dict_bytes = 0;
145 stat_info.isam = isam;
146 stat_info.isamc = isamc;
147 stat_info.isam_bounds[0] = 1;
148 stat_info.isam_bounds[1] = 2;
149 stat_info.isam_bounds[2] = 3;
150 stat_info.isam_bounds[3] = 6;
151 stat_info.isam_bounds[4] = 10;
152 stat_info.isam_bounds[5] = 20;
153 stat_info.isam_bounds[6] = 30;
154 stat_info.isam_bounds[7] = 50;
155 stat_info.isam_bounds[8] = 100;
156 stat_info.isam_bounds[9] = 200;
157 stat_info.isam_bounds[10] = 5000;
158 stat_info.isam_bounds[11] = 10000;
159 stat_info.isam_bounds[12] = 20000;
160 stat_info.isam_bounds[13] = 50000;
161 stat_info.isam_bounds[14] = 100000;
162 stat_info.isam_bounds[15] = 200000;
163 stat_info.isam_bounds[16] = 500000;
164 stat_info.isam_bounds[17] = 1000000;
165 stat_info.isam_bounds[18] = 0;
167 for (i = 0; i<20; i++)
168 stat_info.isam_occurrences[i] = 0;
170 dict_scan (dict, term_dict, &before, &after, &stat_info, inv_stat_handle);
174 fprintf (stderr, " Blocks Occur Size KB Bytes/Entry\n");
175 for (i = 0; isc_block_used (isamc, i) >= 0; i++)
177 fprintf (stderr, " %8d %8d", isc_block_used (isamc, i),
178 stat_info.no_isam_entries[i]);
180 if (stat_info.no_isam_entries[i])
181 fprintf (stderr, " %8d %f",
182 (int) ((1023.0 + (double) isc_block_used(isamc, i) *
183 isc_block_size(isamc,i))/1024),
184 ((double) isc_block_used(isamc, i) *
185 isc_block_size(isamc,i))/
186 stat_info.no_isam_entries[i]);
187 fprintf (stderr, "\n");
191 fprintf (stderr, "\n%d words using %d bytes\n",
192 stat_info.no_dict_entries, stat_info.no_dict_bytes);
193 fprintf (stderr, " Occurrences Words\n");
195 for (i = 0; stat_info.isam_bounds[i]; i++)
197 int here = stat_info.isam_bounds[i];
198 fprintf (stderr, "%7d-%-7d %7d\n",
199 prev, here, stat_info.isam_occurrences[i]);
202 fprintf (stderr, "%7d- %7d\n",
203 prev, stat_info.isam_occurrences[i]);
205 rec_close (&records);