//public string InformationAboutFrame()
            //{
            //    float layoutMeasureDurationMs = ToMs(LayoutMeasureDuration);
            //    float drawDurationMs = ToMs(DrawDuration);
            //    float gpuCommandMs = ToMs(CommandIssueDuration);
            //    var totalDurationMs = ToMs(TotalDuration);
            //    var allFrames = FrameNumber;
            //    var jankyFrames = JunkyFrameNumber;

            //    float othersMs = totalDurationMs - layoutMeasureDurationMs - drawDurationMs - gpuCommandMs;
            //    float jankyPercent = (float)jankyFrames / allFrames * 100;

            //    var msg = $"Janky frame detected on Activity with total duration: {totalDurationMs}\n";
            //    msg += $"Layout/measure: {layoutMeasureDurationMs}ms, draw:{drawDurationMs}ms, gpuCommand:{gpuCommandMs}ms others:{othersMs}ms\n";
            //    msg += "Janky frames: " + jankyFrames + "/" + allFrames + "(" + jankyPercent + "%)";
            //    return msg;

            //    //Log.Warn("FrameMetricsDataData", msg);
            //}

            public void Calculate()
            {
                if (!this.Frames.Any())
                {
                    return;
                }

                _report.Add(JUNKY_FRAMES_TOTAL, this.Frames.Length.ToString());


                var jfp = this.Frames.Select(x => ((float)x.JunkyFrameNumber / x.FrameNumber * 100)).Sum() / this.Frames.Length;

                _report.Add(JUNKY_FRAMES_PERCENTAGE_AVG, jfp.ToString("F2"));


                _report.Add(RENDER_JUNKY_FRAMES_MIN, FrameMetricsData.ToMs(this.Frames.Min(x => x.TotalDuration)).ToString("F2"));
                _report.Add(RENDER_JUNKY_FRAMES_MAX, FrameMetricsData.ToMs(this.Frames.Max(x => x.TotalDuration)).ToString("F2"));
                _report.Add(RENDER_JUNKY_FRAMES_AVG, FrameMetricsData.ToMs(this.Frames.Sum(x => x.TotalDuration) / this.Frames.Length).ToString("F2"));


                _report.Add(LAYOUT_FRAMES_MIN, FrameMetricsData.ToMs(this.Frames.Min(x => x.LayoutMeasureDuration)).ToString("F2"));
                _report.Add(LAYOUT_FRAMES_MAX, FrameMetricsData.ToMs(this.Frames.Max(x => x.LayoutMeasureDuration)).ToString("F2"));
                _report.Add(LAYOUT_FRAMES_AVG, FrameMetricsData.ToMs(this.Frames.Sum(x => x.LayoutMeasureDuration) / this.Frames.Length).ToString("F2"));

                _report.Add(DRAW_FRAMES_MIN, FrameMetricsData.ToMs(this.Frames.Min(x => x.DrawDuration)).ToString("F2"));
                _report.Add(DRAW_FRAMES_MAX, FrameMetricsData.ToMs(this.Frames.Max(x => x.DrawDuration)).ToString("F2"));
                _report.Add(DRAW_FRAMES_AVG, FrameMetricsData.ToMs(this.Frames.Sum(x => x.DrawDuration) / this.Frames.Length).ToString("F2"));

                _report.Add(GPU_FRAMES_MIN, FrameMetricsData.ToMs(this.Frames.Min(x => x.CommandIssueDuration)).ToString("F2"));
                _report.Add(GPU_FRAMES_MAX, FrameMetricsData.ToMs(this.Frames.Max(x => x.CommandIssueDuration)).ToString("F2"));
                _report.Add(GPU_FRAMES_AVG, FrameMetricsData.ToMs(this.Frames.Sum(x => x.CommandIssueDuration) / this.Frames.Length).ToString("F2"));
            }
Exemple #2
0
 internal void PushNewFrame(FrameMetricsData frameData)
 {
     this._storage.Add(frameData);
     Log.Warn("FrameMetricsDataData", frameData.InformationAboutFrame());
 }
Exemple #3
0
            //private readonly int TotalDuration = (int)FrameMetricsId.TotalDuration;
            //public OnFrameMetricsAvailableListener(string activityName)
            //{
            //    _activityName = activityName;
            //}
            //public void Dispose()
            //{
            //}
            //public IntPtr Handle { get; }
            public void OnFrameMetricsAvailable(Window window, FrameMetrics frameMetrics, int dropCountSinceLastInvocation)
            {
                //if (Looper.MainLooper == Looper.MyLooper())
                //{
                //    Log.Error("THIS IS UI THREAD", "UI THREAD");
                //}

                var frameMetricsCopy = new FrameMetrics(frameMetrics);
                //frameMetrics.GetMetric((int)FrameMetricsId.AnimationDuration);

                allFrames++;
                var totalDuration = frameMetricsCopy.GetMetric((int)FrameMetricsId.TotalDuration);
                var totalDurationMs = (float)(0.000001 * totalDuration);
                if (totalDurationMs > warningLevelMs)
                {
                    jankyFrames++;
                    //var msg = $"Janky frame detected on {_activityName} with total duration: {totalDurationMs}\n";

                    var d = new FrameMetricsData()
                    {
                        Offset = PTrackerTimeProvider.Source.Elapsed,
                        FrameNumber = allFrames,
                        TotalDuration = totalDuration,
                        LayoutMeasureDuration = frameMetricsCopy.GetMetric((int)FrameMetricsId.LayoutMeasureDuration),
                        DrawDuration = frameMetricsCopy.GetMetric((int)FrameMetricsId.DrawDuration),
                        CommandIssueDuration = frameMetricsCopy.GetMetric((int)FrameMetricsId.CommandIssueDuration),
                        JunkyFrameNumber = jankyFrames
                        //AnimationDuration = frameMetricsCopy.GetMetric((int)FrameMetricsId.AnimationDuration),
                        //FirstDrawFrame = frameMetricsCopy.GetMetric((int)FrameMetricsId.FirstDrawFrame),
                        //InputHandlingDuration = frameMetricsCopy.GetMetric((int)FrameMetricsId.InputHandlingDuration),
                        //IntendedVsyncTimestamp = frameMetricsCopy.GetMetric((int)FrameMetricsId.IntendedVsyncTimestamp),
                        //SwapBuffersDuration = frameMetricsCopy.GetMetric((int)FrameMetricsId.SwapBuffersDuration),
                        //SyncDuration = frameMetricsCopy.GetMetric((int)FrameMetricsId.SyncDuration),
                        //UnknownDelayDuration = frameMetricsCopy.GetMetric((int)FrameMetricsId.UnknownDelayDuration),
                        //VsyncTimestamp = frameMetricsCopy.GetMetric((int)FrameMetricsId.VsyncTimestamp),
                    };

                    _renderingMetricsRecorder.PushNewFrame(d);

                    //float layoutMeasureDurationMs = (float)(0.000001 * frameMetricsCopy.GetMetric((int)FrameMetricsId.LayoutMeasureDuration));
                    //float drawDurationMs = (float)(0.000001 * frameMetricsCopy.GetMetric((int)FrameMetricsId.DrawDuration));
                    //float gpuCommandMs = (float)(0.000001 * frameMetricsCopy.GetMetric((int)FrameMetricsId.CommandIssueDuration));
                    //float othersMs = totalDurationMs - layoutMeasureDurationMs - drawDurationMs - gpuCommandMs;
                    //float jankyPercent = (float)jankyFrames / allFrames * 100;
                    //msg += $"Layout/measure: {layoutMeasureDurationMs}ms, draw:{drawDurationMs}ms, gpuCommand:{gpuCommandMs}ms others:{othersMs}ms\n";
                    //msg += "Janky frames: " + jankyFrames + "/" + allFrames + "(" + jankyPercent + "%)";
                    //if (showWarning && totalDurationMs > errorLevelMs)
                    //{
                    //    Log.Error("FrameMetricsDataData", msg);
                    //}
                    //else if (showError)
                    //{
                    //    Log.Warn("FrameMetricsDataData", msg);
                    //}

                    //var d = new FrameMetricsData()
                    //{
                    //    FrameNumber = allFrames,
                    //    LayoutMeasureDuration = layoutMeasureDurationMs,
                    //    DrawDuration = drawDurationMs,
                    //    CommandIssueDuration = gpuCommandMs,

                    //};
                }
            }