-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstat.c
63 lines (53 loc) · 1.73 KB
/
stat.c
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
/**
* CS 537 Programming Assignment 4 (Fall 2020)
* @file stat.c
* @brief Tracks statistics from simulation
* @author Julien de Castelnau
*/
#include "stat.h"
#include "memory.h"
#include "process.h"
#include <stdlib.h>
#include <stdio.h>
static struct stat_t* ProgStats;
// Initialize stat structure
void Stat_init() {
ProgStats = (struct stat_t*)malloc(sizeof(struct stat_t));
if ((ProgStats) == NULL) {
perror("Error allocating memory for stats data structure.");
exit(EXIT_FAILURE);
}
ProgStats->tmu = 0;
ProgStats->trp = 0;
ProgStats->tmr = 0;
ProgStats->tpi = 0;
}
// No matter what happens this tick, this will still be called and still applies.
void Stat_default(unsigned long numTicks) {
ProgStats->tmu += Memory_howManyAllocPages() * numTicks;
// ONLY ONE PROCESS CAN BE IN THE 'RUNNING' QUEUE AT A TIME!
ProgStats->trp += (((int)Process_existsWithStatus(RUNNABLE))) * numTicks;
}
// This tick, a hit happened
void Stat_hit() {
ProgStats->tmr += 1;
}
// This tick, a miss happened
void Stat_miss() {
ProgStats->tpi += 1;
}
// Print the stats out directly, given an end time for the program.
void Stat_printStats(unsigned long time) {
float amu = ProgStats->tmu / (float)time;
float arp = ProgStats->trp / (float)time;
//printf("(tmu=%lu)\n", ProgStats->tmu);
printf("\x1B[1m\x1B[7m%s\x1B[0m\n"," PERFORMANCE ");
printf(" \x1B[91mAMU: \x1B[0m %f\n", amu/Memory_getTotalSize());
printf(" \x1B[33mARP: \x1B[0m %f\n", arp);
printf(" \x1B[92mTMR: \x1B[0m %lu\n", ProgStats->tmr);
printf(" \x1B[96mTPI: \x1B[0m %lu\n", ProgStats->tpi);
printf(" \x1B[95mRTime:\x1B[0m %lu\n", time);
}
unsigned long Stat_tmr_so_far() {
return ProgStats->tmr;
}