1 /* $Id: invstat.c,v 1.37 2004-08-06 12:28:22 adam Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
30 struct inv_stat_info {
32 zint no_isam_entries[9];
36 int isam_occurrences[20];
38 int isamb_levels[10][5];
45 #define SINGLETON_TYPE 8 /* the type to use for singletons that */
46 /* have no block and no block type */
48 static void print_dict_item (ZebraMaps zm, const char *s, zint count,
49 int firstsys, int firstseq, int lastsys, int lastseq )
52 char keybuf[IT_MAX_WORD+1];
54 const char *from = s + 2;
58 const char *res = zebra_maps_output (zm, reg_type, &from);
66 /* yaz_log (LOG_LOG, "%s", keybuf); */
67 printf("%10d %s %d.%d - %d.%d\n",count, keybuf,
68 firstsys,firstseq, lastsys,lastseq);
71 static int inv_stat_handle (char *name, const char *info, int pos,
76 struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
83 stat_info->no_dict_entries++;
84 stat_info->no_dict_bytes += strlen(name);
86 assert (*info == sizeof(ISAMS_P));
87 memcpy (&isam_p, info+1, sizeof(ISAMS_P));
89 if (stat_info->zh->reg->isams)
95 pp = isams_pp_open (stat_info->zh->reg->isams, isam_p);
96 occur = isams_pp_num (pp);
97 while (isams_pp_read(pp, &key))
102 stat_info->cksum = stat_info->cksum * 65509 +
103 key.sysno + 11 * key.seqno;
113 assert (occurx == occur);
114 stat_info->no_isam_entries[0] += occur;
117 if (stat_info->zh->reg->isam)
121 ispt = is_position (stat_info->zh->reg->isam, (int) isam_p);
122 occur = is_numkeys (ispt);
123 stat_info->no_isam_entries[is_type(isam_p)] += occur;
126 if (stat_info->zh->reg->isamc)
132 pp = isc_pp_open (stat_info->zh->reg->isamc, isam_p);
133 occur = isc_pp_num (pp);
134 while (isc_pp_read(pp, &key))
139 stat_info->cksum = stat_info->cksum * 65509 +
140 key.sysno + 11 * key.seqno;
150 assert (occurx == occur);
151 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
154 if (stat_info->zh->reg->isamb)
158 int cat = (int) (isam_p & 3);
163 pp = isamb_pp_open_x(stat_info->zh->reg->isamb, isam_p, &level);
165 while (isamb_pp_read(pp, &key))
170 stat_info->cksum = stat_info->cksum * 65509 +
171 key.sysno + 11 * key.seqno;
181 isamb_pp_close_x (pp, &size, &blocks);
182 stat_info->isamb_blocks[cat] += blocks;
183 stat_info->isamb_sizes[cat] += size;
186 stat_info->isamb_levels[cat][level] ++;
187 stat_info->no_isam_entries[cat] += occur;
190 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
192 ++(stat_info->isam_occurrences[i]);
193 if (stat_info->dumpwords)
194 print_dict_item(stat_info->zh->reg->zebra_maps, name, occur,
195 firstsys,firstseq, lastsys, lastseq);
199 int zebra_register_statistics (ZebraHandle zh, int dumpdict)
204 int after = 1000000000;
205 struct inv_stat_info stat_info;
206 char term_dict[2*IT_MAX_WORD+2];
208 if (zebra_begin_read (zh))
212 stat_info.dumpwords=dumpdict;
217 for (i = 0; i<=SINGLETON_TYPE; i++)
218 stat_info.no_isam_entries[i] = 0;
219 stat_info.no_dict_entries = 0;
220 stat_info.no_dict_bytes = 0;
221 stat_info.isam_bounds[0] = 1;
222 stat_info.isam_bounds[1] = 2;
223 stat_info.isam_bounds[2] = 3;
224 stat_info.isam_bounds[3] = 6;
225 stat_info.isam_bounds[4] = 10;
226 stat_info.isam_bounds[5] = 20;
227 stat_info.isam_bounds[6] = 30;
228 stat_info.isam_bounds[7] = 50;
229 stat_info.isam_bounds[8] = 100;
230 stat_info.isam_bounds[9] = 200;
231 stat_info.isam_bounds[10] = 5000;
232 stat_info.isam_bounds[11] = 10000;
233 stat_info.isam_bounds[12] = 20000;
234 stat_info.isam_bounds[13] = 50000;
235 stat_info.isam_bounds[14] = 100000;
236 stat_info.isam_bounds[15] = 200000;
237 stat_info.isam_bounds[16] = 500000;
238 stat_info.isam_bounds[17] = 1000000;
239 stat_info.isam_bounds[18] = 0;
243 for (i = 0; i<20; i++)
244 stat_info.isam_occurrences[i] = 0;
246 for (i = 0; i<10; i++)
249 for (j = 0; j<5; j++)
250 stat_info.isamb_levels[i][j] = 0;
251 stat_info.isamb_sizes[i] = 0;
252 stat_info.isamb_blocks[i] = 0;
255 dict_scan (zh->reg->dict, term_dict, &before, &after, &stat_info,
260 fprintf (stdout, " Blocks Occur Size KB Bytes/Entry\n");
261 for (i = 0; isc_block_used (zh->reg->isamc, i) >= 0; i++)
263 fprintf (stdout, " %8" ZINT_FORMAT0 " %8d", isc_block_used (zh->reg->isamc, i),
264 stat_info.no_isam_entries[i]);
266 if (stat_info.no_isam_entries[i])
267 fprintf (stdout, " %8d %f",
268 (int) ((1023.0 + (double)
269 isc_block_used(zh->reg->isamc, i) *
270 isc_block_size(zh->reg->isamc,i))/1024),
271 ((double) isc_block_used(zh->reg->isamc, i) *
272 isc_block_size(zh->reg->isamc,i))/
273 stat_info.no_isam_entries[i]);
274 fprintf (stdout, "\n");
280 for (i = 0; i<4; i++)
283 int bsize = isamb_block_info(zh->reg->isamb, i);
286 fprintf (stdout, "Category %d\n", i);
287 fprintf (stdout, "Block size %d\n", bsize);
288 fprintf (stdout, "Blocks: %d\n", stat_info.isamb_blocks[i]);
289 fprintf (stdout, "Size: %d\n", stat_info.isamb_sizes[i]);
290 fprintf (stdout, "Entries: %d\n", stat_info.no_isam_entries[i]);
291 fprintf (stdout, "Total %d\n", stat_info.isamb_blocks[i]*
293 for (j = 0; j<5; j++)
294 if (stat_info.isamb_levels[i][j])
295 fprintf (stdout, "Level%d %d\n", j,
296 stat_info.isamb_levels[i][j]);
297 fprintf (stdout, "\n");
300 fprintf (stdout, "Checksum %08lX\n", stat_info.cksum);
302 fprintf (stdout, "Distinct words %d\n", stat_info.no_dict_entries);
304 for (i = 0; i<9; i++)
305 occur += stat_info.no_isam_entries[i];
306 fprintf (stdout, "Word pos %d\n", occur);
307 fprintf (stdout, " Occurrences Words\n");
309 for (i = 0; stat_info.isam_bounds[i]; i++)
311 int here = stat_info.isam_bounds[i];
312 fprintf (stdout, "%7d-%-7d %7d\n",
313 prev, here, stat_info.isam_occurrences[i]);
316 fprintf (stdout, "%7d- %7d\n",
317 prev, stat_info.isam_occurrences[i]);
318 xmalloc_trav("unfreed"); /*! while hunting memory leaks */