"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.h

Go to the documentation of this file.
00001 /*
00002  * stats.h - statistical package interfaces
00003  *
00004  * This file is a part of the SimpleScalar tool suite written by
00005  * Todd M. Austin as a part of the Multiscalar Research Project.
00006  *  
00007  * The tool suite is currently maintained by Doug Burger and Todd M. Austin.
00008  * 
00009  * Copyright (C) 1994, 1995, 1996, 1997, 1998 by Todd M. Austin
00010  *
00011  * This source file is distributed "as is" in the hope that it will be
00012  * useful.  The tool set comes with no warranty, and no author or
00013  * distributor accepts any responsibility for the conseqauences of its
00014  * use. 
00015  * 
00016  * Everyone is granted permission to copy, modify and redistribute
00017  * this tool set under the following conditions:
00018  * 
00019  *    This source code is distributed for non-commercial use only. 
00020  *    Please contact the maintainer for restrictions applying to 
00021  *    commercial use.
00022  *
00023  *    Permission is granted to anyone to make or distribute copies
00024  *    of this source code, either as received or modified, in any
00025  *    medium, provided that all copyright notices, permission and
00026  *    nonwarranty notices are preserved, and that the distributor
00027  *    grants the recipient permission for further redistribution as
00028  *    permitted by this document.
00029  *
00030  *    Permission is granted to distribute this file in compiled
00031  *    or executable form under the same conditions that apply for
00032  *    source code, provided that either:
00033  *
00034  *    A. it is accompanied by the corresponding machine-readable
00035  *       source code,
00036  *    B. it is accompanied by a written offer, with no time limit,
00037  *       to give anyone a machine-readable copy of the corresponding
00038  *       source code in return for reimbursement of the cost of
00039  *       distribution.  This written offer must permit verbatim
00040  *       duplication by anyone, or
00041  *    C. it is distributed by someone who received only the
00042  *       executable form, and is accompanied by a copy of the
00043  *       written offer of source code that they received concurrently.
00044  *
00045  * In other words, you are welcome to use, share and improve this
00046  * source file.  You are forbidden to forbid anyone else to use, share
00047  * and improve what you give them.
00048  *
00049  * INTERNET: dburger@cs.wisc.edu
00050  * US Mail:  1210 W. Dayton Street, Madison, WI 53706
00051  *
00052  * $Id: stats.h,v 1.1.1.1 2000/05/26 15:18:59 taustin Exp $
00053  *
00054  * $Log: stats.h,v $
00055  * Revision 1.1.1.1  2000/05/26 15:18:59  taustin
00056  * SimpleScalar Tool Set
00057  *
00058  *
00059  * Revision 1.3  1999/12/31 18:54:02  taustin
00060  * quad_t naming conflicts removed
00061  *
00062  * Revision 1.2  1998/08/27 16:40:23  taustin
00063  * implemented host interface description in host.h
00064  * added target interface support
00065  * added support for MS VC++ compilation
00066  * added support for qword's
00067  *
00068  * Revision 1.1  1997/03/11  01:34:26  taustin
00069  * Initial revision
00070  *
00071  *
00072  */
00073 
00074 #ifndef STAT_H
00075 #define STAT_H
00076 
00077 #include <stdio.h>
00078 
00079 #include "host.h"
00080 #include "machine.h"
00081 #include "eval.h"
00082 
00083 /*
00084  * The stats package is a uniform module for handling statistical variables,
00085  * including counters, distributions, and expressions.  The user must first
00086  * create a stats database using stat_new(), then statical counters are added
00087  * to the database using the *_reg_*() functions.  Interfaces are included to
00088  * allocate and manipulate distributions (histograms) and general expression
00089  * of other statistical variables constants.  Statistical variables can be
00090  * located by name using stat_find_stat().  And, statistics can be print in
00091  * a highly standardized and stylized fashion using stat_print_stats().
00092  */
00093 
00094 /* stat variable classes */
00095 enum stat_class_t {
00096   sc_int = 0,                   /* integer stat */
00097   sc_uint,                      /* unsigned integer stat */
00098 #ifdef HOST_HAS_QWORD
00099   sc_qword,                     /* qword integer stat */
00100   sc_sqword,                    /* signed qword integer stat */
00101 #endif /* HOST_HAS_QWORD */
00102   sc_float,                     /* single-precision FP stat */
00103   sc_double,                    /* double-precision FP stat */
00104   sc_dist,                      /* array distribution stat */
00105   sc_sdist,                     /* sparse array distribution stat */
00106   sc_formula,                   /* stat expression formula */
00107   sc_NUM
00108 };
00109 
00110 /* sparse array distributions are implemented with a hash table */
00111 #define HTAB_SZ                 1024
00112 #define HTAB_HASH(I)            ((((I) >> 8) ^ (I)) & (HTAB_SZ - 1))
00113 
00114 /* hash table bucket definition */
00115 struct bucket_t {
00116   struct bucket_t *next;        /* pointer to the next bucket */
00117   md_addr_t index;              /* bucket index - as large as an addr */
00118   unsigned int count;           /* bucket count */
00119 };
00120 
00121 /* forward declaration */
00122 struct stat_stat_t;
00123 
00124 /* enable distribution components:  index, count, probability, cumulative */
00125 #define PF_COUNT                0x0001
00126 #define PF_PDF                  0x0002
00127 #define PF_CDF                  0x0004
00128 #define PF_ALL                  (PF_COUNT|PF_PDF|PF_CDF)
00129 
00130 /* user-defined print function, if this option is selected, a function of this
00131    form is called for each bucket in the distribution, in ascending index
00132    order */
00133 typedef void
00134 (*print_fn_t)(struct stat_stat_t *stat, /* the stat variable being printed */
00135               md_addr_t index,          /* entry index to print */
00136               int count,                /* entry count */
00137               double sum,               /* cumulative sum */
00138               double total);            /* total count for distribution */
00139 
00140 /* statistical variable definition */
00141 struct stat_stat_t {
00142   struct stat_stat_t *next;     /* pointer to next stat in database list */
00143   char *name;                   /* stat name */
00144   char *desc;                   /* stat description */
00145   char *format;                 /* stat output print format */
00146   enum stat_class_t sc;         /* stat class */
00147   union stat_variant_t {
00148     /* sc == sc_int */
00149     struct stat_for_int_t {
00150       int *var;                 /* integer stat variable */
00151       int init_val;             /* initial integer value */
00152     } for_int;
00153     /* sc == sc_uint */
00154     struct stat_for_uint_t {
00155       unsigned int *var;        /* unsigned integer stat variable */
00156       unsigned int init_val;    /* initial unsigned integer value */
00157     } for_uint;
00158 #ifdef HOST_HAS_QWORD
00159     /* sc == sc_qword */
00160     struct stat_for_qword_t {
00161       qword_t *var;             /* qword integer stat variable */
00162       qword_t init_val;         /* qword integer value */
00163     } for_qword;
00164     /* sc == sc_sqword */
00165     struct stat_for_sqword_t {
00166       sqword_t *var;            /* signed qword integer stat variable */
00167       sqword_t init_val;        /* signed qword integer value */
00168     } for_sqword;
00169 #endif /* HOST_HAS_QWORD */
00170     /* sc == sc_float */
00171     struct stat_for_float_t {
00172       float *var;               /* float stat variable */
00173       float init_val;           /* initial float value */
00174     } for_float;
00175     /* sc == sc_double */
00176     struct stat_for_double_t {
00177       double *var;              /* double stat variable */
00178       double init_val;          /* initial double value */
00179     } for_double;
00180     /* sc == sc_dist */
00181     struct stat_for_dist_t {
00182       unsigned int init_val;    /* initial dist value */
00183       unsigned int *arr;        /* non-sparse array pointer */
00184       unsigned int arr_sz;      /* array size */
00185       unsigned int bucket_sz;   /* array bucket size */
00186       int pf;                   /* printables */
00187       char **imap;              /* index -> string map */
00188       print_fn_t print_fn;      /* optional user-specified print fn */
00189       unsigned int overflows;   /* total overflows in stat_add_samples() */
00190     } for_dist;
00191     /* sc == sc_sdist */
00192     struct stat_for_sdist_t {
00193       unsigned int init_val;    /* initial dist value */
00194       struct bucket_t **sarr;   /* sparse array pointer */
00195       int pf;                   /* printables */
00196       print_fn_t print_fn;      /* optional user-specified print fn */
00197     } for_sdist;
00198     /* sc == sc_formula */
00199     struct stat_for_formula_t {
00200       char *formula;            /* stat formula, see eval.h for format */
00201     } for_formula;
00202   } variant;
00203 };
00204 
00205 /* statistical database */
00206 struct stat_sdb_t {
00207   struct stat_stat_t *stats;            /* list of stats in database */
00208   struct eval_state_t *evaluator;       /* an expression evaluator */
00209 };
00210 
00211 /* evaluate a stat as an expression */
00212 struct eval_value_t
00213 stat_eval_ident(struct eval_state_t *es);/* expression stat to evaluate */
00214 
00215 /* create a new stats database */
00216 struct stat_sdb_t *stat_new(void);
00217 
00218 /* delete a stats database */
00219 void
00220 stat_delete(struct stat_sdb_t *sdb);    /* stats database */
00221 
00222 /* register an integer statistical variable */
00223 struct stat_stat_t *
00224 stat_reg_int(struct stat_sdb_t *sdb,    /* stat database */
00225              char *name,                /* stat variable name */
00226              char *desc,                /* stat variable description */
00227              int *var,                  /* stat variable */
00228              int init_val,              /* stat variable initial value */
00229              char *format);             /* optional variable output format */
00230 
00231 /* register an unsigned integer statistical variable */
00232 struct stat_stat_t *
00233 stat_reg_uint(struct stat_sdb_t *sdb,   /* stat database */
00234               char *name,               /* stat variable name */
00235               char *desc,               /* stat variable description */
00236               unsigned int *var,        /* stat variable */
00237               unsigned int init_val,    /* stat variable initial value */
00238               char *format);            /* optional variable output format */
00239 
00240 #ifdef HOST_HAS_QWORD
00241 /* register a qword integer statistical variable */
00242 struct stat_stat_t *
00243 stat_reg_qword(struct stat_sdb_t *sdb,  /* stat database */
00244                char *name,              /* stat variable name */
00245                char *desc,              /* stat variable description */
00246                qword_t *var,            /* stat variable */
00247                qword_t init_val,        /* stat variable initial value */
00248                char *format);           /* optional variable output format */
00249 
00250 /* register a signed qword integer statistical variable */
00251 struct stat_stat_t *
00252 stat_reg_sqword(struct stat_sdb_t *sdb, /* stat database */
00253                 char *name,             /* stat variable name */
00254                 char *desc,             /* stat variable description */
00255                 sqword_t *var,          /* stat variable */
00256                 sqword_t init_val,      /* stat variable initial value */
00257                 char *format);          /* optional variable output format */
00258 #endif /* HOST_HAS_QWORD */
00259 
00260 /* register a float statistical variable */
00261 struct stat_stat_t *
00262 stat_reg_float(struct stat_sdb_t *sdb,  /* stat database */
00263                char *name,              /* stat variable name */
00264                char *desc,              /* stat variable description */
00265                float *var,              /* stat variable */
00266                float init_val,          /* stat variable initial value */
00267                char *format);           /* optional variable output format */
00268 
00269 /* register a double statistical variable */
00270 struct stat_stat_t *
00271 stat_reg_double(struct stat_sdb_t *sdb, /* stat database */
00272                 char *name,             /* stat variable name */
00273                 char *desc,             /* stat variable description */
00274                 double *var,            /* stat variable */
00275                 double init_val,        /* stat variable initial value */
00276                 char *format);          /* optional variable output format */
00277 
00278 /* create an array distribution (w/ fixed size buckets) in stat database SDB,
00279    the array distribution has ARR_SZ buckets with BUCKET_SZ indicies in each
00280    bucked, PF specifies the distribution components to print for optional
00281    format FORMAT; the indicies may be optionally replaced with the strings
00282    from IMAP, or the entire distribution can be printed with the optional
00283    user-specified print function PRINT_FN */
00284 struct stat_stat_t *
00285 stat_reg_dist(struct stat_sdb_t *sdb,   /* stat database */
00286               char *name,               /* stat variable name */
00287               char *desc,               /* stat variable description */
00288               unsigned int init_val,    /* dist initial value */
00289               unsigned int arr_sz,      /* array size */
00290               unsigned int bucket_sz,   /* array bucket size */
00291               int pf,                   /* print format, use PF_* defs */
00292               char *format,             /* optional variable output format */
00293               char **imap,              /* optional index -> string map */
00294               print_fn_t print_fn);     /* optional user print function */
00295 
00296 /* create a sparse array distribution in stat database SDB, while the sparse
00297    array consumes more memory per bucket than an array distribution, it can
00298    efficiently map any number of indicies from 0 to 2^32-1, PF specifies the
00299    distribution components to print for optional format FORMAT; the indicies
00300    may be optionally replaced with the strings from IMAP, or the entire
00301    distribution can be printed with the optional user-specified print function
00302    PRINT_FN */
00303 struct stat_stat_t *
00304 stat_reg_sdist(struct stat_sdb_t *sdb,  /* stat database */
00305                char *name,              /* stat variable name */
00306                char *desc,              /* stat variable description */
00307                unsigned int init_val,   /* dist initial value */
00308                int pf,                  /* print format, use PF_* defs */
00309                char *format,            /* optional variable output format */
00310                print_fn_t print_fn);    /* optional user print function */
00311 
00312 /* add NSAMPLES to array or sparse array distribution STAT */
00313 void
00314 stat_add_samples(struct stat_stat_t *stat,/* stat database */
00315                  md_addr_t index,       /* distribution index of samples */
00316                  int nsamples);         /* number of samples to add to dist */
00317 
00318 /* add a single sample to array or sparse array distribution STAT */
00319 void
00320 stat_add_sample(struct stat_stat_t *stat,/* stat variable */
00321                 md_addr_t index);       /* index of sample */
00322 
00323 /* register a double statistical formula, the formula is evaluated when the
00324    statistic is printed, the formula expression may reference any registered
00325    statistical variable and, in addition, the standard operators '(', ')', '+',
00326    '-', '*', and '/', and literal (i.e., C-format decimal, hexidecimal, and
00327    octal) constants are also supported; NOTE: all terms are immediately
00328    converted to double values and the result is a double value, see eval.h
00329    for more information on formulas */
00330 struct stat_stat_t *
00331 stat_reg_formula(struct stat_sdb_t *sdb,/* stat database */
00332                  char *name,            /* stat variable name */
00333                  char *desc,            /* stat variable description */
00334                  char *formula,         /* formula expression */
00335                  char *format);         /* optional variable output format */
00336 
00337 /* print the value of stat variable STAT */
00338 void
00339 stat_print_stat(struct stat_sdb_t *sdb, /* stat database */
00340                 struct stat_stat_t *stat,/* stat variable */
00341                 FILE *fd);              /* output stream */
00342 
00343 /* print the value of all stat variables in stat database SDB */
00344 void
00345 stat_print_stats(struct stat_sdb_t *sdb,/* stat database */
00346                  FILE *fd);             /* output stream */
00347 
00348 
00349 /* find a stat variable, returns NULL if it is not found */
00350 struct stat_stat_t *
00351 stat_find_stat(struct stat_sdb_t *sdb,  /* stat database */
00352                char *stat_name);        /* stat name */
00353                
00354 #endif /* STAT_H */


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