@@ -342,7 +342,7 @@ function showGanttChart(output, outputDiv) {
342
342
output . schedule . forEach ( ( element ) => {
343
343
if ( element [ 0 ] == - 2 ) { //context switch
344
344
ganttChartData . push ( [
345
- "Row " ,
345
+ "Time " ,
346
346
"CS" ,
347
347
"grey" ,
348
348
startGantt * 1000 ,
@@ -351,16 +351,16 @@ function showGanttChart(output, outputDiv) {
351
351
352
352
} else if ( element [ 0 ] == - 1 ) { //nothing
353
353
ganttChartData . push ( [
354
- "Row " ,
355
- "" ,
354
+ "Time " ,
355
+ "Empty " ,
356
356
"black" ,
357
357
startGantt * 1000 ,
358
358
( startGantt + element [ 1 ] ) * 1000
359
359
] ) ;
360
360
361
361
} else { //process
362
362
ganttChartData . push ( [
363
- "Row " ,
363
+ "Time " ,
364
364
"P" + element [ 0 ] ,
365
365
"" ,
366
366
startGantt * 1000 ,
@@ -369,7 +369,6 @@ function showGanttChart(output, outputDiv) {
369
369
}
370
370
startGantt += element [ 1 ] ;
371
371
} ) ;
372
- ganttChartData . sort ( ( a , b ) => parseInt ( a [ 1 ] . substring ( 1 , a [ 1 ] . length ) ) - parseInt ( b [ 1 ] . substring ( 1 , b [ 1 ] . length ) ) ) ;
373
372
let ganttChart = document . createElement ( "div" ) ;
374
373
ganttChart . id = "gantt-chart" ;
375
374
@@ -788,6 +787,8 @@ function CPUScheduler(input, utility, output) {
788
787
moveElement ( element , currentTimeLog . remain , currentTimeLog . ready ) ;
789
788
moveElement ( element , currentTimeLog . block , currentTimeLog . ready ) ;
790
789
} ) ;
790
+ output . timeLog . push ( JSON . parse ( JSON . stringify ( currentTimeLog ) ) ) ;
791
+ currentTimeLog . move = [ ] ;
791
792
}
792
793
let currentTimeLog = new TimeLog ( ) ;
793
794
currentTimeLog . remain = input . processId ;
@@ -798,10 +799,6 @@ function CPUScheduler(input, utility, output) {
798
799
let timeQuantum = Number ( document . querySelector ( "#tq" ) . value ) ;
799
800
while ( utility . done . some ( ( element ) => element == false ) ) {
800
801
updateReadyQueue ( currentTimeLog ) ;
801
- if ( currentTimeLog . ready . length > 0 ) {
802
- output . timeLog . push ( JSON . parse ( JSON . stringify ( currentTimeLog ) ) ) ;
803
- currentTimeLog . move = [ ] ;
804
- }
805
802
let found = - 1 ;
806
803
if ( currentTimeLog . running . length == 1 ) {
807
804
found = currentTimeLog . running [ 0 ] ;
@@ -866,16 +863,18 @@ function CPUScheduler(input, utility, output) {
866
863
moveElement ( found , currentTimeLog . running , currentTimeLog . block ) ;
867
864
currentTimeLog . move . push ( 4 ) ;
868
865
}
866
+ output . timeLog . push ( JSON . parse ( JSON . stringify ( currentTimeLog ) ) ) ;
867
+ currentTimeLog . move = [ ] ;
869
868
updateReadyQueue ( currentTimeLog ) ;
870
869
} else {
871
870
updateReadyQueue ( currentTimeLog ) ;
872
871
moveElement ( found , currentTimeLog . running , currentTimeLog . ready ) ;
873
872
currentTimeLog . move . push ( 3 ) ;
873
+ output . timeLog . push ( JSON . parse ( JSON . stringify ( currentTimeLog ) ) ) ;
874
+ currentTimeLog . move = [ ] ;
874
875
}
875
876
output . schedule . push ( [ - 2 , contextSwitch ] ) ;
876
877
for ( let i = 0 ; i < contextSwitch ; i ++ , currentTimeLog . time ++ ) {
877
- output . timeLog . push ( JSON . parse ( JSON . stringify ( currentTimeLog ) ) ) ;
878
- currentTimeLog . move = [ ] ;
879
878
updateReadyQueue ( currentTimeLog ) ;
880
879
}
881
880
}
@@ -897,11 +896,12 @@ function CPUScheduler(input, utility, output) {
897
896
moveElement ( found , currentTimeLog . running , currentTimeLog . ready ) ;
898
897
currentTimeLog . move . push ( 3 ) ;
899
898
}
899
+ output . timeLog . push ( JSON . parse ( JSON . stringify ( currentTimeLog ) ) ) ;
900
+ currentTimeLog . move = [ ] ;
900
901
if ( currentTimeLog . running . length == 0 ) //context switch
901
902
{
902
903
output . schedule . push ( [ - 2 , contextSwitch ] ) ;
903
904
for ( let i = 0 ; i < contextSwitch ; i ++ , currentTimeLog . time ++ ) {
904
- output . timeLog . push ( JSON . parse ( JSON . stringify ( currentTimeLog ) ) ) ;
905
905
updateReadyQueue ( currentTimeLog ) ;
906
906
}
907
907
}
@@ -910,7 +910,6 @@ function CPUScheduler(input, utility, output) {
910
910
output . schedule . push ( [ - 1 , 1 ] ) ;
911
911
}
912
912
output . timeLog . push ( JSON . parse ( JSON . stringify ( currentTimeLog ) ) ) ;
913
- currentTimeLog . move = [ ] ;
914
913
}
915
914
output . schedule . pop ( ) ;
916
915
}
0 commit comments