Ejemplo n.º 1
0
 public GanttView(ContextSwitchManager csm, Window caller)
 {
     InitializeComponent();
     this.DrawGantt(csm);
     this.Owner = caller;
     this.Show();
 }
Ejemplo n.º 2
0
        /// <summary>
        /// A very unfortunately named function. Handles the logic for the demo.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            //FCFS Instantiation
            ProcessQueue fcfsQueue = new FCFS();
            this.PopulateDemoQueue(fcfsQueue);
            ContextSwitchManager csmFCFS = new ContextSwitchManager();
            Grid fcfsparent = this.tabfcfs;
            Thread threadfcfs = new Thread(() => RunQueue(fcfsQueue, csmFCFS));

            //SJF Instantiation
            ProcessQueue sjfQueue = new SJF();
            this.PopulateDemoQueue(sjfQueue);
            ContextSwitchManager csmSJF = new ContextSwitchManager();
            Grid sjfparent = this.tabsjf;
            Thread threadsjf = new Thread(() => RunQueue(sjfQueue, csmSJF));

            //MLFQ Instantiation
            MultiLevelQueue mlfqQueue = new MLFQ();
            ProcessQueue mlfqRR6 = new RR(6);
            this.PopulateDemoQueue(mlfqRR6);
            ProcessQueue mlfqRR11 = new RR(11);
            ProcessQueue mlfqFCFS = new FCFS();
            mlfqQueue.AddProcessQueue(mlfqRR6);
            mlfqQueue.AddProcessQueue(mlfqRR11);
            mlfqQueue.AddProcessQueue(mlfqFCFS);
            ContextSwitchManager csmMLFQ = new ContextSwitchManager();
            Grid mlfqparent = this.tabmlfq;
            Thread threadmlfq = new Thread(() => RunQueue(mlfqQueue, csmMLFQ));

            //Spawn off the threads.
            threadfcfs.Start();
            threadsjf.Start();
            threadmlfq.Start();

            //Join back up with the threads.
            threadfcfs.Join();
            threadsjf.Join();
            threadmlfq.Join();

            this.PopulateResults(fcfsQueue, csmFCFS, fcfsparent);
            this.PopulateResults(sjfQueue, csmSJF, sjfparent);
            this.PopulateResults(mlfqQueue, csmMLFQ, mlfqparent);

            this.GenerateTextFile("fcfsFall2013.txt", csmFCFS);
            this.GenerateTextFile("sjfFall2013.txt", csmSJF);
            this.GenerateTextFile("mlfqFall2013.txt", csmMLFQ);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Draw the Gantt Chart.
        /// </summary>
        /// <param name="csm"></param>
        private void DrawGantt(ContextSwitchManager csm)
        {
            double widthmult = 20.0;
            double minWidthAllowed = 5.0;
            double labelOffset = (widthmult/5);
            double totalWidth = 0.0;
            int prevTime = 0;
            int totalHeight = 0;

            //Iterate through all elements.
            for (int i = 0; i < csm.Switches.Count - 1; i++)
            //for (int i = 0; i<=14; i++)
            {
                //Determine the current time.
                int curTime = csm.Switches[i+1].Time - csm.Switches[i].Time;

                Label PrevTimeLabel = null;

                //double width = curTime * widthmult;
                double width = 50.0;
                double height = 20.0;

                if (totalWidth >= 500)
                {
                    totalWidth = 0.0;
                    totalHeight++;

                    Border previous = (Border)this.CANVAS.Children[this.CANVAS.Children.Count - 2];

                    PrevTimeLabel = new Label()
                    {
                        Margin = new Thickness { Left = previous.Margin.Left + ((TextBlock)previous.Child).Width - 15, Top = ((Label)this.CANVAS.Children[this.CANVAS.Children.Count-1]).Margin.Top },
                        Width = 30.0,
                        Content = csm.Switches[i].Time,
                        HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
                        HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center,
                        VerticalAlignment = System.Windows.VerticalAlignment.Center,
                        VerticalContentAlignment = System.Windows.VerticalAlignment.Center,
                        FontSize = 10.0
                    };

                }

                TextBlock tb = new TextBlock()
                {
                    FontFamily = new FontFamily("Arial"),
                    Foreground = this.getRGBABrush(0,0,0,255),
                    Padding = new Thickness(0.0,4.0,0,0),
                    //Width = width >= minWidthAllowed ? width : minWidthAllowed,
                    Width = width,
                    Height = height,
                    Background = csm.Switches[i].Running == null ? this.getRGBABrush(255,0,0,128) : this.getRGBABrush(0,255,0,200),
                    Text = csm.Switches[i].Running == null ? "[idle]" : csm.Switches[i].Running.Name,
                    TextAlignment = TextAlignment.Center,
                    HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
                    VerticalAlignment = System.Windows.VerticalAlignment.Center,
                    FontSize = 12.0
                };
                tb.Width = width >= minWidthAllowed ? width : minWidthAllowed;

                Border b = new Border()
                {
                    Margin = new Thickness { Left = totalWidth, Top = totalHeight * 50 },
                    BorderBrush = Brushes.Black,
                    BorderThickness = new Thickness(1.0),
                    Child = tb
                };

                Label time = new Label()
                {
                    Margin = new Thickness { Left = totalWidth-13, Top = totalHeight * 50 + tb.Height - 5 },
                    Width = 30.0,
                    Content = csm.Switches[i].Time,
                    HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
                    HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center,
                    VerticalAlignment = System.Windows.VerticalAlignment.Center,
                    VerticalContentAlignment = System.Windows.VerticalAlignment.Center,
                    FontSize = 10.0
                };

                if (PrevTimeLabel != null) this.CANVAS.Children.Add(PrevTimeLabel);
                this.CANVAS.Children.Add(b);
                this.CANVAS.Children.Add(time);

                //The last label.
                if (i == csm.Switches.Count - 2)
                {
                    Label finaltime = new Label()
                    {
                        Margin = new Thickness { Left = totalWidth + tb.Width-13, Top = totalHeight * 50 + tb.Height - 5 },
                        Width = 30.0,
                        Content = csm.Switches[i].Time+csm.Switches[i].Running.CurrentTime,
                        HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
                        HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center,
                        VerticalAlignment = System.Windows.VerticalAlignment.Center,
                        VerticalContentAlignment = System.Windows.VerticalAlignment.Center,
                        FontSize = 10.0
                    };
                    this.CANVAS.Children.Add(finaltime);
                }

                //Incrementors
                totalWidth += tb.Width;
                prevTime = curTime;
            }

            this.CANVAS.Height = this.CANVAS.ActualHeight;
            this.CANVAS.Width = this.CANVAS.ActualWidth;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Generates the Required Text Files.
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="csm"></param>
 private void GenerateTextFile(string fileName, ContextSwitchManager csm)
 {
     string fulluri = System.Environment.CurrentDirectory + "\\" + fileName;
     System.IO.File.WriteAllText(@fulluri, csm.ToString());
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Runs a queue & provides info to a contextswitchmanager.
 /// </summary>
 /// <param name="q"></param>
 /// <param name="csm"></param>
 private void RunQueue(IQueue q, ContextSwitchManager csm)
 {
     while (q.State != QueueState.COMPLETE)
     {
         q.Run();
         if (q.ContextSwitch || q.State == QueueState.COMPLETE) csm.Switches.Add(new ContextSwitchRecord(q));
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Populates the results of a TabItem
        /// </summary>
        /// <param name="queue"></param>
        /// <param name="csm"></param>
        /// <param name="g"></param>
        private void PopulateResults(IQueue queue, ContextSwitchManager csm, Grid g)
        {
            //Determine the grid view.
            DataGrid dg = (DataGrid)g.Children[0];

            //Determine the CPU Util View
            Label cpuutil = (Label)g.Children[1];

            //Determine the GanttView button.
            Button ganttView = (Button)g.Children[2];

            #region Display Logic

            //Datatable to display results.
            DataTable dt = new DataTable();
            dt.Columns.Add("Process");
            dt.Columns.Add("WT");
            dt.Columns.Add("TT");
            dt.Columns.Add("RT");

            queue.CompleteProcs.Sort((x, y) => x.Name.CompareTo(y.Name));

            foreach (Process p in queue.CompleteProcs)
            {
                dt.Rows.Add(p.Name, p.WaitingTime, p.TurnaroundTime, p.ResponseTime);
            }

            double avgWaitingTime = 0;
            double avgTurnaroundTime = 0;
            double avgResponseTime = 0;

            foreach (Process p in queue.CompleteProcs)
            {
                avgWaitingTime += p.WaitingTime;
                avgTurnaroundTime += p.TurnaroundTime;
                avgResponseTime += p.ResponseTime;
            }

            avgWaitingTime /= queue.CompleteProcs.Count;
            avgTurnaroundTime /= queue.CompleteProcs.Count;
            avgResponseTime /= queue.CompleteProcs.Count;

            dt.Rows.Add("Avg", avgWaitingTime, avgTurnaroundTime, avgResponseTime);

            dg.ItemsSource = dt.DefaultView;
            dg.HorizontalGridLinesBrush = dg.VerticalGridLinesBrush = new SolidColorBrush(Colors.LightGray);

            cpuutil.Content = "CPU Utilization: " + Decimal.Round((queue.CPUUtil * 100), 2) + "%";

            ganttView.IsEnabled = true;
            ganttView.Click += delegate { GetGanttView(csm); };
            #endregion
        }
Ejemplo n.º 7
0
 private void GetGanttView(ContextSwitchManager csm)
 {
     GanttView gv = new GanttView(csm, this);
 }