1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2010 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 struct inv_stat_info {
29 zint no_isam_entries[9];
33 int isam_occurrences[20];
35 int isamb_levels[10][5];
37 zint isamb_blocks[10];
42 #define SINGLETON_TYPE 8 /* the type to use for singletons that */
43 /* have no block and no block type */
45 static void print_dict_item (ZebraHandle zh, const char *s, zint count,
46 int firstsys, int firstseq, int lastsys, int lastseq )
48 char dst[IT_MAX_WORD+1];
50 int len = key_SU_decode(&ord, (const unsigned char *) s);
51 const char *index_type;
58 zebraExplain_lookup_ord (zh->reg->zei, ord, &index_type, &db, 0);
60 zebra_term_untrans(zh, index_type, dst, s + len);
62 printf("%02d:%10" ZINT_FORMAT0 " %s %d.%d - %d.%d\n", ord, count, dst,
63 firstsys, firstseq, lastsys, lastseq);
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;
78 stat_info->no_dict_entries++;
79 stat_info->no_dict_bytes += strlen(name);
81 assert (*info == sizeof(ISAM_P));
82 memcpy (&isam_p, info+1, sizeof(ISAM_P));
84 if (stat_info->zh->reg->isams)
90 pp = isams_pp_open (stat_info->zh->reg->isams, isam_p);
91 occur = isams_pp_num (pp);
92 while (isams_pp_read(pp, &key))
96 assert (occurx == occur);
97 stat_info->no_isam_entries[0] += occur;
100 if (stat_info->zh->reg->isamc)
106 pp = isamc_pp_open (stat_info->zh->reg->isamc, isam_p);
107 occur = isamc_pp_num (pp);
108 while (isamc_pp_read(pp, &key))
112 assert (occurx == occur);
113 stat_info->no_isam_entries[isamc_type(isam_p)] += occur;
116 if (stat_info->zh->reg->isamb)
120 int cat = CAST_ZINT_TO_INT(isam_p & 3);
125 pp = isamb_pp_open_x(stat_info->zh->reg->isamb, isam_p, &level, 0);
127 while (isamb_pp_read(pp, &key))
131 isamb_pp_close_x (pp, &size, &blocks);
132 stat_info->isamb_blocks[cat] += blocks;
133 stat_info->isamb_sizes[cat] += size;
136 stat_info->isamb_levels[cat][level] ++;
137 stat_info->no_isam_entries[cat] += occur;
140 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
142 ++(stat_info->isam_occurrences[i]);
143 if (stat_info->dumpwords)
144 print_dict_item(stat_info->zh, name, occur,
145 firstsys, firstseq, lastsys, lastseq);
149 static void show_bfs_stats(BFiles bfs)
152 const char *directory = 0;
153 double used_bytes, max_bytes;
154 printf("Register:\n");
155 while (bfs_register_directory_stat(bfs, i, &directory,
156 &used_bytes, &max_bytes))
158 printf ("%s %10.0lf %10.0lf\n", directory, used_bytes, max_bytes);
163 while (bfs_shadow_directory_stat(bfs, i, &directory,
164 &used_bytes, &max_bytes))
166 printf ("%s %10.0lf %10.0lf\n", directory, used_bytes, max_bytes);
171 int zebra_register_statistics (ZebraHandle zh, int dumpdict)
176 int after = 1000000000;
177 struct inv_stat_info stat_info;
178 char term_dict[2*IT_MAX_WORD+2];
180 if (zebra_begin_read (zh))
183 show_bfs_stats(zebra_get_bfs(zh));
186 stat_info.dumpwords=dumpdict;
191 for (i = 0; i<=SINGLETON_TYPE; i++)
192 stat_info.no_isam_entries[i] = 0;
193 stat_info.no_dict_entries = 0;
194 stat_info.no_dict_bytes = 0;
195 stat_info.isam_bounds[0] = 1;
196 stat_info.isam_bounds[1] = 2;
197 stat_info.isam_bounds[2] = 3;
198 stat_info.isam_bounds[3] = 6;
199 stat_info.isam_bounds[4] = 10;
200 stat_info.isam_bounds[5] = 20;
201 stat_info.isam_bounds[6] = 30;
202 stat_info.isam_bounds[7] = 50;
203 stat_info.isam_bounds[8] = 100;
204 stat_info.isam_bounds[9] = 200;
205 stat_info.isam_bounds[10] = 5000;
206 stat_info.isam_bounds[11] = 10000;
207 stat_info.isam_bounds[12] = 20000;
208 stat_info.isam_bounds[13] = 50000;
209 stat_info.isam_bounds[14] = 100000;
210 stat_info.isam_bounds[15] = 200000;
211 stat_info.isam_bounds[16] = 500000;
212 stat_info.isam_bounds[17] = 1000000;
213 stat_info.isam_bounds[18] = 0;
217 for (i = 0; i<20; i++)
218 stat_info.isam_occurrences[i] = 0;
220 for (i = 0; i<10; i++)
223 for (j = 0; j<5; j++)
224 stat_info.isamb_levels[i][j] = 0;
225 stat_info.isamb_sizes[i] = 0;
226 stat_info.isamb_blocks[i] = 0;
229 dict_scan (zh->reg->dict, term_dict, &before, &after, &stat_info,
234 fprintf (stdout, " Blocks Occur Size KB Bytes/Entry\n");
235 for (i = 0; isamc_block_used (zh->reg->isamc, i) >= 0; i++)
237 fprintf (stdout, " %8" ZINT_FORMAT0 " %8" ZINT_FORMAT0,
238 isamc_block_used (zh->reg->isamc, i),
239 stat_info.no_isam_entries[i]);
241 if (stat_info.no_isam_entries[i])
242 fprintf(stdout, " %8d %f",
243 (int) ((1023.0 + (double)
244 isamc_block_used(zh->reg->isamc, i) *
245 isamc_block_size(zh->reg->isamc,i))/1024),
246 ((double) isamc_block_used(zh->reg->isamc, i) *
247 isamc_block_size(zh->reg->isamc,i))/
248 stat_info.no_isam_entries[i]);
249 fprintf (stdout, "\n");
255 for (i = 0; i<4; i++)
258 int bsize = isamb_block_info(zh->reg->isamb, i);
261 fprintf (stdout, "Category %d\n", i);
262 fprintf (stdout, "Block size %d\n", bsize);
263 fprintf (stdout, "Blocks: " ZINT_FORMAT "\n", stat_info.isamb_blocks[i]);
264 fprintf (stdout, "Size: " ZINT_FORMAT "\n", stat_info.isamb_sizes[i]);
265 fprintf (stdout, "Entries: " ZINT_FORMAT "\n",
266 stat_info.no_isam_entries[i]);
267 fprintf (stdout, "Total " ZINT_FORMAT "\n", stat_info.isamb_blocks[i]*
269 for (j = 0; j<5; j++)
270 if (stat_info.isamb_levels[i][j])
271 fprintf (stdout, "Level%d %d\n", j,
272 stat_info.isamb_levels[i][j]);
273 fprintf (stdout, "\n");
276 fprintf (stdout, "Checksum %08lX\n", stat_info.cksum);
278 fprintf (stdout, "Distinct words %d\n", stat_info.no_dict_entries);
280 for (i = 0; i<9; i++)
281 occur += stat_info.no_isam_entries[i];
282 fprintf (stdout, "Word pos " ZINT_FORMAT "\n", occur);
283 fprintf (stdout, " Occurrences Words\n");
285 for (i = 0; stat_info.isam_bounds[i]; i++)
287 int here = stat_info.isam_bounds[i];
288 fprintf (stdout, "%7d-%-7d %7d\n",
289 prev, here, stat_info.isam_occurrences[i]);
292 fprintf (stdout, "%7d- %7d\n",
293 prev, stat_info.isam_occurrences[i]);
294 rec_prstat(zh->reg->records, 0);
295 xmalloc_trav("unfreed"); /*! while hunting memory leaks */
303 * c-file-style: "Stroustrup"
304 * indent-tabs-mode: nil
306 * vim: shiftwidth=4 tabstop=8 expandtab