Ejemplo n.º 1
0
    private DataStatistics() //如果在测完数据不手动设置instance == null,则会出现数据堆积。因为这是个单例模式
    {
        instance = this;

        if (MainEditor.labelTitle.Equals(MainEditor.ANDRIOD_PLATFORM))
        {
            standardPlatformData = new AndriodStandardData();
        }
        else if (MainEditor.labelTitle.Equals(MainEditor.PC_PLATFORM))
        {
            standardPlatformData = new PCStandardData();
        }

        profilerProperty = new ProfilerProperty();

        monoProperty          = new Property("MonoMemory");
        textureProperty       = new Property("TextureMemory");
        animationProperty     = new Property("AnimationMemory");
        audioProperty         = new Property("AudioMemory");
        meshProperty          = new Property("MeshMemory");
        gameobjectProperty    = new Property("GameObjects");
        drawCallProperty      = new Property("DrawCalls");
        trisProperty          = new Property("Tris");
        fpsProperty           = new RateProperty("FPS", standardPlatformData.FPS);
        renderingTimeProperty = new Property("CpuRenderingTime");
        animationTimeProperty = new Property("CpuAnimationTime");
        uiTimeProperty        = new Property("CpuUiTime");
        scriptsTimeProperty   = new Property("CpuScriptsTime");
    }
Ejemplo n.º 2
0
        public static FunctionData Create(ProfilerProperty property)
        {
            var functionData = functionDataAllocator.Allocate();

            functionData.functionPath = property.propertyPath;
            for (int i = 0; i < columns.Length; ++i)
            {
                var column = columns[i];
#if UNITY_5_5_OR_NEWER
                if (column == ProfilerColumn.DontSort)
                {
                    continue;
                }
#endif
                var functionDataValue = FunctionDataValue.Create();
                functionDataValue.column = columnNames[i];
#if UNITY_2019_1_OR_NEWER
                functionDataValue.value = property.GetColumn((int)column);
#else
                functionDataValue.value = property.GetColumn(column);
#endif

                functionData.values[i] = functionDataValue;
            }
            return(functionData);
        }
            public void Add(long key, Texture2D data)
            {
                if (Get(key) == null)
                {
                    if (m_CacheQueue[m_CacheQueueFront] != -1)
                    {
                        long      removeKey = m_CacheQueue[m_CacheQueueFront];
                        Texture2D tex;
                        if (m_Cache.TryGetValue(removeKey, out tex))
                        {
                            m_Cache.Remove(removeKey);
                            ProfilerProperty.ReleaseUISystemProfilerRender(tex);
                        }
                    }

                    m_CacheQueue[m_CacheQueueFront] = key;
                    m_Cache[key] = data;

                    m_CacheQueueFront++;
                    if (m_CacheQueueFront == m_Capacity)
                    {
                        m_CacheQueueFront = 0;
                    }
                }
            }
        public static List <string> CPUFunctionDetail(int beginFrame, int endFrame, string funcName)
        {
            List <string> details = new List <string>(endFrame - beginFrame + 1);

            if (details == null || string.IsNullOrEmpty(funcName))
            {
                UnityEngine.Debug.LogWarning("请输入函数名");
                return(null);
            }

            for (int i = beginFrame - 1; i < endFrame; i++)
            {
                SetCurrentFrame(i);
                ProfilerProperty property = FindFunc(funcName);
                if (property != null)
                {
                    details.Add(string.Format("totalTime:{0}ms({1})  selfTime:{2}ms({3})  CGMemory:{4}  RelatedObj:{5}",
                                              property.GetColumn(ProfilerColumn.TotalTime),
                                              property.GetColumn(ProfilerColumn.TotalPercent),
                                              property.GetColumn(ProfilerColumn.SelfTime),
                                              property.GetColumn(ProfilerColumn.SelfPercent),
                                              property.GetColumn(ProfilerColumn.GCMemory),
                                              property.GetColumn(ProfilerColumn.ObjectName)));
                }
                else
                {
                    details.Add("null");
                }
            }
            return(details);
        }
        public static List <List <string> > HighUsedFunc(int beginFrame, int endFrame, float threshold)
        {
            List <List <string> > funNames = new List <List <string> >();

            for (int i = beginFrame - 1; i < endFrame; i++)
            {
                SetCurrentFrame(i);
                if (!IsPropertyEmpty())
                {
                    List <string>    funName  = new List <string>();
                    ProfilerProperty property = CPUOrGPUproperty;
                    while (property.Next(property.HasChildren))
                    {
                        string str = System.Text.RegularExpressions.Regex.Replace(property.GetColumn(ProfilerColumn.TotalPercent), @"[^\d.\d]", "");
                        if (float.Parse(str) > threshold)
                        {
                            funName.Add(string.Format("{0}----耗时:{1}ms({2})\t",
                                                      property.propertyName, property.GetColumn(ProfilerColumn.TotalTime), property.GetColumn(ProfilerColumn.TotalPercent)));
                        }
                    }
                    funNames.Add(funName);
                }
            }

            return(funNames);
        }
Ejemplo n.º 6
0
 private void DrawCPUOrRenderingToolbar(ProfilerProperty property)
 {
     EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, new GUILayoutOption[0]);
     string[] displayedOptions = new string[]
     {
         "Hierarchy",
         "Timeline",
         "Raw Hierarchy"
     };
     int[] optionValues = new int[]
     {
         0,
         1,
         2
     };
     this.m_ViewType = (ProfilerViewType)EditorGUILayout.IntPopup((int)this.m_ViewType, displayedOptions, optionValues, EditorStyles.toolbarDropDown, new GUILayoutOption[]
     {
         GUILayout.Width(100f)
     });
     GUILayout.FlexibleSpace();
     GUILayout.Label(string.Format("CPU:{0}ms   GPU:{1}ms", property.frameTime, property.frameGpuTime), EditorStyles.miniLabel, new GUILayoutOption[0]);
     GUI.enabled = (ProfilerDriver.GetNextFrameIndex(this.m_CurrentFrame) == -1);
     if (GUILayout.Button((!GUI.enabled) ? ProfilerWindow.ms_Styles.noFrameDebugger : ProfilerWindow.ms_Styles.frameDebugger, EditorStyles.toolbarButton, new GUILayoutOption[0]))
     {
         FrameDebuggerWindow frameDebuggerWindow = FrameDebuggerWindow.ShowFrameDebuggerWindow();
         frameDebuggerWindow.EnableIfNeeded();
     }
     GUI.enabled = true;
     GUILayout.FlexibleSpace();
     this.SearchFieldGUI();
     EditorGUILayout.EndHorizontal();
     this.HandleCommandEvents();
 }
Ejemplo n.º 7
0
        public static ProfilerData GetProfilerData(int firstFrameIndex, int lastFrameIndex, string selectedPropertyPath = "")
        {
            var profilerSortColumn = ProfilerColumn.TotalTime;
            var viewType           = ProfilerViewType.Hierarchy;
            var property           = new ProfilerProperty();

            var profilerData = new ProfilerData();

            for (int frameIndex = firstFrameIndex; frameIndex <= lastFrameIndex; ++frameIndex)
            {
                property.SetRoot(frameIndex, profilerSortColumn, viewType);
                property.onlyShowGPUSamples = false;

                var        frameData     = new FrameData();
                const bool enterChildren = true;
                while (property.Next(enterChildren))
                {
                    bool shouldSaveProperty = string.IsNullOrEmpty(selectedPropertyPath) || property.propertyPath == selectedPropertyPath;
                    if (shouldSaveProperty)
                    {
                        var functionData = FunctionData.Create(property);
                        frameData.functions.Add(functionData);
                        //Debug.Log(functionData.ToString());
                    }
                }
                property.Cleanup();
                profilerData.frames.Add(frameData);
                //Debug.Log(frameData.ToString());
            }
            //Debug.Log(profilerData.ToString());
            return(profilerData);
        }
Ejemplo n.º 8
0
        public static float GetDataMean(string selectedPropertyPath = "")
        {
            var profilerSortColumn = ProfilerColumn.TotalTime;
            var viewType           = ProfilerViewType.Hierarchy;
            var property           = new ProfilerProperty();

            float meanValue = 0;
            int   i         = 0;

            for (int frameIndex = ProfilerDriver.firstFrameIndex; frameIndex <= ProfilerDriver.lastFrameIndex; ++frameIndex)
            {
                property.SetRoot(frameIndex, profilerSortColumn, viewType);
                property.onlyShowGPUSamples = false;

                const bool enterChildren = true;

                while (property.Next(enterChildren))
                {
                    bool shouldSaveProperty = string.IsNullOrEmpty(selectedPropertyPath) || property.propertyPath == selectedPropertyPath;
                    if (shouldSaveProperty)
                    {
                        meanValue += float.Parse(property.GetColumn(ProfilerColumn.TotalGPUTime));
                        ++i;
                    }
                }
                property.Cleanup();
            }

            meanValue /= i;

            return(meanValue);
        }
Ejemplo n.º 9
0
        public ProfilerProperty CreateProperty(bool details)
        {
            ProfilerProperty profilerProperty   = new ProfilerProperty();
            ProfilerColumn   profilerSortColumn = (this.m_CurrentArea != ProfilerArea.CPU) ? ((!details) ? this.m_GPUHierarchyGUI.sortType : this.m_GPUDetailHierarchyGUI.sortType) : ((!details) ? this.m_CPUHierarchyGUI.sortType : this.m_CPUDetailHierarchyGUI.sortType);

            profilerProperty.SetRoot(this.GetActiveVisibleFrameIndex(), profilerSortColumn, this.m_ViewType);
            profilerProperty.onlyShowGPUSamples = (this.m_CurrentArea == ProfilerArea.GPU);
            return(profilerProperty);
        }
Ejemplo n.º 10
0
 private static bool CheckFrameData(ProfilerProperty property)
 {
     if (!property.frameDataReady)
     {
         GUILayout.Label(ProfilerWindow.ms_Styles.noData, ProfilerWindow.ms_Styles.background, new GUILayoutOption[0]);
         return(false);
     }
     return(true);
 }
 public ProfilerRowInfo(ProfilerProperty profilerProperty)
 {
     propertyPath = profilerProperty.propertyPath;
     depth        = profilerProperty.depth;
     functionName = profilerProperty.GetColumn(ProfilerColumn.FunctionName);
     totalPercent = profilerProperty.GetColumn(ProfilerColumn.TotalPercent);
     selfPercent  = profilerProperty.GetColumn(ProfilerColumn.SelfPercent);
     calls        = profilerProperty.GetColumn(ProfilerColumn.Calls);
     gcMemory     = profilerProperty.GetColumn(ProfilerColumn.GCMemory);
     totalTime    = profilerProperty.GetColumn(ProfilerColumn.TotalTime);
     selfTime     = profilerProperty.GetColumn(ProfilerColumn.SelfTime);
 }
Ejemplo n.º 12
0
    private void Reset()
    {
#if UNITY_EDITOR
        m_Drawcall = 0;
        m_Screen   = "";

        if (m_Property != null)
        {
            m_Property.Dispose();
            m_Property = null;
        }
#endif
    }
Ejemplo n.º 13
0
    /// <summary>
    /// プロファイラーの情報のキャプチャ
    /// </summary>
    private void CaptureProfilerData()
    {
        // ProfilerのRootPropertyを取得
        var property = new ProfilerProperty();

        // Profilerに表示されているCurrentFrame+1のデータが取れる
        property.SetRoot(_captureIndex - 1, ProfilerColumn.SelfTime, ProfilerViewType.Hierarchy);

        if (property.HasChildren)
        {
            _profilerPropertyData.Clear();

            _logText  = string.Empty;
            _logText += "Name, SelfTime, SelfPercent \n";
            _logText += "---\n";
        }


        // PropertyのHierarchyを辿る
        while (property.Next(true))
        {
            var value = property.GetColumnAsSingle(ProfilerColumn.SelfTime);

            // 全部取れるので適当な閾値で切る
            if (value > _collectionThreshold)
            {
                var addData = new CollectColumn();

                addData._name = property.propertyName;

                for (int i = 0; i < System.Enum.GetValues(typeof(ProfilerColumn)).Length; i++)
                {
                    if (Enum.IsDefined(typeof(ProfilerColumn), i))
                    {
                        var columnElement = (ProfilerColumn)Enum.ToObject(typeof(ProfilerColumn), i);

                        addData._columnValue[i] = property.GetColumn(columnElement);
                    }
                }

                _profilerPropertyData.Add(addData);

                _logText += String.Format("{0}, {1}, {2}. \n",
                                          addData._name,
                                          addData._columnValue[(int)ProfilerColumn.SelfTime],
                                          addData._columnValue[(int)ProfilerColumn.SelfPercent]);
            }
        }

        _logText += "---\n";
    }
    private void UpdateProperties()
    {
        ProfilerProperty profilerProperty = new ProfilerProperty();

        profilerProperty.SetRoot(SelectedFrame, columnToSort, ProfilerViewType.Hierarchy);
        profilerProperty.onlyShowGPUSamples = false;

        cachedProfilerProperties.Clear();
        while (profilerProperty.Next(true))
        {
            cachedProfilerProperties.Add(new ProfilerRowInfo(profilerProperty));
        }

        Repaint();
    }
Ejemplo n.º 15
0
        public ProfilerProperty CreateProperty(int sortType)
        {
            int targetedFrame = GetActiveVisibleFrameIndex();

            if (targetedFrame < ProfilerDriver.lastFrameIndex - ProfilerDriver.maxHistoryLength)
            {
                return(null);
            }

            var property = new ProfilerProperty();

            property.SetRoot(targetedFrame, sortType, (int)m_ViewType);
            property.onlyShowGPUSamples = m_CurrentArea == ProfilerArea.GPU;
            return(property);
        }
        /// <summary>
        /// 计算GC次数,并记录在什么时候
        /// </summary>
        public static List <int> GCCollectCount(int beginFrame, int endFrame, string funcName, ref float totalTime)
        {
            List <int> frame = new List <int>();

            for (int i = beginFrame - 1; i < endFrame; i++)
            {
                SetCurrentFrame(i);
                ProfilerProperty property = FindFunc(funcName);
                if (property != null)
                {
                    totalTime += float.Parse(property.GetColumn(ProfilerColumn.TotalTime));
                    frame.Add(i + 1);
                }
            }
            return(frame);
        }
Ejemplo n.º 17
0
    public static void DumpProfilerFrame()
    {
        var property = new ProfilerProperty();

        property.SetRoot(GetSelectedFrame(), ProfilerColumn.TotalPercent, ProfilerViewType.Hierarchy);
        property.onlyShowGPUSamples = false;

        if (File.Exists(HtmlOutputPath))
        {
            File.Delete(HtmlOutputPath);
        }
        var stream = File.OpenWrite(HtmlOutputPath);
        var writer = new StreamWriter(stream);

        while (property.Next(true))
        {
            writer.Write(GetTagSpace(property.depth));
            writer.Write(property.GetColumn(ProfilerColumn.FunctionName));

//			writer.Write("<td>");
//			writer.Write(property.GetColumn(ProfilerColumn.TotalPercent));
//			writer.Write("</td>");
//
//			writer.Write("<td>");
//			writer.Write(property.GetColumn(ProfilerColumn.SelfPercent));
//			writer.Write("</td>");
//
//			writer.Write("<td>");
//			writer.Write(property.GetColumn(ProfilerColumn.Calls));
//			writer.Write("</td>");
//
            writer.Write(LONG_SPACE);
            writer.Write(property.GetColumn(ProfilerColumn.GCMemory));

            writer.Write(SPACE);
            writer.Write(property.GetColumn(ProfilerColumn.TotalTime));
            writer.Write("ms");

            writer.Write(SPACE);
            writer.Write(property.GetColumn(ProfilerColumn.SelfTime));
            writer.Write("ms");

            writer.Write(writer.NewLine);
        }

        writer.Close();
    }
        /// <summary>
        /// 更新并获取CPU or GPU数据,获取后判断是否获取成功
        /// </summary>
        /// <returns></returns>
        private static bool IsPropertyEmpty()
        {
            CPUOrGPUproperty = GetCPUOrGPUProperty();
            if (CPUOrGPUproperty == null)
            {
                UnityEngine.Debug.LogError("ProfierWindow 的 GetRootProfilerProperty 调用失败, 未获取到 m_CPUOrGPUProfilerProperty");
                return(true);
            }

            if (!CPUOrGPUproperty.frameDataReady)
            {
                UnityEngine.Debug.LogError("当前帧未有数据,请检查采样的帧数据在Profiler图像内的帧范围内");
                return(true);
            }

            return(false);
        }
Ejemplo n.º 19
0
 public FunctionData(ProfilerProperty property)
 {
     Values       = new FunctionDataValue[AllColumns.Length];
     FunctionPath = property.propertyPath;
     for (int i = 0; i < AllColumns.Length; i++)
     {
         var column = AllColumns[i];
         if (column == ProfilerColumn.DontSort)
         {
             continue;
         }
         Values[i] = new FunctionDataValue(
             column,
             property.GetColumn(column)
             );
     }
 }
Ejemplo n.º 20
0
            public void Clear()
            {
                foreach (long current in this.m_CacheQueue)
                {
                    Texture2D t;
                    if (this.m_Cache.TryGetValue(current, out t))
                    {
                        ProfilerProperty.ReleaseUISystemProfilerRender(t);
                    }
                }
                this.m_Cache.Clear();
                this.m_CacheQueue.Clear();
                IEnumerable <long> collection = from value in Enumerable.Repeat <long>(-1L, this.m_Capacity)
                                                select value;

                this.m_CacheQueue.AddRange(collection);
                this.m_CacheQueueFront = 0;
            }
            public void Clear()
            {
                foreach (long removeKey in m_CacheQueue)
                {
                    Texture2D tex;
                    if (m_Cache.TryGetValue(removeKey, out tex))
                    {
                        ProfilerProperty.ReleaseUISystemProfilerRender(tex);
                    }
                }
                m_Cache.Clear();
                m_CacheQueue.Clear();

                IEnumerable <long> initQueueEnumerable = from value in Enumerable.Repeat(-1L, m_Capacity) select value;

                m_CacheQueue.AddRange(initQueueEnumerable);
                m_CacheQueueFront = 0;
            }
        // TODO, 可能有同名,返回值为数组更好
        private static ProfilerProperty FindFunc(string funcName)
        {
            if (IsPropertyEmpty())
            {
                return(null);
            }

            ProfilerProperty property = CPUOrGPUproperty;

            while (property.Next(property.HasChildren))
            {
                if (property.propertyName == funcName)
                {
                    return(property);
                }
            }

            return(null);
        }
Ejemplo n.º 23
0
        private void DrawCPUOrRenderingPane(ProfilerHierarchyGUI mainPane, ProfilerHierarchyGUI detailPane, ProfilerTimelineGUI timelinePane)
        {
            ProfilerProperty profilerProperty = this.CreateProperty(false);

            this.DrawCPUOrRenderingToolbar(profilerProperty);
            if (!ProfilerWindow.CheckFrameData(profilerProperty))
            {
                profilerProperty.Cleanup();
                return;
            }
            if (timelinePane != null && this.m_ViewType == ProfilerViewType.Timeline)
            {
                float num = (float)this.m_VertSplit.realSizes[1];
                num -= EditorStyles.toolbar.CalcHeight(GUIContent.none, 10f) + 2f;
                timelinePane.DoGUI(this.GetActiveVisibleFrameIndex(), base.position.width, base.position.height - num, num);
                profilerProperty.Cleanup();
            }
            else
            {
                SplitterGUILayout.BeginHorizontalSplit(this.m_ViewSplit, new GUILayoutOption[0]);
                GUILayout.BeginVertical(new GUILayoutOption[0]);
                bool expandAll = false;
                mainPane.DoGUI(profilerProperty, this.m_SearchString, expandAll);
                profilerProperty.Cleanup();
                GUILayout.EndVertical();
                GUILayout.BeginVertical(new GUILayoutOption[0]);
                ProfilerProperty profilerProperty2 = this.CreateProperty(true);
                ProfilerProperty detailedProperty  = mainPane.GetDetailedProperty(profilerProperty2);
                profilerProperty2.Cleanup();
                if (detailedProperty != null)
                {
                    detailPane.DoGUI(detailedProperty, string.Empty, expandAll);
                    detailedProperty.Cleanup();
                }
                else
                {
                    ProfilerWindow.DrawEmptyCPUOrRenderingDetailPane();
                }
                GUILayout.EndVertical();
                SplitterGUILayout.EndHorizontalSplit();
            }
        }
Ejemplo n.º 24
0
        public ProfilerData(int firstFrameIndex, int lastFrameIndex)
        {
            var profilerSortColumn = ProfilerColumn.TotalTime;
            var viewType           = ProfilerViewType.Hierarchy;
            var property           = new ProfilerProperty();

            for (var index = firstFrameIndex; index <= lastFrameIndex; index++)
            {
                property.SetRoot(index, profilerSortColumn, viewType);
                property.onlyShowGPUSamples = false;

                var frameData = new FrameData();
                while (property.Next(true))
                {
                    var functionData = new FunctionData(property);
                    frameData.Functions.Add(functionData);
                }
                property.Cleanup();
                Frames.Add(frameData);
            }
        }
Ejemplo n.º 25
0
 public void Add(long key, Texture2D data)
 {
     if (this.Get(key) == null)
     {
         if (this.m_CacheQueue[this.m_CacheQueueFront] != -1L)
         {
             long      key2 = this.m_CacheQueue[this.m_CacheQueueFront];
             Texture2D t;
             if (this.m_Cache.TryGetValue(key2, out t))
             {
                 this.m_Cache.Remove(key2);
                 ProfilerProperty.ReleaseUISystemProfilerRender(t);
             }
         }
         this.m_CacheQueue[this.m_CacheQueueFront] = key;
         this.m_Cache[key] = data;
         this.m_CacheQueueFront++;
         if (this.m_CacheQueueFront == this.m_Capacity)
         {
             this.m_CacheQueueFront = 0;
         }
     }
 }
Ejemplo n.º 26
0
        public static FunctionData Create(ProfilerProperty property)
        {
            var functionData = new FunctionData();
            var columns      = Enum.GetValues(typeof(ProfilerColumn));

            functionData.values       = new FunctionDataValue[columns.Length];
            functionData.functionPath = property.propertyPath;
            for (int i = 0; i < columns.Length; ++i)
            {
                var column = (ProfilerColumn)columns.GetValue(i);
#if UNITY_5_5_OR_NEWER
                if (column == ProfilerColumn.DontSort)
                {
                    continue;
                }
#endif
                var functionDataValue = new FunctionDataValue();
                functionDataValue.column = column.ToString();
                functionDataValue.value  = property.GetColumn(column);
                functionData.values[i]   = functionDataValue;
            }
            return(functionData);
        }
Ejemplo n.º 27
0
        public override void DrawView(Rect position)
        {
            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
            ProfilerAudioView newShowDetailedAudioPane = m_ShowDetailedAudioPane;

            if (AudioDeepProfileToggle())
            {
                if (GUILayout.Toggle(newShowDetailedAudioPane == ProfilerAudioView.Channels, "Channels", EditorStyles.toolbarButton))
                {
                    newShowDetailedAudioPane = ProfilerAudioView.Channels;
                }
                if (GUILayout.Toggle(newShowDetailedAudioPane == ProfilerAudioView.Groups, "Groups", EditorStyles.toolbarButton))
                {
                    newShowDetailedAudioPane = ProfilerAudioView.Groups;
                }
                if (GUILayout.Toggle(newShowDetailedAudioPane == ProfilerAudioView.ChannelsAndGroups, "Channels and groups", EditorStyles.toolbarButton))
                {
                    newShowDetailedAudioPane = ProfilerAudioView.ChannelsAndGroups;
                }
                if (Unsupported.IsDeveloperMode() && GUILayout.Toggle(newShowDetailedAudioPane == ProfilerAudioView.DSPGraph, "DSP Graph", EditorStyles.toolbarButton))
                {
                    newShowDetailedAudioPane = ProfilerAudioView.DSPGraph;
                }
                if (Unsupported.IsDeveloperMode() && GUILayout.Toggle(newShowDetailedAudioPane == ProfilerAudioView.Clips, "Clips", EditorStyles.toolbarButton))
                {
                    newShowDetailedAudioPane = ProfilerAudioView.Clips;
                }
                if (newShowDetailedAudioPane != m_ShowDetailedAudioPane)
                {
                    m_ShowDetailedAudioPane  = newShowDetailedAudioPane;
                    m_LastAudioProfilerFrame = -1; // force update
                }
                if (m_ShowDetailedAudioPane == ProfilerAudioView.DSPGraph)
                {
                    m_ShowInactiveDSPChains = GUILayout.Toggle(m_ShowInactiveDSPChains, "Show inactive", EditorStyles.toolbarButton);
                    if (m_ShowInactiveDSPChains)
                    {
                        m_HighlightAudibleDSPChains = GUILayout.Toggle(m_HighlightAudibleDSPChains, "Highlight audible", EditorStyles.toolbarButton);
                    }
                    GUILayout.FlexibleSpace();
                    EditorGUILayout.EndHorizontal();

                    var graphRect = DrawAudioStatsPane(ref m_PaneScroll_AudioDSPLeft);

                    m_PaneScroll_AudioDSPRight = GUI.BeginScrollView(graphRect, m_PaneScroll_AudioDSPRight, new Rect(0, 0, 10000, 20000));

                    var clippingRect = new Rect(m_PaneScroll_AudioDSPRight.x, m_PaneScroll_AudioDSPRight.y, graphRect.width, graphRect.height);

                    if (m_AudioProfilerDSPView == null)
                    {
                        m_AudioProfilerDSPView = new AudioProfilerDSPView();
                    }

                    ProfilerProperty property = m_ProfilerWindow.CreateProperty();
                    if (CheckFrameData(property))
                    {
                        m_AudioProfilerDSPView.OnGUI(clippingRect, property, m_ShowInactiveDSPChains, m_HighlightAudibleDSPChains, ref m_DSPGraphZoomFactor, ref m_PaneScroll_AudioDSPRight);
                    }
                    if (property != null)
                    {
                        property.Dispose();
                    }

                    GUI.EndScrollView();

                    m_ProfilerWindow.Repaint();
                }
                else if (m_ShowDetailedAudioPane == ProfilerAudioView.Clips)
                {
                    GUILayout.FlexibleSpace();
                    EditorGUILayout.EndHorizontal();

                    var treeRect = DrawAudioStatsPane(ref m_PaneScroll_AudioClips);

                    // TREE
                    if (m_AudioProfilerClipTreeViewState == null)
                    {
                        m_AudioProfilerClipTreeViewState = new AudioProfilerClipTreeViewState();
                    }

                    if (m_AudioProfilerClipViewBackend == null)
                    {
                        m_AudioProfilerClipViewBackend = new AudioProfilerClipViewBackend(m_AudioProfilerClipTreeViewState);
                    }

                    ProfilerProperty property = m_ProfilerWindow.CreateProperty();
                    if (CheckFrameData(property))
                    {
                        var currentFrame = m_ProfilerWindow.GetActiveVisibleFrameIndex();
                        if (currentFrame == -1 || m_LastAudioProfilerFrame != currentFrame)
                        {
                            m_LastAudioProfilerFrame = currentFrame;
                            var sourceItems = property.GetAudioProfilerClipInfo();
                            if (sourceItems != null && sourceItems.Length > 0)
                            {
                                var items = new List <AudioProfilerClipInfoWrapper>();
                                foreach (var s in sourceItems)
                                {
                                    items.Add(new AudioProfilerClipInfoWrapper(s, property.GetAudioProfilerNameByOffset(s.assetNameOffset)));
                                }
                                m_AudioProfilerClipViewBackend.SetData(items);
                                if (m_AudioProfilerClipView == null)
                                {
                                    m_AudioProfilerClipView = new AudioProfilerClipView(m_ProfilerWindow as EditorWindow, m_AudioProfilerClipTreeViewState);
                                    m_AudioProfilerClipView.Init(treeRect, m_AudioProfilerClipViewBackend);
                                }
                            }
                        }
                        if (m_AudioProfilerClipView != null)
                        {
                            m_AudioProfilerClipView.OnGUI(treeRect);
                        }
                    }
                    if (property != null)
                    {
                        property.Dispose();
                    }
                }
                else
                {
                    bool resetAllAudioClipPlayCountsOnPlay = GUILayout.Toggle(AudioUtil.resetAllAudioClipPlayCountsOnPlay, "Reset play count on play", EditorStyles.toolbarButton);
                    if (resetAllAudioClipPlayCountsOnPlay != AudioUtil.resetAllAudioClipPlayCountsOnPlay)
                    {
                        AudioUtil.resetAllAudioClipPlayCountsOnPlay = resetAllAudioClipPlayCountsOnPlay;
                    }
                    if (Unsupported.IsDeveloperMode())
                    {
                        GUILayout.Space(5);
                        bool showAllGroups    = EditorPrefs.GetBool("AudioProfilerShowAllGroups");
                        bool newShowAllGroups = GUILayout.Toggle(showAllGroups, "Show all groups (dev mode only)", EditorStyles.toolbarButton);
                        if (showAllGroups != newShowAllGroups)
                        {
                            EditorPrefs.SetBool("AudioProfilerShowAllGroups", newShowAllGroups);
                        }
                    }
                    GUILayout.FlexibleSpace();
                    EditorGUILayout.EndHorizontal();

                    var treeRect = DrawAudioStatsPane(ref m_PaneScroll_AudioChannels);

                    // TREE
                    if (m_AudioProfilerGroupTreeViewState == null)
                    {
                        m_AudioProfilerGroupTreeViewState = new AudioProfilerGroupTreeViewState();
                    }

                    if (m_AudioProfilerGroupViewBackend == null)
                    {
                        m_AudioProfilerGroupViewBackend = new AudioProfilerGroupViewBackend(m_AudioProfilerGroupTreeViewState);
                    }

                    ProfilerProperty property = m_ProfilerWindow.CreateProperty();
                    if (CheckFrameData(property))
                    {
                        var currentFrame = m_ProfilerWindow.GetActiveVisibleFrameIndex();
                        if (currentFrame == -1 || m_LastAudioProfilerFrame != currentFrame)
                        {
                            m_LastAudioProfilerFrame = currentFrame;
                            var sourceItems = property.GetAudioProfilerGroupInfo();
                            if (sourceItems != null && sourceItems.Length > 0)
                            {
                                var items = new List <AudioProfilerGroupInfoWrapper>();
                                foreach (var s in sourceItems)
                                {
                                    bool isGroup = (s.flags & AudioProfilerGroupInfoHelper.AUDIOPROFILER_FLAGS_GROUP) != 0;
                                    if (m_ShowDetailedAudioPane == ProfilerAudioView.Channels && isGroup)
                                    {
                                        continue;
                                    }
                                    if (m_ShowDetailedAudioPane == ProfilerAudioView.Groups && !isGroup)
                                    {
                                        continue;
                                    }
                                    items.Add(new AudioProfilerGroupInfoWrapper(s, property.GetAudioProfilerNameByOffset(s.assetNameOffset), property.GetAudioProfilerNameByOffset(s.objectNameOffset), m_ShowDetailedAudioPane == ProfilerAudioView.Channels));
                                }
                                m_AudioProfilerGroupViewBackend.SetData(items);
                                if (m_AudioProfilerGroupView == null)
                                {
                                    m_AudioProfilerGroupView = new AudioProfilerGroupView(m_ProfilerWindow as EditorWindow, m_AudioProfilerGroupTreeViewState);
                                    m_AudioProfilerGroupView.Init(treeRect, m_AudioProfilerGroupViewBackend);
                                }
                            }
                        }
                        if (m_AudioProfilerGroupView != null)
                        {
                            m_AudioProfilerGroupView.OnGUI(treeRect, m_ShowDetailedAudioPane == ProfilerAudioView.Channels);
                        }
                    }
                    if (property != null)
                    {
                        property.Dispose();
                    }
                }
            }
            else
            {
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
                DrawOverviewText(ProfilerArea.Audio, position);
            }
        }
Ejemplo n.º 28
0
 static bool CheckFrameData(ProfilerProperty property)
 {
     return(property != null && property.frameDataReady);
 }
Ejemplo n.º 29
0
 private Texture2D Generate(int frameIndex, int renderDataIndex, int renderDataCount, bool overdraw)
 {
     return(m_Disposed ? null : ProfilerProperty.UISystemProfilerRender(frameIndex, renderDataIndex, renderDataCount, overdraw));
 }
        static void Update()
        {
            var stopFrameIndex = ProfilerDriver.lastFrameIndex;


            var frameIndex = Math.Max(frameCursor + 1, ProfilerDriver.firstFrameIndex);

            while (frameIndex <= stopFrameIndex)
            {
                var samples   = new Dictionary <int, StackSample>();
                var relations = new Dictionary <int, int>();

                var cursor   = new Stack <int>();
                var sequence = 0;

                var root = new ProfilerProperty();
                root.SetRoot(frameIndex, ProfilerColumn.TotalTime, ProfilerViewType.Hierarchy);
                root.onlyShowGPUSamples = false;
                while (root.Next(true))
                {
                    var depth = root.depth;
                    while (cursor.Count + 1 > depth)
                    {
                        cursor.Pop();
                    }

                    var drawCalls = root.GetColumnAsSingle(ProfilerColumn.DrawCalls);
                    samples.Add(sequence, new StackSample
                    {
                        id           = sequence,
                        name         = root.propertyName,
                        callsCount   = (int)root.GetColumnAsSingle(ProfilerColumn.Calls),
                        gcAllocBytes = (int)root.GetColumnAsSingle(ProfilerColumn.GCMemory),
                        totalTime    = root.GetColumnAsSingle(ProfilerColumn.TotalTime),
                        selfTime     = root.GetColumnAsSingle(ProfilerColumn.SelfTime),
                    });

                    if (cursor.Count != 0)
                    {
                        relations[sequence] = cursor.Peek();
                    }

                    if (root.HasChildren)
                    {
                        cursor.Push(sequence);
                    }

                    ++sequence;
                }

                // encode frame index
                var frameFPS = float.Parse(root.frameFPS);
                stream.Write(frameIndex);
                stream.Write(string.IsNullOrEmpty(root.frameTime) ? (1000f / frameFPS) : float.Parse(root.frameTime));
                stream.Write(frameFPS);

                //encode statistics
                for (var area = 0; area < profilerAreaCount; area++)
                {
                    var statistics = metadatas[(int)area];
                    stream.Write((byte)area);
                    for (var i = 0; i < statistics.Count; i++)
                    {
                        var maxValue   = 0.0f;
                        var identifier = statistics[i];
                        ProfilerDriver.GetStatisticsValues(identifier, frameIndex, 1.0f, provider, out maxValue);
                        stream.Write(provider[0]);
                    }
                }

                // encode samples
                stream.Write(samples.Count);
                foreach (var pair in samples)
                {
                    var v = pair.Value;
                    stream.Write(v.id);
                    stream.Write(getStringRef(v.name));
                    stream.Write(v.callsCount);
                    stream.Write(v.gcAllocBytes);
                    stream.Write(v.totalTime);
                    stream.Write(v.selfTime);
                }
                // encode relations
                stream.Write(relations.Count);
                foreach (var pair in relations)
                {
                    stream.Write(pair.Key);
                    stream.Write(pair.Value);
                }
                stream.Write((uint)0x12345678); // magic number

                // next frame
                ++frameIndex;
            }

            frameCursor = stopFrameIndex;
        }