"I am a person who works hard and plays hard."

Yuan Wei
Second Year Graduate Student Department of Computer Science
University of Virginia Charlottesville, VA 22903
Email: yw3f@cs.virginia.edu


Source Code Analysis

Main Page   Compound List   File List   Compound Members   File Members  

stats.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
#include "host.h"
#include "misc.h"
#include "machine.h"
#include "eval.h"
#include "stats.h"

Include dependency graph for stats.c:

Include dependency graph

Go to the source code of this file.

Functions


Function Documentation

void add_stat struct stat_sdb_t   sdb,
struct stat_stat_t   stat
[static]
 

Definition at line 254 of file stats.c.

References stat_stat_t::next, and stat_sdb_t::stats.

Referenced by stat_reg_dist(), stat_reg_double(), stat_reg_float(), stat_reg_formula(), stat_reg_int(), stat_reg_sdist(), and stat_reg_uint().

00256 {
00257   struct stat_stat_t *elt, *prev;
00258 
00259   /* append at end of stat database list */
00260   for (prev=NULL, elt=sdb->stats; elt != NULL; prev=elt, elt=elt->next)
00261     /* nada */;
00262 
00263   /* append stat to stats chain */
00264   if (prev != NULL)
00265     prev->next = stat;
00266   else /* prev == NULL */
00267     sdb->stats = stat;
00268   stat->next = NULL;
00269 }

int compare_fn void *    p1,
void *    p2
[static]
 

Definition at line 655 of file stats.c.

Referenced by print_sdist().

00656 {
00657   struct bucket_t **pb1 = p1, **pb2 = p2;
00658 
00659   /* compare indices */
00660   if ((*pb1)->index < (*pb2)->index)
00661     return -1;
00662   else if ((*pb1)->index > (*pb2)->index)
00663     return 1;
00664   else /* ((*pb1)->index == (*pb2)->index) */
00665     return 0;
00666 }

void print_dist struct stat_stat_t   stat,
FILE *    fd
[static]
 

Definition at line 670 of file stats.c.

References stat_stat_t::stat_variant_t::stat_for_dist_t::arr, stat_stat_t::stat_variant_t::stat_for_dist_t::arr_sz, stat_stat_t::stat_variant_t::stat_for_dist_t::bucket_sz, stat_stat_t::desc, fatal(), stat_stat_t::stat_variant_t::for_dist, stat_stat_t::format, stat_stat_t::stat_variant_t::stat_for_dist_t::imap, MAX, stat_stat_t::name, stat_stat_t::stat_variant_t::stat_for_dist_t::overflows, stat_stat_t::stat_variant_t::stat_for_dist_t::pf, PF_CDF, PF_COUNT, PF_PDF, stat_stat_t::stat_variant_t::stat_for_dist_t::print_fn, and stat_stat_t::variant.

Referenced by stat_print_stat().

00672 {
00673   unsigned int i, bcount, imax, imin;
00674   double btotal, bsum, bvar, bavg, bsqsum;
00675   int pf = stat->variant.for_dist.pf;
00676 
00677   /* count and sum entries */
00678   bcount = 0; btotal = 0.0; bvar = 0.0; bsqsum = 0.0;
00679   imax = 0; imin = UINT_MAX;
00680   for (i=0; i<stat->variant.for_dist.arr_sz; i++)
00681     {
00682       bcount++;
00683       btotal += stat->variant.for_dist.arr[i];
00684       /* on-line variance computation, tres cool, no!?! */
00685       bsqsum += ((double)stat->variant.for_dist.arr[i] *
00686                  (double)stat->variant.for_dist.arr[i]);
00687       bavg = btotal / MAX((double)bcount, 1.0);
00688       bvar = (bsqsum - ((double)bcount * bavg * bavg)) / 
00689         (double)(((bcount - 1) > 0) ? (bcount - 1) : 1);
00690     }
00691 
00692   /* print header */
00693   fprintf(fd, "\n");
00694   fprintf(fd, "%-22s # %s\n", stat->name, stat->desc);
00695   fprintf(fd, "%s.array_size = %u\n",
00696           stat->name, stat->variant.for_dist.arr_sz);
00697   fprintf(fd, "%s.bucket_size = %u\n",
00698           stat->name, stat->variant.for_dist.bucket_sz);
00699 
00700   fprintf(fd, "%s.count = %u\n", stat->name, bcount);
00701   fprintf(fd, "%s.total = %.0f\n", stat->name, btotal);
00702   if (bcount > 0)
00703     {
00704       fprintf(fd, "%s.imin = %u\n", stat->name, 0U);
00705       fprintf(fd, "%s.imax = %u\n", stat->name, bcount);
00706     }
00707   else
00708     {
00709       fprintf(fd, "%s.imin = %d\n", stat->name, -1);
00710       fprintf(fd, "%s.imax = %d\n", stat->name, -1);
00711     }
00712   fprintf(fd, "%s.average = %8.4f\n", stat->name, btotal/MAX(bcount, 1.0));
00713   fprintf(fd, "%s.std_dev = %8.4f\n", stat->name, sqrt(bvar));
00714   fprintf(fd, "%s.overflows = %u\n",
00715           stat->name, stat->variant.for_dist.overflows);
00716 
00717   fprintf(fd, "# pdf == prob dist fn, cdf == cumulative dist fn\n");
00718   fprintf(fd, "# %14s ", "index");
00719   if (pf & PF_COUNT)
00720     fprintf(fd, "%10s ", "count");
00721   if (pf & PF_PDF)
00722     fprintf(fd, "%6s ", "pdf");
00723   if (pf & PF_CDF)
00724     fprintf(fd, "%6s ", "cdf");
00725   fprintf(fd, "\n");
00726 
00727   fprintf(fd, "%s.start_dist\n", stat->name);
00728 
00729   if (bcount > 0)
00730     {
00731       /* print the array */
00732       bsum = 0.0;
00733       for (i=0; i<bcount; i++)
00734         {
00735           bsum += (double)stat->variant.for_dist.arr[i];
00736           if (stat->variant.for_dist.print_fn)
00737             {
00738               stat->variant.for_dist.print_fn(stat,
00739                                               i,
00740                                               stat->variant.for_dist.arr[i],
00741                                               bsum,
00742                                               btotal);
00743             }
00744           else
00745             {
00746               if (stat->format == NULL)
00747                 {
00748                   if (stat->variant.for_dist.imap)
00749                     fprintf(fd, "%-16s ", stat->variant.for_dist.imap[i]);
00750                   else
00751                     fprintf(fd, "%16u ",
00752                             i * stat->variant.for_dist.bucket_sz);
00753                   if (pf & PF_COUNT)
00754                     fprintf(fd, "%10u ", stat->variant.for_dist.arr[i]);
00755                   if (pf & PF_PDF)
00756                     fprintf(fd, "%6.2f ",
00757                             (double)stat->variant.for_dist.arr[i] /
00758                             MAX(btotal, 1.0) * 100.0);
00759                   if (pf & PF_CDF)
00760                     fprintf(fd, "%6.2f ", bsum/MAX(btotal, 1.0) * 100.0);
00761                 }
00762               else
00763                 {
00764                   if (pf == (PF_COUNT|PF_PDF|PF_CDF))
00765                     {
00766                       if (stat->variant.for_dist.imap)
00767                         fprintf(fd, stat->format,
00768                                 stat->variant.for_dist.imap[i],
00769                                 stat->variant.for_dist.arr[i],
00770                                 (double)stat->variant.for_dist.arr[i] /
00771                                 MAX(btotal, 1.0) * 100.0,
00772                                 bsum/MAX(btotal, 1.0) * 100.0);
00773                       else
00774                         fprintf(fd, stat->format,
00775                                 i * stat->variant.for_dist.bucket_sz,
00776                                 stat->variant.for_dist.arr[i],
00777                                 (double)stat->variant.for_dist.arr[i] /
00778                                 MAX(btotal, 1.0) * 100.0,
00779                                 bsum/MAX(btotal, 1.0) * 100.0);
00780                     }
00781                   else
00782                     fatal("distribution format not yet implemented");
00783                 }
00784               fprintf(fd, "\n");
00785             }
00786         }
00787     }
00788 
00789   fprintf(fd, "%s.end_dist\n", stat->name);
00790 }

void print_sdist struct stat_stat_t   stat,
FILE *    fd
[static]
 

Definition at line 794 of file stats.c.

References compare_fn(), bucket_t::count, stat_stat_t::desc, fatal(), stat_stat_t::stat_variant_t::for_sdist, stat_stat_t::format, HTAB_SZ, bucket_t::index, MAX, myfprintf(), stat_stat_t::name, bucket_t::next, stat_stat_t::stat_variant_t::stat_for_sdist_t::pf, PF_CDF, PF_COUNT, PF_PDF, stat_stat_t::stat_variant_t::stat_for_sdist_t::print_fn, stat_stat_t::stat_variant_t::stat_for_sdist_t::sarr, and stat_stat_t::variant.

Referenced by stat_print_stat().

00796 {
00797   unsigned int i, bcount;
00798   md_addr_t imax, imin;
00799   double btotal, bsum, bvar, bavg, bsqsum;
00800   struct bucket_t *bucket;
00801   int pf = stat->variant.for_sdist.pf;
00802 
00803   /* count and sum entries */
00804   bcount = 0; btotal = 0.0; bvar = 0.0; bsqsum = 0.0;
00805   imax = 0; imin = UINT_MAX;
00806   for (i=0; i<HTAB_SZ; i++)
00807     {
00808       for (bucket = stat->variant.for_sdist.sarr[i];
00809            bucket != NULL;
00810            bucket = bucket->next)
00811         {
00812           bcount++;
00813           btotal += bucket->count;
00814           /* on-line variance computation, tres cool, no!?! */
00815           bsqsum += ((double)bucket->count * (double)bucket->count);
00816           bavg = btotal / (double)bcount;
00817           bvar = (bsqsum - ((double)bcount * bavg * bavg)) / 
00818             (double)(((bcount - 1) > 0) ? (bcount - 1) : 1);
00819           if (bucket->index < imin)
00820             imin = bucket->index;
00821           if (bucket->index > imax)
00822             imax = bucket->index;
00823         }
00824     }
00825 
00826   /* print header */
00827   fprintf(fd, "\n");
00828   fprintf(fd, "%-22s # %s\n", stat->name, stat->desc);
00829   fprintf(fd, "%s.count = %u\n", stat->name, bcount);
00830   fprintf(fd, "%s.total = %.0f\n", stat->name, btotal);
00831   if (bcount > 0)
00832     {
00833       myfprintf(fd, "%s.imin = 0x%p\n", stat->name, imin);
00834       myfprintf(fd, "%s.imax = 0x%p\n", stat->name, imax);
00835     }
00836   else
00837     {
00838       fprintf(fd, "%s.imin = %d\n", stat->name, -1);
00839       fprintf(fd, "%s.imax = %d\n", stat->name, -1);
00840     }
00841   fprintf(fd, "%s.average = %8.4f\n", stat->name, btotal/bcount);
00842   fprintf(fd, "%s.std_dev = %8.4f\n", stat->name, sqrt(bvar));
00843   fprintf(fd, "%s.overflows = 0\n", stat->name);
00844 
00845   fprintf(fd, "# pdf == prob dist fn, cdf == cumulative dist fn\n");
00846   fprintf(fd, "# %14s ", "index");
00847   if (pf & PF_COUNT)
00848     fprintf(fd, "%10s ", "count");
00849   if (pf & PF_PDF)
00850     fprintf(fd, "%6s ", "pdf");
00851   if (pf & PF_CDF)
00852     fprintf(fd, "%6s ", "cdf");
00853   fprintf(fd, "\n");
00854 
00855   fprintf(fd, "%s.start_dist\n", stat->name);
00856 
00857   if (bcount > 0)
00858     {
00859       unsigned int bindex;
00860       struct bucket_t **barr;
00861 
00862       /* collect all buckets */
00863       barr = (struct bucket_t **)calloc(bcount, sizeof(struct bucket_t *));
00864       if (!barr)
00865         fatal("out of virtual memory");
00866       for (bindex=0,i=0; i<HTAB_SZ; i++)
00867         {
00868           for (bucket = stat->variant.for_sdist.sarr[i];
00869                bucket != NULL;
00870                bucket = bucket->next)
00871             {
00872               barr[bindex++] = bucket;
00873             }
00874         }
00875 
00876       /* sort the array by index */
00877       qsort(barr, bcount, sizeof(struct bucket_t *), (void *)compare_fn);
00878 
00879       /* print the array */
00880       bsum = 0.0;
00881       for (i=0; i<bcount; i++)
00882         {
00883           bsum += (double)barr[i]->count;
00884           if (stat->variant.for_sdist.print_fn)
00885             {
00886               stat->variant.for_sdist.print_fn(stat,
00887                                                barr[i]->index,
00888                                                barr[i]->count,
00889                                                bsum,
00890                                                btotal);
00891             }
00892           else
00893             {
00894               if (stat->format == NULL)
00895                 {
00896                   myfprintf(fd, "0x%p ", barr[i]->index);
00897                   if (pf & PF_COUNT)
00898                     fprintf(fd, "%10u ", barr[i]->count);
00899                   if (pf & PF_PDF)
00900                     fprintf(fd, "%6.2f ",
00901                             (double)barr[i]->count/MAX(btotal, 1.0) * 100.0);
00902                   if (pf & PF_CDF)
00903                     fprintf(fd, "%6.2f ", bsum/MAX(btotal, 1.0) * 100.0);
00904                 }
00905               else
00906                 {
00907                   if (pf == (PF_COUNT|PF_PDF|PF_CDF))
00908                     {
00909                       myfprintf(fd, stat->format,
00910                                 barr[i]->index, barr[i]->count,
00911                                 (double)barr[i]->count/MAX(btotal, 1.0)*100.0,
00912                                 bsum/MAX(btotal, 1.0) * 100.0);
00913                     }
00914                   else if (pf == (PF_COUNT|PF_PDF))
00915                     {
00916                       myfprintf(fd, stat->format,
00917                                 barr[i]->index, barr[i]->count,
00918                                 (double)barr[i]->count/MAX(btotal, 1.0)*100.0);
00919                     }
00920                   else if (pf == PF_COUNT)
00921                     {
00922                       myfprintf(fd, stat->format,
00923                                 barr[i]->index, barr[i]->count);
00924                     }
00925                   else
00926                     fatal("distribution format not yet implemented");
00927                 }
00928               fprintf(fd, "\n");
00929             }
00930         }
00931 
00932       /* all done, release bucket pointer array */
00933       free(barr);
00934     }
00935 
00936   fprintf(fd, "%s.end_dist\n", stat->name);
00937 }

void stat_add_sample struct stat_stat_t   stat,
md_addr_t    index
 

Definition at line 614 of file stats.c.

References stat_add_samples().

Referenced by sim_main().

00616 {
00617   stat_add_samples(stat, index, 1);
00618 }

void stat_add_samples struct stat_stat_t   stat,
md_addr_t    index,
int    nsamples
 

Definition at line 557 of file stats.c.

References stat_stat_t::stat_variant_t::stat_for_dist_t::arr, stat_stat_t::stat_variant_t::stat_for_dist_t::arr_sz, stat_stat_t::stat_variant_t::stat_for_dist_t::bucket_sz, bucket_t::count, fatal(), stat_stat_t::stat_variant_t::for_dist, stat_stat_t::stat_variant_t::for_sdist, HTAB_HASH, HTAB_SZ, bucket_t::index, stat_stat_t::stat_variant_t::stat_for_sdist_t::init_val, bucket_t::next, stat_stat_t::stat_variant_t::stat_for_dist_t::overflows, panic(), stat_stat_t::stat_variant_t::stat_for_sdist_t::sarr, stat_stat_t::sc, sc_dist, sc_sdist, and stat_stat_t::variant.

Referenced by ruu_dispatch(), sim_main(), and stat_add_sample().

00560 {
00561   switch (stat->sc)
00562     {
00563     case sc_dist:
00564       {
00565         unsigned int i;
00566 
00567         /* compute array index */
00568         i = index / stat->variant.for_dist.bucket_sz;
00569 
00570         /* check for overflow */
00571         if (i >= stat->variant.for_dist.arr_sz)
00572           stat->variant.for_dist.overflows += nsamples;
00573         else
00574           stat->variant.for_dist.arr[i] += nsamples;
00575       }
00576       break;
00577     case sc_sdist:
00578       {
00579         struct bucket_t *bucket;
00580         int hash = HTAB_HASH(index);
00581 
00582         if (hash < 0 || hash >= HTAB_SZ)
00583           panic("hash table index overflow");
00584 
00585         /* find bucket */
00586         for (bucket = stat->variant.for_sdist.sarr[hash];
00587              bucket != NULL;
00588              bucket = bucket->next)
00589           {
00590             if (bucket->index == index)
00591               break;
00592           }
00593         if (!bucket)
00594           {
00595             /* add a new sample bucket */
00596             bucket = (struct bucket_t *)calloc(1, sizeof(struct bucket_t));
00597             if (!bucket)
00598               fatal("out of virtual memory");
00599             bucket->next = stat->variant.for_sdist.sarr[hash];
00600             stat->variant.for_sdist.sarr[hash] = bucket;
00601             bucket->index = index;
00602             bucket->count = stat->variant.for_sdist.init_val;
00603           }
00604         bucket->count += nsamples;
00605       }
00606       break;
00607     default:
00608       panic("stat variable is not an array distribution");
00609     }
00610 }

void stat_delete struct stat_sdb_t   sdb
 

Definition at line 191 of file stats.c.

References stat_stat_t::stat_variant_t::stat_for_dist_t::arr, eval_delete(), stat_sdb_t::evaluator, stat_stat_t::stat_variant_t::for_dist, stat_stat_t::stat_variant_t::for_sdist, HTAB_SZ, stat_stat_t::next, bucket_t::next, panic(), stat_stat_t::stat_variant_t::stat_for_sdist_t::sarr, stat_stat_t::sc, sc_dist, sc_double, sc_float, sc_formula, sc_int, sc_sdist, sc_uint, stat_sdb_t::stats, and stat_stat_t::variant.

00192 {
00193   int i;
00194   struct stat_stat_t *stat, *stat_next;
00195   struct bucket_t *bucket, *bucket_next;
00196 
00197   /* free all individual stat variables */
00198   for (stat = sdb->stats; stat != NULL; stat = stat_next)
00199     {
00200       stat_next = stat->next;
00201       stat->next = NULL;
00202 
00203       /* free stat */
00204       switch (stat->sc)
00205         {
00206         case sc_int:
00207         case sc_uint:
00208 #ifdef HOST_HAS_QWORD
00209         case sc_qword:
00210         case sc_sqword:
00211 #endif /* HOST_HAS_QWORD */
00212         case sc_float:
00213         case sc_double:
00214         case sc_formula:
00215           /* no other storage to deallocate */
00216           break;
00217         case sc_dist:
00218           /* free distribution array */
00219           free(stat->variant.for_dist.arr);
00220           stat->variant.for_dist.arr = NULL;
00221           break;
00222         case sc_sdist:
00223           /* free all hash table buckets */
00224           for (i=0; i<HTAB_SZ; i++)
00225             {
00226               for (bucket = stat->variant.for_sdist.sarr[i];
00227                    bucket != NULL;
00228                    bucket = bucket_next)
00229                 {
00230                   bucket_next = bucket->next;
00231                   bucket->next = NULL;
00232                   free(bucket);
00233                 }
00234               stat->variant.for_sdist.sarr[i] = NULL;
00235             }
00236           /* free hash table array */
00237           free(stat->variant.for_sdist.sarr);
00238           stat->variant.for_sdist.sarr = NULL;
00239           break;
00240         default:
00241           panic("bogus stat class");
00242         }
00243       /* free stat variable record */
00244       free(stat);
00245     }
00246   sdb->stats = NULL;
00247   eval_delete(sdb->evaluator);
00248   sdb->evaluator = NULL;
00249   free(sdb);
00250 }

struct eval_value_t stat_eval_ident struct eval_state_t   es
 

Definition at line 87 of file stats.c.

References ERR_NOERR, ERR_UNDEFVAR, et_double, et_float, et_int, et_uint, eval_delete(), eval_expr(), eval_new(), fatal(), stat_stat_t::stat_variant_t::for_double, stat_stat_t::stat_variant_t::for_float, stat_stat_t::stat_variant_t::for_formula, stat_stat_t::stat_variant_t::for_int, stat_stat_t::stat_variant_t::for_uint, stat_stat_t::stat_variant_t::stat_for_formula_t::formula, stat_stat_t::name, stat_stat_t::next, panic(), stat_stat_t::sc, sc_dist, sc_double, sc_float, sc_formula, sc_int, sc_sdist, sc_uint, stat_sdb_t::stats, eval_value_t::type, eval_value_t::value, stat_stat_t::stat_variant_t::stat_for_int_t::var, stat_stat_t::stat_variant_t::stat_for_uint_t::var, stat_stat_t::stat_variant_t::stat_for_float_t::var, stat_stat_t::stat_variant_t::stat_for_double_t::var, and stat_stat_t::variant.

00088 {
00089   struct stat_sdb_t *sdb = es->user_ptr;
00090   struct stat_stat_t *stat;
00091   static struct eval_value_t err_value = { et_int, { 0 } };
00092   struct eval_value_t val;
00093 
00094   /* locate the stat variable */
00095   for (stat = sdb->stats; stat != NULL; stat = stat->next)
00096     {
00097       if (!strcmp(stat->name, es->tok_buf))
00098         {
00099           /* found it! */
00100           break;
00101         }
00102     }
00103   if (!stat)
00104     {
00105       /* could not find stat variable */
00106       eval_error = ERR_UNDEFVAR;
00107       return err_value;
00108     }
00109   /* else, return the value of stat */
00110 
00111   /* convert the stat variable value to a typed expression value */
00112   switch (stat->sc)
00113     {
00114     case sc_int:
00115       val.type = et_int;
00116       val.value.as_int = *stat->variant.for_int.var;
00117       break;
00118     case sc_uint:
00119       val.type = et_uint;
00120       val.value.as_uint = *stat->variant.for_uint.var;
00121       break;
00122 #ifdef HOST_HAS_QWORD
00123     case sc_qword:
00124       /* FIXME: cast to double, eval package doesn't support long long's */
00125       val.type = et_double;
00126 #ifdef _MSC_VER /* FIXME: MSC does not implement qword_t to dbl conversion */
00127       val.value.as_double = (double)(sqword_t)*stat->variant.for_qword.var;
00128 #else /* !_MSC_VER */
00129       val.value.as_double = (double)*stat->variant.for_qword.var;
00130 #endif /* _MSC_VER */
00131       break;
00132     case sc_sqword:
00133       /* FIXME: cast to double, eval package doesn't support long long's */
00134       val.type = et_double;
00135       val.value.as_double = (double)*stat->variant.for_sqword.var;
00136       break;
00137 #endif /* HOST_HAS_QWORD */
00138     case sc_float:
00139       val.type = et_float;
00140       val.value.as_float = *stat->variant.for_float.var;
00141       break;
00142     case sc_double:
00143       val.type = et_double;
00144       val.value.as_double = *stat->variant.for_double.var;
00145       break;
00146     case sc_dist:
00147     case sc_sdist:
00148       fatal("stat distributions not allowed in formula expressions");
00149       break;
00150     case sc_formula:
00151       {
00152         /* instantiate a new evaluator to avoid recursion problems */
00153         struct eval_state_t *es = eval_new(stat_eval_ident, sdb);
00154         char *endp;
00155 
00156         val = eval_expr(es, stat->variant.for_formula.formula, &endp);
00157         if (eval_error != ERR_NOERR || *endp != '\0')
00158           {
00159             /* pass through eval_error */
00160             val = err_value;
00161           }
00162         /* else, use value returned */
00163         eval_delete(es);
00164       }
00165       break;
00166     default:
00167       panic("bogus stat class");
00168     }
00169 
00170   return val;
00171 }

struct stat_stat_t* stat_find_stat struct stat_sdb_t   sdb,
char *    stat_name
 

Definition at line 1038 of file stats.c.

References stat_stat_t::name, and stat_stat_t::next.

Referenced by dlite_stat(), ident_evaluator(), and sim_reg_stats().

01040 {
01041   struct stat_stat_t *stat;
01042 
01043   for (stat = sdb->stats; stat != NULL; stat = stat->next)
01044     {
01045       if (!strcmp(stat->name, stat_name))
01046         break;
01047     }
01048   return stat;
01049 }

struct stat_sdb_t* stat_new void   
 

Definition at line 175 of file stats.c.

References eval_new(), stat_sdb_t::evaluator, fatal(), and stat_sdb_t::stats.

Referenced by main().

00176 {
00177   struct stat_sdb_t *sdb;
00178 
00179   sdb = (struct stat_sdb_t *)calloc(1, sizeof(struct stat_sdb_t));
00180   if (!sdb)
00181     fatal("out of virtual memory");
00182 
00183   sdb->stats = NULL;
00184   sdb->evaluator = eval_new(stat_eval_ident, sdb);
00185 
00186   return sdb;
00187 }

void stat_print_stat struct stat_sdb_t   sdb,
struct stat_stat_t   stat,
FILE *    fd
 

Definition at line 941 of file stats.c.

References stat_stat_t::desc, ERR_NOERR, eval_delete(), eval_expr(), eval_new(), stat_stat_t::stat_variant_t::for_double, stat_stat_t::stat_variant_t::for_float, stat_stat_t::stat_variant_t::for_formula, stat_stat_t::stat_variant_t::for_int, stat_stat_t::stat_variant_t::for_uint, stat_stat_t::format, stat_stat_t::stat_variant_t::stat_for_formula_t::formula, myfprintf(), mysprintf(), stat_stat_t::name, panic(), print_dist(), print_sdist(), stat_stat_t::sc, sc_dist, sc_double, sc_float, sc_formula, sc_int, sc_sdist, sc_uint, stat_stat_t::stat_variant_t::stat_for_int_t::var, stat_stat_t::stat_variant_t::stat_for_uint_t::var, stat_stat_t::stat_variant_t::stat_for_float_t::var, stat_stat_t::stat_variant_t::stat_for_double_t::var, and stat_stat_t::variant.

Referenced by dlite_stat(), and stat_print_stats().

00944 {
00945   struct eval_value_t val;
00946 
00947   switch (stat->sc)
00948     {
00949     case sc_int:
00950       fprintf(fd, "%-22s ", stat->name);
00951       myfprintf(fd, stat->format, *stat->variant.for_int.var);
00952       fprintf(fd, " # %s", stat->desc);
00953       break;
00954     case sc_uint:
00955       fprintf(fd, "%-22s ", stat->name);
00956       myfprintf(fd, stat->format, *stat->variant.for_uint.var);
00957       fprintf(fd, " # %s", stat->desc);
00958       break;
00959 #ifdef HOST_HAS_QWORD
00960     case sc_qword:
00961       {
00962         char buf[128];
00963 
00964         fprintf(fd, "%-22s ", stat->name);
00965         mysprintf(buf, stat->format, *stat->variant.for_qword.var);
00966         fprintf(fd, "%s # %s", buf, stat->desc);
00967       }
00968       break;
00969     case sc_sqword:
00970       {
00971         char buf[128];
00972 
00973         fprintf(fd, "%-22s ", stat->name);
00974         mysprintf(buf, stat->format, *stat->variant.for_sqword.var);
00975         fprintf(fd, "%s # %s", buf, stat->desc);
00976       }
00977       break;
00978 #endif /* HOST_HAS_QWORD */
00979     case sc_float:
00980       fprintf(fd, "%-22s ", stat->name);
00981       myfprintf(fd, stat->format, (double)*stat->variant.for_float.var);
00982       fprintf(fd, " # %s", stat->desc);
00983       break;
00984     case sc_double:
00985       fprintf(fd, "%-22s ", stat->name);
00986       myfprintf(fd, stat->format, *stat->variant.for_double.var);
00987       fprintf(fd, " # %s", stat->desc);
00988       break;
00989     case sc_dist:
00990       print_dist(stat, fd);
00991       break;
00992     case sc_sdist:
00993       print_sdist(stat, fd);
00994       break;
00995     case sc_formula:
00996       {
00997         /* instantiate a new evaluator to avoid recursion problems */
00998         struct eval_state_t *es = eval_new(stat_eval_ident, sdb);
00999         char *endp;
01000 
01001         fprintf(fd, "%-22s ", stat->name);
01002         val = eval_expr(es, stat->variant.for_formula.formula, &endp);
01003         if (eval_error != ERR_NOERR || *endp != '\0')
01004           fprintf(fd, "<error: %s>", eval_err_str[eval_error]);
01005         else
01006           myfprintf(fd, stat->format, eval_as_double(val));
01007         fprintf(fd, " # %s", stat->desc);
01008 
01009         /* done with the evaluator */
01010         eval_delete(es);
01011       }
01012       break;
01013     default:
01014       panic("bogus stat class");
01015     }
01016   fprintf(fd, "\n");
01017 }

void stat_print_stats struct stat_sdb_t   sdb,
FILE *    fd
 

Definition at line 1021 of file stats.c.

References stat_stat_t::next, stat_print_stat(), and stat_sdb_t::stats.

Referenced by cheetah_mstate_obj(), dlite_stats(), and sim_print_stats().

01023 {
01024   struct stat_stat_t *stat;
01025 
01026   if (!sdb)
01027     {
01028       /* no stats */
01029       return;
01030     }
01031 
01032   for (stat=sdb->stats; stat != NULL; stat=stat->next)
01033     stat_print_stat(sdb, stat, fd);
01034 }

struct stat_stat_t* stat_reg_dist struct stat_sdb_t   sdb,
char *    name,
char *    desc,
unsigned int    init_val,
unsigned int    arr_sz,
unsigned int    bucket_sz,
int    pf,
char *    format,
char **    imap,
print_fn_t    print_fn
 

Definition at line 466 of file stats.c.

References add_stat(), stat_stat_t::stat_variant_t::stat_for_dist_t::arr, stat_stat_t::stat_variant_t::stat_for_dist_t::arr_sz, stat_stat_t::stat_variant_t::stat_for_dist_t::bucket_sz, stat_stat_t::desc, fatal(), stat_stat_t::stat_variant_t::for_dist, stat_stat_t::format, stat_stat_t::stat_variant_t::stat_for_dist_t::imap, stat_stat_t::stat_variant_t::stat_for_dist_t::init_val, mystrdup(), stat_stat_t::name, stat_stat_t::stat_variant_t::stat_for_dist_t::overflows, stat_stat_t::stat_variant_t::stat_for_dist_t::pf, stat_stat_t::stat_variant_t::stat_for_dist_t::print_fn, stat_stat_t::sc, sc_dist, and stat_stat_t::variant.

Referenced by sim_reg_stats().

00476 {
00477   unsigned int i;
00478   struct stat_stat_t *stat;
00479   unsigned int *arr;
00480 
00481   stat = (struct stat_stat_t *)calloc(1, sizeof(struct stat_stat_t));
00482   if (!stat)
00483     fatal("out of virtual memory");
00484 
00485   stat->name = mystrdup(name);
00486   stat->desc = mystrdup(desc);
00487   stat->format = format ? format : NULL;
00488   stat->sc = sc_dist;
00489   stat->variant.for_dist.init_val = init_val;
00490   stat->variant.for_dist.arr_sz = arr_sz;
00491   stat->variant.for_dist.bucket_sz = bucket_sz;
00492   stat->variant.for_dist.pf = pf;
00493   stat->variant.for_dist.imap = imap;
00494   stat->variant.for_dist.print_fn = print_fn;
00495   stat->variant.for_dist.overflows = 0;
00496 
00497   arr = (unsigned int *)calloc(arr_sz, sizeof(unsigned int));
00498   if (!arr)
00499     fatal("out of virtual memory");
00500   stat->variant.for_dist.arr = arr;
00501 
00502   /* link onto SDB chain */
00503   add_stat(sdb, stat);
00504 
00505   /* initialize stat */
00506   for (i=0; i < arr_sz; i++)
00507     arr[i] = init_val;
00508 
00509   return stat;
00510 }

struct stat_stat_t* stat_reg_double struct stat_sdb_t   sdb,
char *    name,
char *    desc,
double *    var,
double    init_val,
char *    format
 

Definition at line 430 of file stats.c.

References add_stat(), stat_stat_t::desc, fatal(), stat_stat_t::stat_variant_t::for_double, stat_stat_t::format, stat_stat_t::stat_variant_t::stat_for_double_t::init_val, mystrdup(), stat_stat_t::name, stat_stat_t::sc, sc_double, stat_stat_t::stat_variant_t::stat_for_double_t::var, and stat_stat_t::variant.

00436 {
00437   struct stat_stat_t *stat;
00438 
00439   stat = (struct stat_stat_t *)calloc(1, sizeof(struct stat_stat_t));
00440   if (!stat)
00441     fatal("out of virtual memory");
00442 
00443   stat->name = mystrdup(name);
00444   stat->desc = mystrdup(desc);
00445   stat->format = format ? format : "%12.4f";
00446   stat->sc = sc_double;
00447   stat->variant.for_double.var = var;
00448   stat->variant.for_double.init_val = init_val;
00449 
00450   /* link onto SDB chain */
00451   add_stat(sdb, stat);
00452 
00453   /* initialize stat */
00454   *var = init_val;
00455 
00456   return stat;
00457 }

struct stat_stat_t* stat_reg_float struct stat_sdb_t   sdb,
char *    name,
char *    desc,
float *    var,
float    init_val,
char *    format
 

Definition at line 399 of file stats.c.

References add_stat(), stat_stat_t::desc, fatal(), stat_stat_t::stat_variant_t::for_float, stat_stat_t::format, stat_stat_t::stat_variant_t::stat_for_float_t::init_val, mystrdup(), stat_stat_t::name, stat_stat_t::sc, sc_float, stat_stat_t::stat_variant_t::stat_for_float_t::var, and stat_stat_t::variant.

00405 {
00406   struct stat_stat_t *stat;
00407 
00408   stat = (struct stat_stat_t *)calloc(1, sizeof(struct stat_stat_t));
00409   if (!stat)
00410     fatal("out of virtual memory");
00411 
00412   stat->name = mystrdup(name);
00413   stat->desc = mystrdup(desc);
00414   stat->format = format ? format : "%12.4f";
00415   stat->sc = sc_float;
00416   stat->variant.for_float.var = var;
00417   stat->variant.for_float.init_val = init_val;
00418 
00419   /* link onto SDB chain */
00420   add_stat(sdb, stat);
00421 
00422   /* initialize stat */
00423   *var = init_val;
00424 
00425   return stat;
00426 }

struct stat_stat_t* stat_reg_formula struct stat_sdb_t   sdb,
char *    name,
char *    desc,
char *    formula,
char *    format
 

Definition at line 628 of file stats.c.

References add_stat(), stat_stat_t::desc, fatal(), stat_stat_t::stat_variant_t::for_formula, stat_stat_t::format, stat_stat_t::stat_variant_t::stat_for_formula_t::formula, mystrdup(), stat_stat_t::name, stat_stat_t::sc, sc_formula, and stat_stat_t::variant.

Referenced by bpred_reg_stats(), cache_reg_stats(), mem_reg_stats(), and sim_reg_stats().

00633 {
00634   struct stat_stat_t *stat;
00635 
00636   stat = (struct stat_stat_t *)calloc(1, sizeof(struct stat_stat_t));
00637   if (!stat)
00638     fatal("out of virtual memory");
00639 
00640   stat->name = mystrdup(name);
00641   stat->desc = mystrdup(desc);
00642   stat->format = format ? format : "%12.4f";
00643   stat->sc = sc_formula;
00644   stat->variant.for_formula.formula = mystrdup(formula);
00645 
00646   /* link onto SDB chain */
00647   add_stat(sdb, stat);
00648 
00649   return stat;
00650 }

struct stat_stat_t* stat_reg_int struct stat_sdb_t   sdb,
char *    name,
char *    desc,
int *    var,
int    init_val,
char *    format
 

Definition at line 273 of file stats.c.

References add_stat(), stat_stat_t::desc, fatal(), stat_stat_t::stat_variant_t::for_int, stat_stat_t::format, stat_stat_t::stat_variant_t::stat_for_int_t::init_val, mystrdup(), stat_stat_t::name, stat_stat_t::sc, sc_int, stat_stat_t::stat_variant_t::stat_for_int_t::var, and stat_stat_t::variant.

Referenced by ld_reg_stats(), and sim_reg_stats().

00279 {
00280   struct stat_stat_t *stat;
00281 
00282   stat = (struct stat_stat_t *)calloc(1, sizeof(struct stat_stat_t));
00283   if (!stat)
00284     fatal("out of virtual memory");
00285 
00286   stat->name = mystrdup(name);
00287   stat->desc = mystrdup(desc);
00288   stat->format = format ? format : "%12d";
00289   stat->sc = sc_int;
00290   stat->variant.for_int.var = var;
00291   stat->variant.for_int.init_val = init_val;
00292 
00293   /* link onto SDB chain */
00294   add_stat(sdb, stat);
00295 
00296   /* initialize stat */
00297   *var = init_val;
00298 
00299   return stat;
00300 }

struct stat_stat_t* stat_reg_sdist struct stat_sdb_t   sdb,
char *    name,
char *    desc,
unsigned int    init_val,
int    pf,
char *    format,
print_fn_t    print_fn
 

Definition at line 520 of file stats.c.

References add_stat(), stat_stat_t::desc, fatal(), stat_stat_t::stat_variant_t::for_sdist, stat_stat_t::format, stat_stat_t::stat_variant_t::stat_for_sdist_t::init_val, mystrdup(), stat_stat_t::name, stat_stat_t::stat_variant_t::stat_for_sdist_t::pf, stat_stat_t::stat_variant_t::stat_for_sdist_t::print_fn, stat_stat_t::stat_variant_t::stat_for_sdist_t::sarr, stat_stat_t::sc, sc_sdist, and stat_stat_t::variant.

Referenced by sim_reg_stats().

00527 {
00528   struct stat_stat_t *stat;
00529   struct bucket_t **sarr;
00530 
00531   stat = (struct stat_stat_t *)calloc(1, sizeof(struct stat_stat_t));
00532   if (!stat)
00533     fatal("out of virtual memory");
00534 
00535   stat->name = mystrdup(name);
00536   stat->desc = mystrdup(desc);
00537   stat->format = format ? format : NULL;
00538   stat->sc = sc_sdist;
00539   stat->variant.for_sdist.init_val = init_val;
00540   stat->variant.for_sdist.pf = pf;
00541   stat->variant.for_sdist.print_fn = print_fn;
00542 
00543   /* allocate hash table */
00544   sarr = (struct bucket_t **)calloc(HTAB_SZ, sizeof(struct bucket_t *));
00545   if (!sarr)
00546     fatal("out of virtual memory");
00547   stat->variant.for_sdist.sarr = sarr;
00548 
00549   /* link onto SDB chain */
00550   add_stat(sdb, stat);
00551 
00552   return stat;
00553 }

struct stat_stat_t* stat_reg_uint struct stat_sdb_t   sdb,
char *    name,
char *    desc,
unsigned int *    var,
unsigned int    init_val,
char *    format
 

Definition at line 304 of file stats.c.

References add_stat(), stat_stat_t::desc, fatal(), stat_stat_t::stat_variant_t::for_uint, stat_stat_t::format, stat_stat_t::stat_variant_t::stat_for_uint_t::init_val, mystrdup(), stat_stat_t::name, stat_stat_t::sc, sc_uint, stat_stat_t::stat_variant_t::stat_for_uint_t::var, and stat_stat_t::variant.

Referenced by ld_reg_stats(), and main().

00310 {
00311   struct stat_stat_t *stat;
00312 
00313   stat = (struct stat_stat_t *)calloc(1, sizeof(struct stat_stat_t));
00314   if (!stat)
00315     fatal("out of virtual memory");
00316 
00317   stat->name = mystrdup(name);
00318   stat->desc = mystrdup(desc);
00319   stat->format = format ? format : "%12u";
00320   stat->sc = sc_uint;
00321   stat->variant.for_uint.var = var;
00322   stat->variant.for_uint.init_val = init_val;
00323 
00324   /* link onto SDB chain */
00325   add_stat(sdb, stat);
00326 
00327   /* initialize stat */
00328   *var = init_val;
00329 
00330   return stat;
00331 }



UVa CS Department of Computer Science
School of Engineering, University of Virginia
151 Engineer's Way, P.O. Box 400740
Charlottesville, Virginia 22904-4740

(434) 982-2200  Fax: (434) 982-2214