OpenCores
URL https://opencores.org/ocsvn/async_sdm_noc/async_sdm_noc/trunk

Subversion Repositories async_sdm_noc

[/] [async_sdm_noc/] [branches/] [init/] [common/] [tb/] [sim_ana.h] - Diff between revs 29 and 30

Only display areas with differences | Details | Blame | View Log

Rev 29 Rev 30
/*
/*
 Asynchronous SDM NoC
 Asynchronous SDM NoC
 (C)2011 Wei Song
 (C)2011 Wei Song
 Advanced Processor Technologies Group
 Advanced Processor Technologies Group
 Computer Science, the Univ. of Manchester, UK
 Computer Science, the Univ. of Manchester, UK
 
 
 Authors:
 Authors:
 Wei Song     wsong83@gmail.com
 Wei Song     wsong83@gmail.com
 
 
 License: LGPL 3.0 or later
 License: LGPL 3.0 or later
 
 
 Simulation analyzer, gethering info. for performance analyses.
 Simulation analyzer, gethering info. for performance analyses.
 
 
 Possible bugs:
 Possible bugs:
 * the histograph function has not been tested yet.
 * the histograph function has not been tested yet.
 
 
 
 
 History:
 History:
 29/06/2010  Initial version. <wsong83@gmail.com>
 29/06/2010  Initial version. <wsong83@gmail.com>
 27/05/2011  Clean up for opensource. <wsong83@gmail.com>
 28/05/2011  Clean up for opensource. <wsong83@gmail.com>
 
 
*/
*/
 
 
#ifndef SIM_ANA_H_
#ifndef SIM_ANA_H_
#define SIM_ANA_H_
#define SIM_ANA_H_
 
 
#include <cstdlib>
#include <cstdlib>
#include <cmath>
#include <cmath>
#include <iostream>
#include <iostream>
#include <fstream>
#include <fstream>
#include <string>
#include <string>
#include "sim_record.h"
#include "sim_record.h"
#include "hash_table.h"
#include "hash_table.h"
 
 
using namespace std;
using namespace std;
 
 
// a data type for accumulative performance, such as throughput analysis
// a data type for accumulative performance, such as throughput analysis
class accu_record{
class accu_record{
 private:
 private:
  double V1, V2;                /* two values to avoid loss of accuracy, V1 save the accumulated V2 of at least 512 records */
  double V1, V2;                /* two values to avoid loss of accuracy, V1 save the accumulated V2 of at least 512 records */
  unsigned int N1, N2;
  unsigned int N1, N2;
 public:
 public:
  accu_record()
  accu_record()
    :V1(0), V2(0), N1(0), N2(0)
    :V1(0), V2(0), N1(0), N2(0)
    {}
    {}
 
 
  accu_record& operator+= (const double m) {
  accu_record& operator+= (const double m) {
    N2++;
    N2++;
    V2 += m;
    V2 += m;
    if(N2 >= N1/512) {
    if(N2 >= N1/512) {
      N1 += N2;
      N1 += N2;
      V1 += V2;
      V1 += V2;
      N2 = 0;
      N2 = 0;
      V2 = 0;
      V2 = 0;
    }
    }
    return(*this);
    return(*this);
  }
  }
 
 
  double avalue() {             /* return averged value */
  double avalue() {             /* return averged value */
    double rt;
    double rt;
 
 
    if(0 == N1+N2)
    if(0 == N1+N2)
      rt = 0;
      rt = 0;
    else
    else
      rt = (V1 + V2) / (N1 + N2);
      rt = (V1 + V2) / (N1 + N2);
 
 
    V1 = 0;
    V1 = 0;
    V2 = 0;
    V2 = 0;
    N1 = 0;
    N1 = 0;
    N2 = 0;
    N2 = 0;
    return rt;
    return rt;
  }
  }
 
 
  double value() {              /* return the accumulative value */
  double value() {              /* return the accumulative value */
    double rt;
    double rt;
 
 
    if(0 == N1+N2)
    if(0 == N1+N2)
      rt = 0;
      rt = 0;
    else
    else
      rt = (V1 + V2);
      rt = (V1 + V2);
 
 
    V1 = 0;
    V1 = 0;
    V2 = 0;
    V2 = 0;
    N1 = 0;
    N1 = 0;
    N2 = 0;
    N2 = 0;
    return rt;
    return rt;
  }
  }
};
};
 
 
/* the major simulation record class, only one such object in one simulation */
/* the major simulation record class, only one such object in one simulation */
class sim_ana {
class sim_ana {
 public:
 public:
 
 
  sim_ana()
  sim_ana()
    : warm_time(0), record_period(0),last_time(0),
    : warm_time(0), record_period(0),last_time(0),
    delay_ana(false), throughput_ana(false), delay_histo_ana(false),
    delay_ana(false), throughput_ana(false), delay_histo_ana(false),
    histo_data(NULL) {}
    histo_data(NULL) {}
 
 
  sim_ana(double mwt, double mrp)
  sim_ana(double mwt, double mrp)
    : warm_time(mwt), record_period(mrp), last_time(0),
    : warm_time(mwt), record_period(mrp), last_time(0),
    delay_ana(false), throughput_ana(false), delay_histo_ana(false),
    delay_ana(false), throughput_ana(false), delay_histo_ana(false),
    histo_data(NULL) {}
    histo_data(NULL) {}
 
 
  ~sim_ana();
  ~sim_ana();
 
 
  /* currently 16 table entries is enough and good for memory efficiency */
  /* currently 16 table entries is enough and good for memory efficiency */
  hash_table<sim_record<2>,16> ANA;
  hash_table<sim_record<2>,16> ANA;
 
 
  bool start(long, double);     /* start to record a new record */
  bool start(long, double);     /* start to record a new record */
  bool record(long, double);    /* record a time stamp */
  bool record(long, double);    /* record a time stamp */
  bool stop(long, double, unsigned int);        /* stop an old record */
  bool stop(long, double, unsigned int);        /* stop an old record */
 
 
  bool set_ana_parameters(double, double); /* set analysis time parameters */
  bool set_ana_parameters(double, double); /* set analysis time parameters */
  bool analyze_delay(string);   /* enable delay analysis */
  bool analyze_delay(string);   /* enable delay analysis */
  bool analyze_throughput(string); /* enable throughput analysis */
  bool analyze_throughput(string); /* enable throughput analysis */
  bool analyze_delay_histo(string, double, double, unsigned int); /* enable delay histo analysis */
  bool analyze_delay_histo(string, double, double, unsigned int); /* enable delay histo analysis */
 
 
 private:
 private:
  double warm_time;
  double warm_time;
  double record_period;
  double record_period;
  double last_time;
  double last_time;
 
 
  bool delay_ana;               /* whether analyze frame delay */
  bool delay_ana;               /* whether analyze frame delay */
  bool throughput_ana;          /* whether analyze throughput */
  bool throughput_ana;          /* whether analyze throughput */
  bool delay_histo_ana;         /* whether analyze frame delay histo */
  bool delay_histo_ana;         /* whether analyze frame delay histo */
  unsigned int delay_histo_binnum; /* bin number of the histo graph */
  unsigned int delay_histo_binnum; /* bin number of the histo graph */
  double delay_histo_start;        /* histo begin level */
  double delay_histo_start;        /* histo begin level */
  double delay_histo_end;          /* histo end level */
  double delay_histo_end;          /* histo end level */
  double delay_histo_gap;          /* gap bewteen two levels (gap = (start-end)/(binnum-2)) */
  double delay_histo_gap;          /* gap bewteen two levels (gap = (start-end)/(binnum-2)) */
  unsigned long * histo_data;
  unsigned long * histo_data;
 
 
  string delay_file;            /* the name for delay analyses result file */
  string delay_file;            /* the name for delay analyses result file */
  string throughput_file;       /* the name for throughput analyses result file */
  string throughput_file;       /* the name for throughput analyses result file */
  string delay_histo_file;      /* the name for histograph analyses file */
  string delay_histo_file;      /* the name for histograph analyses file */
 
 
  accu_record fm_dly;           /* records of frame delay */
  accu_record fm_dly;           /* records of frame delay */
  accu_record pth_dly;          /* records of path delay */
  accu_record pth_dly;          /* records of path delay */
  accu_record th_value;         /* records of throughput */
  accu_record th_value;         /* records of throughput */
};
};
 
 
#endif
#endif
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.