Esempio n. 1
0
        internal static void UpdateSingleChart(ProfilerChart chart, int firstEmptyFrame, int firstFrame)
        {
            float totalMaxValue         = 1;
            int   unstackableChartIndex = -1;
            var   maxValues             = new float[chart.m_Series.Length];

            for (int i = 0, count = chart.m_Series.Length; i < count; ++i)
            {
                int   identifier = ProfilerDriver.GetStatisticsIdentifierForArea(chart.m_Area, chart.m_Series[i].name);
                float maxValue;
                ProfilerDriver.GetStatisticsValues(identifier, firstEmptyFrame, 1.0f, chart.m_Series[i].yValues, out maxValue);
                chart.m_Series[i].yScale = chart.m_DataScale;
                maxValue *= chart.m_DataScale;

                // Minimum size so we don't generate nans during drawing
                maxValue = Mathf.Max(maxValue, 0.0001F);

                if (maxValue > totalMaxValue)
                {
                    totalMaxValue = maxValue;
                }

                if (chart.m_Type == Chart.ChartType.Line)
                {
                    // Scale line charts so they never hit the top. Scale them slightly differently for each line
                    // so that in "no stuff changing" case they will not end up being exactly the same.
                    maxValues[i] = maxValue * (1.05f + i * 0.05f);
                    chart.m_Series[i].rangeAxis = new Vector2(0f, maxValues[i]);
                }
                else
                {
                    maxValues[i] = maxValue;
                    if (chart.m_Area == ProfilerArea.CPU)
                    {
                        if (chart.m_Series[i].name == k_CPUUnstackableSeriesName)
                        {
                            unstackableChartIndex = i;
                            break;
                        }
                    }
                }
            }
            if (chart.m_Area == ProfilerArea.NetworkMessages || chart.m_Area == ProfilerArea.NetworkOperations)
            {
                for (int i = 0, count = chart.m_Series.Length; i < count; ++i)
                {
                    chart.m_Series[i].rangeAxis = new Vector2(0f, 0.9f * totalMaxValue);
                }
                chart.m_Data.maxValue = totalMaxValue;
            }
            chart.m_Data.Assign(chart.m_Series, unstackableChartIndex, firstEmptyFrame, firstFrame);
            ProfilerDriver.GetStatisticsAvailable(chart.m_Area, firstEmptyFrame, chart.m_Data.dataAvailable);

            if (chart is UISystemProfilerChart)
            {
                ((UISystemProfilerChart)chart).Update(firstFrame, ProfilerDriver.maxHistoryLength - 1);
            }
        }
Esempio n. 2
0
        void OnChartClosed(Chart sender)
        {
            ProfilerChart profilerChart = (ProfilerChart)sender;

            profilerChart.active = false;
            m_ProfilerModules[(int)profilerChart.m_Area].OnDisable();
            m_ProfilerModules[(int)profilerChart.m_Area].OnClosed();
            m_CurrentArea = null;
            GUIUtility.ExitGUI();
        }
Esempio n. 3
0
        ProfilerChart CreateProfilerChart(ProfilerArea i, Chart.ChartType chartType, float scale, int length)
        {
            ProfilerChart newChart = (i == ProfilerArea.UIDetails)
                ? new UISystemProfilerChart(chartType, scale, length)
                : new ProfilerChart(i, chartType, scale, length);

            newChart.selected += OnChartSelected;
            newChart.closed   += OnChartClosed;
            return(newChart);
        }
Esempio n. 4
0
 void OnLostFocus()
 {
     if (GUIUtility.hotControl != 0)
     {
         // The chart may not have had the chance to release the hot control before we lost focus.
         // This happens when changing the selected frame, which may pause the game and switch the focus to another view.
         for (int c = 0; c < m_Charts.Length; ++c)
         {
             ProfilerChart chart = m_Charts[c];
             chart.OnLostFocus();
         }
     }
 }
Esempio n. 5
0
        private void ComputeChartScaleValue(ProfilerArea i, int historyLength, int firstEmptyFrame, int firstFrame)
        {
            ProfilerChart chart               = m_Charts[(int)i];
            float         timeMax             = 0.0f;
            float         timeMaxExcludeFirst = 0.0f;

            for (int k = 0; k < historyLength; k++)
            {
                float timeNow = 0.0F;
                for (int j = 0; j < chart.m_Series.Length; j++)
                {
                    var series = chart.m_Data.unstackableSeriesIndex == j && chart.m_Data.hasOverlay ?
                                 chart.m_Data.overlays[j] : chart.m_Series[j];

                    if (series.enabled)
                    {
                        timeNow += series.yValues[k];
                    }
                }
                if (timeNow > timeMax)
                {
                    timeMax = timeNow;
                }
                if (timeNow > timeMaxExcludeFirst && k + firstEmptyFrame >= firstFrame + 1)
                {
                    timeMaxExcludeFirst = timeNow;
                }
            }
            if (timeMaxExcludeFirst != 0.0f)
            {
                timeMax = timeMaxExcludeFirst;
            }

            timeMax = Math.Min(timeMax * chart.m_DataScale, m_ChartMaxClamp);

            // Do not apply the new scale immediately, but gradually go towards it
            if (m_ChartOldMax[(int)i] > 0.0f)
            {
                timeMax = Mathf.Lerp(m_ChartOldMax[(int)i], timeMax, 0.4f);
            }
            m_ChartOldMax[(int)i] = timeMax;

            for (int k = 0; k < chart.m_Data.numSeries; ++k)
            {
                chart.m_Data.series[k].rangeAxis = new Vector2(0f, timeMax);
            }
            UpdateChartGrid(timeMax, chart.m_Data);
        }
Esempio n. 6
0
        private void Initialize()
        {
            int len = ProfilerDriver.maxHistoryLength - 1;

            this.m_Charts = new ProfilerChart[7];
            Color[] colors = ProfilerColors.colors;
            for (ProfilerArea profilerArea = ProfilerArea.CPU; profilerArea < ProfilerArea.AreaCount; profilerArea++)
            {
                float           dataScale = 1f;
                Chart.ChartType type      = Chart.ChartType.Line;
                string[]        graphStatisticsPropertiesForArea = ProfilerDriver.GetGraphStatisticsPropertiesForArea(profilerArea);
                int             num = graphStatisticsPropertiesForArea.Length;
                if (profilerArea == ProfilerArea.GPU || profilerArea == ProfilerArea.CPU)
                {
                    type      = Chart.ChartType.StackedFill;
                    dataScale = 0.001f;
                }
                ProfilerChart profilerChart = new ProfilerChart(profilerArea, type, dataScale, num);
                for (int i = 0; i < num; i++)
                {
                    profilerChart.m_Series[i] = new ChartSeries(graphStatisticsPropertiesForArea[i], len, colors[i]);
                }
                this.m_Charts[(int)profilerArea] = profilerChart;
            }
            if (this.m_ReferenceListView == null)
            {
                this.m_ReferenceListView = new MemoryTreeList(this, null);
            }
            if (this.m_MemoryListView == null)
            {
                this.m_MemoryListView = new MemoryTreeListClickable(this, this.m_ReferenceListView);
            }
            this.UpdateCharts();
            this.BuildColumns();
            ProfilerChart[] charts = this.m_Charts;
            for (int j = 0; j < charts.Length; j++)
            {
                ProfilerChart profilerChart2 = charts[j];
                profilerChart2.LoadAndBindSettings();
            }
        }
Esempio n. 7
0
        private void UpdateCharts()
        {
            int historyLength   = ProfilerDriver.maxHistoryLength - 1;
            int firstEmptyFrame = ProfilerDriver.lastFrameIndex - historyLength;
            int firstFrame      = Mathf.Max(ProfilerDriver.firstFrameIndex, firstEmptyFrame);

            // Collect chart values
            foreach (var chart in m_Charts)
            {
                UpdateSingleChart(chart, firstEmptyFrame, firstFrame);
            }

            // CPU chart overlay values
            string        selectedName  = ProfilerDriver.selectedPropertyPath;
            bool          hasCPUOverlay = (selectedName != string.Empty) && m_CurrentArea == ProfilerArea.CPU;
            ProfilerChart cpuChart      = m_Charts[(int)ProfilerArea.CPU];

            if (hasCPUOverlay)
            {
                cpuChart.m_Data.hasOverlay = true;
                int numCharts = cpuChart.m_Data.numSeries;
                for (int i = 0; i < numCharts; ++i)
                {
                    var chart = cpuChart.m_Data.series[i];
                    cpuChart.m_Data.overlays[i] = new ChartSeriesViewData(chart.name, chart.yValues.Length, chart.color);
                    for (int frameIdx = 0; frameIdx < chart.yValues.Length; ++frameIdx)
                    {
                        cpuChart.m_Data.overlays[i].xValues[frameIdx] = (float)frameIdx;
                    }
                    int   identifier = ProfilerDriver.GetStatisticsIdentifierForArea(cpuChart.m_Area, UnityString.Format("Selected{0}", chart.name));
                    float maxValue;
                    ProfilerDriver.GetStatisticsValues(identifier, firstEmptyFrame, 1.0f, cpuChart.m_Data.overlays[i].yValues, out maxValue);
                    cpuChart.m_Data.overlays[i].yScale = cpuChart.m_DataScale;
                }
            }
            else
            {
                cpuChart.m_Data.hasOverlay = false;
            }

            // CPU, GPU & UI chart scale value
            for (int i = 0; i < ms_StackedAreas.Length; i++)
            {
                ComputeChartScaleValue(ms_StackedAreas[i], historyLength, firstEmptyFrame, firstFrame);
            }

            // Is GPU Profiling supported warning
            string warning = null;

            if (!ProfilerDriver.isGPUProfilerSupported)
            {
                warning = "GPU profiling is not supported by the graphics card driver. Please update to a newer version if available.";

                if (Application.platform == RuntimePlatform.OSXEditor)
                {
                    if (!ProfilerDriver.isGPUProfilerSupportedByOS)
                    {
                        warning = "GPU profiling requires Mac OS X 10.7 (Lion) and a capable video card. GPU profiling is currently not supported on mobile.";
                    }
                    else
                    {
                        warning = "GPU profiling is not supported by the graphics card driver (or it was disabled because of driver bugs).";
                    }
                }
            }
            m_Charts[(int)ProfilerArea.GPU].m_NotSupportedWarning = warning;
        }
Esempio n. 8
0
        void Initialize()
        {
            // When reinitializing (e.g. because Colorblind mode or PlatformModule changed) we don't need a new state
            if (m_AttachProfilerState == null)
            {
                m_AttachProfilerState = ConnectionUtility.GetAttachToPlayerState(this, (player) => ClearFramesCallback());
            }

            int historySize = ProfilerUserSettings.frameCount;

            m_Charts = new ProfilerChart[Profiler.areaCount];

            Color[] chartAreaColors = ProfilerColors.chartAreaColors;

            for (int i = 0; i < Profiler.areaCount; i++)
            {
                float           scale           = 1.0f;
                Chart.ChartType chartType       = Chart.ChartType.Line;
                string[]        statisticsNames = ProfilerDriver.GetGraphStatisticsPropertiesForArea((ProfilerArea)i);
                int             length          = statisticsNames.Length;
                if (Array.IndexOf(ms_StackedAreas, (ProfilerArea)i) != -1)
                {
                    chartType = Chart.ChartType.StackedFill;
                    scale     = 1.0f / 1000.0f;
                }

                ProfilerChart chart = CreateProfilerChart((ProfilerArea)i, chartType, scale, length);

                if (chart.m_Area == ProfilerArea.CPU)
                {
                    chart.SetOnSeriesToggleCallback(OnToggleCPUChartSeries);
                }

                for (int s = 0; s < length; s++)
                {
                    chart.m_Series[s] = new ChartSeriesViewData(statisticsNames[s], historySize, chartAreaColors[s % chartAreaColors.Length]);
                    for (int frameIdx = 0; frameIdx < historySize; ++frameIdx)
                    {
                        chart.m_Series[s].xValues[frameIdx] = (float)frameIdx;
                    }
                }

                m_Charts[(int)i] = chart;
            }

            if (m_VertSplit == null || m_VertSplit.relativeSizes == null || m_VertSplit.relativeSizes.Length == 0)
            {
                m_VertSplit = new SplitterState(new[] { 50f, 50f }, new[] { k_VertSplitterMinSizes, k_VertSplitterMinSizes }, null);
            }
            // 2 times the min splitter size plus one line height for the toolbar up top
            minSize = new Vector2(Chart.kSideWidth + k_RightPaneMinSize, k_VertSplitterMinSizes * m_VertSplit.minSizes.Length + k_LineHeight);

            // TODO: only create modules for active charts and otherwise lazy initialize them.
            if (m_ProfilerModules == null)
            {
                m_ProfilerModules = new ProfilerModuleBase[]
                {
                    new CPUProfilerModule(),                  //CPU
                    new GPUProfilerModule(),                  //GPU
                    new RenderingProfilerModule(),            //Rendering
                    new MemoryProfilerModule(),               //Memory
                    new AudioProfilerModule(),                //Audio
                    new VideoProfilerModule(),                //Video
                    new PhysicsProfilerModule(),              //Physics
                    new Physics2DProfilerModule(),            //Physics2D
                    new NetworkingMessagesProfilerModule(),   //NetworkMessages
                    new NetworkingOperationsProfilerModule(), //NetworkOperations
                    new UIProfilerModule(),                   //UI
                    new UIDetailsProfilerModule(),            //UIDetails
                    new GlobalIlluminationProfilerModule(),   //GlobalIllumination
                };
            }

            foreach (var module in m_ProfilerModules)
            {
                module?.OnEnable(this);
            }

            UpdateCharts();
            foreach (var chart in m_Charts)
            {
                chart.LoadAndBindSettings();
            }

            m_Initialized = true;
        }
Esempio n. 9
0
        private void UpdateCharts()
        {
            int num  = ProfilerDriver.maxHistoryLength - 1;
            int num2 = ProfilerDriver.lastFrameIndex - num;
            int num3 = Mathf.Max(ProfilerDriver.firstFrameIndex, num2);

            ProfilerChart[] charts = this.m_Charts;
            for (int i = 0; i < charts.Length; i++)
            {
                ProfilerChart profilerChart = charts[i];
                float[]       array         = new float[profilerChart.m_Series.Length];
                for (int j = 0; j < profilerChart.m_Series.Length; j++)
                {
                    int   statisticsIdentifier = ProfilerDriver.GetStatisticsIdentifier(profilerChart.m_Series[j].identifierName);
                    float num4;
                    ProfilerDriver.GetStatisticsValues(statisticsIdentifier, num2, profilerChart.m_DataScale, profilerChart.m_Series[j].data, out num4);
                    num4 = Mathf.Max(num4, 0.0001f);
                    float num5;
                    if (profilerChart.m_Type == Chart.ChartType.Line)
                    {
                        num5 = 1f / (num4 * (1.05f + (float)j * 0.05f));
                    }
                    else
                    {
                        num5 = 1f / num4;
                    }
                    array[j] = num5;
                }
                if (profilerChart.m_Type == Chart.ChartType.Line)
                {
                    profilerChart.m_Data.AssignScale(array);
                }
                profilerChart.m_Data.Assign(profilerChart.m_Series, num2, num3);
            }
            string        selectedPropertyPath = ProfilerDriver.selectedPropertyPath;
            bool          flag           = selectedPropertyPath != string.Empty && this.m_CurrentArea == ProfilerArea.CPU;
            ProfilerChart profilerChart2 = this.m_Charts[0];

            if (flag)
            {
                profilerChart2.m_Data.hasOverlay = true;
                ChartSeries[] series = profilerChart2.m_Series;
                for (int k = 0; k < series.Length; k++)
                {
                    ChartSeries chartSeries           = series[k];
                    int         statisticsIdentifier2 = ProfilerDriver.GetStatisticsIdentifier("Selected" + chartSeries.identifierName);
                    chartSeries.CreateOverlayData();
                    float num6;
                    ProfilerDriver.GetStatisticsValues(statisticsIdentifier2, num2, profilerChart2.m_DataScale, chartSeries.overlayData, out num6);
                }
            }
            else
            {
                profilerChart2.m_Data.hasOverlay = false;
            }
            for (ProfilerArea profilerArea = ProfilerArea.CPU; profilerArea <= ProfilerArea.GPU; profilerArea++)
            {
                ProfilerChart profilerChart3 = this.m_Charts[(int)profilerArea];
                float         num7           = 0f;
                float         num8           = 0f;
                for (int l = 0; l < num; l++)
                {
                    float num9 = 0f;
                    for (int m = 0; m < profilerChart3.m_Series.Length; m++)
                    {
                        if (profilerChart3.m_Series[m].enabled)
                        {
                            num9 += profilerChart3.m_Series[m].data[l];
                        }
                    }
                    if (num9 > num7)
                    {
                        num7 = num9;
                    }
                    if (num9 > num8 && l + num2 >= num3 + 1)
                    {
                        num8 = num9;
                    }
                }
                if (num8 != 0f)
                {
                    num7 = num8;
                }
                num7 = Math.Min(num7, this.m_ChartMaxClamp);
                if (this.m_ChartOldMax[(int)profilerArea] > 0f)
                {
                    num7 = Mathf.Lerp(this.m_ChartOldMax[(int)profilerArea], num7, 0.4f);
                }
                this.m_ChartOldMax[(int)profilerArea] = num7;
                profilerChart3.m_Data.AssignScale(new float[]
                {
                    1f / num7
                });
                ProfilerWindow.UpdateChartGrid(num7, profilerChart3.m_Data);
            }
            string notSupportedWarning = null;

            if (ProfilerDriver.isGPUProfilerBuggyOnDriver)
            {
                notSupportedWarning = "Graphics card driver returned invalid timing information. Please update to a newer version if available.";
            }
            else
            {
                if (!ProfilerDriver.isGPUProfilerSupported)
                {
                    notSupportedWarning = "GPU profiling is not supported by the graphics card driver. Please update to a newer version if available.";
                    if (Application.platform == RuntimePlatform.OSXEditor)
                    {
                        if (!ProfilerDriver.isGPUProfilerSupportedByOS)
                        {
                            notSupportedWarning = "GPU profiling requires Mac OS X 10.7 (Lion) and a capable video card. GPU profiling is currently not supported on mobile.";
                        }
                        else
                        {
                            notSupportedWarning = "GPU profiling is not supported by the graphics card driver (or it was disabled because of driver bugs).";
                        }
                    }
                }
            }
            this.m_Charts[1].m_Chart.m_NotSupportedWarning = notSupportedWarning;
        }
Esempio n. 10
0
        private void OnGUI()
        {
            this.CheckForPlatformModuleChange();
            if (ProfilerWindow.ms_Styles == null)
            {
                ProfilerWindow.ms_Styles = new ProfilerWindow.Styles();
            }
            if (!this.m_HasProfilerLicense)
            {
                GUILayout.Label(ProfilerWindow.ms_Styles.noLicense, EditorStyles.largeLabel, new GUILayoutOption[0]);
                return;
            }
            this.DrawMainToolbar();
            SplitterGUILayout.BeginVerticalSplit(this.m_VertSplit, new GUILayoutOption[0]);
            this.m_GraphPos = EditorGUILayout.BeginScrollView(this.m_GraphPos, ProfilerWindow.ms_Styles.profilerGraphBackground, new GUILayoutOption[0]);
            if (this.m_PrevLastFrame != ProfilerDriver.lastFrameIndex)
            {
                this.UpdateCharts();
                this.m_PrevLastFrame = ProfilerDriver.lastFrameIndex;
            }
            int num = this.m_CurrentFrame;

            Chart.ChartAction[] array = new Chart.ChartAction[this.m_Charts.Length];
            for (int i = 0; i < this.m_Charts.Length; i++)
            {
                ProfilerChart profilerChart = this.m_Charts[i];
                if (profilerChart.active)
                {
                    num = profilerChart.DoChartGUI(num, this.m_CurrentArea, out array[i]);
                }
            }
            bool flag = false;

            if (num != this.m_CurrentFrame)
            {
                this.SetCurrentFrame(num);
                flag = true;
            }
            for (int j = 0; j < this.m_Charts.Length; j++)
            {
                ProfilerChart profilerChart2 = this.m_Charts[j];
                if (profilerChart2.active)
                {
                    if (array[j] == Chart.ChartAction.Closed)
                    {
                        if (this.m_CurrentArea == (ProfilerArea)j)
                        {
                            this.m_CurrentArea = ProfilerArea.CPU;
                        }
                        profilerChart2.active = false;
                    }
                    else
                    {
                        if (array[j] == Chart.ChartAction.Activated)
                        {
                            this.m_CurrentArea = (ProfilerArea)j;
                            if (this.m_CurrentArea != ProfilerArea.CPU && this.m_CPUHierarchyGUI.selectedIndex != -1)
                            {
                                this.ClearSelectedPropertyPath();
                            }
                            flag = true;
                        }
                    }
                }
            }
            if (flag)
            {
                base.Repaint();
                GUIUtility.ExitGUI();
            }
            GUILayout.EndScrollView();
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            switch (this.m_CurrentArea)
            {
            case ProfilerArea.CPU:
                this.DrawCPUOrRenderingPane(this.m_CPUHierarchyGUI, this.m_CPUDetailHierarchyGUI, this.m_CPUTimelineGUI);
                goto IL_255;

            case ProfilerArea.GPU:
                this.DrawCPUOrRenderingPane(this.m_GPUHierarchyGUI, this.m_GPUDetailHierarchyGUI, null);
                goto IL_255;

            case ProfilerArea.Memory:
                this.DrawMemoryPane(this.m_ViewSplit);
                goto IL_255;

            case ProfilerArea.Audio:
                this.DrawAudioPane();
                goto IL_255;
            }
            this.DrawPane(this.m_CurrentArea);
IL_255:
            GUILayout.EndVertical();
            SplitterGUILayout.EndVerticalSplit();
        }