public static AdaptivePerformanceProfilerStats.ScalerInfo[] GetScalerFromProfilerStream(int frame)
 {
     using (var frameData = UnityEditorInternal.ProfilerDriver.GetRawFrameDataView(frame, 0))
     {
         var returnVal = new AdaptivePerformanceProfilerStats.ScalerInfo[] {};
         if (frameData != null)
         {
             var clientInfos =
                 frameData.GetFrameMetaData <AdaptivePerformanceProfilerStats.ScalerInfo>(AdaptivePerformanceProfilerStats.kAdaptivePerformanceProfilerModuleGuid, AdaptivePerformanceProfilerStats.kScalerDataTag);
             if (clientInfos.Length != 0)
             {
                 returnVal = clientInfos.ToArray();
             }
         }
         return(returnVal);
     }
 }
    void ReloadData(long selectedFrameIndex)
    {
        var selectedFrameIndexInt32 = Convert.ToInt32(selectedFrameIndex);

        using (var frameData = UnityEditorInternal.ProfilerDriver.GetRawFrameDataView(selectedFrameIndexInt32, 0))
        {
            if (frameData == null || !frameData.valid)
            {
                m_DetailsViewLabel.text = "No Adaptive Performance Frame Data.";
                return;
            }

            var thermalWarningLevel = (WarningLevel)ExtractAdaptivePerformanceCounterValueInt(frameData, "Thermal Warning Level");
            var bottleneck          = (PerformanceBottleneck)ExtractAdaptivePerformanceCounterValueInt(frameData, "Bottleneck");
            m_DetailsViewLabel.text = $"CPU frametime: {ExtractAdaptivePerformanceCounterValueFloat(frameData, "CPU frametime")} \t\t" +
                                      $"Average CPU frametime: {ExtractAdaptivePerformanceCounterValueFloat(frameData, "CPU avg frametime")} \n" +
                                      $"GPU frametime: {ExtractAdaptivePerformanceCounterValueFloat(frameData, "GPU frametime")} \t\t" +
                                      $"Average GPU frametime: {ExtractAdaptivePerformanceCounterValueFloat(frameData, "GPU avg frametime")} \n" +
                                      $"Frametime: {ExtractAdaptivePerformanceCounterValueFloat(frameData, "Frametime")} \t\t\t" +
                                      $"Average frametime: {ExtractAdaptivePerformanceCounterValueFloat(frameData, "Avg frametime")} \n" +
                                      $"\n" +
                                      $"CPU performance level: {ExtractAdaptivePerformanceCounterValueInt(frameData, "CPU performance level")} \n" +
                                      $"GPU performance level: {ExtractAdaptivePerformanceCounterValueInt(frameData, "GPU performance level")} \n" +
                                      $"\n" +
                                      $"Temperature Level: {ExtractAdaptivePerformanceCounterValueFloat(frameData, "Temperature Level")} \n" +
                                      $"Temperature Trend: {ExtractAdaptivePerformanceCounterValueFloat(frameData, "Temperature Trend")} \n" +
                                      $"\n" +
                                      $"Thermal Warning Level: {thermalWarningLevel} \n" +
                                      $"Bottleneck: {bottleneck} \n";

            if (m_BottleneckLabel != null)
            {
                if (bottleneck == PerformanceBottleneck.CPU)
                {
                    m_BottleneckLabel.text = "CPU";
                }
                else if (bottleneck == PerformanceBottleneck.GPU)
                {
                    m_BottleneckLabel.text = "GPU";
                }
                else if (bottleneck == PerformanceBottleneck.TargetFrameRate)
                {
                    m_BottleneckLabel.text = "Target Framerate";
                }
                else
                {
                    m_BottleneckLabel.text = "Unknown";
                }
            }

            if (m_UsageDial != null)
            {
                if (thermalWarningLevel == WarningLevel.NoWarning)
                {
                    m_UsageDial.Value     = 25;
                    m_UsageDialLabel.text = "No Warning";
                }
                else if (thermalWarningLevel == WarningLevel.ThrottlingImminent)
                {
                    m_UsageDial.Value     = 60;
                    m_UsageDialLabel.text = "Throttling Imminent";
                }
                else if (thermalWarningLevel >= WarningLevel.Throttling)
                {
                    m_UsageDial.Value     = 90;
                    m_UsageDialLabel.text = "Throttling";
                }
            }

            var returnVal   = new AdaptivePerformanceProfilerStats.ScalerInfo[] {};
            var scalerInfos = GetScalerFromProfilerStream(selectedFrameIndexInt32);
            unsafe
            {
                foreach (var scalerInfo in scalerInfos)
                {
                    const int arraySize = 320;
                    var       arr       = new byte[arraySize];
                    Marshal.Copy((IntPtr)scalerInfo.scalerName, arr, 0, arraySize);
                    var scalerName = Encoding.ASCII.GetString(arr).Replace(" ", "");
                    scalerName = scalerName.Replace("\0", "");
                    var viewName     = m_Scalers.Q <Label>($"{scalerName}-element-label");
                    var barFill      = m_Scalers.Q <VisualElement>($"{scalerName}-element-bar-fill");
                    var maxLabel     = m_Scalers.Q <Label>($"{scalerName}-element-max-label");
                    var currentLabel = m_Scalers.Q <Label>($"{scalerName}-element-current-label");

                    if (currentLabel == null || maxLabel == null || barFill == null || viewName == null)
                    {
                        continue;
                    }

                    currentLabel.text = $"{scalerInfo.currentLevel}";
                    if (scalerInfo.enabled == 0 && scalerInfo.overrideLevel == -1)
                    {
                        barFill.style.backgroundColor = m_inactiveColor;
                    }
                    else
                    {
                        if (scalerInfo.applied == 1)
                        {
                            barFill.style.backgroundColor = m_appliedScalerColor;
                        }
                        else
                        {
                            barFill.style.backgroundColor = m_unappliedScalerColor;
                        }
                    }
                    var height = new Length((((float)scalerInfo.currentLevel / (float)scalerInfo.maxLevel)) * 100.0f, LengthUnit.Percent);
                    barFill.style.height       = height;
                    barFill.style.bottom       = new Length(-200, LengthUnit.Pixel);
                    barFill.transform.rotation = Quaternion.Euler(0f, 0f, 180f);
                    barFill.transform.position = m_barFillPosition;
                    maxLabel.text = $"{scalerInfo.maxLevel}";
                }
            }
        }
    }