Fixed a bug in isamd, failed to store a single key when its bits
[idzebra-moved-to-github.git] / index / invstat.c
index dd808da..27636ae 100644 (file)
@@ -24,11 +24,35 @@ struct inv_stat_info {
     int isamb_sizes[10];
     int isamb_blocks[10];
     unsigned long cksum;
+    int dumpwords;
 };
 
 #define SINGLETON_TYPE 8 /* the type to use for singletons that */ 
                          /* have no block and no block type */
 
+static void print_dict_item (ZebraMaps zm, const char *s, int count,
+            int firstsys, int firstseq, int lastsys, int lastseq )
+{
+    int reg_type = s[1];
+    char keybuf[IT_MAX_WORD+1];
+    char *to = keybuf;
+    const char *from = s + 2;
+
+    while (*from)
+    {
+        const char *res = zebra_maps_output (zm, reg_type, &from);
+        if (!res)
+            *to++ = *from++;
+        else
+            while (*res)
+                *to++ = *res++;
+    }
+    *to = '\0';
+    /* yaz_log (LOG_LOG, "%s", keybuf); */
+    printf("%10d %s %d.%d - %d.%d\n",count, keybuf,
+              firstsys,firstseq, lastsys,lastseq);
+}
+
 static int inv_stat_handle (char *name, const char *info, int pos,
                             void *client)
 {
@@ -36,6 +60,10 @@ static int inv_stat_handle (char *name, const char *info, int pos,
     int i = 0;
     struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
     ISAMS_P isam_p;
+    int firstsys=-1;
+    int firstseq=-1;
+    int lastsys=-1;
+    int lastseq=-1;
 
     stat_info->no_dict_entries++;
     stat_info->no_dict_bytes += strlen(name);
@@ -43,6 +71,7 @@ static int inv_stat_handle (char *name, const char *info, int pos,
     assert (*info == sizeof(ISAMS_P));
     memcpy (&isam_p, info+1, sizeof(ISAMS_P));
 
+
     if (stat_info->zh->reg->isams)
     {
         ISAMS_PP pp;
@@ -56,6 +85,13 @@ static int inv_stat_handle (char *name, const char *info, int pos,
             stat_info->cksum = stat_info->cksum * 65509 + 
                 key.sysno + 11 * key.seqno;
             occurx++;
+            if (-1==firstsys)
+            {
+                firstseq=key.seqno;
+                firstsys=key.sysno;
+            }
+            lastsys=key.sysno;
+            lastseq=key.seqno;
        }
         assert (occurx == occur);
        stat_info->no_isam_entries[0] += occur;
@@ -83,6 +119,13 @@ static int inv_stat_handle (char *name, const char *info, int pos,
             stat_info->cksum = stat_info->cksum * 65509 + 
                 key.sysno + 11 * key.seqno;
             occurx++;
+            if (-1==firstsys)
+            {
+                firstseq=key.seqno;
+                firstsys=key.sysno;
+            }
+            lastsys=key.sysno;
+            lastseq=key.seqno;
        }
         assert (occurx == occur);
        stat_info->no_isam_entries[isc_type(isam_p)] += occur;
@@ -102,6 +145,13 @@ static int inv_stat_handle (char *name, const char *info, int pos,
             stat_info->cksum = stat_info->cksum * 65509 + 
                 key.sysno + 11 * key.seqno;
             occurx++;
+            if (-1==firstsys)
+            {
+                firstseq=key.seqno;
+                firstsys=key.sysno;
+            }
+            lastsys=key.sysno;
+            lastseq=key.seqno;
             if ( pp->is->method->debug >8 )
               logf (LOG_LOG,"sysno=%d seqno=%d (%x/%x) oc=%d/%d ofs=%d ",
                   key.sysno, key.seqno,
@@ -137,6 +187,13 @@ static int inv_stat_handle (char *name, const char *info, int pos,
             stat_info->cksum = stat_info->cksum * 65509 + 
                 key.sysno + 11 * key.seqno;
             occur++;
+            if (-1==firstsys)
+            {
+                firstseq=key.seqno;
+                firstsys=key.sysno;
+            }
+            lastsys=key.sysno;
+            lastseq=key.seqno;
         }
         isamb_pp_close_x (pp, &size, &blocks);
         stat_info->isamb_blocks[cat] += blocks;
@@ -150,10 +207,13 @@ static int inv_stat_handle (char *name, const char *info, int pos,
     while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
         i++;
     ++(stat_info->isam_occurrences[i]);
+    if (stat_info->dumpwords)
+       print_dict_item(stat_info->zh->reg->zebra_maps, name, occur,
+          firstsys,firstseq, lastsys, lastseq);
     return 0;
 }
 
-void zebra_register_statistics (ZebraHandle zh)
+void zebra_register_statistics (ZebraHandle zh, int dumpdict)
 {
     int blocks;
     int size;
@@ -169,6 +229,7 @@ void zebra_register_statistics (ZebraHandle zh)
        return;
 
     stat_info.zh = zh;
+    stat_info.dumpwords=dumpdict;
 
     term_dict[0] = 1;
     term_dict[1] = 0;
@@ -315,7 +376,15 @@ void zebra_register_statistics (ZebraHandle zh)
 /*
  *
  * $Log: invstat.c,v $
- * Revision 1.29  2002-06-19 10:29:17  adam
+ * Revision 1.31  2002-07-11 16:16:00  heikki
+ * Fixed a bug in isamd, failed to store a single key when its bits
+ * did not fit into a singleton.
+ *
+ * Revision 1.30  2002/07/11 13:03:01  heikki
+ * Added dumpdict command line option to dump the
+ * dictionary before doing the usual stats
+ *
+ * Revision 1.29  2002/06/19 10:29:17  adam
  * align block sizes for isam sys. Better plot for test
  *
  * Revision 1.28  2002/04/30 19:31:09  adam