stats.c
1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* 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);
}