Example #1
0
        public static PtInfo[] BuildTrackerList(PtInfo[] previousTrackers, ColumnId sortBy, bool sortAsc, bool sort = true)
        {
            var trackerNames = EditorPerformanceTracker.GetAvailableTrackers();
            var trackers     = new PtInfo[trackerNames.Length];

            for (int i = 0; i < trackerNames.Length; ++i)
            {
                var trackerName = trackerNames[i];
                if (!EditorPerformanceTracker.Exists(trackerName))
                {
                    continue;
                }
                trackers[i].name        = trackerName;
                trackers[i].sampleCount = EditorPerformanceTracker.GetSampleCount(trackerName);
                trackers[i].peakTime    = EditorPerformanceTracker.GetPeakTime(trackerName);
                trackers[i].avgTime     = EditorPerformanceTracker.GetAverageTime(trackerName);
                trackers[i].totalTime   = EditorPerformanceTracker.GetTotalTime(trackerName);
                trackers[i].lastTime    = EditorPerformanceTracker.GetLastTime(trackerName);
                trackers[i].usage       = EditorPerformanceTracker.GetTotalUsage(trackerName);
                trackers[i].timestamp   = EditorPerformanceTracker.GetTimestamp(trackerName);
                trackers[i].updated     = false;

                // Tracker previous changes
                var pti = FindTrackerIndex(trackerName, previousTrackers);
                if (pti == -1)
                {
                    continue;
                }

                var ppt = previousTrackers[pti];
                trackers[i].dtSampleCount = trackers[i].sampleCount - ppt.sampleCount;
                trackers[i].dtPeakTime    = trackers[i].peakTime - ppt.peakTime;
                trackers[i].dtLastTime    = trackers[i].lastTime - ppt.lastTime;
                trackers[i].dtAvgTime     = trackers[i].avgTime - ppt.avgTime;
                trackers[i].updated       = trackers[i].dtSampleCount > 0;
            }

            if (sort)
            {
                Sort(trackers, sortBy, sortAsc);
            }

            return(trackers);
        }
Example #2
0
 public static string FormatAgeToolTip(PtInfo t)
 {
     return($"Occurred {t.timestamp} second(s) after startup");
 }
Example #3
0
 public static string FormatAge(PtInfo t, double currentTime)
 {
     return(t.updated ? $"{ToEngineeringNotation(currentTime - t.timestamp)}s" : "---");
 }
Example #4
0
 private bool IsPinnedTracker(PtInfo tracker)
 {
     return(m_PinnedTrackerNames.Contains(tracker.name));
 }
Example #5
0
        private void BindTracker(VisualElement element, PtInfo tracker, int modelIndex, List <PtInfo> trackerList)
        {
            element.style.backgroundColor = (modelIndex % 2) == 0 ? PtStyles.evenRowColor : PtStyles.oddRowColor;
            element.userData = new RowUserData
            {
                tracker    = tracker,
                modelIndex = modelIndex
            };

            var columnIndex = 0;
            var pinIcon     = element.ElementAt(columnIndex++);

            if (pinIcon != null)
            {
                if (pinIcon.userData != null)
                {
                    pinIcon.UnregisterCallback((EventCallback <MouseDownEvent>)pinIcon.userData);
                }
                EventCallback <MouseDownEvent> mouseDownCallback = evt => { TogglePinnedItem(modelIndex, trackerList); };
                pinIcon.userData = mouseDownCallback;
                pinIcon.RegisterCallback(mouseDownCallback);

                if (IsPinnedTracker(tracker))
                {
                    pinIcon.EnableInClassList("perf-pin-off", false);
                    pinIcon.EnableInClassList("perf-pin-on", true);
                }
                else
                {
                    pinIcon.EnableInClassList("perf-pin-off", true);
                    pinIcon.EnableInClassList("perf-pin-on", false);
                }
            }

            // Implement trackerName as a TextField to support text selection.
            var trackerName = element.ElementAt(columnIndex++) as TextField;

            if (trackerName.value != tracker.name)
            {
                trackerName.value = tracker.name;
            }

            if (IsColumnVisible(ColumnId.SampleCount))
            {
                var sampleCount = element.ElementAt(columnIndex++) as Button;
                sampleCount.text = tracker.sampleCount.ToString();
            }

            if (IsColumnVisible(ColumnId.Age))
            {
                var age = element.ElementAt(columnIndex++) as Label;
                age.text        = PtModel.FormatAge(tracker, EditorApplication.timeSinceStartup);
                age.style.color = tracker.updated ? PtStyles.warningColor : PtStyles.normalColor;
            }

            if (IsColumnVisible(ColumnId.PeakTime))
            {
                var peakTime = element.ElementAt(columnIndex++) as Label;
                peakTime.text        = PtModel.FormatTime(tracker.peakTime, tracker.dtPeakTime);
                peakTime.style.color = GetLabelTimeColor(tracker.peakTime, 0.5, 1.0);
            }

            if (IsColumnVisible(ColumnId.AvgTime))
            {
                var avgTime = element.ElementAt(columnIndex++) as Label;
                avgTime.text        = PtModel.FormatTime(tracker.avgTime, tracker.dtAvgTime);
                avgTime.style.color = GetLabelTimeColor(tracker.avgTime, 0.1, 0.5);
            }

            if (IsColumnVisible(ColumnId.LastTime))
            {
                var lastTime = element.ElementAt(columnIndex++) as Label;
                lastTime.text        = PtModel.FormatTimeChange(tracker.lastTime, tracker.dtLastTime);
                lastTime.style.color = GetLabelTimeChangeColor(tracker.dtLastTime);
            }

            if (IsColumnVisible(ColumnId.TotalTime))
            {
                var totalTime = element.ElementAt(columnIndex++) as Label;
                totalTime.text        = PtModel.FormatTimeRate(tracker.totalTime, tracker.usage);
                totalTime.style.color = GetLabelTimeColor(tracker.totalTime, 5, 10.0);
            }

            var actionBtn = element.ElementAt(columnIndex++) as Button;

            UpdateActionButton(actionBtn, tracker.name);
        }