From be3618a4e946627e559c0302ca08b91e43817cb8 Mon Sep 17 00:00:00 2001 From: Mouser Date: Mon, 26 Nov 2018 06:20:58 +0300 Subject: [PATCH 1/3] Optimize console by reducing amount of calcSize calls. Make all lines fixed height Add full message in details section --- Editor/UberLoggerEditorWindow.cs | 73 +++++++++++++++++--------------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/Editor/UberLoggerEditorWindow.cs b/Editor/UberLoggerEditorWindow.cs index bd67cb6..fb41a6c 100755 --- a/Editor/UberLoggerEditorWindow.cs +++ b/Editor/UberLoggerEditorWindow.cs @@ -169,9 +169,13 @@ public void OnGUI() EntryStyleBackEven = new GUIStyle(unitySmallLogLine); EntryStyleBackEven.normal = unityLogLineEven.normal; - EntryStyleBackEven.margin = new RectOffset(0,0,0,0); - EntryStyleBackEven.border = new RectOffset(0,0,0,0); + EntryStyleBackEven.margin = new RectOffset(0, 0, 0, 0); + EntryStyleBackEven.border = new RectOffset(0, 0, 0, 0); EntryStyleBackEven.fixedHeight = 0; + EntryStyleBackEven.fixedWidth = 0; + EntryStyleBackEven.wordWrap = true; + EntryStyleBackEven.clipping = TextClipping.Overflow; + EntryStyleBackEven.stretchWidth = true; EntryStyleBackOdd = new GUIStyle(EntryStyleBackEven); EntryStyleBackOdd.normal = unityLogLineOdd.normal; @@ -397,7 +401,7 @@ GUIContent GetLogLineGUIContent(UberLogger.LogInfo log, bool showTimes, bool sho showMessage ); - var content = new GUIContent(showMessage, GetIconForLog(log)); + var content = new GUIContent(showMessage); return content; } @@ -424,8 +428,6 @@ public void DrawLogList(float height) // If we've been marked dirty, we need to recalculate the elements to be displayed if(Dirty) { - LogListMaxWidth = 0; - LogListLineHeight = 0; CollapseBadgeMaxWidth = 0; RenderLogs.Clear(); @@ -455,18 +457,17 @@ public void DrawLogList(float height) } } + int maxCollapseCount = 0; foreach(var countedLog in collapsedLinesList) { - var content = GetLogLineGUIContent(countedLog.Log, ShowTimes, ShowChannels); RenderLogs.Add(countedLog); - var logLineSize = logLineStyle.CalcSize(content); - LogListMaxWidth = Mathf.Max(LogListMaxWidth, logLineSize.x); - LogListLineHeight = Mathf.Max(LogListLineHeight, logLineSize.y); - var collapseBadgeContent = new GUIContent(countedLog.Count.ToString()); - var collapseBadgeSize = collapseBadgeStyle.CalcSize(collapseBadgeContent); - CollapseBadgeMaxWidth = Mathf.Max(CollapseBadgeMaxWidth, collapseBadgeSize.x); + maxCollapseCount = Mathf.Max(maxCollapseCount, countedLog.Count); + } + var collapseBadgeContent = new GUIContent(maxCollapseCount.ToString()); + var collapseBadgeSize = collapseBadgeStyle.CalcSize(collapseBadgeContent); + CollapseBadgeMaxWidth = Mathf.Max(CollapseBadgeMaxWidth, collapseBadgeSize.x); } //If we're not collapsed, display everything in order else @@ -475,31 +476,25 @@ public void DrawLogList(float height) { if(ShouldShowLog(filterRegex, log)) { - var content = GetLogLineGUIContent(log, ShowTimes, ShowChannels); RenderLogs.Add(new CountedLog(log, 1)); - var logLineSize = logLineStyle.CalcSize(content); - LogListMaxWidth = Mathf.Max(LogListMaxWidth, logLineSize.x); - LogListLineHeight = Mathf.Max(LogListLineHeight, logLineSize.y); } } } - - LogListMaxWidth += CollapseBadgeMaxWidth; } var scrollRect = new Rect(DrawPos, new Vector2(position.width, height)); - float lineWidth = Mathf.Max(LogListMaxWidth, scrollRect.width); - var contentRect = new Rect(0, 0, lineWidth, RenderLogs.Count*LogListLineHeight); + var contentRect = new Rect(0, 0, scrollRect.width, RenderLogs.Count*LogListLineHeight); + var viewRect = contentRect; + viewRect.width -= 50; Vector2 lastScrollPosition = LogListScrollPosition; - LogListScrollPosition = GUI.BeginScrollView(scrollRect, LogListScrollPosition, contentRect); + LogListScrollPosition = GUI.BeginScrollView(scrollRect, LogListScrollPosition, viewRect, GUIStyle.none, GUI.skin.verticalScrollbar); //If we're following the messages but the user has moved, cancel following if(ScrollFollowMessages) { if(lastScrollPosition.y - LogListScrollPosition.y > LogListLineHeight) { - UberDebug.UnityLog(String.Format("{0} {1}", lastScrollPosition.y, LogListScrollPosition.y)); ScrollFollowMessages = false; } } @@ -513,13 +508,13 @@ public void DrawLogList(float height) firstRenderLogIndex = Mathf.Clamp(firstRenderLogIndex, 0, RenderLogs.Count); lastRenderLogIndex = Mathf.Clamp(lastRenderLogIndex, 0, RenderLogs.Count); buttonY = firstRenderLogIndex*LogListLineHeight; - - for(int renderLogIndex=firstRenderLogIndex; renderLogIndex0) { @@ -616,9 +614,11 @@ public void DrawLogDetails() float contentHeight = 0; float contentWidth = 0; float lineHeight = 0; + var messageContent = new GUIContent(log.Message); + var messageHeight = logLineStyle.CalcHeight(messageContent, position.width); - for(int c1=0; c1 RenderLogs = new List(); - float LogListMaxWidth = 0; - float LogListLineHeight = 0; float CollapseBadgeMaxWidth = 0; } From 72eded78f38e3235cb2669c5a1e587ad4b351c75 Mon Sep 17 00:00:00 2001 From: Mouser Date: Tue, 27 Nov 2018 20:27:30 +0300 Subject: [PATCH 2/3] Fix icon background. Fix log details selection and wrapping --- Editor/UberLoggerEditorWindow.cs | 48 +++++++++++++++++++------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/Editor/UberLoggerEditorWindow.cs b/Editor/UberLoggerEditorWindow.cs index fb41a6c..c65b79b 100755 --- a/Editor/UberLoggerEditorWindow.cs +++ b/Editor/UberLoggerEditorWindow.cs @@ -173,18 +173,18 @@ public void OnGUI() EntryStyleBackEven.border = new RectOffset(0, 0, 0, 0); EntryStyleBackEven.fixedHeight = 0; EntryStyleBackEven.fixedWidth = 0; - EntryStyleBackEven.wordWrap = true; + EntryStyleBackEven.clipping = TextClipping.Overflow; EntryStyleBackEven.stretchWidth = true; EntryStyleBackOdd = new GUIStyle(EntryStyleBackEven); EntryStyleBackOdd.normal = unityLogLineOdd.normal; - // EntryStyleBackOdd = new GUIStyle(unityLogLine); + DetailsEntryStyleBackEven = new GUIStyle(EntryStyleBackEven); + DetailsEntryStyleBackOdd = new GUIStyle(EntryStyleBackOdd); SizerLineColour = new Color(defaultLineColor.r*0.5f, defaultLineColor.g*0.5f, defaultLineColor.b*0.5f); - // GUILayout.BeginVertical(GUILayout.Height(topPanelHeaderHeight), GUILayout.MinHeight(topPanelHeaderHeight)); ResizeTopPane(); DrawPos = Vector2.zero; DrawToolbar(); @@ -411,7 +411,7 @@ GUIContent GetLogLineGUIContent(UberLogger.LogInfo log, bool showTimes, bool sho public void DrawLogList(float height) { var oldColor = GUI.backgroundColor; - + GUI.SetNextControlName(LogListControlName); float buttonY = 0; @@ -499,7 +499,8 @@ public void DrawLogList(float height) } } - float logLineX = CollapseBadgeMaxWidth; + EntryStyleBackEven.padding.left = (int) (CollapseBadgeMaxWidth + LogListLineHeight + 4); + EntryStyleBackOdd.padding.left = EntryStyleBackEven.padding.left; //Render all the elements int firstRenderLogIndex = (int) (LogListScrollPosition.y/LogListLineHeight); @@ -513,7 +514,6 @@ public void DrawLogList(float height) var countedLog = RenderLogs[renderLogIndex]; var log = countedLog.Log; logLineStyle = (renderLogIndex%2==0) ? EntryStyleBackEven : EntryStyleBackOdd; - logLineStyle.wordWrap = false; if (renderLogIndex==SelectedRenderLog) { GUI.backgroundColor = new Color(0.5f, 0.5f, 1); @@ -525,15 +525,13 @@ public void DrawLogList(float height) //Make all messages single line var content = GetLogLineGUIContent(log, ShowTimes, ShowChannels); - var drawRect = new Rect(logLineX, buttonY, contentRect.width, LogListLineHeight); - var iconRect = drawRect; - iconRect.width = LogListLineHeight; - GUI.DrawTexture(iconRect, GetIconForLog(log), ScaleMode.ScaleAndCrop); - drawRect.x += iconRect.width + 4; + var drawRect = new Rect(0, buttonY, contentRect.width, LogListLineHeight); + if (GUI.Button(drawRect, content, logLineStyle)) { + GUI.FocusControl(LogListControlName); //Select a message, or jump to source if it's double-clicked - if(renderLogIndex==SelectedRenderLog) + if (renderLogIndex==SelectedRenderLog) { if(EditorApplication.timeSinceStartup-LastMessageClickTime RenderLogs = new List(); float CollapseBadgeMaxWidth = 0; - + private const string LogListControlName = "LogList"; } From 6f7bc608af6ac7be42db43e084820b31470c414e Mon Sep 17 00:00:00 2001 From: Mouser Date: Tue, 27 Nov 2018 22:39:12 +0300 Subject: [PATCH 3/3] Add caching and optimizations Only update new log lines. Cache gui styles. --- Editor/UberLoggerEditorWindow.cs | 144 +++++++++++++++++++------------ UberLoggerEditor.cs | 4 +- 2 files changed, 90 insertions(+), 58 deletions(-) diff --git a/Editor/UberLoggerEditorWindow.cs b/Editor/UberLoggerEditorWindow.cs index c65b79b..084228d 100755 --- a/Editor/UberLoggerEditorWindow.cs +++ b/Editor/UberLoggerEditorWindow.cs @@ -77,6 +77,8 @@ void OnEnable() WarningIcon = SmallWarningIcon; MessageIcon = SmallMessageIcon; Dirty = true; + FilterChanged = true; + NeedToUpdateStyles = true; Repaint(); } @@ -150,41 +152,16 @@ public void HandleCopyToClipboard() } Vector2 DrawPos; + bool NeedToUpdateStyles; + bool FilterChanged; + int NextIndexToAdd; public void OnGUI() { - //Set up the basic style, based on the Unity defaults - //A bit hacky, but means we don't have to ship an editor guistyle and can fit in to pro and free skins - Color defaultLineColor = GUI.backgroundColor; - GUIStyle unityLogLineEven = null; - GUIStyle unityLogLineOdd = null; - GUIStyle unitySmallLogLine = null; - - foreach(var style in GUI.skin.customStyles) + if (NeedToUpdateStyles) { - if (style.name=="CN EntryBackEven") unityLogLineEven = style; - else if(style.name=="CN EntryBackOdd") unityLogLineOdd = style; - else if(style.name=="CN StatusInfo") unitySmallLogLine = style; + UpdateStyles(); } - EntryStyleBackEven = new GUIStyle(unitySmallLogLine); - - EntryStyleBackEven.normal = unityLogLineEven.normal; - EntryStyleBackEven.margin = new RectOffset(0, 0, 0, 0); - EntryStyleBackEven.border = new RectOffset(0, 0, 0, 0); - EntryStyleBackEven.fixedHeight = 0; - EntryStyleBackEven.fixedWidth = 0; - - EntryStyleBackEven.clipping = TextClipping.Overflow; - EntryStyleBackEven.stretchWidth = true; - - EntryStyleBackOdd = new GUIStyle(EntryStyleBackEven); - EntryStyleBackOdd.normal = unityLogLineOdd.normal; - - DetailsEntryStyleBackEven = new GUIStyle(EntryStyleBackEven); - DetailsEntryStyleBackOdd = new GUIStyle(EntryStyleBackOdd); - - SizerLineColour = new Color(defaultLineColor.r*0.5f, defaultLineColor.g*0.5f, defaultLineColor.b*0.5f); - ResizeTopPane(); DrawPos = Vector2.zero; DrawToolbar(); @@ -196,7 +173,8 @@ public void OnGUI() if(Dirty) { - CurrentLogList = EditorLogger.CopyLogInfo(); + CurrentLogList.Clear(); + EditorLogger.CopyLogInfoTo(CurrentLogList); } DrawLogList(logPanelHeight); @@ -214,6 +192,46 @@ public void OnGUI() MakeDirty = false; Repaint(); } + else + { + FilterChanged = false; + } + } + + private void UpdateStyles() + { + //Set up the basic style, based on the Unity defaults + //A bit hacky, but means we don't have to ship an editor guistyle and can fit in to pro and free skins + Color defaultLineColor = GUI.backgroundColor; + GUIStyle unityLogLineEven = null; + GUIStyle unityLogLineOdd = null; + GUIStyle unitySmallLogLine = null; + + foreach (var style in GUI.skin.customStyles) + { + if (style.name == "CN EntryBackEven") unityLogLineEven = style; + else if (style.name == "CN EntryBackOdd") unityLogLineOdd = style; + else if (style.name == "CN StatusInfo") unitySmallLogLine = style; + } + + EntryStyleBackEven = new GUIStyle(unitySmallLogLine); + + EntryStyleBackEven.normal = unityLogLineEven.normal; + EntryStyleBackEven.margin = new RectOffset(0, 0, 0, 0); + EntryStyleBackEven.border = new RectOffset(0, 0, 0, 0); + EntryStyleBackEven.fixedHeight = 0; + EntryStyleBackEven.fixedWidth = 0; + + EntryStyleBackEven.clipping = TextClipping.Overflow; + EntryStyleBackEven.stretchWidth = true; + + EntryStyleBackOdd = new GUIStyle(EntryStyleBackEven); + EntryStyleBackOdd.normal = unityLogLineOdd.normal; + + DetailsEntryStyleBackEven = new GUIStyle(EntryStyleBackEven); + DetailsEntryStyleBackOdd = new GUIStyle(EntryStyleBackOdd); + + SizerLineColour = new Color(defaultLineColor.r * 0.5f, defaultLineColor.g * 0.5f, defaultLineColor.b * 0.5f); } //Some helper functions to draw buttons that are only as big as their text @@ -257,6 +275,7 @@ void DrawToolbar() Vector2 elementSize; if(ButtonClamped("Clear", EditorStyles.toolbarButton, out elementSize)) { + FilterChanged = true; EditorLogger.Clear(); } DrawPos.x += elementSize.x; @@ -282,6 +301,7 @@ void DrawToolbar() if(collapse!=Collapse) { MakeDirty = true; + FilterChanged = true; Collapse = collapse; SelectedRenderLog = -1; } @@ -315,6 +335,7 @@ void DrawToolbar() //If the errors/warning to show has changed, clear the selected message if(showErrors!=ShowErrors || showWarnings!=ShowWarnings || showMessages!=ShowMessages) { + FilterChanged = true; ClearSelectedMessage(); MakeDirty = true; } @@ -348,6 +369,7 @@ void DrawChannels() CurrentChannel = channels[currentChannelIndex]; ClearSelectedMessage(); MakeDirty = true; + FilterChanged = true; } DrawPos.y+=size.y; } @@ -428,53 +450,58 @@ public void DrawLogList(float height) // If we've been marked dirty, we need to recalculate the elements to be displayed if(Dirty) { - CollapseBadgeMaxWidth = 0; - RenderLogs.Clear(); + if (FilterChanged) + { + CollapseBadgeMaxWidth = 0; + MaxCollapseCount = 0; + RenderLogs.Clear(); + NextIndexToAdd = 0; + + CollapsedLines.Clear(); + CollapsedLinesList.Clear(); + } //When collapsed, count up the unique elements and use those to display if(Collapse) { - var collapsedLines = new Dictionary(); - var collapsedLinesList = new List(); - - foreach(var log in CurrentLogList) + for (var i = NextIndexToAdd; i < CurrentLogList.Count; i++) { - if(ShouldShowLog(filterRegex, log)) + var log = CurrentLogList[i]; + if (ShouldShowLog(filterRegex, log)) { var matchString = log.Message + "!$" + log.Severity + "!$" + log.Channel; CountedLog countedLog; - if(collapsedLines.TryGetValue(matchString, out countedLog)) + if (CollapsedLines.TryGetValue(matchString, out countedLog)) { countedLog.Count++; } else { countedLog = new CountedLog(log, 1); - collapsedLines.Add(matchString, countedLog); - collapsedLinesList.Add(countedLog); + CollapsedLines.Add(matchString, countedLog); + CollapsedLinesList.Add(countedLog); + RenderLogs.Add(countedLog); + } + + if (MaxCollapseCount < countedLog.Count) + { + MaxCollapseCount = countedLog.Count; } } } - int maxCollapseCount = 0; - foreach(var countedLog in collapsedLinesList) - { - RenderLogs.Add(countedLog); - - maxCollapseCount = Mathf.Max(maxCollapseCount, countedLog.Count); - - } - var collapseBadgeContent = new GUIContent(maxCollapseCount.ToString()); + var collapseBadgeContent = new GUIContent(MaxCollapseCount.ToString()); var collapseBadgeSize = collapseBadgeStyle.CalcSize(collapseBadgeContent); CollapseBadgeMaxWidth = Mathf.Max(CollapseBadgeMaxWidth, collapseBadgeSize.x); } //If we're not collapsed, display everything in order else { - foreach(var log in CurrentLogList) + for (var i = NextIndexToAdd; i < CurrentLogList.Count; i++) { - if(ShouldShowLog(filterRegex, log)) + var log = CurrentLogList[i]; + if (ShouldShowLog(filterRegex, log)) { RenderLogs.Add(new CountedLog(log, 1)); } @@ -587,6 +614,8 @@ public void DrawLogList(float height) LogListScrollPosition.y = ((RenderLogs.Count+1)*LogListLineHeight)-scrollRect.height; } + NextIndexToAdd = CurrentLogList.Count; + GUI.EndScrollView(); DrawPos.y += height; DrawPos.x = 0; @@ -811,6 +840,7 @@ void DrawFilter() { ClearSelectedMessage(); FilterRegex = filterRegex; + FilterChanged = true; MakeDirty = true; } @@ -980,6 +1010,12 @@ void ClearSelectedMessage() bool ShowMessages = true; int SelectedCallstackFrame = 0; bool ShowFrameSource = false; + List RenderLogs = new List(); + Dictionary CollapsedLines = new Dictionary(); + List CollapsedLinesList = new List(); + int MaxCollapseCount = 0; + float CollapseBadgeMaxWidth = 0; + const string LogListControlName = "LogList"; class CountedLog { @@ -991,8 +1027,4 @@ public CountedLog(UberLogger.LogInfo log, Int32 count) Count = count; } } - - List RenderLogs = new List(); - float CollapseBadgeMaxWidth = 0; - private const string LogListControlName = "LogList"; } diff --git a/UberLoggerEditor.cs b/UberLoggerEditor.cs index b357a80..e4eb043 100755 --- a/UberLoggerEditor.cs +++ b/UberLoggerEditor.cs @@ -144,11 +144,11 @@ public void Clear() } } - public List CopyLogInfo() + public void CopyLogInfoTo(List container) { lock(this) { - return new List(LogInfo); + container.AddRange(LogInfo); } }