1 /* $Id: invstat.c,v 1.35 2003-06-20 14:21:23 heikki 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
29 #include "../isamc/isamd-p.h"
31 struct inv_stat_info {
33 int no_isam_entries[9];
37 int isam_occurrences[20];
39 int isamb_levels[10][5];
46 #define SINGLETON_TYPE 8 /* the type to use for singletons that */
47 /* have no block and no block type */
49 static void print_dict_item (ZebraMaps zm, const char *s, int count,
50 int firstsys, int firstseq, int lastsys, int lastseq )
53 char keybuf[IT_MAX_WORD+1];
55 const char *from = s + 2;
59 const char *res = zebra_maps_output (zm, reg_type, &from);
67 /* yaz_log (LOG_LOG, "%s", keybuf); */
68 printf("%10d %s %d.%d - %d.%d\n",count, keybuf,
69 firstsys,firstseq, lastsys,lastseq);
72 static int inv_stat_handle (char *name, const char *info, int pos,
77 struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
84 stat_info->no_dict_entries++;
85 stat_info->no_dict_bytes += strlen(name);
87 if (!stat_info->zh->reg->isamd)
89 assert (*info == sizeof(ISAMS_P));
90 memcpy (&isam_p, info+1, sizeof(ISAMS_P));
93 if (stat_info->zh->reg->isams)
99 pp = isams_pp_open (stat_info->zh->reg->isams, isam_p);
100 occur = isams_pp_num (pp);
101 while (isams_pp_read(pp, &key))
103 stat_info->cksum = stat_info->cksum * 65509 +
104 key.sysno + 11 * key.seqno;
114 assert (occurx == occur);
115 stat_info->no_isam_entries[0] += occur;
118 if (stat_info->zh->reg->isam)
122 ispt = is_position (stat_info->zh->reg->isam, isam_p);
123 occur = is_numkeys (ispt);
124 stat_info->no_isam_entries[is_type(isam_p)] += occur;
127 if (stat_info->zh->reg->isamc)
133 pp = isc_pp_open (stat_info->zh->reg->isamc, isam_p);
134 occur = isc_pp_num (pp);
135 while (isc_pp_read(pp, &key))
137 stat_info->cksum = stat_info->cksum * 65509 +
138 key.sysno + 11 * key.seqno;
148 assert (occurx == occur);
149 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
152 if (stat_info->zh->reg->isamd)
157 /* printf("[%d: %d %d %d %d %d %d] ", */
158 /* info[0], info[1], info[2], info[3], info[4], info[5], info[7]);*/
159 pp = isamd_pp_open (stat_info->zh->reg->isamd, info+1, info[0]);
161 occur = isamd_pp_num (pp);
162 while (isamd_pp_read(pp, &key))
164 stat_info->cksum = stat_info->cksum * 65509 +
165 key.sysno + 11 * key.seqno;
167 /* printf("%d.%d ", key.sysno, key.seqno); */ /*!*/
175 if ( pp->is->method->debug >8 )
176 logf (LOG_LOG,"sysno=%d seqno=%d (%x/%x) oc=%d/%d ofs=%d ",
177 key.sysno, key.seqno,
178 key.sysno, key.seqno,
179 occur,occurx, pp->offset);
181 /* printf("\n"); */ /*!*/
183 if ( pp->is->method->debug >7 )
184 logf(LOG_LOG,"item %d=%d:%d says %d keys, counted %d",
185 isam_p, isamd_type(isam_p), isamd_block(isam_p),
189 logf(LOG_LOG,"Count error!!! read %d, counted %d", occur, occurx);
190 assert (occurx == occur);
194 stat_info->no_isam_entries[i] += occur;
197 if (stat_info->zh->reg->isamb)
201 int cat = isam_p & 3;
206 pp = isamb_pp_open_x(stat_info->zh->reg->isamb, isam_p, &level);
208 while (isamb_pp_read(pp, &key))
210 stat_info->cksum = stat_info->cksum * 65509 +
211 key.sysno + 11 * key.seqno;
221 isamb_pp_close_x (pp, &size, &blocks);
222 stat_info->isamb_blocks[cat] += blocks;
223 stat_info->isamb_sizes[cat] += size;
226 stat_info->isamb_levels[cat][level] ++;
227 stat_info->no_isam_entries[cat] += occur;
230 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
232 ++(stat_info->isam_occurrences[i]);
233 if (stat_info->dumpwords)
234 print_dict_item(stat_info->zh->reg->zebra_maps, name, occur,
235 firstsys,firstseq, lastsys, lastseq);
239 int zebra_register_statistics (ZebraHandle zh, int dumpdict)
247 int after = 1000000000;
248 struct inv_stat_info stat_info;
249 char term_dict[2*IT_MAX_WORD+2];
251 if (zebra_begin_read (zh))
255 stat_info.dumpwords=dumpdict;
260 for (i = 0; i<=SINGLETON_TYPE; i++)
261 stat_info.no_isam_entries[i] = 0;
262 stat_info.no_dict_entries = 0;
263 stat_info.no_dict_bytes = 0;
264 stat_info.isam_bounds[0] = 1;
265 stat_info.isam_bounds[1] = 2;
266 stat_info.isam_bounds[2] = 3;
267 stat_info.isam_bounds[3] = 6;
268 stat_info.isam_bounds[4] = 10;
269 stat_info.isam_bounds[5] = 20;
270 stat_info.isam_bounds[6] = 30;
271 stat_info.isam_bounds[7] = 50;
272 stat_info.isam_bounds[8] = 100;
273 stat_info.isam_bounds[9] = 200;
274 stat_info.isam_bounds[10] = 5000;
275 stat_info.isam_bounds[11] = 10000;
276 stat_info.isam_bounds[12] = 20000;
277 stat_info.isam_bounds[13] = 50000;
278 stat_info.isam_bounds[14] = 100000;
279 stat_info.isam_bounds[15] = 200000;
280 stat_info.isam_bounds[16] = 500000;
281 stat_info.isam_bounds[17] = 1000000;
282 stat_info.isam_bounds[18] = 0;
286 for (i = 0; i<20; i++)
287 stat_info.isam_occurrences[i] = 0;
289 for (i = 0; i<10; i++)
292 for (j = 0; j<5; j++)
293 stat_info.isamb_levels[i][j] = 0;
294 stat_info.isamb_sizes[i] = 0;
295 stat_info.isamb_blocks[i] = 0;
298 dict_scan (zh->reg->dict, term_dict, &before, &after, &stat_info,
303 fprintf (stdout, " Blocks Occur Size KB Bytes/Entry\n");
304 for (i = 0; isc_block_used (zh->reg->isamc, i) >= 0; i++)
306 fprintf (stdout, " %8d %8d", isc_block_used (zh->reg->isamc, i),
307 stat_info.no_isam_entries[i]);
309 if (stat_info.no_isam_entries[i])
310 fprintf (stdout, " %8d %f",
311 (int) ((1023.0 + (double)
312 isc_block_used(zh->reg->isamc, i) *
313 isc_block_size(zh->reg->isamc,i))/1024),
314 ((double) isc_block_used(zh->reg->isamc, i) *
315 isc_block_size(zh->reg->isamc,i))/
316 stat_info.no_isam_entries[i]);
317 fprintf (stdout, "\n");
322 fprintf (stdout, " Blocks Occur KB Bytes/Entry\n");
323 if (zh->reg->isamd->method->debug >0)
324 logf(LOG_LOG," Blocks Occur KB Bytes/Entry");
325 for (i = 0; i<=SINGLETON_TYPE; i++)
327 blocks= isamd_block_used(zh->reg->isamd,i);
328 size= isamd_block_size(zh->reg->isamd,i);
329 count=stat_info.no_isam_entries[i];
330 if (i==SINGLETON_TYPE)
332 if (stat_info.no_isam_entries[i])
334 fprintf (stdout, "%c %7d %7d %7d %5.2f\n",
335 (i==SINGLETON_TYPE)?('z'):('A'+i),
338 (int) ((1023.0 + (double) blocks * size)/1024),
339 ((double) blocks * size)/count);
340 if (zh->reg->isamd->method->debug >0)
341 logf(LOG_LOG, "%c %7d %7d %7d %5.2f",
342 (i==SINGLETON_TYPE)?('z'):('A'+i),
345 (int) ((1023.0 + (double) blocks * size)/1024),
346 ((double) blocks * size)/count);
350 if ( (zh->reg->isamd) && (zh->reg->isamd->method->debug>0))
351 fprintf (stdout, "\n%d words using %d bytes\n",
352 stat_info.no_dict_entries, stat_info.no_dict_bytes);
356 for (i = 0; i<4; i++)
359 int bsize = isamb_block_info(zh->reg->isamb, i);
362 fprintf (stdout, "Category %d\n", i);
363 fprintf (stdout, "Block size %d\n", bsize);
364 fprintf (stdout, "Blocks: %d\n", stat_info.isamb_blocks[i]);
365 fprintf (stdout, "Size: %d\n", stat_info.isamb_sizes[i]);
366 fprintf (stdout, "Entries: %d\n", stat_info.no_isam_entries[i]);
367 fprintf (stdout, "Total %d\n", stat_info.isamb_blocks[i]*
369 for (j = 0; j<5; j++)
370 if (stat_info.isamb_levels[i][j])
371 fprintf (stdout, "Level%d %d\n", j,
372 stat_info.isamb_levels[i][j]);
373 fprintf (stdout, "\n");
376 fprintf (stdout, "Checksum %08lX\n", stat_info.cksum);
378 fprintf (stdout, "Distinct words %d\n", stat_info.no_dict_entries);
380 for (i = 0; i<9; i++)
381 occur += stat_info.no_isam_entries[i];
382 fprintf (stdout, "Word pos %d\n", occur);
383 fprintf (stdout, " Occurrences Words\n");
385 for (i = 0; stat_info.isam_bounds[i]; i++)
387 int here = stat_info.isam_bounds[i];
388 fprintf (stdout, "%7d-%-7d %7d\n",
389 prev, here, stat_info.isam_occurrences[i]);
392 fprintf (stdout, "%7d- %7d\n",
393 prev, stat_info.isam_occurrences[i]);
394 xmalloc_trav("unfreed"); /*! while hunting memory leaks */