Subversion Repositories programming

Rev

Rev 415 | Rev 417 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 415 Rev 416
Line 125... Line 125...
125
 
125
 
126
        log.add (new LogEntry (cur_proc, cur_time, LogEntry.MsgType.START));
126
        log.add (new LogEntry (cur_proc, cur_time, LogEntry.MsgType.START));
127
    }
127
    }
128
 
128
 
129
    /**
129
    /**
130
     * Run the current process. Also increment the current time.
130
     * Run the current process, increment the current time, and update the wait
-
 
131
     * times for all of the processes that are waiting.
131
     */
132
     */
132
    protected void scheduleCurrent ()
133
    protected void scheduleCurrent ()
133
    {
134
    {
-
 
135
        /* Update the wait times for all waiting processes */
-
 
136
        for (Process p : run_queue)
-
 
137
            p.time_wait++;
-
 
138
 
-
 
139
        /* Run the current process for one tick */
134
        cur_proc.time_left--;
140
        cur_proc.time_left--;
-
 
141
 
-
 
142
        /* Update the time */
135
        cur_time++;
143
        cur_time++;
136
    }
144
    }
137
 
145
 
138
    /**
146
    /**
139
     * Print a Gantt Chart detailing the results of this scheduler's run.
147
     * Print a Gantt Chart detailing the results of this scheduler's run.
Line 196... Line 204...
196
            System.out.println ();
204
            System.out.println ();
197
        }
205
        }
198
    }
206
    }
199
 
207
 
200
    /**
208
    /**
-
 
209
     * Find the average wait time of processes.
-
 
210
     */
-
 
211
    protected void printWaitTimes ()
-
 
212
    {
-
 
213
        int numprocs = 0;
-
 
214
        int totalwait = 0;
-
 
215
 
-
 
216
        for (LogEntry e : log)
-
 
217
        {
-
 
218
            if (e.msg == LogEntry.MsgType.COMPLETE)
-
 
219
            {
-
 
220
                numprocs++;
-
 
221
                totalwait += e.proc.time_wait;
-
 
222
            }
-
 
223
        }
-
 
224
 
-
 
225
        System.out.printf ("Average wait time: %d wait time / %d procs = %.2f\n",
-
 
226
                totalwait, numprocs, (float)totalwait / (float)numprocs);
-
 
227
    }
-
 
228
 
-
 
229
    /**
201
     * Run the simulation of the scheduler. Note that this only works once,
230
     * Run the simulation of the scheduler. Note that this only works once,
202
     * if you try to run it twice, it is unlikely that it will work.
231
     * if you try to run it twice, it is unlikely that it will work.
203
     */
232
     */
204
    public void run ()
233
    public void run ()
205
    {
234
    {
Line 213... Line 242...
213
 
242
 
214
        /* Gantt Chart */
243
        /* Gantt Chart */
215
        printGanttChart ();
244
        printGanttChart ();
216
 
245
 
217
        /* Print time taken */
246
        /* Print time taken */
-
 
247
        printWaitTimes ();
218
        System.out.println ("\nSimulation took " + cur_time + " time units to complete!");
248
        System.out.println ("Simulation took " + cur_time + " time units to complete!");
219
    }
249
    }
220
}
250
}
221
 
251
 
222
/* vim: set ts=4 sts=4 sw=4 expandtab: */
252
/* vim: set ts=4 sts=4 sw=4 expandtab: */
223
 
253