Granville Barnett

Creating a quick scheduling simulation using CPUSS

Just a quick note, and most is self explanatory (download CPUSS here).  I'll talk about the code after.

using System;

using System.Collections.Generic;

using Cpuss;

using Cpuss.Strategies;

namespace ConsoleApplication1

{

    class Program

    {

        static void Main()

        {

            Runner runner = new Runner(20, 10, 65, new Sjf());

            runner.Completed += (o, e) => Console.WriteLine("Simulation Time: {0}ns Total No. Processes: {1}\n\n", e.TotalTime, e.ProcessCount);

            runner.Run();

            Console.WriteLine("Process Metrics:\n\n");

            foreach (KeyValuePair<int, Process> process in runner.Metrics)

            {

                Process p = process.Value;

                Console.WriteLine("PID: {0} Arrival Time: {1} Start Time: {2} Completion Time: {3}",

                    p.Id, p.ArrivalTime, p.StartTime, p.CompletionTime);

            }

        }

    }

}

First of all in this case I am creating a simulation using 20 small , 10 medium, 65 large processes (I explained the bounds of the burst time values in this post).  The Completed event is pretty self explanatory, this is raised when the simulation has finished executing, i.e. there are no more processes in the ready queue to execute.  To start the simulation you need only call the Run method on the Runner instance.

Following the simulation I print out a few of the property values of the metrics gathered throughout the course of the simulation:

  • Id (synonymous with PID)
  • Arrival Time
  • Start Time
  • Completion Time

I could of included Burst Time as well, but for this demo to make the screen shot look more civilised and less busy (and I understand the console is not the best UI choice to present such data which will be resolved in later releases).

That's it.

CWindowssystem32cmd.exe

Download CPUSS.

Comments

No Comments