table_stats.h

00001 /* File:      table_stats.h
00002 ** Author(s): Ernie Johnson
00003 ** Contact:   xsb-contact@cs.sunysb.edu
00004 ** 
00005 ** Copyright (C) The Research Foundation of SUNY, 1986, 1993-1998
00006 ** 
00007 ** XSB is free software; you can redistribute it and/or modify it under the
00008 ** terms of the GNU Library General Public License as published by the Free
00009 ** Software Foundation; either version 2 of the License, or (at your option)
00010 ** any later version.
00011 ** 
00012 ** XSB is distributed in the hope that it will be useful, but WITHOUT ANY
00013 ** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014 ** FOR A PARTICULAR PURPOSE.  See the GNU Library General Public License for
00015 ** more details.
00016 ** 
00017 ** You should have received a copy of the GNU Library General Public License
00018 ** along with XSB; if not, write to the Free Software Foundation,
00019 ** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00020 **
00021 ** $Id: table_stats.h,v 1.11 2006/01/13 23:56:57 tswift Exp $
00022 ** 
00023 */
00024 
00025 
00026 #ifndef TABLE_STATISTICS
00027 
00028 #define TABLE_STATISTICS
00029 
00030 #include "struct_manager.h"
00031 
00032 /*=========================================================================*/
00033 
00034 /*
00035  *       Interface for Reporting Tabling-Component Usage Statistics
00036  *       ==========================================================
00037  */
00038 
00039 
00040 /*
00041  *                       Recording Current Usage
00042  *                       -----------------------
00043  */
00044 
00045 
00046 /* For Generic Nodes
00047    ----------------- */
00048 typedef struct {
00049   counter nBlocks;      /* num blocks of nodes allocated (if applicable) */
00050   counter nAlloced;     /* total number of nodes allocated */
00051   counter nFree;        /* number of allocated nodes not currently in use */
00052   counter size;         /* size of your particular node */
00053 } NodeStats;
00054 
00055 #define NodeStats_NumBlocks(NS)         ( (NS).nBlocks )
00056 
00057 #define NodeStats_NumAllocNodes(NS)     ( (NS).nAlloced )
00058 #define NodeStats_NumFreeNodes(NS)      ( (NS).nFree )
00059 #define NodeStats_NumUsedNodes(NS)      ( (NS).nAlloced - (NS).nFree )
00060 
00061 #define NodeStats_NodeSize(NS)          ( (NS).size )
00062 
00063 #define NodeStats_SizeAllocNodes(NS)    ( NodeStats_NumAllocNodes(NS)   \
00064                                           * NodeStats_NodeSize(NS) )
00065 #define NodeStats_SizeFreeNodes(NS)     ( NodeStats_NumFreeNodes(NS)    \
00066                                           * NodeStats_NodeSize(NS) )
00067 #define NodeStats_SizeUsedNodes(NS)     ( NodeStats_NumUsedNodes(NS)    \
00068                                           * NodeStats_NodeSize(NS) )
00069 
00070 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
00071 
00072 /* For Hash Tables
00073    --------------- */
00074 typedef struct {
00075   NodeStats hdr;        /* contains stats about the headers */
00076   counter ttlBkts;      /* total number of buckets allocated */
00077   counter ttlUsedBkts;  /* number of nonempty buckets */
00078   counter occupancy;    /* number of objects maintained by the hash table(s) */
00079   counter bktSize;      /* size of each bucket (usually just a pointer) */
00080 } HashStats;
00081 
00082 #define HashStats_NumBlocks(HS)         NodeStats_NumBlocks((HS).hdr)
00083 
00084 #define HashStats_NumAllocHeaders(HS)   NodeStats_NumAllocNodes((HS).hdr)
00085 #define HashStats_NumFreeHeaders(HS)    NodeStats_NumFreeNodes((HS).hdr)
00086 #define HashStats_NumUsedHeaders(HS)    NodeStats_NumUsedNodes((HS).hdr)
00087 
00088 #define HashStats_HeaderSize(HS)        NodeStats_NodeSize((HS).hdr)
00089 
00090 #define HashStats_SizeAllocHeaders(HS)  NodeStats_SizeAllocNodes((HS).hdr)
00091 #define HashStats_SizeUsedHeaders(HS)   NodeStats_SizeUsedNodes((HS).hdr)
00092 #define HashStats_SizeFreeHeaders(HS)   NodeStats_SizeFreeNodes((HS).hdr)
00093 
00094 #define HashStats_NumBuckets(HS)        ( (HS).ttlBkts )
00095 #define HashStats_NonEmptyBuckets(HS)   ( (HS).ttlUsedBkts )
00096 #define HashStats_EmptyBuckets(HS)      ( (HS).ttlBkts - (HS).ttlUsedBkts )
00097 #define HashStats_TotalOccupancy(HS)    ( (HS).occupancy )
00098 
00099 #define HashStats_BucketSize(HS)        ( (HS).bktSize )
00100 
00101 #define HashStats_SizeAllocBuckets(HS)  ( HashStats_NumBuckets(HS) *    \
00102                                           HashStats_BucketSize(HS) )
00103 
00104 #define HashStats_SizeAllocTotal(HS)    ( HashStats_SizeAllocHeaders(HS) + \
00105                                           HashStats_SizeAllocBuckets(HS) )
00106 #define HashStats_SizeUsedTotal(HS)     ( HashStats_SizeUsedHeaders(HS) +  \
00107                                           HashStats_SizeAllocBuckets(HS) )
00108 #define HashStats_SizeFreeTotal(HS)     HashStats_SizeFreeHeaders(HS)
00109 
00110 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
00111 
00112 /* Collection Routines
00113    ------------------- */
00114 NodeStats subgoal_statistics(CTXTdeclc Structure_Manager *);
00115 NodeStats node_statistics(Structure_Manager *);
00116 HashStats hash_statistics(Structure_Manager *);
00117 
00118 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
00119 
00120 /* Helpful Totaling Routines
00121    ------------------------- */
00122 
00123 #ifndef MULTI_THREAD
00124 #define CurrentTotalTableSpaceAlloc(BTN,BTHT,VARSF,PRODSF,CONSSF,           \
00125                                     ALN,TSTN,TSTHT,TSI)                     \
00126   ( NodeStats_SizeAllocNodes(BTN)  +  HashStats_SizeAllocTotal(BTHT)  +     \
00127     NodeStats_SizeAllocNodes(VARSF)  +  NodeStats_SizeAllocNodes(PRODSF)  + \
00128     NodeStats_SizeAllocNodes(CONSSF)  +  NodeStats_SizeAllocNodes(ALN)  +   \
00129     NodeStats_SizeAllocNodes(TSTN)  +  HashStats_SizeAllocTotal(TSTHT)  +   \
00130     NodeStats_SizeAllocNodes(TSI) )
00131 
00132 #define CurrentTotalTableSpaceUsed(BTN,BTHT,VARSF,PRODSF,CONSSF,          \
00133                                    ALN,TSTN,TSTHT,TSI)                    \
00134   ( NodeStats_SizeUsedNodes(BTN)  +  HashStats_SizeUsedTotal(BTHT)  +     \
00135     NodeStats_SizeUsedNodes(VARSF)  +  NodeStats_SizeUsedNodes(PRODSF)  + \
00136     NodeStats_SizeUsedNodes(CONSSF)  +  NodeStats_SizeUsedNodes(ALN)  +   \
00137     NodeStats_SizeUsedNodes(TSTN)  +  HashStats_SizeUsedTotal(TSTHT)  +   \
00138     NodeStats_SizeUsedNodes(TSI) )
00139 
00140 #else
00141 
00142 #define CurrentTotalTableSpaceAlloc(BTN,BTHT,VARSF,PRODSF,CONSSF,           \
00143                                     ALN,TSTN,TSTHT,TSI)                     \
00144   ( NodeStats_SizeAllocNodes(BTN)  +  HashStats_SizeAllocTotal(BTHT)  +     \
00145     NodeStats_SizeAllocNodes(VARSF)  +  NodeStats_SizeAllocNodes(PRODSF)  + \
00146     NodeStats_SizeAllocNodes(CONSSF)  +  NodeStats_SizeAllocNodes(ALN)  +   \
00147     NodeStats_SizeAllocNodes(TSTN)  +  HashStats_SizeAllocTotal(TSTHT)  +   \
00148     NodeStats_SizeAllocNodes(TSI) )
00149 
00150 #define CurrentTotalTableSpaceUsed(BTN,BTHT,VARSF,PRODSF,CONSSF,          \
00151                                    ALN,TSTN,TSTHT,TSI)                    \
00152   ( NodeStats_SizeUsedNodes(BTN)  +  HashStats_SizeUsedTotal(BTHT)  +     \
00153     NodeStats_SizeUsedNodes(VARSF)  +  NodeStats_SizeUsedNodes(PRODSF)  + \
00154     NodeStats_SizeUsedNodes(CONSSF)  +  NodeStats_SizeUsedNodes(ALN)  +   \
00155     NodeStats_SizeUsedNodes(TSTN)  +  HashStats_SizeUsedTotal(TSTHT)  +   \
00156     NodeStats_SizeUsedNodes(TSI) )
00157 
00158 #define CurrentSharedTableSpaceAlloc(BTN,BTHT,VARSF,ALN)                \
00159   ( NodeStats_SizeAllocNodes(BTN)  +  HashStats_SizeAllocTotal(BTHT)  +     \
00160     NodeStats_SizeAllocNodes(VARSF)  +  NodeStats_SizeAllocNodes(ALN) )
00161 
00162 #define CurrentPrivateTableSpaceAlloc(BTN,BTHT,VARSF,PRODSF,CONSSF,         \
00163                                     ALN,TSTN,TSTHT,TSI)                     \
00164   ( NodeStats_SizeAllocNodes(BTN)  +  HashStats_SizeAllocTotal(BTHT)  +     \
00165     NodeStats_SizeAllocNodes(VARSF)  +  NodeStats_SizeAllocNodes(PRODSF)  + \
00166     NodeStats_SizeAllocNodes(CONSSF)  +  NodeStats_SizeAllocNodes(ALN)  +   \
00167     NodeStats_SizeAllocNodes(TSTN)  +  HashStats_SizeAllocTotal(TSTHT)  +   \
00168     NodeStats_SizeAllocNodes(TSI) )
00169 
00170 #define CurrentSharedTableSpaceUsed(BTN,BTHT,VARSF,ALN)                 \
00171   ( NodeStats_SizeUsedNodes(BTN)  +  HashStats_SizeUsedTotal(BTHT)  +   \
00172     NodeStats_SizeUsedNodes(VARSF) + NodeStats_SizeUsedNodes(ALN) )
00173 
00174 #define CurrentPrivateTableSpaceUsed(BTN,BTHT,VARSF,PRODSF,CONSSF,        \
00175                                    ALN,TSTN,TSTHT,TSI)                    \
00176   ( NodeStats_SizeUsedNodes(BTN)  +  HashStats_SizeUsedTotal(BTHT)  +     \
00177     NodeStats_SizeUsedNodes(VARSF)  +  NodeStats_SizeUsedNodes(PRODSF)  + \
00178     NodeStats_SizeUsedNodes(CONSSF)  +  NodeStats_SizeUsedNodes(ALN)  +   \
00179     NodeStats_SizeUsedNodes(TSTN)  +  HashStats_SizeUsedTotal(TSTHT)  +   \
00180     NodeStats_SizeUsedNodes(TSI) )
00181 
00182 #endif
00183 
00184 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
00185 
00186 /* Printing Routines
00187    ----------------- */
00188 void print_detailed_tablespace_stats(CTXTdecl);
00189 
00190 /*-------------------------------------------------------------------------*/
00191 
00192 /*
00193  *                       Recording Maximum Usage
00194  *                       -----------------------
00195  */
00196 
00197 /* Reset Usage
00198    ----------- */
00199 void reset_maximum_tablespace_stats(void);
00200 
00201 /* Poll Current Usage for New Maximum
00202    ---------------------------------- */
00203 void compute_maximum_tablespace_stats(CTXTdecl);
00204 void update_maximum_tablespace_stats(NodeStats *btn, HashStats *btht,
00205                                      NodeStats *varsf, NodeStats *prodsf,
00206                                      NodeStats *conssf, NodeStats *aln,
00207                                      NodeStats *tstn, HashStats *tstht,
00208                                      NodeStats *tsi);
00209 
00210 /* Read Currently Recorded Maximum Values
00211    -------------------------------------- */
00212 /**** One should first force a check of the maximum usage before ****/
00213 /**** querying for these values. ****/
00214 counter maximum_answer_list_nodes(void);
00215 counter maximum_timestamp_index_nodes(void);
00216 unsigned long  maximum_total_tablespace_usage(void);
00217 
00218 /*=========================================================================*/
00219 
00220 /*
00221  *   Interface for Recording and Reporting Tabling-Operation Statistics
00222  *   ==================================================================
00223  */
00224 
00225 
00226 /*
00227  *                      For Subsumptive Evaluations
00228  *                      ---------------------------
00229  */
00230 
00231 typedef struct {
00232   struct {               /* Call Check/Insert Operation */
00233     counter total;       /* - total number of call-check/insert ops */
00234     counter complete;    /* - calls which were satisfied by completed table */
00235     struct {
00236       counter n;         /* - number of created producers */
00237       counter vrnt;      /* - number of calls which are variants of an
00238                            established producer */
00239     } producer;
00240     struct {
00241       counter total;     /* - total number of properly subsumed calls */
00242       counter entry;     /* - number of properly subsumed calls that were given
00243                            an entry in the call table */
00244     } subsumed;
00245   } CallCI;
00246   struct {               /* Answer Check/Insert Operation */
00247     counter total;       /* - total number of answer-check/insert ops */
00248     counter inserts;     /* - number of inserted substitutions */
00249   } AnsCI;
00250   counter consumption;   /* Answer Consumptions for all consumer subgoals */
00251   counter identify;      /* Relevant Answer Collections for all subsumed
00252                             subgoals */
00253 } NumSubOps;
00254 
00255 #define INIT_NUMSUBOPS   { {0,0,{0,0},{0,0}}, {0,0}, 0, 0 }
00256 extern NumSubOps numSubOps;
00257 
00258 #define NumSubOps_CallCheckInsert          numSubOps.CallCI.total
00259 #define NumSubOps_CallToCompletedTable     numSubOps.CallCI.complete
00260 #define NumSubOps_ProducerCall             numSubOps.CallCI.producer.n
00261 #define NumSubOps_VariantCall              numSubOps.CallCI.producer.vrnt
00262 #define NumSubOps_SubsumedCall             numSubOps.CallCI.subsumed.total
00263 #define NumSubOps_SubsumedCallEntry        numSubOps.CallCI.subsumed.entry
00264 #define NumSubOps_AnswerCheckInsert        numSubOps.AnsCI.total
00265 #define NumSubOps_AnswerInsert             numSubOps.AnsCI.inserts
00266 #define NumSubOps_AnswerConsumption        numSubOps.consumption
00267 #define NumSubOps_IdentifyRelevantAnswers  numSubOps.identify
00268 
00269 
00270 void reset_subsumption_stats(void);
00271 void print_detailed_subsumption_stats(void);
00272 
00273 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
00274 
00275 /*
00276  *                        For Variant Evaluations
00277  *                        -----------------------
00278  */
00279 
00280 /* Move code to here from trie* files */
00281 
00282 /*=========================================================================*/
00283 
00284 
00285 #endif

Generated on Wed Jul 26 13:30:42 2006 for XSB by  doxygen 1.4.5