/* ******************************************************************************* * Copyright (c) 1996 Martin Poole * ******************************************************************************* ** ** WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! ** ** Any changes to be made to this file should first be checked with ** mplib1 source control for library integrity. ** ** mplib1 source control can be reached at mplib1@quatermass.co.uk ** * * $Source$ * $Author$ * $Date$ * $Revision$ * ******************************************************************************* * * Change History * * $Log$ * ******************************************************************************* */ #ident "$Header$" /* ------------------------------------------------------------------ Include files ------------------------------------------------------------------ */ #include #include #include #include #include #include #include #include #include #include #include "../include/dl_lru_private.h" /* ------------------------------------------------------------------ defines ------------------------------------------------------------------ */ #ifndef NULL #define NULL ((void *)0) #endif struct vchar_gen { unsigned short len; unsigned char arr[1]; }; typedef struct vchar_gen *vchar_ptr; struct cache_stat { struct Cache_List *cl; struct Cache_Group_Item *cgi; struct Cache_Item *ci; struct Cache_Field *cf; int num_search_rules; struct full_search_rule *fsrp; FILE *fp; }; /* ------------------------------------------------------------------ Some static variables ------------------------------------------------------------------ */ static const char *search_rule_strs[]= { "==", ">=", ">", "<=", "<", "!=" }; /* ------------------------------------------------------------------ Code starts here ------------------------------------------------------------------ */ static void Print_Field( void *vp1, void *vp2 ) { struct Cache_Field *cf; struct cache_stat *cs; char *cp; vchar_ptr vp; char cbuf[240]; cf = vp1; cs = vp2; cp = (char *)(cs->ci->ci_Item) + cf->cf_f_offset; memset( cbuf, '\0', 240 ); switch(cf->cf_field_type) { case CF_INT : fprintf( cs->fp, " %d", *((int *)cp) ); break; case CF_DOUBLE : fprintf( cs->fp, " %f", *((double *)cp) ); break; case CF_CHAR : fprintf( cs->fp, " %c", *cp ); break; case CF_STRING : fprintf( cs->fp, " %*.*s", cf->cf_field_size, (int)cf->cf_field_size, cp ); break; case CF_VARCHAR : vp = (vchar_ptr)cp; fprintf( cs->fp, " <%d>", vp->len ); memcpy(cbuf,&vp->arr[0],vp->len); cbuf[vp->len]='\0'; fprintf( cs->fp, " %s", cbuf ); break; } return; } static void Print_CI( struct Cache_Item *ci, struct cache_stat *cs ) { cs->ci = ci; if (ci->ci_Name) fprintf( cs->fp, " Item: %s\n", ci->ci_Name ); Walk_List( &cs->cl->cl_Fields, (Walk_List_t)Print_Field, cs ); fprintf( cs->fp, "\n" ); return; } static void Print_Rules( FILE *fp, struct full_search_rule *frsp, int num_rules ) { fprintf( fp, "Search Rules:\n" ); while (num_rules--) { fprintf( fp, " : <%s> %s\n", frsp->cf->cf_Name, search_rule_strs[frsp->comparison_method] ); frsp++; }; return; } static void Print_CGI_Header( FILE *fp, struct full_search_rule *frsp, int num_rules ) { if (frsp->comparison_method== SEARCH_EQ) { fprintf( fp, " CGI List: <%s> %s\n", frsp->cf->cf_Name, search_rule_strs[frsp->comparison_method] ); }else { while (num_rules--) { fprintf( fp, " CGI List: <%s> %s\n", frsp->cf->cf_Name, search_rule_strs[frsp->comparison_method] ); frsp++; }; } return; } static void Print_CGI( struct Cache_Group_Item *cgi, struct cache_stat *cs ) { cs->cgi = cgi; fprintf( cs->fp, " CGI: %x %d ", cgi->cgi_Flags, cs->num_search_rules ); cs->ci = &cgi->cgi_Item; Print_Field( cs->fsrp->cf, cs ); fprintf( cs->fp, "\n" ); cs->num_search_rules--; cs->fsrp++; if (cs->num_search_rules==0 || cs->fsrp->comparison_method != SEARCH_EQ) Walk_List( &cgi->cgi_Items.fl_Search_List, (Walk_List_t)Print_CI, cs ); else { Print_CGI_Header( cs->fp, cs->fsrp, cs->num_search_rules ); Walk_List( &cgi->cgi_Items.fl_Search_List, (Walk_List_t)Print_CGI, cs ); } cs->num_search_rules++; cs->fsrp--; return; } static void Print_Fields( struct Cache_Field *cf, FILE *fp ) { fprintf( fp, " <%-40.40s> <%d> <%d> <%d> <%d>\n", cf->cf_Name, cf->cf_field_type, cf->cf_field_size, cf->cf_field_num, cf->cf_f_offset ); return; } static void Cache_List_Stat( FILE *fp, struct Cache_List *cl, int contents ) { struct cache_stat my_stat; fprintf( fp, "List: \"%s\"\n\n", cl->cl_Name ); fprintf( fp, " Max: %8d\tCurr: %8d\n", cl->cl_max_items, cl->cl_curr_items ); fprintf( fp, " Size: %8d\tFlags: %8d\n", cl->cl_data_size, cl->cl_flags ); fprintf( fp, " Mode: %s\n", (cl->cl_flags & CACHE_CACHE_ON)?"Caching":"Statistics"); fprintf( fp, " Case: %s\n", (cl->cl_flags & CACHE_IGNORE_CASE)?"Ignore":"Check"); fprintf( fp, " Alloc: %s\n", (cl->cl_flags & CACHE_DEMAND_ALLOC)?"Demand":"Pre-Allocate"); fprintf( fp, " Flush: %s\n", (cl->cl_flags & CACHE_FLUSHABLE)?"Flushable":"NOT Flushable"); if (cl->cl_search_rules) fprintf( fp, " Insert: %s\n", (cl->cl_flags & CACHE_INSERT_MANY)?"Many":"Single"); fprintf( fp, " Hit: %8d\tMiss: %8d\n", cl->cl_cache_hits, cl->cl_cache_misses ); fprintf( fp, " Rep: %8d\tFail: %8d\n", cl->cl_cache_replaces, cl->cl_complete_misses ); fprintf( fp, " Fields\n" ); Walk_List( &cl->cl_Fields, (Walk_List_t)Print_Fields, fp ); if ( contents ) { if ( cl->cl_search_rules==NULL || cl->cl_search_rules->comparison_method!=SEARCH_EQ ) { my_stat.cl = cl; my_stat.fp = fp; Walk_List( &cl->cl_Items.fl_Search_List, (Walk_List_t)Print_CI, &my_stat ); }else { my_stat.cl = cl; my_stat.fp = fp; my_stat.fsrp = cl->cl_search_rules; my_stat.num_search_rules = cl->cl_num_search_rules; Print_Rules( fp, my_stat.fsrp, my_stat.num_search_rules ); Print_CGI_Header( fp, my_stat.fsrp, my_stat.num_search_rules ); Walk_List( &cl->cl_Items.fl_Search_List, (Walk_List_t)Print_CGI, &my_stat ); } } fprintf( fp, "\n" ); return; } int Cache_Stats( FILE *fp, const char *list_name, int contents ) { struct Cache_List *cl; List_t *Master_List; Master_List = Get_Cache_Master_List(); if (list_name) { cl = (struct Cache_List *)Find_Item_By_Name( Master_List, list_name ); if (cl) Cache_List_Stat( fp, cl, contents ); } else { cl = (struct Cache_List *)Master_List->ln_Head.ln_Succ; while (cl->cl_Node.ln_Succ) { Cache_List_Stat( fp, cl, contents ); cl = (struct Cache_List *)cl->cl_Node.ln_Succ; }; } return(0); } /* -- End of File -- */