2 * Copyright (C) 1994-1998, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.7 1998-03-13 15:30:50 adam
8 * New functions isc_block_used and isc_block_size. Fixed 'leak'
11 * Revision 1.6 1998/03/06 13:54:02 adam
12 * Fixed two nasty bugs in isc_merge.
14 * Revision 1.5 1997/09/17 12:19:13 adam
15 * Zebra version corresponds to YAZ version 1.4.
16 * Changed Zebra server so that it doesn't depend on global common_resource.
18 * Revision 1.4 1996/11/08 11:10:21 adam
19 * Buffers used during file match got bigger.
20 * Compressed ISAM support everywhere.
21 * Bug fixes regarding masking characters in queries.
22 * Redesigned Regexp-2 queries.
24 * Revision 1.3 1996/06/04 10:18:58 adam
25 * Minor changes - removed include of ctype.h.
27 * Revision 1.2 1996/05/22 08:25:56 adam
30 * Revision 1.1 1996/05/14 14:04:34 adam
31 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
42 struct inv_stat_info {
45 int no_isam_entries[8];
49 int isam_occurrences[20];
53 static int inv_stat_handle (char *name, const char *info, int pos,
58 struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
61 stat_info->no_dict_entries++;
62 stat_info->no_dict_bytes += strlen(name);
64 assert (*info == sizeof(ISAM_P));
65 memcpy (&isam_p, info+1, sizeof(ISAM_P));
71 ispt = is_position (stat_info->isam, isam_p);
72 occur = is_numkeys (ispt);
81 pp = isc_pp_open (stat_info->isamc, isam_p);
82 occur = isc_pp_num (pp);
83 while (isc_pp_read(pp, buf))
85 assert (occurx == occur);
86 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
90 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
92 ++(stat_info->isam_occurrences[i]);
96 void inv_prstat (BFiles bfs)
104 int after = 1000000000;
105 struct inv_stat_info stat_info;
106 char term_dict[2*IT_MAX_WORD+2];
111 dict = dict_open (bfs, FNAME_DICT, 100, 0);
114 logf (LOG_FATAL, "dict_open fail");
117 if (!res_get_match (common_resource, "isam", "i", NULL))
119 isamc = isc_open (bfs, FNAME_ISAMC, 0, key_isamc_m (common_resource));
122 logf (LOG_FATAL, "isc_open fail");
128 isam = is_open (bfs, FNAME_ISAM, key_compare, 0,
129 sizeof(struct it_key), common_resource);
132 logf (LOG_FATAL, "is_open fail");
136 records = rec_open (bfs, 0);
138 for (i = 0; i<8; i++)
139 stat_info.no_isam_entries[i] = 0;
140 stat_info.no_dict_entries = 0;
141 stat_info.no_dict_bytes = 0;
142 stat_info.isam = isam;
143 stat_info.isamc = isamc;
144 stat_info.isam_bounds[0] = 1;
145 stat_info.isam_bounds[1] = 2;
146 stat_info.isam_bounds[2] = 3;
147 stat_info.isam_bounds[3] = 6;
148 stat_info.isam_bounds[4] = 10;
149 stat_info.isam_bounds[5] = 20;
150 stat_info.isam_bounds[6] = 30;
151 stat_info.isam_bounds[7] = 50;
152 stat_info.isam_bounds[8] = 100;
153 stat_info.isam_bounds[9] = 200;
154 stat_info.isam_bounds[10] = 5000;
155 stat_info.isam_bounds[11] = 10000;
156 stat_info.isam_bounds[12] = 20000;
157 stat_info.isam_bounds[13] = 50000;
158 stat_info.isam_bounds[14] = 100000;
159 stat_info.isam_bounds[15] = 200000;
160 stat_info.isam_bounds[16] = 500000;
161 stat_info.isam_bounds[17] = 1000000;
162 stat_info.isam_bounds[18] = 0;
164 for (i = 0; i<20; i++)
165 stat_info.isam_occurrences[i] = 0;
167 dict_scan (dict, term_dict, &before, &after, &stat_info, inv_stat_handle);
171 fprintf (stderr, " Blocks Occur Size KB Bytes/Entry\n");
172 for (i = 0; isc_block_used (isamc, i) >= 0; i++)
174 fprintf (stderr, " %8d %8d", isc_block_used (isamc, i),
175 stat_info.no_isam_entries[i]);
177 if (stat_info.no_isam_entries[i])
178 fprintf (stderr, " %8d %f",
179 (int) ((1023.0 + (double) isc_block_used(isamc, i) *
180 isc_block_size(isamc,i))/1024),
181 ((double) isc_block_used(isamc, i) *
182 isc_block_size(isamc,i))/
183 stat_info.no_isam_entries[i]);
184 fprintf (stderr, "\n");
188 fprintf (stderr, "\n%d words using %d bytes\n",
189 stat_info.no_dict_entries, stat_info.no_dict_bytes);
190 fprintf (stderr, " Occurrences Words\n");
192 for (i = 0; stat_info.isam_bounds[i]; i++)
194 int here = stat_info.isam_bounds[i];
195 fprintf (stderr, "%7d-%-7d %7d\n",
196 prev, here, stat_info.isam_occurrences[i]);
199 fprintf (stderr, "%7d- %7d\n",
200 prev, stat_info.isam_occurrences[i]);
202 rec_close (&records);