stats.c 1.98 KB
/*
 * Copyright (C) 1998 by the Board of Trustees
 *    of Leland Stanford Junior University.
 * Copyright (C) 1998 Digital Equipment Corporation
 *
 * This file is part of the SimOS distribution.
 * See LICENSE file for terms of the license.
 *
 */


#include <stdio.h>
#include <sys/time.h>
#include <strings.h>
#include <sys/resource.h>

#include "simtypes.h"
#include "sim_error.h"
#include "eventcallback.h"
#include "alpha.h"
#include "machine_params.h"
#include "cpu_interface.h"
#include "tb.h"
#include "qc.h"


static struct {
   SimTime interval;
   EventCallbackHdr hdr;
   struct timeval firstTime;
   struct timeval prevTime;
   SimTime prevInstr;
   char * (*simulatorStats)();
} stats;

static double TimeDiff(struct timeval *old, struct timeval *new)
{
   double diff;
   
   diff=new->tv_sec - old->tv_sec; 
   diff += 0.000001 * (new->tv_usec - old->tv_usec);
   return diff;
}


static void StatsCallback(int cpuNum, EventCallbackHdr *hdr,void *arg)
{
   SimTime totalInstr=0;
   int i;
   struct timeval now;
   double diffFirst, diffPrev;

   
   gettimeofday(&now,NULL);
   diffFirst = TimeDiff(&stats.firstTime, &now);
   diffPrev = TimeDiff(&stats.prevTime,&now);

   for (i=0;i<TOTAL_CPUS;i++) {
      totalInstr += CPUVec.InstrCount(i);
   }
   CPUPrint("PERIODIC %4ld  %8.1f KIPS avg %8.1f KIPS %s\n",
	      CPUVec.CycleCount(0) / stats.interval,
	      (totalInstr-stats.prevInstr) / 1000.0 / diffPrev,
	      totalInstr / 1000.0 / diffFirst,
	    stats.simulatorStats());
   stats.prevInstr = totalInstr;
   stats.prevTime = now;

   AnnExec(AnnFind("simos","periodic"));

   EventDoCallback(cpuNum,StatsCallback,hdr,0,stats.interval);
   
   QCConsistencyCheck(curPE,curPE->curDQC,TB_DATA);  

}


   
void InitSimulatorStats(SimTime interval, char * (*simulatorStats)())
{
   stats.interval = interval;
   stats.simulatorStats = simulatorStats;
   gettimeofday(&stats.firstTime,NULL);
   gettimeofday(&stats.prevTime,NULL);
   EventDoCallback(0,StatsCallback,&stats.hdr,0,stats.interval);
}