Пример #1
0
        private void btnStep_Click(object sender, EventArgs e)
        {
            cmbImplement.Enabled         = false;
            chkCountMissShifts.Enabled   = false;
            chkFastMode.Enabled          = false;
            chkExternalCacheInfo.Enabled = false;
            RaceTrackLogic logic = cmbImplement.SelectedItem as RaceTrackLogic;

            try
            {
                logic.ProcessTrace(traces.Dequeue(), ref shiftCount, ref rwCount, ref rCount, chkCountMissShifts.Checked);
                lblShiftCount.Text = "移动次数:" + shiftCount;
                lblRWCount.Text    = "读写次数:" + rwCount;
                lblRCount.Text     = "读次数:" + rCount;
            }
            catch (RaceTrackLogic.CacheReadMissException)
            {
                Log("CacheReadMiss!");
                lblCacheReadMiss.Text = "读Miss次数:" + ++readMissCount;
                lblShiftCount.Text    = "移动次数:" + shiftCount;
                lblRWCount.Text       = "读写次数:" + rwCount;
                lblRCount.Text        = "读次数:" + rCount;
            }
            catch (RaceTrackLogic.CacheCorruptException)
            {
                Log("【致命】Cache损坏!");
                timTracePlay.Stop();
                return;
            }
            if (traceCount >= TRACE_WINDOW_SIZE)
            {
                lstTrace.Items.RemoveAt(0);
                lstTrace.Items[TRACE_WINDOW_SIZE / 2 - 1].BackColor = Color.White;
                lstTrace.Items[TRACE_WINDOW_SIZE / 2].BackColor     = Color.Yellow;
            }
            else
            {
                lstTrace.Items[traceCount - TRACE_WINDOW_SIZE / 2].BackColor     = Color.White;
                lstTrace.Items[traceCount - TRACE_WINDOW_SIZE / 2 + 1].BackColor = Color.Yellow;
            }
            if (!srTraceReader.EndOfStream)
            {
                Trace t = new Trace(srTraceReader.ReadLine());
                traces.Enqueue(t);
                lstTrace.Items.Add(Trace2Row(traceCount++, t));
            }
            if (traces.Count == 0)
            {
                btnStep.Enabled = false;
                if (timTracePlay.Enabled == true)
                {
                    btnPlay_Click(null, null);
                }
            }
        }
Пример #2
0
 private void btnPlay_Click(object sender, EventArgs e)
 {
     if (chkFastMode.Checked)
     {
         if (fastPlayInProgress)
         {
             requestFastPlayEnd      = true;
             inComparisionMode       = false;
             btnPlay.Text            = "运行";
             btnStep.Enabled         = true;
             btnReset.Enabled        = true;
             btnCompareBegin.Enabled = true;
             chklstComparedImplementations.Enabled = true;
         }
         else
         {
             btnReset_Click(null, null);
             Log("模拟开始!请耐心等待或点击“暂停”来结束。");
             lstTrace.Items.Clear();
             fastPlayInProgress           = true;
             requestFastPlayEnd           = false;
             btnPlay.Text                 = "暂停";
             btnStep.Enabled              = false;
             cmbImplement.Enabled         = false;
             chkFastMode.Enabled          = false;
             chkExternalCacheInfo.Enabled = false;
             chkCountMissShifts.Enabled   = false;
             btnReset.Enabled             = false;
             RaceTrackLogic logic           = cmbImplement.SelectedItem as RaceTrackLogic;
             bool           countMissShifts = chkCountMissShifts.Checked;
             new Thread(() =>
             {
                 while (!srTraceReader.EndOfStream)
                 {
                     traces.Enqueue(new Trace(srTraceReader.ReadLine()));
                 }
                 while (traces.Count > 0)
                 {
                     if (requestFastPlayEnd)
                     {
                         this.Invoke(_FastPlayFinish, "模拟中止。请重置后再次进行。");
                         return;
                     }
                     try
                     {
                         logic.ProcessTrace(traces.Dequeue(), ref shiftCount, ref rwCount, ref rCount, countMissShifts);
                     }
                     catch (RaceTrackLogic.CacheReadMissException)
                     {
                         ++readMissCount;
                     }
                     catch (RaceTrackLogic.CacheCorruptException)
                     {
                         this.Invoke(_FastPlayFinish, "【致命】Cache损坏!");
                         return;
                     }
                 }
                 this.Invoke(_FastPlayFinish, "模拟结束,请关注状态栏结果。");
             }).Start();
         }
     }
     else
     {
         if (timTracePlay.Enabled)
         {
             timTracePlay.Stop();
             btnPlay.Text     = "运行";
             btnStep.Enabled  = true;
             btnReset.Enabled = true;
         }
         else
         {
             timTracePlay.Start();
             btnPlay.Text     = "暂停";
             btnStep.Enabled  = false;
             btnReset.Enabled = false;
         }
     }
 }