2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss, Heikki Levanto
14 #include "../isamc/isamh-p.h"
15 #include "../isamc/isamd-p.h"
17 struct inv_stat_info {
23 int no_isam_entries[9];
27 int isam_occurrences[20];
31 #define SINGLETON_TYPE 8 /* the type to use for singletons that */
32 /* have no block and no block type */
34 static int inv_stat_handle (char *name, const char *info, int pos,
39 struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
42 stat_info->no_dict_entries++;
43 stat_info->no_dict_bytes += strlen(name);
45 assert (*info == sizeof(ISAM_P));
46 memcpy (&isam_p, info+1, sizeof(ISAM_P));
53 ispt = is_position (stat_info->isam, isam_p);
54 occur = is_numkeys (ispt);
63 pp = isc_pp_open (stat_info->isamc, isam_p);
64 occur = isc_pp_num (pp);
65 while (isc_pp_read(pp, &key))
67 //printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
70 assert (occurx == occur);
71 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
80 pp = isamh_pp_open (stat_info->isamh, isam_p);
82 occur = isamh_pp_num (pp);
83 while (isamh_pp_read(pp, &key))
86 //logf (LOG_LOG,"sysno=%d seqno=%d (%x/%x) oc=%d/%d ofs=%d ",
87 // key.sysno, key.seqno,
88 // key.sysno, key.seqno,
89 // occur,occurx, pp->offset);
91 if (occurx != occur) {
92 logf(LOG_LOG,"Count error!!! read %d, counted %d", occur, occurx);
93 //isamh_pp_dump(stat_info->isamh, isam_p);
95 stat_info->no_isam_entries[isamh_type(isam_p)] += occur;
104 pp = isamd_pp_open (stat_info->isamd, isam_p);
106 occur = isamd_pp_num (pp);
107 while (isamd_pp_read(pp, &key))
110 if ( pp->is->method->debug >8 )
111 logf (LOG_LOG,"sysno=%d seqno=%d (%x/%x) oc=%d/%d ofs=%d ",
112 key.sysno, key.seqno,
113 key.sysno, key.seqno,
114 occur,occurx, pp->offset);
116 if ( pp->is->method->debug >7 )
117 logf(LOG_LOG,"item %d=%d:%d says %d keys, counted %d",
118 isam_p, isamd_type(isam_p), isamd_block(isam_p),
121 logf(LOG_LOG,"Count error!!! read %d, counted %d", occur, occurx);
122 assert (occurx == occur);
123 if ( is_singleton(isam_p) )
124 stat_info->no_isam_entries[SINGLETON_TYPE] += occur;
126 stat_info->no_isam_entries[isamd_type(isam_p)] += occur;
129 if (stat_info->isams)
135 pp = isams_pp_open (stat_info->isams, isam_p);
136 occur = isams_pp_num (pp);
137 while (isams_pp_read(pp, &key))
139 //printf ("sysno=%d seqno=%d\n", key.sysno, key.seqno);
142 assert (occurx == occur);
143 stat_info->no_isam_entries[isc_type(isam_p)] += occur;
147 while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
149 ++(stat_info->isam_occurrences[i]);
153 void inv_prstat (BFiles bfs)
164 int after = 1000000000;
165 struct inv_stat_info stat_info;
166 char term_dict[2*IT_MAX_WORD+2];
174 dict = dict_open (bfs, FNAME_DICT, 100, 0, 0);
177 logf (LOG_FATAL, "dict_open fail");
180 if (res_get_match (common_resource, "isam", "i", NULL))
182 isam = is_open (bfs, FNAME_ISAM, key_compare, 0,
183 sizeof(struct it_key), common_resource);
186 logf (LOG_FATAL, "is_open fail");
190 else if (res_get_match (common_resource, "isam", "s", NULL))
192 struct ISAMS_M_s isams_m;
193 isams = isams_open (bfs, FNAME_ISAMS, 0,
194 key_isams_m(common_resource, &isams_m));
197 logf (LOG_FATAL, "isams_open fail");
201 else if (res_get_match (common_resource, "isam", "h", NULL))
203 isamh = isamh_open (bfs, FNAME_ISAMH, 0, key_isamh_m(common_resource));
206 logf (LOG_FATAL, "isamh_open fail");
210 else if (res_get_match (common_resource, "isam", "d", NULL))
212 struct ISAMD_M_s isamd_m;
213 isamd = isamd_open (bfs, FNAME_ISAMD, 0,
214 key_isamd_m(common_resource,&isamd_m));
217 logf (LOG_FATAL, "isamd_open fail");
223 struct ISAMC_M_s isamc_m;
224 isamc = isc_open (bfs, FNAME_ISAMC, 0,
225 key_isamc_m (common_resource, &isamc_m));
228 logf (LOG_FATAL, "isc_open fail");
232 records = rec_open (bfs, 0, 0);
234 for (i = 0; i<=SINGLETON_TYPE; i++)
235 stat_info.no_isam_entries[i] = 0;
236 stat_info.no_dict_entries = 0;
237 stat_info.no_dict_bytes = 0;
238 stat_info.isam = isam;
239 stat_info.isamc = isamc;
240 stat_info.isams = isams;
241 stat_info.isamh = isamh;
242 stat_info.isamd = isamd;
243 stat_info.isam_bounds[0] = 1;
244 stat_info.isam_bounds[1] = 2;
245 stat_info.isam_bounds[2] = 3;
246 stat_info.isam_bounds[3] = 6;
247 stat_info.isam_bounds[4] = 10;
248 stat_info.isam_bounds[5] = 20;
249 stat_info.isam_bounds[6] = 30;
250 stat_info.isam_bounds[7] = 50;
251 stat_info.isam_bounds[8] = 100;
252 stat_info.isam_bounds[9] = 200;
253 stat_info.isam_bounds[10] = 5000;
254 stat_info.isam_bounds[11] = 10000;
255 stat_info.isam_bounds[12] = 20000;
256 stat_info.isam_bounds[13] = 50000;
257 stat_info.isam_bounds[14] = 100000;
258 stat_info.isam_bounds[15] = 200000;
259 stat_info.isam_bounds[16] = 500000;
260 stat_info.isam_bounds[17] = 1000000;
261 stat_info.isam_bounds[18] = 0;
263 for (i = 0; i<20; i++)
264 stat_info.isam_occurrences[i] = 0;
266 dict_scan (dict, term_dict, &before, &after, &stat_info, inv_stat_handle);
270 fprintf (stderr, " Blocks Occur Size KB Bytes/Entry\n");
271 for (i = 0; isc_block_used (isamc, i) >= 0; i++)
273 fprintf (stderr, " %8d %8d", isc_block_used (isamc, i),
274 stat_info.no_isam_entries[i]);
276 if (stat_info.no_isam_entries[i])
277 fprintf (stderr, " %8d %f",
278 (int) ((1023.0 + (double) isc_block_used(isamc, i) *
279 isc_block_size(isamc,i))/1024),
280 ((double) isc_block_used(isamc, i) *
281 isc_block_size(isamc,i))/
282 stat_info.no_isam_entries[i]);
283 fprintf (stderr, "\n");
288 fprintf (stderr, " Blocks Occur KB Bytes/Entry\n");
289 if (isamd->method->debug >0)
290 logf(LOG_LOG," Blocks Occur KB Bytes/Entry");
291 for (i = 0; i<=SINGLETON_TYPE; i++)
293 blocks= isamd_block_used(isamd,i);
294 size= isamd_block_size(isamd,i);
295 count=stat_info.no_isam_entries[i];
296 if (i==SINGLETON_TYPE)
298 if (stat_info.no_isam_entries[i])
300 fprintf (stderr, "%c %7d %7d %7d %5.2f\n",
301 (i==SINGLETON_TYPE)?('z'):('A'+i),
304 (int) ((1023.0 + (double) blocks * size)/1024),
305 ((double) blocks * size)/count);
306 if (isamd->method->debug >0)
307 logf(LOG_LOG, "%c %7d %7d %7d %5.2f",
308 (i==SINGLETON_TYPE)?('z'):('A'+i),
311 (int) ((1023.0 + (double) blocks * size)/1024),
312 ((double) blocks * size)/count);
316 if ( (isamd) && (isamd->method->debug>0))
317 fprintf (stderr, "\n%d words using %d bytes\n",
318 stat_info.no_dict_entries, stat_info.no_dict_bytes);
319 fprintf (stderr, " Occurrences Words\n");
320 if ( (isamd) && (isamd->method->debug>0) )
322 logf(LOG_LOG, "%d words using %d bytes",
323 stat_info.no_dict_entries, stat_info.no_dict_bytes);
324 logf(LOG_LOG, " Occurrences Words");
327 for (i = 0; stat_info.isam_bounds[i]; i++)
329 int here = stat_info.isam_bounds[i];
330 fprintf (stderr, "%7d-%-7d %7d\n",
331 prev, here, stat_info.isam_occurrences[i]);
332 if ( (isamd) && (isamd->method->debug>0) &&
333 stat_info.isam_occurrences[i] )
335 logf(LOG_LOG,"%7d-%-7d %7d",
336 prev, here, stat_info.isam_occurrences[i]);
340 fprintf (stderr, "%7d- %7d\n",
341 prev, stat_info.isam_occurrences[i]);
342 if ( (isamd) && (isamd->method->debug>0) &&
343 ( stat_info.isam_occurrences[i] ||
344 stat_info.isam_occurrences[i+1]) )
345 logf(LOG_LOG,"%7d- %7d",
346 prev, stat_info.isam_occurrences[i]);
347 rec_close (&records);
361 xmalloc_trav("unfreed"); /*! while hunting memory leaks */
367 * $Log: invstat.c,v $
368 * Revision 1.18 1999-10-06 11:46:36 heikki
369 * mproved statistics on isam-d
371 * Revision 1.17 1999/08/20 08:28:37 heikki
374 * Revision 1.16 1999/08/18 08:38:22 heikki
375 * Memory leak hunting
377 * Revision 1.15 1999/08/18 08:34:53 heikki
380 * Revision 1.14 1999/07/14 10:59:26 adam
381 * Changed functions isc_getmethod, isams_getmethod.
382 * Improved fatal error handling (such as missing EXPLAIN schema).
384 * Revision 1.13 1999/07/08 14:23:27 heikki
385 * Fixed a bug in isamh_pp_read and cleaned up a bit
387 * Revision 1.12 1999/07/06 12:28:04 adam
388 * Updated record index structure. Format includes version ID. Compression
389 * algorithm ID is stored for each record block.
391 * Revision 1.11 1999/05/15 14:36:38 adam
392 * Updated dictionary. Implemented "compression" of dictionary.
394 * Revision 1.10 1999/05/12 13:08:06 adam
395 * First version of ISAMS.
397 * Revision 1.9 1999/02/12 13:29:23 adam
398 * Implemented position-flag for registers.
400 * Revision 1.8 1999/02/02 14:50:53 adam
401 * Updated WIN32 code specific sections. Changed header.
403 * Revision 1.7 1998/03/13 15:30:50 adam
404 * New functions isc_block_used and isc_block_size. Fixed 'leak'
405 * in isc_alloc_block.
407 * Revision 1.6 1998/03/06 13:54:02 adam
408 * Fixed two nasty bugs in isc_merge.
410 * Revision 1.5 1997/09/17 12:19:13 adam
411 * Zebra version corresponds to YAZ version 1.4.
412 * Changed Zebra server so that it doesn't depend on global common_resource.
414 * Revision 1.4 1996/11/08 11:10:21 adam
415 * Buffers used during file match got bigger.
416 * Compressed ISAM support everywhere.
417 * Bug fixes regarding masking characters in queries.
418 * Redesigned Regexp-2 queries.
420 * Revision 1.3 1996/06/04 10:18:58 adam
421 * Minor changes - removed include of ctype.h.
423 * Revision 1.2 1996/05/22 08:25:56 adam
426 * Revision 1.1 1996/05/14 14:04:34 adam
427 * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT