-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStats.cpp
149 lines (104 loc) · 3.05 KB
/
Stats.cpp
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <iomanip>
#include "Stats.h"
#include <math.h>
void Stats::OutputMem(vector<char> memory)
{
MemMap(memory); //print memory map
PercentHoles(memory); //print percentage of holes in memory map
return;
}
void Stats::MemMap(vector<char> memory)
{
//print memory units 1 - 64
cout<<"000 ";
for(int i=0; i<64; i++)
{
cout<<memory[i];
}
//print memory units 65 - 128
cout<<"\n064 ";
for(int i=64; i<128; i++)
{
cout<<memory[i];
}
//print memory units 129 - 192
cout<<"\n128 ";
for(int i=128; i<192; i++)
{
cout<<memory[i];
}
//print memory units 193 - 256
cout<<"\n192 ";
for(int i=192; i<256; i++)
{
cout<<memory[i];
}
cout<<'\n';
return;
}
void Stats::PercentHoles(vector<char> memory)
{
const float MEMORY_SIZE = 256.0; //size of memory in memory units
float holeCount=0.0;
float holePercent=0.0;
for(int i=0; i<MEMORY_SIZE; i++) //search through entire memory
{
if(memory[i]=='_')
{
holeCount++; //count the number of holes in memory
}
}
holePercent = (holeCount / MEMORY_SIZE) * 100; //divide number of holes by total number of memory units (256)
logHolePercent(holePercent);
cout << setprecision(4) << "Percent Holes: " << holePercent << "%" << endl;
return;
}
void Stats::logHolePercent(float percentHole)
{
_percentHoleData.push_back(percentHole); //add data for percent hole calculation
return;
}
void Stats::ProcessStates(vector<Job*> Jobs, int clockTime)
{
cout<<"Job# |Current | Running | Ready | Waiting | DataSize | Arrival | Complete"<<endl;
cout<<" | State | | | | | Time | Time "<<endl;
cout<<"=========+========+=========+=======+=========+==========+=========+========="<<endl;
//print information for each process
for(int i=0; i<Jobs.size(); i++)
{
if (Jobs[i]->getArrivalTime() <= clockTime)
{
cout << "pid" << setw(5) << Jobs[i]->getProcessId() << " |"
<< setw(7) << Jobs[i]->getCurrentState() << " |"
<< setw(8) << Jobs[i]->getRunningTime() << " |"
<< setw(6) << Jobs[i]->getReadyTime() << " |"
<< setw(8) << Jobs[i]->getWaitingTime() << " |"
<< setw(9) << Jobs[i]->getDataSize() << " |"
<< setw(8) << Jobs[i]->getArrivalTime() << " |"
<< setw(9) << Jobs[i]->getCompletionTime() << endl;
}
}
cout<<"=========+========+=========+=======+=========+==========+=========+========="<<endl;
return;
}
void Stats::getAvgHolePercent()
{
float _avgHolePercent=0;
for(int i=0; i<_percentHoleData.size(); i++)
{
_avgHolePercent+=_percentHoleData[i]; //sum all percent hole calculations
}
_avgHolePercent/=_percentHoleData.size(); //divide by total to get the average
cout << setprecision(4) << _avgHolePercent << "%" << endl;
return;
}
float Stats::getAvgWaitTime(vector<Job*> Jobs)
{
float _avgWaitTime=0;
for(int i=0; i<Jobs.size(); i++)
{
_avgWaitTime+=(float)Jobs[i]->getWaitingTime(); //sum all wait times
}
_avgWaitTime/=(float)Jobs.size(); //divide by total to get the average
return _avgWaitTime;
}