-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPRINT_HELPERS.h
More file actions
108 lines (92 loc) · 3.92 KB
/
PRINT_HELPERS.h
File metadata and controls
108 lines (92 loc) · 3.92 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifndef PRINT_HELPERS_H
#define PRINT_HELPERS_H
/********************* SOME PRINTING HELPERS *********************/
#include "process.h"
/**
* Prints to standard output the original input
* process_list is the original processes inputted (in array form)
*/
void printStart(_process process_list[])
{
printf("The original input was: %i", TOTAL_CREATED_PROCESSES);
uint32_t i = 0;
for (; i < TOTAL_CREATED_PROCESSES; ++i)
{
printf(" ( %i %i %i %i)", process_list[i].A, process_list[i].B,
process_list[i].C, process_list[i].M);
}
printf("\n");
}
/**
* Prints to standard output the final output
* finished_process_list is the terminated processes (in array form) in the order they each finished in.
*/
void printFinal(_process finished_process_list[])
{
printf("The (sorted) input is: %i", TOTAL_CREATED_PROCESSES);
uint32_t i = 0;
for (; i < TOTAL_FINISHED_PROCESSES; ++i)
{
printf(" ( %i %i %i %i)", finished_process_list[i].A, finished_process_list[i].B,
finished_process_list[i].C, finished_process_list[i].M);
}
printf("\n");
} // End of the print final function
/**
* Prints out specifics for each process.
* @param process_list The original processes inputted, in array form
*/
void printProcessSpecifics(_process process_list[])
{
uint32_t i = 0;
printf("\n");
for (; i < TOTAL_CREATED_PROCESSES; ++i)
{
printf(MAGENTA"Process %i:\n"RESET, process_list[i].processID);
printf("\t(A,B,C,M) = (%i,%i,%i,%i)\n", process_list[i].A, process_list[i].B,
process_list[i].C, process_list[i].M);
printf("\tFinishing time: %i\n", process_list[i].finishingTime);
printf("\tTurnaround time: %i\n", process_list[i].finishingTime - process_list[i].A);
printf("\tI/O time: %i\n", process_list[i].currentIOBlockedTime);
printf("\tWaiting time: %i\n", process_list[i].currentWaitingTime);
printf("\n");
}
} // End of the print process specifics function
/**
* Prints out the summary data
* process_list The original processes inputted, in array form
*/
void printSummaryData(_process process_list[])
{
uint32_t i = 0;
double total_amount_of_time_utilizing_cpu = 0.0;
double total_amount_of_time_io_blocked = 0.0;
double total_amount_of_time_spent_waiting = 0.0;
double total_turnaround_time = 0.0;
uint32_t final_finishing_time = CURRENT_CYCLE - 1;
for (; i < TOTAL_CREATED_PROCESSES; ++i)
{
total_amount_of_time_utilizing_cpu += process_list[i].currentCPUTimeRun;
total_amount_of_time_io_blocked += process_list[i].currentIOBlockedTime;
total_amount_of_time_spent_waiting += process_list[i].currentWaitingTime;
total_turnaround_time += (process_list[i].finishingTime - process_list[i].A);
}
// Calculates the CPU utilisation
double cpu_util = total_amount_of_time_utilizing_cpu / final_finishing_time;
// Calculates the IO utilisation
double io_util = (double) TOTAL_NUMBER_OF_CYCLES_SPENT_BLOCKED / final_finishing_time;
// Calculates the throughput (Number of processes over the final finishing time times 100)
double throughput = 100 * ((double) TOTAL_CREATED_PROCESSES/ final_finishing_time);
// Calculates the average turnaround time
double avg_turnaround_time = total_turnaround_time / TOTAL_CREATED_PROCESSES;
// Calculates the average waiting time
double avg_waiting_time = total_amount_of_time_spent_waiting / TOTAL_CREATED_PROCESSES;
printf(MAGENTA"Summary Data:\n"RESET);
printf("\tFinishing time: %i\n", CURRENT_CYCLE - 1);
printf("\tCPU Utilisation: %6f\n", cpu_util);
printf("\tI/O Utilisation: %6f\n", io_util);
printf("\tThroughput: %6f processes per hundred cycles\n", throughput);
printf("\tAverage turnaround time: %6f\n", avg_turnaround_time);
printf("\tAverage waiting time: %6f\n", avg_waiting_time);
} // End of the print summary data function
#endif