-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauxFx.cpp
165 lines (146 loc) · 5.04 KB
/
auxFx.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* File Name : auxFx.cpp
* Primary Author : Francesco Polizzi
* Contributing Author(s) :
* Date Created : 26 April 2016
* Date Last Modified : 11 May 2016
*
* Description : This is the file for our OS Simulation driver where all
* auxiliary functions are called
*
*/
// libraries to include
#include <iostream>
#include <fstream>
#include <iomanip>
#include "simulation_header.h"
using namespace std;
/* AVG_LTQ
* Author: Francesco Polizzi
* Other contributors:
* Last revised: May 3, 2015
* Description: Calculating the the LTQ avg wait time
*/
double avg_ltq(int total_jobs, double ltq_wait) {
// calculate average
double average = ltq_wait/total_jobs;
// return average
return average;
}
/* AVG_STQ
* Author: Francesco Polizzi
* Other contributors:
* Last revised: May 3, 2015
* Description: Calculating the the STQ avg wait time
*/
double avg_stq(int total_jobs, double stq_wait){
// calculate average
double average = stq_wait/total_jobs;
// return average
return average;
}
/* AVG_IOQ
* Author: Francesco Polizzi
* Other contributors:
* Last revised: May 3, 2015
* Description: Calculating the the IOQ avg wait time
*/
double avg_ioq(int total_jobs, double ioq_wait){
// calculate average
double average = ioq_wait/total_jobs;
// return average
return average;
}
/* AVG_RESPONSE_TIME
* Author: Francesco Polizzi
* Other contributors:
* Last revised: May 3, 2015
* Description: Calculating the average response time on all jobs
*/
double avg_response_time(int total_jobs, double response_time){
// calculate average
double average = response_time/total_jobs;
// return average
return average;
}
/* AVG_TURNAROUND_TIME
* Author: Francesco Polizzi
* Other contributors:
* Last revised: May 3, 2015
* Description: Calculating the average turnaround time on all jobs
*/
double avg_turnaround_time(int total_jobs, double turnaround_time){
// calculate average
double average = turnaround_time/total_jobs;
// return average
return average;
}
/* CPU_UTILIZATION
* Author: Francesco Polizzi
* Other contributors:
* Last revised: May 3, 2015
* Description: Calculating the CPU Utilization for jobs
*/
double cpu_utilization(int productive_time, double total_time){
// calculate CPU utilization
double cpuUtilization = productive_time/total_time;
// return CPU utilization
return cpuUtilization;
}
/* PRINT_OUTPUT
* Author: Francesco Polizzi
* Other contributors:
* Last revised: May 3, 2015
* Description: Printing our information output to the user
*/
void print_output(string algorithmUsed, int timeToComplete, int contextSwitchTime,
double cpuUtilization, int avgResponse, int avgTurnaround, double systemThroughput,
double avgLTQ, double avgSTQ, double avgIOQ, ofstream& Outfile){
// print our output
Outfile << fixed << setprecision(2);
Outfile << "Developed using \"" << algorithmUsed << "\" algorithm." << endl << endl;
Outfile << "Total Simulation Time :" << setw(8) << timeToComplete << endl;
Outfile << "Total Context Switch Time :" << setw(8) << contextSwitchTime << endl;
Outfile << "CPU Utilization Rate :" << setw(8) << cpuUtilization << "%" << endl;
Outfile << "Average Response Time :" << setw(8) << avgResponse << endl;
Outfile << "Average Turnaround Time :" << setw(8) << avgTurnaround << endl;
Outfile << fixed << setprecision(4);
Outfile << "System Throughput :" << setw(8) << systemThroughput << endl;
Outfile << fixed << setprecision(2);
Outfile << "Average LTQ Wait Time :" << setw(8) << avgLTQ << endl;
Outfile << "Average STQ Wait Time :" << setw(8) << avgSTQ << endl;
Outfile << "Average IOQ Wait Time :" << setw(8) << avgIOQ << endl;
}
/* PRINT_HEADER
* Author: Francesco Polizzi
* Other contributors:
* Last revised: May 3, 2015
* Description: Printing our header to the user
*/
void print_header(ofstream& Outfile){
// print our output header
Outfile << setw(22) << "Francesco Polizzi, ";
Outfile << "Katie Schaffer, ";
Outfile << "Jeremy Viner, ";
Outfile << "& Hein Htet Zaw" << endl;
Outfile << setw(30) << "CSC 40600";
Outfile << setw(17) << "Section 11" << endl;
Outfile << setw(30) << "Spring 2016";
Outfile << setw(20) << "Assignment #2" << endl;
Outfile << setw(35) << "-----------------------------------";
Outfile << setw(35) << "-----------------------------------\n\n";
}
/* PRINT_HEADER
* Author: Francesco Polizzi
* Other contributors:
* Last revised: May 3, 2015
* Description: Printing our footer to the user
*/
void print_footer(ofstream& Outfile){
// print our output footer
Outfile << endl;
Outfile << setw(35) << " --------------------------------- " << endl;
Outfile << setw(35) << "| END OF PROGRAM OUTPUT |" << endl;
Outfile << setw(35) << " --------------------------------- " << endl;
Outfile << "" << endl;
}