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

📄 userstat.cc

📁 ml-rsim 多处理器模拟器 支持类bsd操作系统
💻 CC
📖 第 1 页 / 共 2 页
字号:
  long long samples;public:  user_stat_trace(char *na, int no) : user_stat(na, no)  {    reset();  };  ~user_stat_trace()  {};  void reset();  void print(int);  void sample(int);};/*=========================================================================*//* Reset trace statistics class                                            *//*=========================================================================*/void user_stat_trace::reset(){  samples = 0;}/*=========================================================================*//* Print trace statistics. If at least one sample exists, report total.    *//*=========================================================================*/void user_stat_trace::print(int fp){  YS__fmsg(fp, "%s (trace)\n", name);  if (samples == 0)    YS__fmsg(fp, "  no samples\n");  else if (samples == 1)    YS__fmsg(fp, "  1 sample\n");  else    YS__fmsg(fp, "  %lld samples\n", samples);  YS__fmsg(fp, "\n");}/*=========================================================================*//* Sample trace statistics: print message and argument, increment count    *//*=========================================================================*/void user_stat_trace::sample(int arg){  samples++;  YS__logmsg(node, "TRACE %.0f: %s %i\n", YS__Simtime, name, arg);}/*=========================================================================*//* Point statistics class - derived from basic statistics class.           *//* Records statistics at sample points. Reports min, max, avg of samples.  *//*=========================================================================*/class user_stat_point : public user_stat{private:  int min;  int max;  long long total;  long long samples;public:  user_stat_point(char *na, int no) : user_stat(na, no)  {    reset();  };  ~user_stat_point()  {};  void reset();  void print(int);  void sample(int);};/*=========================================================================*//* Reset point statistics class                                            *//*=========================================================================*/void user_stat_point::reset(){  samples = 0ll;  min     = INT_MAX;  max     = INT_MIN;  total   = 0ll;}/*=========================================================================*//* Print point statistics. If at least one sample exists, report total.    *//*=========================================================================*/void user_stat_point::print(int fp){  YS__fmsg(fp, "%s (point)\n", name);  if (samples == 0)    YS__fmsg(fp, "  no samples\n");  else    {      YS__fmsg(fp, "  %lld sample%c\n", samples, samples > 1 ? 's' : ' ');      YS__fmsg(fp, "  Total: %12lld\n", total);      YS__fmsg(fp, "  Avg:   %12.3f\n", (double)total / (double)samples);      YS__fmsg(fp, "  Min:   %12d\n", min);      YS__fmsg(fp, "  Max:   %12d\n", max);    }  YS__fmsg(fp, "\n");}/*=========================================================================*//* Sample point statistics: record max/min, add total, increment count     *//*=========================================================================*/void user_stat_point::sample(int arg){  samples++;  total += arg;    if (arg > max)    max = arg;  if (arg < min)    min = arg;}/*=========================================================================*//* Per-node user statistics: constructor.                                  *//*=========================================================================*/user_stats::user_stats(int n){  node       = n;  num_elemns = 0;  elemns     = NULL;}/*=========================================================================*//* Per-node user statistics: destructor.                                   *//*=========================================================================*/user_stats::~user_stats(){  if (elemns != NULL)    free(elemns);  num_elemns = 0;  elemns = NULL;}/*=========================================================================*//* Reset user statistics - call reset routine for all statistics objects.  *//*=========================================================================*/void user_stats::reset(){  for (int n = 0; n < num_elemns; n++)    elemns[n]->reset();}/*=========================================================================*//* Print user statistics - call print routine for all statistics objects.  *//*=========================================================================*/void user_stats::print(int fp){  for (int n = 0; n < num_elemns; n++)    elemns[n]->print(fp);}/*=========================================================================*//* Allocate a statistics object: scan list of existing objects, if name    *//* exists return handle, otherwise grow array of objects and create new    *//* object of specified type.                                               *//*=========================================================================*/int user_stats::alloc(int type, char *name){  int n;  user_stat ** new_elemns;  for (n = 0; n < num_elemns; n++)    if (strcmp(elemns[n]->getname(), name) == 0)      break;  if (n < num_elemns)    return(n);  num_elemns++;  if (elemns == (user_stat**)NULL)    {      elemns = (user_stat**)malloc(sizeof(user_stat*) * num_elemns);      if (elemns == NULL)	YS__errmsg(0, "Malloc failed in %s:%i\n", __FILE__, __LINE__);    }  else    {      new_elemns = (user_stat**)malloc(sizeof(user_stat*) * num_elemns);      if (new_elemns == NULL)	YS__errmsg(0, "Malloc failed in %s:%i\n", __FILE__, __LINE__);      memcpy(new_elemns, elemns, sizeof(user_stat*) * (num_elemns-1));      free(elemns);      elemns = new_elemns;    }  switch (type)    {    case USER_STAT_INTERVAL:      elemns[n] = new user_stat_interval(name, node);      return(n);    case USER_STAT_TRACE:      elemns[n] = new user_stat_trace(name, node);      return(n);    case USER_STAT_POINT:      elemns[n] = new user_stat_point(name, node);      return(n);    default:      YS__warnmsg(node, "Illegal UserStat type %i in user_stats::add\n", type);      num_elemns--;      return(-1);    }}/*=========================================================================*//* Record user statistics sample: call corresponding routine of object.    *//*=========================================================================*/void user_stats::sample(int id, int val){  if ((id < 0) || (id >= num_elemns))    {      YS__warnmsg(0, "Sample on invalid ID %i in user_stats::sample\n", id);      return;    }  elemns[id]->sample(val);}

⌨️ 快捷键说明

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