예제 #1
0
        private void MainLoop()
        {
            const float DesiredFrameRate = 60F;
            const float ExpectedDelta    = 1F / DesiredFrameRate;

            var rateCounter = new RateCounter(DesiredFrameRate);
            var loopWatch   = new Stopwatch();

            var stopwatchInvalid = true;

            while (true)
            {
                if (IsPaused)
                {
                    // Application is paused, we should wait
                    stopwatchInvalid = true;
                    Thread.Sleep(250);
                    continue;
                }

                // == Process Phase

                if (SurfaceView.CanRender)
                {
                    var ctx = SurfaceView.RenderContext;

                    // Get time since last frame
                    var delta = stopwatchInvalid ? ExpectedDelta : loopWatch.ElapsedTicks / (float)Stopwatch.Frequency;
                    stopwatchInvalid = false;

                    // (Re)Start measuring time
                    loopWatch.Restart();

                    ctx.ResetState();
                    Update(ctx, delta);

                    FrameRate = rateCounter.Rate;

                    if (ShowFPSOverlay)
                    {
                        ctx.ResetState();

                        var surfaceWidth = ctx.Surface.Width;

                        var text = $"FPS: {FrameRate.ToString("0.00")}";
                        var size = Font.Default.MeasureText(text, 16);

                        ctx.Color = Color.DarkGray;
                        ctx.DrawRect(new Rectangle(surfaceWidth - 16 - size.Width - 3, 16, size.Width + 4, size.Height + 1));

                        ctx.Color = Color.Pink;
                        ctx.DrawText(text, new Vector(surfaceWidth - 16, 16), Font.Default, 16, TextAlign.Right);
                    }

                    //
                    ctx.RefreshScreen();
                    rateCounter.Tick();
                }
            }
        }
        internal RouterMetrics(Router router)
        {
            var routeTables = router.Length;

            statusCodesCounters       = new StatusCodeCounter[routeTables][];
            hourlyStatusCodesCounters = new HourlyStatusCodeCounter[routeTables][];
            handlerTimes          = new HandlerTime[routeTables][];
            responseRateCounters  = new RateCounter[routeTables][];
            totalRequestBytesIn   = new long[routeTables][];
            totalResponseBytesOut = new long[routeTables][];

            for (int i = 0; i < routeTables; i++)
            {
                var endpoints = router[i].Length;
                statusCodesCounters[i]       = new StatusCodeCounter[endpoints];
                hourlyStatusCodesCounters[i] = new HourlyStatusCodeCounter[endpoints];
                handlerTimes[i]         = new HandlerTime[endpoints];
                responseRateCounters[i] = new RateCounter[endpoints];

                totalRequestBytesIn[i]   = new long[endpoints];
                totalResponseBytesOut[i] = new long[endpoints];

                for (int j = 0; j < endpoints; j++)
                {
                    statusCodesCounters[i][j]       = new StatusCodeCounter();
                    hourlyStatusCodesCounters[i][j] = new HourlyStatusCodeCounter(7 * 24);
                    handlerTimes[i][j]         = new HandlerTime(1024);
                    responseRateCounters[i][j] = new RateCounter(100);

                    totalRequestBytesIn[i][j]   = 0;
                    totalResponseBytesOut[i][j] = 0;
                }
            }
        }
        public RateCounterView()
        {
            // InitializeComponent();
            RateCounter SampleLayout = new RateCounter();

            SampleLayout.width = 258;
            SampleLayout.hight = 60;
            StackLayout Sample = SampleLayout.testpage(50, Color.Green);//this is the default image which has been provided as default image.

            SampleLayout.width = 155;
            SampleLayout.hight = 59;
            StackLayout Sample1 = SampleLayout.testpage(12, Color.Blue, "three_ratingTransparent.png");//this is the image which has been used under Resouces folder in Android project.
            var         layout  = new StackLayout();

            layout.Children.Add(Sample);
            layout.Children.Add(Sample1);
            Content = layout;
        }