⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stat.c

📁 ml-rsim 多处理器模拟器 支持类bsd操作系统
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 2002 The Board of Trustees of the University of Illinois and *                    William Marsh Rice University * Copyright (c) 2002 The University of Utah * Copyright (c) 2002 The University of Notre Dame du Lac * * All rights reserved. * * Based on RSIM 1.0, developed by: *   Professor Sarita Adve's RSIM research group *   University of Illinois at Urbana-Champaign and     William Marsh Rice University *   http://www.cs.uiuc.edu/rsim and http://www.ece.rice.edu/~rsim/dist.html * ML-RSIM/URSIM extensions by: *   The Impulse Research Group, University of Utah *   http://www.cs.utah.edu/impulse *   Lambert Schaelicke, University of Utah and University of Notre Dame du Lac *   http://www.cse.nd.edu/~lambert *   Mike Parker, University of Utah *   http://www.cs.utah.edu/~map * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal with the Software without restriction, including without * limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to * whom the Software is furnished to do so, subject to the following * conditions: * * 1. Redistributions of source code must retain the above copyright notice, *    this list of conditions and the following disclaimers.  * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimers in the *    documentation and/or other materials provided with the distribution. * 3. Neither the names of Professor Sarita Adve's RSIM research group, *    the University of Illinois at Urbana-Champaign, William Marsh Rice *    University, nor the names of its contributors may be used to endorse *    or promote products derived from this Software without specific prior *    written permission.  * 4. Neither the names of the ML-RSIM project, the URSIM project, the *    Impulse research group, the University of Utah, the University of *    Notre Dame du Lac, nor the names of its contributors may be used to *    endorse or promote products derived from this software without specific *    prior written permission.  * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS WITH THE SOFTWARE.  *//*  stat.c  This file provides functions related to the YACSIM "Statrec" statistics  collection library.  */#include "Processor/simio.h"#include "sim_main/simsys.h"#include "sim_main/util.h"#include "sim_main/tr.stat.h"#include <malloc.h>#include <string.h>#include <math.h>#define IsPowerOf2(x) ((((x)-1) & (x)) == 0)/***************************************************************************//* STATREC Operations: Statistics records are used to collect and          *//* display statistics for a simulation.  Each STATREC can compute a        *//* running mean, standard deviation, max, mean and histogram.  Collected   *//* statistics may be displayed in a standard format, or they can be        *//* constructed in any user defined format using operations that return     *//* all relevant STATREC information                                        *//***************************************************************************//* Creates and returns a pointer to a new statistics record                */STATREC *NewStatrec(int node, const char *srname, int typ, int meanflg,		    int histflg, int nbins, int lowbin, int highbin){  STATREC *srptr;  int i;  double d;  PSDELAY;  srptr = (STATREC*)YS__PoolGetObj(&YS__StatPool);  srptr->id = YS__idctr++;  strncpy(srptr->name, srname, 31);                       /* copy its name */  srptr->name[31]    = '\0';  srptr->meanflag    = meanflg;  srptr->sum         = 0;  srptr->sumsq       = 0;  srptr->sumwt       = 0;  srptr->samples     = 0;  srptr->interval    = 0;              /* Interval of last interval staterec					  update                           */  srptr->intervalerr = 0;              /* Set if interval of interval					  statrec is ever neg              */  if (typ == POINT)    srptr->type = PNTSTATTYPE;  else if (typ == INTERVAL)    srptr->type = INTSTATTYPE;  else    YS__errmsg(node, "Invalid statistics record type, use POINT or INTERVAL");  if (histflg == HIST || histflg == HISTSPECIAL)    {                                  /* Histograms will be collected     */      srptr->histspecial = (histflg == HISTSPECIAL);      d = (double)(highbin - lowbin) / (double)nbins;      i = (int)d;      while (((double)rint(d) != d) || (!IsPowerOf2(i)))	{	  highbin++;	  	  d = (double)(highbin - lowbin) / (double)nbins;	  i = (int)d;	}      srptr->bins = nbins+1;      srptr->hist = (long long*)malloc((srptr->bins)*sizeof(long long));       if (srptr->hist == NULL)	YS__errmsg(node, "Malloc fails in NewStatrec");      for (i = 0; i < srptr->bins; i++)	srptr->hist[i] = 0;                            /* Clear all bins   */      if (nbins > 0)	srptr->hist_incr = (highbin - lowbin) / nbins;         /* Bin size */      else	srptr->hist_incr = 0;      srptr->hist_shift = NumOfBits((highbin - lowbin) / nbins, 1);      srptr->hist_offset = srptr->hist_incr - 1 - srptr->hist_low;      srptr->hist_low  = lowbin;      srptr->hist_high = highbin;      TRACE_STATREC_new2;               /* Creating statistics record ...  */    }  else if (histflg == NOHIST)    {                                   /* Histograms not collected        */      srptr->hist = NULL;      srptr->bins = 0;      TRACE_STATREC_new1;               /* Creating Statistics record ...  */    }   else    YS__errmsg(node,	       "Invalid histogram flag, use HIST, NOHIST, or HISTSPECIAL");  return srptr;}/***************************************************************************/int YS__StatrecId(STATREC *srptr)      /* Returns the system defined ID or 0			                  if TrID is 0                     */{  if (TraceIDs)    return srptr->id;  else    return 0;}/***************************************************************************/void StatrecReset(STATREC *srptr)        /* Resets the statrec             */{  int i;  PSDELAY;  if (srptr->hist)                       /* Clear all histogram bins       */    for (i = 0; i < srptr->bins; i++)      *(srptr->hist+i) = 0;  if (srptr->meanflag == MEANS)    {                                    /* Reset all sum-related fields   */      srptr->sum = 0;      srptr->sumsq = 0;      srptr->sumwt = 0;    }  srptr->samples = 0;                     /* Clear sample count            */  srptr->intervalerr = 0;        /* Set if interval of interval statrec is				    ever neg                               */  srptr->interval = 0;           /* Interval of last interval update       */  TRACE_STATREC_reset;           /* Resetting statistics records ...       */}/***************************************************************************/void StatrecUpdate(STATREC *srptr, int v, long long t){  int i;  PSDELAY;  if (srptr->type == PNTSTATTYPE)    {                                    /* Its a point statistics record  */      if (srptr->samples == 0)	{                                /* This is the first sample       */	  srptr->maxval = v;	  srptr->minval = v;	}             if (srptr->meanflag == MEANS)	{                                /* Collect means                  */	  srptr->sum += v*t;             /* Accumulate sums                */	  srptr->sumsq += t*v*v;	  srptr->sumwt += t;	}      if (srptr->hist)                   /* Collect histograms             */	{	  if (v + srptr->hist_low <= srptr->hist_high)	    srptr->hist[(v + srptr->hist_offset) >> srptr->hist_shift] += t;	}      if (v > srptr->maxval)	srptr->maxval = v;      if (v < srptr->minval)	srptr->minval = v;      srptr->samples++;      TRACE_STATREC_pupdate;             /* Updating point stats record ...*/      return;    }  if (srptr->type == INTSTATTYPE)    {                                    /* This is an interval statistics					     record                        */      if (srptr->samples == 0)	{                                /* This is the first sample       */	  srptr->lastt = t;              /* Updates of interval statrecs   */	  srptr->lastv = v;              /* require 2 values to compute an */	                                 /* interval, so this  sample only */	  srptr->maxval = 0;             /* initializes the first of them  */	  srptr->minval = 0;             /* Max & min refers to intervals  */	}                                /* not values                     */      else	{                                /* This is not the first sample   */	  srptr->interval = t - srptr->lastt;      /* New interval computed*/	  if (srptr->interval < 0)	    srptr->intervalerr = 1;                /* Not a valid interval */	  if (srptr->meanflag == MEANS)            /* collect means        */	    {                                      /* accumulate sums      */	      srptr->sum += srptr->lastv * srptr->interval;	      srptr->sumsq += srptr->interval * srptr->lastv * srptr->lastv; 	      srptr->sumwt += srptr->interval;                	    }	  if (srptr->hist)                         /* Collect histograms   */	    if (srptr->interval >= 0.0)	      srptr->hist[(srptr->lastv + srptr->hist_offset) >> srptr->hist_shift] +=		srptr->interval;	  if (v > srptr->maxval)	    srptr->maxval = v;	  if (v < srptr->minval)	    srptr->minval = v;	  srptr->lastv = v;              /* Remember last value & time     */	                                 /* to compute next interval       */	  srptr->lastt = t;	}      srptr->samples++;      TRACE_STATREC_iupdate;             /* Updating interval stats record */      return;    }}/***************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -