Exemplo n.º 1
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            SystemNavigationManager.GetForCurrentView().BackRequested += App_BackRequested;
            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
                AppViewBackButtonVisibility.Visible;

            progressSimulation.IsActive = true;
            txtPercentDone.Visibility   = Visibility.Visible;
            imageIcon.Visibility        = Visibility.Visible;
            stackReport.Visibility      = Visibility.Collapsed;
            dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;

            Tuple <Cache, StorageFile, int> tuple = (Tuple <Cache, StorageFile, int>)e.Parameter;

            cache = tuple.Item1;
            StorageFile logFile   = tuple.Item2;
            int         numLayers = tuple.Item3;

            StreamReader reader = null;
            Stream       stream = null;

            try
            {
                fileSize     = (await logFile.GetBasicPropertiesAsync()).Size;
                fileSizeRead = 0;
                stream       = await logFile.OpenStreamForReadAsync();

                reader = new StreamReader(stream, new ASCIIEncoding());
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            LogParser     parser   = new LogParser(reader, false);
            int           numToAvg = 2000;
            List <Logger> logger   = new List <Logger>();

            for (int i = 0; i < numLayers; i++)
            {
                logger.Add(new Logger(numToAvg));
            }

            if (reader != null && stream != null && stream.CanRead)
            {
                for (int i = 0; !parser.CloseIfDone(); i++)
                {
                    MemInst inst = parser.GetNextInst();
                    if (inst != null)
                    {
                        fileSizeRead += (ulong)inst.lineSize;
                        float temp = fileSizeRead * 100.0f / fileSize;
                        if (temp > percentage + 8f)
                        {
                            percentage = temp;
                            await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                txtPercentDone.Text = percentage.ToString("0") + "%";
                            });
                        }

                        if (inst.type == InstType.LOAD)
                        {
                            int where = cache.check(inst.addr, 1);

                            // If there wasn't a hit in any layer, log all the misses
                            if (where == 0)
                            {
                                for (int j = 0; j < numLayers; j++)
                                {
                                    logger[j].add(false);
                                }
                            }
                            // Otherwise, mark hits and misses accordingly
                            else
                            {
                                for (int j = 0; j < where; j++)
                                {
                                    logger[j].add(where - 1 == j);
                                }
                            }
                        }
                    }
                }

                reader.Dispose();
                stream.Dispose();

                List <List <float> > hist = new List <List <float> >();
                for (int i = 0; i < numLayers; i++)
                {
                    hist.Add(logger[i].getHistory());
                }

                int pc = numToAvg;
                averageHitRate1 = 0f;
                averageHitRate2 = 0f;
                averageHitRate3 = 0f;

                foreach (var item in hist[0])
                {
                    HitRateItem dataPoint = new HitRateItem();
                    dataPoint.Rate = item;
                    dataPoint.PC   = pc;
                    plotList1.Add(dataPoint);
                    averageHitRate1 += item;

                    pc += numToAvg;
                }

                averageHitRate1        /= hist[0].Count;
                txtAverageHitRate1.Text = averageHitRate1.ToString();

                if (hist.Count > 1)
                {
                    pc = numToAvg;
                    foreach (var item in hist[1])
                    {
                        HitRateItem dataPoint = new HitRateItem();
                        dataPoint.Rate = item;
                        dataPoint.PC   = pc;
                        plotList2.Add(dataPoint);
                        averageHitRate2 += item;

                        pc += numToAvg;
                    }
                    averageHitRate2        /= hist[1].Count;
                    txtAverageHitRate2.Text = averageHitRate2.ToString();
                }
                else
                {
                    panelL2.Visibility        = Visibility.Collapsed;
                    chartL2HitRate.Visibility = Visibility.Collapsed;
                }

                if (hist.Count > 2)
                {
                    pc = numToAvg;
                    foreach (var item in hist[2])
                    {
                        HitRateItem dataPoint = new HitRateItem();
                        dataPoint.Rate = item;
                        dataPoint.PC   = pc;
                        plotList3.Add(dataPoint);
                        averageHitRate3 += item;

                        pc += numToAvg;
                    }
                    averageHitRate3        /= hist[2].Count;
                    txtAverageHitRate3.Text = averageHitRate3.ToString();
                }
                else
                {
                    panelL3.Visibility        = Visibility.Collapsed;
                    chartL3HitRate.Visibility = Visibility.Collapsed;
                }


                txtLogFileName.Text = logFile.Name;

                progressSimulation.IsActive         = false;
                txtPercentDone.Visibility           = Visibility.Collapsed;
                imageIcon.Visibility                = Visibility.Collapsed;
                chartL1HitRate.PrimaryAxis.Header   = "Number of Requests";
                chartL1HitRate.SecondaryAxis.Header = "Hit Rate";
                chartL2HitRate.PrimaryAxis.Header   = "Number of Requests";
                chartL2HitRate.SecondaryAxis.Header = "Hit Rate";
                chartL3HitRate.PrimaryAxis.Header   = "Number of Requests";
                chartL3HitRate.SecondaryAxis.Header = "Hit Rate";
                stackReport.Visibility              = Visibility.Visible;
            }
        }