bool SelectAllFramesContainingMarker(string markerName, ProfileAnalysis inAnalysis)
        {
            if (inAnalysis == null)
            {
                return(false);
            }

            selectedIndices.Clear();

            MarkerData markerData = inAnalysis.GetMarkerByName(markerName);

            if (markerData == null)
            {
                return(true);
            }

            foreach (var frameTime in markerData.frames)
            {
                selectedIndices.Add(frameTime.frameIndex);
            }

            // Order from lowest to highest so the start/end frame display makes sense
            selectedIndices.Sort();

            return(true);
        }
Example #2
0
        int SortByAtMedian(MarkerData a, MarkerData b)
        {
            if (a.msAtMedian == b.msAtMedian)
            {
                return(-a.medianFrameIndex.CompareTo(b.medianFrameIndex));
            }

            return(-a.msAtMedian.CompareTo(b.msAtMedian));
        }
        int CalculateDepthDifference(ProfileAnalysis leftAnalysis, ProfileAnalysis rightAnalysis, List <MarkerPairing> pairings)
        {
            if (pairings.Count <= 0)
            {
                mostCommonDepthDiff = 0;
                return(0);
            }

            var leftMarkers  = leftAnalysis.GetMarkers();
            var rightMarkers = rightAnalysis.GetMarkers();

            int totalCount = 0;
            Dictionary <int, int> depthDifferences = new Dictionary <int, int>();

            foreach (var pairing in pairings)
            {
                if (pairing.leftIndex >= 0 && pairing.rightIndex >= 0)
                {
                    MarkerData leftMarker      = leftMarkers[pairing.leftIndex];
                    MarkerData rightMarker     = rightMarkers[pairing.rightIndex];
                    int        markerDepthDiff = rightMarker.minDepth - leftMarker.minDepth;

                    int value = 0;
                    depthDifferences.TryGetValue(markerDepthDiff, out value);
                    depthDifferences[markerDepthDiff] = value + 1;
                    totalCount += 1;
                }
            }

            var newDepthDiff = 0;

            // Find most common depth difference
            int maxCount = 0;

            foreach (var diff in depthDifferences.Keys)
            {
                if (depthDifferences[diff] > maxCount)
                {
                    maxCount     = depthDifferences[diff];
                    newDepthDiff = diff;
                }
            }

            return(mostCommonDepthDiff = newDepthDiff);
        }
        public List <FrameTime> GetTopNByTime(MarkerData marker, int n)
        {
            if (marker.frames.Count <= 0)
            {
                return(new List <FrameTime>());
            }

            List <FrameTime> sortedFrames = new List <FrameTime>(marker.frames);

            sortedFrames.Sort(FrameTime.CompareMsDescending);

            var frameTimes = new List <FrameTime>();

            for (int i = 0; i < Math.Min(n, sortedFrames.Count); i++)
            {
                frameTimes.Add(sortedFrames[i]);
            }

            return(frameTimes);
        }
        private bool SelectAllFramesContainingMarker(string markerName, ProfileAnalysis inAnalysis)
        {
            if (inAnalysis == null)
            {
                return(false);
            }

            MarkerData markerData = inAnalysis.GetMarkerByName(markerName);

            if (markerData == null)
            {
                return(false);
            }

            selectedIndices.Clear();
            foreach (var frameTime in markerData.frames)
            {
                selectedIndices.Add(frameTime.frameIndex);
            }

            return(true);
        }
 public static float GetCountMean(MarkerData marker)
 {
     return(marker != null ? marker.countMean : 0.0f);
 }
 public static double GetMsTotal(MarkerData marker)
 {
     return(marker != null ? marker.msTotal : 0.0);
 }
Example #8
0
 float RightCountMean(ComparisonTreeViewItem item)
 {
     return(MarkerData.GetCountMean(GetRightMarker(item)));
 }
 public static int GetCount(MarkerData marker)
 {
     return(marker != null ? marker.count : 0);
 }
        public void Draw(ProfileAnalysis analysis, Rect rect, Color barColor, int barCount, float timeRange, int depthFilter, Color selectedBackground, Color selectedBorder, Color selectedText, bool includeOthers, bool includeUnaccounted)
        {
            if (analysis == null)
            {
                return;
            }

            FrameSummary frameSummary = analysis.GetFrameSummary();

            if (frameSummary == null)
            {
                return;
            }

            var markers = analysis.GetMarkers();

            if (markers == null)
            {
                return;
            }

            // Start by adding frame link button for median frame
            int  buttonWidth = 50;
            int  buttonWidthWithoutMargins = buttonWidth - 4;
            Rect buttonRect = new Rect(rect.x, rect.y, buttonWidthWithoutMargins, rect.height);

            m_ProfileAnalyzerWindow.DrawFrameIndexButton(buttonRect, frameSummary.medianFrameIndex);

            // After the marker graph we want an indication of the time range
            int    rangeLabelWidth  = 60;
            Rect   rangeLabelRect   = new Rect(rect.x + rect.width - rangeLabelWidth, rect.y, rangeLabelWidth, rect.height);
            string timeRangeString  = ToDisplayUnits(timeRange, true);
            string frameTimeString  = ToDisplayUnits(frameSummary.msMedian, true, 0);
            string timeRangeTooltip = string.Format("{0} median frame time", frameTimeString);

            GUI.Label(rangeLabelRect, new GUIContent(timeRangeString, timeRangeTooltip));

            // Reduce the size of the marker graph for the button/label we just added
            rect.x     += buttonWidth;
            rect.width -= (buttonWidth + rangeLabelWidth);

            // Show marker graph
            float x      = 0;
            float y      = 0;
            float width  = rect.width;
            float height = rect.height;

            int max = barCount;
            int at  = 0;

            var   selectedPairingMarkerName = m_ProfileAnalyzerWindow.GetSelectedMarkerName();
            float spacing = 2;

            float other = 0.0f;

            List <string> nameFilters  = m_ProfileAnalyzerWindow.GetNameFilters();
            List <string> nameExcludes = m_ProfileAnalyzerWindow.GetNameExcludes();

            if (timeRange <= 0.0f)
            {
                timeRange = frameSummary.msMedian;
            }

            float msToWidth = (width - spacing) / timeRange;

            float totalMarkerTime = 0;

            if (m_2D.DrawStart(rect, Draw2D.Origin.BottomLeft))
            {
                m_2D.DrawFilledBox(x, y, width, height, m_BackgroundColor);

                foreach (var marker in markers)
                {
                    float ms = MarkerData.GetMsAtMedian(marker);
                    totalMarkerTime += ms;

                    if (depthFilter >= 0 && marker.minDepth != depthFilter)
                    {
                        continue;
                    }

                    if (nameFilters.Count > 0)
                    {
                        if (!m_ProfileAnalyzerWindow.NameInFilterList(marker.name, nameFilters))
                        {
                            continue;
                        }
                    }
                    if (nameExcludes.Count > 0)
                    {
                        if (m_ProfileAnalyzerWindow.NameInExcludeList(marker.name, nameExcludes))
                        {
                            continue;
                        }
                    }

                    if (at < max)
                    {
                        float w = ms * msToWidth;
                        if (x + w > width)
                        {
                            w = width - x;
                        }
                        if (marker.name == selectedPairingMarkerName)
                        {
                            m_2D.DrawFilledBox(x + 1, y + 1, w, height - 2, selectedBorder);
                            m_2D.DrawFilledBox(x + 2, y + 2, w - 2, height - 4, selectedBackground);
                        }
                        else
                        {
                            m_2D.DrawFilledBox(x + 2, y + 2, w - 2, height - 4, barColor);
                        }

                        x += w;
                    }
                    else
                    {
                        other += ms;
                        if (!includeOthers)
                        {
                            break;
                        }
                    }

                    at++;
                }

                if (includeOthers && other > 0.0f)
                {
                    x += DrawBar(x, y, other, msToWidth, width, height, barColor);
                }
                if (includeUnaccounted && totalMarkerTime < frameSummary.msMedian)
                {
                    float unaccounted = frameSummary.msMedian - totalMarkerTime;
                    Color color       = new Color(barColor.r * 0.5f, barColor.g * 0.5f, barColor.b * 0.5f, barColor.a);
                    x += DrawBar(x, y, unaccounted, msToWidth, width, height, color);
                }

                m_2D.DrawEnd();
            }
            else if (includeOthers)
            {
                // Need to calculate the size of the others for the input phase if not drawing at this time
                at = 0;
                foreach (var marker in markers)
                {
                    float ms = MarkerData.GetMsAtMedian(marker);
                    totalMarkerTime += ms;

                    if (depthFilter >= 0 && marker.minDepth != depthFilter)
                    {
                        continue;
                    }

                    if (nameFilters.Count > 0)
                    {
                        if (!m_ProfileAnalyzerWindow.NameInFilterList(marker.name, nameFilters))
                        {
                            continue;
                        }
                    }
                    if (nameExcludes.Count > 0)
                    {
                        if (m_ProfileAnalyzerWindow.NameInExcludeList(marker.name, nameExcludes))
                        {
                            continue;
                        }
                    }

                    if (at >= max)
                    {
                        other += ms;
                        if (!includeOthers)
                        {
                            break;
                        }
                    }

                    at++;
                }
            }

            at = 0;
            x  = 0.0f;
            GUIStyle centreAlignStyle = new GUIStyle(GUI.skin.label);

            centreAlignStyle.alignment        = TextAnchor.MiddleCenter;
            centreAlignStyle.normal.textColor = m_TextColor;
            GUIStyle leftAlignStyle = new GUIStyle(GUI.skin.label);

            leftAlignStyle.alignment        = TextAnchor.MiddleLeft;
            leftAlignStyle.normal.textColor = m_TextColor;
            Color contentColor = GUI.contentColor;

            for (int index = 0; index < markers.Count; index++)
            {
                var marker = markers[index];
                if (depthFilter >= 0 && marker.minDepth != depthFilter)
                {
                    continue;
                }

                if (nameFilters.Count > 0)
                {
                    if (!m_ProfileAnalyzerWindow.NameInFilterList(marker.name, nameFilters))
                    {
                        continue;
                    }
                }
                if (nameExcludes.Count > 0)
                {
                    if (m_ProfileAnalyzerWindow.NameInExcludeList(marker.name, nameExcludes))
                    {
                        continue;
                    }
                }

                if (at < max)
                {
                    float w = MarkerData.GetMsAtMedian(marker) * msToWidth;
                    if (x + w > width)
                    {
                        w = width - x;
                    }

                    Rect     labelRect   = new Rect(rect.x + x, rect.y, w, rect.height);
                    GUIStyle style       = centreAlignStyle;
                    String   displayName = "";
                    if (w >= 20)
                    {
                        displayName = marker.name;
                        Vector2 size = centreAlignStyle.CalcSize(new GUIContent(marker.name));
                        if (size.x > w)
                        {
                            var words = marker.name.Split('.');
                            displayName = words[words.Length - 1];
                            style       = leftAlignStyle;
                        }
                    }
                    float  percentAtMedian = MarkerData.GetMsAtMedian(marker) * 100 / timeRange;
                    string tooltip         = string.Format("{0}\n{1:f2}% ({2} on median frame {3})\n\nMedian marker time (in currently selected frames)\n{4} on frame {5}",
                                                           marker.name,
                                                           percentAtMedian, ToDisplayUnits(marker.msAtMedian, true, 0), frameSummary.medianFrameIndex,
                                                           ToDisplayUnits(marker.msMedian, true, 0), marker.medianFrameIndex);
                    if (marker.name == selectedPairingMarkerName)
                    {
                        style.normal.textColor = selectedText;
                    }
                    else
                    {
                        style.normal.textColor = m_TextColor;
                    }
                    GUI.Label(labelRect, new GUIContent(displayName, tooltip), style);

                    Event current = Event.current;
                    if (labelRect.Contains(current.mousePosition))
                    {
                        if (current.type == EventType.ContextClick)
                        {
                            GenericMenu menu = new GenericMenu();

                            menu.AddItem(Styles.menuItemSelectFramesInAll, false, () => m_ProfileAnalyzerWindow.SelectFramesContainingMarker(marker.name, false));
                            menu.AddItem(Styles.menuItemSelectFramesInCurrent, false, () => m_ProfileAnalyzerWindow.SelectFramesContainingMarker(marker.name, true));
                            menu.AddItem(Styles.menuItemSelectFramesAll, false, m_ProfileAnalyzerWindow.SelectAllFrames);
                            menu.AddSeparator("");
                            if (!m_ProfileAnalyzerWindow.GetNameFilters().Contains(marker.name))
                            {
                                menu.AddItem(Styles.menuItemAddToIncludeFilter, false, () => m_ProfileAnalyzerWindow.AddToIncludeFilter(marker.name));
                            }
                            else
                            {
                                menu.AddItem(Styles.menuItemRemoveFromIncludeFilter, false, () => m_ProfileAnalyzerWindow.RemoveFromIncludeFilter(marker.name));
                            }
                            if (!m_ProfileAnalyzerWindow.GetNameExcludes().Contains(marker.name))
                            {
                                menu.AddItem(Styles.menuItemAddToExcludeFilter, false, () => m_ProfileAnalyzerWindow.AddToExcludeFilter(marker.name));
                            }
                            else
                            {
                                menu.AddItem(Styles.menuItemRemoveFromExcludeFilter, false, () => m_ProfileAnalyzerWindow.RemoveFromExcludeFilter(marker.name));
                            }
                            menu.AddSeparator("");
                            menu.AddItem(Styles.menuItemSetAsParentMarkerFilter, false, () => m_ProfileAnalyzerWindow.SetAsParentMarkerFilter(marker.name));
                            menu.AddItem(Styles.menuItemClearParentMarkerFilter, false, () => m_ProfileAnalyzerWindow.SetAsParentMarkerFilter(""));
                            menu.AddSeparator("");
                            menu.AddItem(Styles.menuItemCopyToClipboard, false, () => CopyToClipboard(current, marker.name));

                            menu.ShowAsContext();

                            current.Use();
                        }
                        if (current.type == EventType.MouseDown)
                        {
                            m_ProfileAnalyzerWindow.SelectMarker(marker.name);
                            m_ProfileAnalyzerWindow.RequestRepaint();
                        }
                    }

                    x += w;
                }
                else
                {
                    break;
                }

                at++;
            }

            if (includeOthers)
            {
                x += DrawBarText(rect, x, other, "Others", msToWidth, timeRange, leftAlignStyle, frameSummary.medianFrameIndex);
            }
            if (includeUnaccounted && totalMarkerTime < frameSummary.msMedian)
            {
                float unaccounted = frameSummary.msMedian - totalMarkerTime;
                x += DrawBarText(rect, x, unaccounted, "Unaccounted", msToWidth, timeRange, leftAlignStyle, frameSummary.medianFrameIndex);
            }
        }
        public int Draw(MarkerData marker, int topNumber, string[] topStrings, int[] topValues)
        {
            GUIStyle style     = GUI.skin.label;
            float    w         = m_WidthColumn0;
            float    h         = style.lineHeight;
            float    ySpacing  = 2;
            float    barHeight = h - ySpacing;

            EditorGUILayout.BeginVertical(GUILayout.Width(w + m_WidthColumn1 + m_WidthColumn2 + m_WidthColumn3));

            topNumber = DrawTopNumber(topNumber, topStrings, topValues);

            /*
             * EditorGUILayout.BeginHorizontal();
             * EditorGUILayout.LabelField("", GUILayout.Width(w));
             * EditorGUILayout.LabelField("Value", GUILayout.Width(LayoutSize.WidthColumn1));
             * EditorGUILayout.LabelField("Frame", GUILayout.Width(LayoutSize.WidthColumn2));
             * EditorGUILayout.EndHorizontal();
             */

            // var frameSummary = m_ProfileSingleView.analysis.GetFrameSummary();
            float barMax = marker.msMax; // frameSummary.msMax

            if (m_Units.Units == Units.Count)
            {
                barMax = marker.countMax;
            }

            // Marker frames are ordered by frame time
            // If we are sorting by count then we need to apply a sort
            bool             showCount = m_Units.Units == Units.Count;
            List <FrameTime> frames    = GetTopN(marker, topNumber, showCount);

            foreach (FrameTime frameTime in frames)
            {
                float barValue  = (m_Units.Units == Units.Count) ? frameTime.count : frameTime.ms;
                float barLength = Math.Min((w * barValue) / barMax, w);

                EditorGUILayout.BeginHorizontal();
                if (m_2D.DrawStart(w, h, Draw2D.Origin.TopLeft, style))
                {
                    m_2D.DrawFilledBox(0, ySpacing, barLength, barHeight, colorBar);
                    m_2D.DrawFilledBox(barLength, ySpacing, w - barLength, barHeight, colorBarBackground);
                    m_2D.DrawEnd();

                    Rect rect = GUILayoutUtility.GetLastRect();
                    GUI.Label(rect, new GUIContent("", m_Units.ToString(barValue, true, 5)));
                }
                EditorGUILayout.LabelField(ToDisplayUnitsWithTooltips(barValue, true), GUILayout.Width(m_WidthColumn2));
                if (m_DrawFrameIndexButton != null)
                {
                    m_DrawFrameIndexButton(frameTime.frameIndex);
                }
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
            }

            // Show blank space for missing frames
            var     content = new GUIContent("", "");
            Vector2 size    = GUI.skin.button.CalcSize(content);

            h = Math.Max(barHeight, size.y);
            for (int i = frames.Count; i < topNumber; i++)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("", GUILayout.Height(h));
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndVertical();

            return(topNumber);
        }
 public static int GetMedianFrameIndex(MarkerData marker)
 {
     return(marker != null ? marker.medianFrameIndex : 0);
 }
 private int SortByAtMedian(MarkerData a, MarkerData b)
 {
     return(-a.msAtMedian.CompareTo(b.msAtMedian));
 }
        public MarkerSummary CalculateTopMarkers()
        {
            if (m_CurrentSettings.rangeSettings.dataView == null)
            {
                return(null);
            }

            ProfileAnalysis analysis = m_CurrentSettings.rangeSettings.dataView.analysis;

            if (analysis == null)
            {
                return(null);
            }

            FrameSummary frameSummary = analysis.GetFrameSummary();

            if (frameSummary == null)
            {
                return(new MarkerSummary());
            }

            var markers = analysis.GetMarkers();

            if (markers == null)
            {
                return(new MarkerSummary());
            }

            float         timeRange    = m_CurrentSettings.timeRange;
            int           depthFilter  = m_CurrentSettings.rangeSettings.depthFilter;
            List <string> nameFilters  = m_CurrentSettings.rangeSettings.nameFilters;
            List <string> nameExcludes = m_CurrentSettings.rangeSettings.nameExcludes;

            // Show marker graph
            float x     = 0;
            float width = 1.0f;

            int max = m_CurrentSettings.barCount;
            int at  = 0;

            float other = 0.0f;

            if (timeRange <= 0.0f)
            {
                timeRange = frameSummary.msMedian;
            }

            float msToWidth = width / timeRange;

            float totalMarkerTime = 0;

            MarkerSummary markerSummary = new MarkerSummary();

            foreach (var marker in markers)
            {
                float msAtMedian = MarkerData.GetMsAtMedian(marker);
                totalMarkerTime += msAtMedian;

                if (depthFilter != ProfileAnalyzer.kDepthAll && marker.minDepth != depthFilter)
                {
                    continue;
                }

                if (nameFilters.Count > 0)
                {
                    if (!m_ProfileAnalyzerWindow.NameInFilterList(marker.name, nameFilters))
                    {
                        continue;
                    }
                }
                if (nameExcludes.Count > 0)
                {
                    if (m_ProfileAnalyzerWindow.NameInExcludeList(marker.name, nameExcludes))
                    {
                        continue;
                    }
                }

                if (at < max)
                {
                    float w                = CaculateWidth(x, msAtMedian, msToWidth, width);
                    float msMedian         = MarkerData.GetMsMedian(marker);
                    int   medianFrameIndex = m_ProfileAnalyzerWindow.GetRemappedUIFrameIndex(marker.medianFrameIndex, m_CurrentSettings.rangeSettings.dataView);
                    markerSummary.entry.Add(new MarkerSummaryEntry(marker.name, msAtMedian, msMedian, x, w, medianFrameIndex, SummaryType.Marker));

                    x += w;
                }
                else
                {
                    other += msAtMedian;
                    if (!m_CurrentSettings.includeOthers)
                    {
                        break;
                    }
                }

                at++;
            }

            if (m_CurrentSettings.includeOthers && other > 0.0f)
            {
                float w = CaculateWidth(x, other, msToWidth, width);
                markerSummary.entry.Add(new MarkerSummaryEntry("Other", other, 0f, x, w, -1, SummaryType.Other));
                x += w;
            }
            if (m_CurrentSettings.includeUnaccounted && totalMarkerTime < frameSummary.msMedian)
            {
                float unaccounted = frameSummary.msMedian - totalMarkerTime;
                float w           = CaculateWidth(x, unaccounted, msToWidth, width);
                markerSummary.entry.Add(new MarkerSummaryEntry("Unaccounted", unaccounted, 0f, x, w, -1, SummaryType.Unaccounted));
                x += w;
            }

            markerSummary.totalTime = totalMarkerTime;

            return(markerSummary);
        }
 public static float GetMsMin(MarkerData marker)
 {
     return(marker != null ? marker.msMin : 0.0f);
 }
Example #16
0
 int RightMedianFrameIndex(ComparisonTreeViewItem item)
 {
     return(MarkerData.GetMedianFrameIndex(GetRightMarker(item)));
 }
Example #17
0
 float LeftCount(ComparisonTreeViewItem item)
 {
     return(MarkerData.GetCount(GetLeftMarker(item)));
 }
Example #18
0
 public ProfileTreeViewItem(int id, int depth, string displayName, MarkerData data) : base(id, depth, displayName)
 {
     this.data       = data;
     cachedRowString = null;
 }
        public ProfileAnalysis Analyze(ProfileData profileData, List <int> selectionIndices, List <string> threadFilters, int depthFilter, bool selfTimes = false, string parentMarker = null, float timeScaleMax = 0)
        {
            m_Progress = 0;
            if (profileData == null)
            {
                return(null);
            }
            if (profileData.GetFrameCount() <= 0)
            {
                return(null);
            }

            int frameCount = selectionIndices.Count;

            if (frameCount < 0)
            {
                return(null);
            }

            if (profileData.HasFrames && !profileData.HasThreads)
            {
                if (!ProfileData.Load(profileData.FilePath, out profileData))
                {
                    return(null);
                }
            }

            bool processMarkers = (threadFilters != null);

            ProfileAnalysis analysis = new ProfileAnalysis();

            if (selectionIndices.Count > 0)
            {
                analysis.SetRange(selectionIndices[0], selectionIndices[selectionIndices.Count - 1]);
            }
            else
            {
                analysis.SetRange(0, 0);
            }

            m_threadNames.Clear();

            int maxMarkerDepthFound = 0;
            var threads             = new Dictionary <string, ThreadData>();
            var markers             = new Dictionary <string, MarkerData>();
            var allMarkers          = new Dictionary <string, int>();


            bool filteringByParentMarker = false;
            int  parentMarkerIndex       = -1;

            if (!IsNullOrWhiteSpace(parentMarker))
            {
                // Returns -1 if this marker doesn't exist in the data set
                parentMarkerIndex       = profileData.GetMarkerIndex(parentMarker);
                filteringByParentMarker = true;
            }

            int at = 0;

            foreach (int frameIndex in selectionIndices)
            {
                int frameOffset = profileData.DisplayFrameToOffset(frameIndex);
                var frameData   = profileData.GetFrame(frameOffset);
                if (frameData == null)
                {
                    continue;
                }
                var msFrame = frameData.msFrame;

                analysis.UpdateSummary(frameIndex, msFrame);

                if (processMarkers)
                {
                    // get the file reader in case we need to rebuild the markers rather than opening
                    // the file for every marker
                    for (int threadIndex = 0; threadIndex < frameData.threads.Count; threadIndex++)
                    {
                        float msTimeOfMinDepthMarkers     = 0.0f;
                        float msIdleTimeOfMinDepthMarkers = 0.0f;

                        var threadData          = frameData.threads[threadIndex];
                        var threadNameWithIndex = profileData.GetThreadName(threadData);

                        ThreadData thread;
                        if (!threads.ContainsKey(threadNameWithIndex))
                        {
                            m_threadNames.Add(threadNameWithIndex);

                            thread = new ThreadData(threadNameWithIndex);

                            analysis.AddThread(thread);
                            threads[threadNameWithIndex] = thread;

                            // Update threadsInGroup for all thread records of the same group name
                            foreach (var threadAt in threads.Values)
                            {
                                if (threadAt == thread)
                                {
                                    continue;
                                }

                                if (thread.threadGroupName == threadAt.threadGroupName)
                                {
                                    threadAt.threadsInGroup += 1;
                                    thread.threadsInGroup   += 1;
                                }
                            }
                        }
                        else
                        {
                            thread = threads[threadNameWithIndex];
                        }

                        bool include = MatchThreadFilter(threadNameWithIndex, threadFilters);

                        int parentMarkerDepth = -1;

                        if (threadData.markers.Count != threadData.markerCount)
                        {
                            if (!threadData.ReadMarkers(profileData.FilePath))
                            {
                                Debug.LogError("failed to read markers");
                            }
                        }

                        foreach (ProfileMarker markerData in threadData.markers)
                        {
                            string markerName = profileData.GetMarkerName(markerData);
                            if (!allMarkers.ContainsKey(markerName))
                            {
                                allMarkers.Add(markerName, 1);
                            }
                            // No longer counting how many times we see the marker (this saves 1/3 of the analysis time).

                            float ms          = markerData.msMarkerTotal - (selfTimes ? markerData.msChildren : 0);
                            var   markerDepth = markerData.depth;
                            if (markerDepth > maxMarkerDepthFound)
                            {
                                maxMarkerDepthFound = markerDepth;
                            }

                            if (markerDepth == 1)
                            {
                                if (markerName == "Idle")
                                {
                                    msIdleTimeOfMinDepthMarkers += ms;
                                }
                                else
                                {
                                    msTimeOfMinDepthMarkers += ms;
                                }
                            }

                            if (!include)
                            {
                                continue;
                            }

                            if (depthFilter != kDepthAll && markerDepth != depthFilter)
                            {
                                continue;
                            }

                            // If only looking for markers below the parent
                            if (filteringByParentMarker)
                            {
                                // If found the parent marker
                                if (markerData.nameIndex == parentMarkerIndex)
                                {
                                    // And we are not already below the parent higher in the depth tree
                                    if (parentMarkerDepth < 0)
                                    {
                                        // record the parent marker depth
                                        parentMarkerDepth = markerData.depth;
                                    }
                                }
                                else
                                {
                                    // If we are now above or beside the parent marker then we are done for this level
                                    if (markerData.depth <= parentMarkerDepth)
                                    {
                                        parentMarkerDepth = -1;
                                    }
                                }

                                if (parentMarkerDepth < 0)
                                {
                                    continue;
                                }
                            }

                            MarkerData marker;
                            if (markers.ContainsKey(markerName))
                            {
                                marker = markers[markerName];
                                if (!marker.threads.Contains(threadNameWithIndex))
                                {
                                    marker.threads.Add(threadNameWithIndex);
                                }
                            }
                            else
                            {
                                marker = new MarkerData(markerName);
                                marker.firstFrameIndex = frameIndex;
                                marker.minDepth        = markerDepth;
                                marker.maxDepth        = markerDepth;
                                marker.threads.Add(threadNameWithIndex);
                                analysis.AddMarker(marker);
                                markers.Add(markerName, marker);
                            }

                            marker.count   += 1;
                            marker.msTotal += ms;

                            // Individual marker time (not total over frame)
                            if (ms < marker.msMinIndividual)
                            {
                                marker.msMinIndividual         = ms;
                                marker.minIndividualFrameIndex = frameIndex;
                            }
                            if (ms > marker.msMaxIndividual)
                            {
                                marker.msMaxIndividual         = ms;
                                marker.maxIndividualFrameIndex = frameIndex;
                            }

                            // Record highest depth foun
                            if (markerDepth < marker.minDepth)
                            {
                                marker.minDepth = markerDepth;
                            }
                            if (markerDepth > marker.maxDepth)
                            {
                                marker.maxDepth = markerDepth;
                            }

                            FrameTime frameTime;
                            if (frameIndex != marker.lastFrame)
                            {
                                marker.presentOnFrameCount += 1;
                                frameTime = new FrameTime(frameIndex, ms, 1);
                                marker.frames.Add(frameTime);
                                marker.lastFrame = frameIndex;
                            }
                            else
                            {
                                frameTime = marker.frames[marker.frames.Count - 1];
                                frameTime = new FrameTime(frameTime.frameIndex, frameTime.ms + ms, frameTime.count + 1);
                                marker.frames[marker.frames.Count - 1] = frameTime;
                            }
                        }

                        if (include)
                        {
                            thread.frames.Add(new ThreadFrameTime(frameIndex, msTimeOfMinDepthMarkers, msIdleTimeOfMinDepthMarkers));
                        }
                    }
                }

                at++;
                m_Progress = (100 * at) / frameCount;
            }

            analysis.GetFrameSummary().totalMarkers = allMarkers.Count;
            analysis.Finalise(timeScaleMax, maxMarkerDepthFound);

            /*
             * foreach (int frameIndex in selectionIndices)
             * {
             *  int frameOffset = profileData.DisplayFrameToOffset(frameIndex);
             *
             *  var frameData = profileData.GetFrame(frameOffset);
             *  foreach (var threadData in frameData.threads)
             *  {
             *      var threadNameWithIndex = profileData.GetThreadName(threadData);
             *
             *      if (filterThreads && threadFilter != threadNameWithIndex)
             *          continue;
             *
             *      const bool enterChildren = true;
             *      foreach (var markerData in threadData.markers)
             *      {
             *          var markerName = markerData.name;
             *          var ms = markerData.msFrame;
             *          var markerDepth = markerData.depth;
             *          if (depthFilter != kDepthAll && markerDepth != depthFilter)
             *              continue;
             *
             *          MarkerData marker = markers[markerName];
             *          bucketIndex = (range > 0) ? (int)(((marker.buckets.Length-1) * (ms - first)) / range) : 0;
             *          if (bucketIndex<0 || bucketIndex > (marker.buckets.Length - 1))
             *          {
             *              // This can happen if a single marker range is longer than the frame start end (which could occur if running on a separate thread)
             *              // Debug.Log(string.Format("Marker {0} : {1}ms exceeds range {2}-{3} on frame {4}", marker.name, ms, first, last, frameIndex));
             *              if (bucketIndex > (marker.buckets.Length - 1))
             *                  bucketIndex = (marker.buckets.Length - 1);
             *              else
             *                  bucketIndex = 0;
             *          }
             *          marker.individualBuckets[bucketIndex] += 1;
             *      }
             *  }
             * }
             */
            m_Progress = 100;
            return(analysis);
        }
 public static float GetMsLowerQuartile(MarkerData marker)
 {
     return(marker != null ? marker.msLowerQuartile : 0.0f);
 }
        public int Draw(MarkerData marker, int topNumber, string[] topStrings, int[] topValues)
        {
            GUIStyle style     = GUI.skin.label;
            float    w         = m_WidthColumn0;
            float    h         = style.lineHeight;
            float    ySpacing  = 2;
            float    barHeight = h - ySpacing;

            EditorGUILayout.BeginVertical(GUILayout.Width(w + m_WidthColumn1 + m_WidthColumn2));

            topNumber = DrawTopNumber(topNumber, topStrings, topValues);

            /*
             * EditorGUILayout.BeginHorizontal();
             * EditorGUILayout.LabelField("", GUILayout.Width(w));
             * EditorGUILayout.LabelField("Value", GUILayout.Width(LayoutSize.WidthColumn1));
             * EditorGUILayout.LabelField("Frame", GUILayout.Width(LayoutSize.WidthColumn2));
             * EditorGUILayout.EndHorizontal();
             */

            // var frameSummary = m_ProfileSingleView.analysis.GetFrameSummary();
            float barMax = marker.msMax; // frameSummary.msMax

            if (m_Units.Units == Units.Count)
            {
                barMax = marker.countMax;
            }
            FrameTime zeroTime = new FrameTime(0, 0.0f, 0);

            int index = marker.frames.Count - 1;

            for (int i = 0; i < topNumber; i++)
            {
                FrameTime frameTime = new FrameTime((index >= 0) ? marker.frames[index] : zeroTime);
                float     barValue  = (m_Units.Units == Units.Count) ? frameTime.count : frameTime.ms;
                float     barLength = Math.Min((w * barValue) / barMax, w);

                EditorGUILayout.BeginHorizontal();
                if (m_2D.DrawStart(w, h, Draw2D.Origin.TopLeft, style))
                {
                    if (i < marker.frames.Count)
                    {
                        m_2D.DrawFilledBox(0, ySpacing, barLength, barHeight, colorBar);
                        m_2D.DrawFilledBox(barLength, ySpacing, w - barLength, barHeight, colorBarBackground);
                    }
                    m_2D.DrawEnd();

                    Rect rect = GUILayoutUtility.GetLastRect();
                    GUI.Label(rect, new GUIContent("", m_Units.ToString(barValue, true, 5)));
                }
                if (i < marker.frames.Count)
                {
                    EditorGUILayout.LabelField(ToDisplayUnitsWithTooltips(barValue, true), GUILayout.Width(m_WidthColumn2));
                    if (m_DrawFrameIndexButton != null)
                    {
                        m_DrawFrameIndexButton(marker.frames[index].frameIndex);
                    }
                }
                EditorGUILayout.EndHorizontal();

                index--;
            }

            EditorGUILayout.EndVertical();

            return(topNumber);
        }
Example #22
0
 float LeftMedian(ComparisonTreeViewItem item)
 {
     return(MarkerData.GetMsMedian(GetLeftMarker(item)));
 }
 public void AddMarker(MarkerData marker)
 {
     m_Markers.Add(marker);
 }
 public static int GetPresentOnFrameCount(MarkerData marker)
 {
     return(marker != null ? marker.presentOnFrameCount : 0);
 }
 public List <FrameTime> GetTopN(MarkerData marker, int n, bool showCount)
 {
     return(showCount ? GetTopNByCount(marker, n) : GetTopNByTime(marker, n));
 }
 public static float GetMsAtMedian(MarkerData marker)
 {
     return(marker != null ? marker.msAtMedian : 0.0f);
 }
 public static float GetMsMaxIndividual(MarkerData marker)
 {
     return(marker != null ? marker.msMaxIndividual : 0.0f);
 }
Example #28
0
 double RightTotal(ComparisonTreeViewItem item)
 {
     return(MarkerData.GetMsTotal(GetRightMarker(item)));
 }