コード例 #1
0
        public static TrackersReport GenerateTrackerReport(TrackerReportOptions options)
        {
            if (string.IsNullOrEmpty(options.trackerFilter))
            {
                options.trackerFilter = ".+";
            }
            var trackerRx        = new Regex(options.trackerFilter, RegexOptions.Compiled | RegexOptions.IgnoreCase);
            var trackers         = PtModel.BuildTrackerList(new PtInfo[] { }, options.sortBy, options.sortAsc, options.sort);
            var filteredTrackers = trackers.Where(tracker => trackerRx.IsMatch(tracker.name)).ToList();
            var report           = new TrackersReport()
            {
                trackers = new List <TrackerInfo>()
            };

            foreach (var tracker in filteredTrackers)
            {
                TrackerInfo info = new TrackerInfo
                {
                    avgTime     = (float)tracker.avgTime,
                    totalTime   = (float)tracker.totalTime,
                    samples     = tracker.sampleCount,
                    peakTime    = (float)tracker.peakTime,
                    trackerName = tracker.name
                };
                report.trackers.Add(info);
            }

            return(report);
        }
コード例 #2
0
        public static string GetTrackersReport(TrackerReportOptions options)
        {
            var trackerRx        = new Regex(options.trackerFilter, RegexOptions.Compiled | RegexOptions.IgnoreCase);
            var trackers         = PtModel.BuildTrackerList(new PtInfo[] { }, options.sortBy, options.sortAsc, options.sort);
            var filteredTrackers = trackers.Where(tracker => trackerRx.IsMatch(tracker.name)).ToList();

            return(GetTrackersReport(filteredTrackers, options));
        }
コード例 #3
0
        private void UpdateHeaderTitle(ColumnId id, Label header)
        {
            var desc        = PtModel.GetColumnDescriptor(id);
            var columnTitle = desc.label;

            if (id == m_SortBy)
            {
                columnTitle = m_SortAsc ? desc.labelAsc : desc.labelDesc;
            }

            header.text = columnTitle;
        }
コード例 #4
0
        public static string GetTrackersReport(IEnumerable <string> trackerNames, TrackerReportOptions options)
        {
            if (!ValidateReportOptions(options))
            {
                return(null);
            }

            var sb = new StringBuilder();
            var maxTrackerNameLength = trackerNames.Max(name => name.Length);

            var moreThanOneLine = false;

            foreach (var trackerName in trackerNames)
            {
                if (!EditorPerformanceTracker.Exists(trackerName))
                {
                    continue;
                }

                var shownTokens = new List <string>();
                if (options.showSamples)
                {
                    shownTokens.Add($"{EditorPerformanceTracker.GetSampleCount(trackerName)} samples");
                }
                if (options.showPeak)
                {
                    shownTokens.Add($"Peak {PtModel.ToEngineeringNotation(EditorPerformanceTracker.GetPeakTime(trackerName))}s");
                }
                if (options.showAvg)
                {
                    shownTokens.Add($"Avg. {PtModel.ToEngineeringNotation(EditorPerformanceTracker.GetAverageTime(trackerName))}s");
                }
                if (options.showTotal)
                {
                    shownTokens.Add($"Total {PtModel.ToEngineeringNotation(EditorPerformanceTracker.GetTotalTime(trackerName))}s");
                }

                if (moreThanOneLine)
                {
                    sb.AppendLine();
                }

                sb.AppendFormat($"{{0,{maxTrackerNameLength}}}: ", trackerName);
                sb.Append(string.Join(", ", shownTokens));
                moreThanOneLine = true;
            }

            return(sb.ToString());
        }
        static void SpamPerformanceActionEvents()
        {
            var trackers = PtModel.BuildTrackerList(new PtInfo[] { }, ColumnId.AvgTime, true, true);

            for (var i = 0; i < 25; ++i)
            {
                var evt = new PerformanceActionEvent(
                    RandomEnum <ActionType>(),
                    RandomValue(trackers).name,
                    RandomEnum <ActionSource>()
                    );

                SendPerformanceActionEvent(evt);
                Debug.Log($"Send action event: {i}");
                Thread.Sleep(500);
            }
        }
コード例 #6
0
 private void BuildTrackers(out bool numberTrackersChanged)
 {
     using (new PerformanceTracker("PerformanceTrackerWindow.BuildTrackers"))
     {
         var oldTrackerCount = m_AllTrackers.Length;
         m_AllTrackers = PtModel.BuildTrackerList(m_AllTrackers, m_SortBy, m_SortAsc);
         var pinnedSortedTrackers   = new List <PtInfo>();
         var unpinnedSortedTrackers = new List <PtInfo>();
         foreach (var tracker in m_AllTrackers)
         {
             if (IsPinnedTracker(tracker))
             {
                 pinnedSortedTrackers.Add(tracker);
             }
             else
             {
                 unpinnedSortedTrackers.Add(tracker);
             }
         }
         numberTrackersChanged = oldTrackerCount != m_AllTrackers.Length;
         var oldCount = m_FilteredTrackers.Count;
         m_PinnedTrackers.Clear();
         m_PinnedTrackers.AddRange(pinnedSortedTrackers);
         m_PinnedTrackersView.style.height = Math.Min(10.0f, pinnedSortedTrackers.Count) * PtStyles.itemHeight;
         m_FilteredTrackers.Clear();
         if (!string.IsNullOrEmpty(m_FilterText))
         {
             var filterTokens = m_FilterText.Split(',').Select(f => f.Trim()).Where(f => f.Length > 0).ToArray();
             if (filterTokens.Length == 1)
             {
                 m_FilteredTrackers.AddRange(unpinnedSortedTrackers.Where(t => t.name.IndexOf(filterTokens[0], StringComparison.OrdinalIgnoreCase) != -1));
             }
             else
             {
                 m_FilteredTrackers.AddRange(unpinnedSortedTrackers.Where(t => filterTokens.Any(f => t.name.IndexOf(f, StringComparison.OrdinalIgnoreCase) != -1)));
             }
         }
         else
         {
             m_FilteredTrackers.AddRange(unpinnedSortedTrackers);
         }
         numberTrackersChanged = numberTrackersChanged || m_FilteredTrackers.Count != oldCount;
         titleContent          = new GUIContent($"Performance Trackers ({m_FilteredTrackers.Count})");
     }
 }
コード例 #7
0
        public static string GetTrackersReport(IEnumerable <PtInfo> trackers, TrackerReportOptions options)
        {
            if (!ValidateReportOptions(options))
            {
                return(null);
            }

            var sb = new StringBuilder();
            var maxTrackerNameLength = trackers.Max(tracker => tracker.name.Length);

            var moreThanOneLine = false;

            foreach (var tracker in trackers)
            {
                var shownTokens = new List <string>();
                if (options.showSamples)
                {
                    shownTokens.Add($"{tracker.sampleCount} samples");
                }
                if (options.showPeak)
                {
                    shownTokens.Add($"Peak {PtModel.ToEngineeringNotation(tracker.peakTime)}s");
                }
                if (options.showAvg)
                {
                    shownTokens.Add($"Avg. {PtModel.ToEngineeringNotation(tracker.avgTime)}s");
                }
                if (options.showTotal)
                {
                    shownTokens.Add($"Total {PtModel.ToEngineeringNotation(tracker.totalTime)}s");
                }

                if (moreThanOneLine)
                {
                    sb.AppendLine();
                }

                sb.AppendFormat($"{{0,{maxTrackerNameLength}}}: ", tracker.name);
                sb.Append(string.Join(", ", shownTokens));
                moreThanOneLine = true;
            }

            return(sb.ToString());
        }
        static void PerformNotifications(double now, string[] trackerNames)
        {
            if (!PerformanceTrackerSettings.notificationEnabled)
            {
                return;
            }

            if (now > s_NextCacheCleanup)
            {
                s_NotifChecks.Clear();
                s_NextCacheCleanup = now + 60;
            }

            var notificationNames = PerformanceTrackerSettings.notificationNames;
            var thresholds        = PerformanceTrackerSettings.notificationThresholds;

            for (int i = 0; i < notificationNames.Length; ++i)
            {
                var notifName = notificationNames[i];
                foreach (var trackerName in trackerNames)
                {
                    if (!trackerName.Contains(notifName))
                    {
                        continue;
                    }

                    var checkKey = notifName.GetHashCode();
                    var avgTime  = EditorPerformanceTracker.GetAverageTime(trackerName);
                    if (!s_NotifChecks.TryGetValue(checkKey, out var threshold))
                    {
                        threshold = thresholds[i];
                    }
                    if (avgTime > threshold)
                    {
                        s_NotifChecks[checkKey] = avgTime;
                        var avgString       = PtModel.ToEngineeringNotation(avgTime);
                        var thresholdString = PtModel.ToEngineeringNotation(thresholds[i]);
                        Debug.LogFormat(LogType.Warning, LogOption.NoStacktrace, null, $"<b>{trackerName}</b> is slower than expected ({avgString}s > {thresholdString}s)");
                        EditorPerformanceTracker.LogCallstack(trackerName);
                    }
                }
            }
        }
        static void SpamPerformanceWindowUsageEvents()
        {
            var trackers = PtModel.BuildTrackerList(new PtInfo[] { }, ColumnId.AvgTime, true, true);

            for (var i = 0; i < 25; ++i)
            {
                var evt = new PerformanceWindowUsageEvent()
                {
                    columns     = RandomValue(kShowColumns),
                    sortBy      = RandomEnum <ColumnId>(),
                    sortAsc     = RandomBool(),
                    filter      = RandomValue(kSearchFields),
                    pinMarkers  = RandomValue(kPins),
                    updateSpeed = (float)RandomValue(PtModel.RefreshRates).rate,
                    usageType   = RandomEnum <WindowUsageType>(),
                    markerName  = RandomValue(trackers).name
                };

                SendPerformanceWindowUsageEvent(evt);
                Debug.Log($"Send windowUsage event: {i}");
                Thread.Sleep(500);
            }
        }
コード例 #10
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);
        }
コード例 #11
0
        private bool IsColumnVisible(ColumnId id)
        {
            var columnDesc = PtModel.GetColumnDescriptor(id);

            return(!columnDesc.supportsHiding || (columnDesc.columnsSelectorMaskId & m_ShownColumn) > 0);
        }