1 /* $Id: invstat.c,v 1.40 2004-09-09 10:08:05 heikki Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
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("%10" ZINT_FORMAT0 " %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->isamc)
123 pp = isc_pp_open (stat_info->zh->reg->isamc, isam_p);
124 occur = isc_pp_num (pp);
125 while (isc_pp_read(pp, &key))
130 stat_info->cksum = stat_info->cksum * 65509 +
131 key.sysno + 11 * key.seqno;
141 assert (occurx == occur);
142 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
145 if (stat_info->zh->reg->isamb)
149 int cat = (int) (isam_p & 3);
154 pp = isamb_pp_open_x(stat_info->zh->reg->isamb, isam_p, &level, 0);
156 while (isamb_pp_read(pp, &key))
161 stat_info->cksum = stat_info->cksum * 65509 +
162 key.sysno + 11 * key.seqno;
172 isamb_pp_close_x (pp, &size, &blocks);
173 stat_info->isamb_blocks[cat] += blocks;
174 stat_info->isamb_sizes[cat] += size;
177 stat_info->isamb_levels[cat][level] ++;
178 stat_info->no_isam_entries[cat] += occur;
181 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
183 ++(stat_info->isam_occurrences[i]);
184 if (stat_info->dumpwords)
185 print_dict_item(stat_info->zh->reg->zebra_maps, name, occur,
186 firstsys,firstseq, lastsys, lastseq);
190 int zebra_register_statistics (ZebraHandle zh, int dumpdict)
195 int after = 1000000000;
196 struct inv_stat_info stat_info;
197 char term_dict[2*IT_MAX_WORD+2];
199 if (zebra_begin_read (zh))
203 stat_info.dumpwords=dumpdict;
208 for (i = 0; i<=SINGLETON_TYPE; i++)
209 stat_info.no_isam_entries[i] = 0;
210 stat_info.no_dict_entries = 0;
211 stat_info.no_dict_bytes = 0;
212 stat_info.isam_bounds[0] = 1;
213 stat_info.isam_bounds[1] = 2;
214 stat_info.isam_bounds[2] = 3;
215 stat_info.isam_bounds[3] = 6;
216 stat_info.isam_bounds[4] = 10;
217 stat_info.isam_bounds[5] = 20;
218 stat_info.isam_bounds[6] = 30;
219 stat_info.isam_bounds[7] = 50;
220 stat_info.isam_bounds[8] = 100;
221 stat_info.isam_bounds[9] = 200;
222 stat_info.isam_bounds[10] = 5000;
223 stat_info.isam_bounds[11] = 10000;
224 stat_info.isam_bounds[12] = 20000;
225 stat_info.isam_bounds[13] = 50000;
226 stat_info.isam_bounds[14] = 100000;
227 stat_info.isam_bounds[15] = 200000;
228 stat_info.isam_bounds[16] = 500000;
229 stat_info.isam_bounds[17] = 1000000;
230 stat_info.isam_bounds[18] = 0;
234 for (i = 0; i<20; i++)
235 stat_info.isam_occurrences[i] = 0;
237 for (i = 0; i<10; i++)
240 for (j = 0; j<5; j++)
241 stat_info.isamb_levels[i][j] = 0;
242 stat_info.isamb_sizes[i] = 0;
243 stat_info.isamb_blocks[i] = 0;
246 dict_scan (zh->reg->dict, term_dict, &before, &after, &stat_info,
251 fprintf (stdout, " Blocks Occur Size KB Bytes/Entry\n");
252 for (i = 0; isc_block_used (zh->reg->isamc, i) >= 0; i++)
254 fprintf (stdout, " %8" ZINT_FORMAT0 " %8" ZINT_FORMAT0,
255 isc_block_used (zh->reg->isamc, i),
256 stat_info.no_isam_entries[i]);
258 if (stat_info.no_isam_entries[i])
259 fprintf (stdout, " %8d %f",
260 (int) ((1023.0 + (double)
261 isc_block_used(zh->reg->isamc, i) *
262 isc_block_size(zh->reg->isamc,i))/1024),
263 ((double) isc_block_used(zh->reg->isamc, i) *
264 isc_block_size(zh->reg->isamc,i))/
265 stat_info.no_isam_entries[i]);
266 fprintf (stdout, "\n");
272 for (i = 0; i<4; i++)
275 int bsize = isamb_block_info(zh->reg->isamb, i);
278 fprintf (stdout, "Category %d\n", i);
279 fprintf (stdout, "Block size %d\n", bsize);
280 fprintf (stdout, "Blocks: %d\n", stat_info.isamb_blocks[i]);
281 fprintf (stdout, "Size: %d\n", stat_info.isamb_sizes[i]);
282 fprintf (stdout, "Entries: " ZINT_FORMAT "\n",
283 stat_info.no_isam_entries[i]);
284 fprintf (stdout, "Total %d\n", stat_info.isamb_blocks[i]*
286 for (j = 0; j<5; j++)
287 if (stat_info.isamb_levels[i][j])
288 fprintf (stdout, "Level%d %d\n", j,
289 stat_info.isamb_levels[i][j]);
290 fprintf (stdout, "\n");
293 fprintf (stdout, "Checksum %08lX\n", stat_info.cksum);
295 fprintf (stdout, "Distinct words %d\n", stat_info.no_dict_entries);
297 for (i = 0; i<9; i++)
298 occur += stat_info.no_isam_entries[i];
299 fprintf (stdout, "Word pos " ZINT_FORMAT "\n", occur);
300 fprintf (stdout, " Occurrences Words\n");
302 for (i = 0; stat_info.isam_bounds[i]; i++)
304 int here = stat_info.isam_bounds[i];
305 fprintf (stdout, "%7d-%-7d %7d\n",
306 prev, here, stat_info.isam_occurrences[i]);
309 fprintf (stdout, "%7d- %7d\n",
310 prev, stat_info.isam_occurrences[i]);
311 xmalloc_trav("unfreed"); /*! while hunting memory leaks */