diff --git a/allocate.c b/allocate.c index 462e4da82a08973e5eedf0c43ceebf541dc28347..a6817a9742235ec029398b1703580bff2f0adfb2 100644 --- a/allocate.c +++ b/allocate.c @@ -174,6 +174,10 @@ int main(int argc, char *argv[]) { printf("Error in test file "); exit(1); } + // log finished processes. + + + // Log started processes. for (int j = 0; j < numCPU; j++) { headProcess = headData(CPUs[j].processQueue); @@ -184,8 +188,11 @@ int main(int argc, char *argv[]) { headProcess->startTime, headProcess->processID, headProcess->timeRemAtStartTime , j); headProcess->justStarted = 0; } + } +// + } fclose(f); } else { @@ -220,19 +227,29 @@ int main(int argc, char *argv[]) { CPUs[j].totalExecutionTimeRemaining -= deltaTime; } } - // Log process starts - for (int j = 0; j < numCPU; j++) { - headProcess = headData(CPUs[j].processQueue); - //next process in queue started - if (headProcess != NULL && headProcess->justStarted) { - // printf("current time: %d\n", currentTime); - printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d\n", - headProcess->startTime, headProcess->processID, headProcess->timeRemaining, j); - headProcess->justStarted = 0; + //logged finished processes + if (headProcess != NULL && headProcess->timeCompleted != -1) { +// printf("%d,FINISHED,pid=%s,proc_remaining=%d\n", +// headProcess->timeCompleted, headProcess->processID, numProcessesLeft); +// current = current->next; +// } + + + // Log process starts + for (int j = 0; j < numCPU; j++) { + headProcess = headData(CPUs[j].processQueue); + //next process in queue started + if (headProcess != NULL && headProcess->justStarted) { + // printf("current time: %d\n", currentTime); + printf("%d,RUNNING,pid=%s,remaining_time=%d,cpu=%d\n", + headProcess->startTime, headProcess->processID, headProcess->timeRemaining, j); + headProcess->justStarted = 0; + } +// } - } // currentTime += deltaTime; + } } // printf("Completed Queue:"); // llist_print(completedProcesses, (void (*)(void *)) &printQEntry); @@ -355,8 +372,8 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll paralizedProcess->timeRemaining = 0; headProcess->timeRemaining = 0; //printf("process had finished: Current time: %d, deltaTime: %d\n", currentTime, deltaTime); - printf("%d,FINISHED,pid=%s,proc_remaining=%d\n", - paralizedProcess->timeCompleted, paralizedProcess->processID, *numProcessesLeft); +// printf("%d,FINISHED,pid=%s,proc_remaining=%d\n", +// paralizedProcess->timeCompleted, paralizedProcess->processID, *numProcessesLeft); // Could accumulate statistics here instead of keeping list of completed processes llist_push(processesComplete, paralizedProcess); } @@ -372,8 +389,8 @@ void advanceProcessQueue(llist *processQueue, int currentTime, int deltaTime, ll } else { // finishedprocess is not parallelisable *numProcessesLeft -= 1; *numProcessComplete += 1; - printf("%d,FINISHED,pid=%s,proc_remaining=%d\n", - headProcess->timeCompleted, headProcess->processID, *numProcessesLeft); +// printf("%d,FINISHED,pid=%s,proc_remaining=%d\n", +// headProcess->timeCompleted, headProcess->processID, *numProcessesLeft); // Could accumulate statistics here instead of keeping list of completed processes llist_push(processesComplete, headProcess); llist_pop(processQueue);