Skip to content

Commit 332e3e9

Browse files
committed
Small improvements and fixes
1 parent 406ee17 commit 332e3e9

28 files changed

+229
-89
lines changed

Doc.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Doc/Motivation.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Why Debug Chan?
2+
3+
For complex projects “just logging to the console” is helpful but also a time waster; logging to the console either means a "free for all" approach (much junk to the console) or a zero trace policy (very little information to frame incoming issues).
4+
5+
Debug Chan is meant to support a principled approach, where developers write (relatively) humanly readable and much less transient traces to document program execution.
6+
7+
As such, debug chan implements three essential features:
8+
9+
**Channeled logging** - select a game object or component to view matching traces.
10+
11+
**Frame logging** - frame based processes often exhibit "stable" frame ranges. When an object look 'stuck', more likely than not they are cycling through the same trace over and over.
12+
13+
**Channeled histories** - view an object's recent (or not so recent) history, aggregated via frame ranges.

Doc/Motivation.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Core.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/DoD/Config.cs renamed to Editor/Core/Config.cs

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,26 @@
22
using System.Linq; using System.IO; using System.Text;
33
using S = System.String;
44
using UnityEditor; using static UnityEditor.EditorPrefs;
5-
using static Activ.Prolog.ConfigKeys;
5+
using static Activ.Loggr.ConfigKeys;
66

7-
namespace Activ.Prolog{
7+
namespace Activ.Loggr{
88
public class Config : AssetPostprocessor{
99

1010
public const int LogLineLength = 32;
1111
public const int MaxLines = 1000;
1212

13-
static List<string> elements = File.Exists(ConfigKeys.Path) ?
14-
(from s in File.ReadAllText(ConfigKeys.Path).Split('\n')
15-
select s.Trim()).ToList() : null;
13+
// -------------------------------------------------------------
1614

17-
public static bool logToFile => elements?.Contains(FileFlag) ?? false;
15+
public static bool allFrames
16+
{ set => SetBool(AllFrames, value); get => GetBool(AllFrames, true); }
1817

1918
public static bool enableInjection{
2019
set{
2120
if(value == enableInjection) return;
2221
SetBool(EnableLogging, value);
23-
Recompile.Apply();
22+
// TODO dep? enableInjection should be prolog config
23+
// not here
24+
Activ.Prolog.Recompile.Apply();
2425
}get{
2526
try{
2627
return GetBool(EnableLogging);
@@ -31,32 +32,42 @@ public static bool enableInjection{
3132
}
3233
}
3334

34-
public static bool allFrames
35-
{ set => SetBool(AllFrames, value); get => GetBool(AllFrames); }
35+
public static float handleSize
36+
{ set => SetFloat(HandleSize, value); get => GetFloat(HandleSize); }
3637

3738
public static bool logToConsole
38-
{ set => SetBool(LogToConsole, value); get => GetBool(LogToConsole); }
39-
40-
public static bool useSelection
41-
{ set => SetBool(UseSelection, value); get => GetBool(UseSelection); }
39+
{ set => SetBool(LogToConsole, value); get => GetBool(LogToConsole, false); }
4240

43-
public static float trailOffset
44-
{ set => SetFloat(TrailOffset, value); get => GetFloat(TrailOffset); }
41+
public static bool logToFile => elements?.Contains(FileFlag) ?? false;
4542

46-
public static float handleSize
47-
{ set => SetFloat(HandleSize, value); get => GetFloat(HandleSize); }
43+
public static int maxMessages
44+
{ set => SetInt(MaxMessages, value); get => GetInt(MaxMessages, 25000); }
4845

4946
public static int rtypeIndex
5047
{ set => SetInt(RTypeIndex, value); get => GetInt(RTypeIndex); }
5148

5249
public static bool step
5350
{ set => SetBool(Step, value); get => GetBool(Step); }
5451

52+
public static float trailOffset
53+
{ set => SetFloat(TrailOffset, value); get => GetFloat(TrailOffset); }
54+
55+
public static bool useSelection
56+
{ set => SetBool(UseSelection, value); get => GetBool(UseSelection, true); }
57+
58+
// -------------------------------------------------------------
59+
5560
public static bool Exclude(string arg) => elements?.Contains(arg) ?? false;
5661

62+
// Static properties -------------------------------------------
63+
64+
static List<string> elements = File.Exists(ConfigKeys.Path) ?
65+
(from s in File.ReadAllText(ConfigKeys.Path).Split('\n')
66+
select s.Trim()).ToList() : null;
67+
5768
static void OnPostprocessAllAssets (S[] i, S[] d, S[] m, S[] mf){
5869
if(!i.Contains(ConfigKeys.Path)) return;
59-
print("Config changed - recompile"); Recompile.Apply();
70+
print("Config changed - recompile"); Activ.Prolog.Recompile.Apply();
6071
}
6172

6273
static void print(string x) => UnityEngine.Debug.Log(x);
File renamed without changes.

Editor/Core/ConfigKeys.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace Activ.Loggr{
2+
public static class ConfigKeys{
3+
4+
public const string UseSelection = "Activ.Loggr.UseSel",
5+
AllFrames = "Activ.Loggr.AllFrames",
6+
Step = "Activ.Loggr.Step",
7+
RTypeIndex = "Prolog.RType",
8+
MaxMessages = "Activ.Loggr.MaxMessages",
9+
EnableLogging = "Prolog.enable",
10+
LogToConsole = "Activ.Loggr.LogToConsole",
11+
FileFlag = "--file",
12+
LogPath = "Assets/log.txt",
13+
Name = "prolog.config",
14+
Path = "Assets/prolog.config",
15+
TrailOffset = "Activ.Loggr.TrailOffset",
16+
HandleSize = "Activ.Loggr.HandleSize";
17+
18+
}}
File renamed without changes.

Editor/Core/UI.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/DoD/UI/LogWindow.cs renamed to Editor/Core/UI/LogWindow.cs

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,20 @@
33
using System.Linq;
44
using static UnityEditor.EditorGUILayout;
55
using static Activ.Prolog.LogWindowModel;
6-
using static Activ.Prolog.Config;
6+
//using static Activ.Prolog.PCfg;
77
using Ed = UnityEditor.EditorApplication;
88
using GL = UnityEngine.GUILayout;
99
using EGL = UnityEditor.EditorGUILayout;
10+
//
11+
using PrologLogger = Activ.Prolog.Logger;
12+
using PrologConfigManager = Activ.Prolog.PrologConfigManager;
13+
using PrologFrame = Activ.Prolog.Frame;
14+
using PrologMessage = Activ.Prolog.Message;
15+
using PrologWindowModel = Activ.Prolog.LogWindowModel;
16+
using PrologHistoryGUI = Activ.Prolog.HistoryGUI;
17+
using PCfg = Activ.Prolog.PrologConfig;
1018

11-
namespace Activ.Prolog{
19+
namespace Activ.Loggr.UI{
1220
public class LogWindow : EditorWindow{
1321

1422
const int FontSize = 13;
@@ -17,34 +25,37 @@ public class LogWindow : EditorWindow{
1725
//
1826
static Font normalButtonFont;
1927
static Font _font;
20-
LogWindowModel model = LogWindowModel.instance;
21-
Frame selectedFrame; // Last selected frame object
22-
Vector2 scroll;
23-
string currentLog;
24-
int frame = -1; // Last frame while playing (store this?)
28+
PrologWindowModel model = PrologWindowModel.instance;
29+
PrologFrame selectedFrame; // Last selected frame object
30+
Vector2 scroll;
31+
string currentLog;
32+
int frame = -1; // Last frame while playing (store this?)
33+
// approx msg count (helps tracking memory overheads)
34+
public static int cumulatedMessageCount;
2535

2636
LogWindow(){
2737
Ed.pauseStateChanged +=
2838
(PauseState s) => { if(s == PauseState.Paused) Repaint(); };
29-
Activ.Loggr.Logger<string, object>.messageReceived += OnMessage;
39+
Activ.Loggr.Logger<string, object>.messageReceived += OnGenericMessage;
3040
}
3141

3242
// From DebugChan
33-
public void OnMessage(string message, object sender){
43+
public void OnGenericMessage(string message, object sender, int messageCount){
44+
cumulatedMessageCount = messageCount;
3445
if(isPlaying && instance){
3546
instance.DoUpdate(null);
3647
}
3748
}
3849

3950
// From Prolog
40-
public static void OnMessage(object sender, Message message){
51+
public static void OnMessage(object sender, PrologMessage message){
4152
if(isPlaying && instance){
4253
instance.model.current = Selection.activeGameObject;
4354
instance.DoUpdate(message);
4455
}
4556
}
4657

47-
void DoUpdate(Message msg)
58+
void DoUpdate(PrologMessage msg)
4859
{ if(frame != Time.frameCount){ frame = Time.frameCount; Repaint(); }}
4960

5061
void OnFocus(){
@@ -54,7 +65,7 @@ void OnFocus(){
5465

5566
void OnGUI(){
5667
if(PrologConfigManager.current == null){
57-
if(GL.Button("Create Prolog config")){
68+
if(GL.Button("Create Debug-Chan config")){
5869
PrologConfigManager.Create();
5970
}
6071
return;
@@ -70,7 +81,7 @@ void OnGUI_Content(){
7081
DrawScrubber();
7182
if(Config.enableInjection) DrawDebuggerTextView();
7283
DrawLoggerTextView();
73-
DrawToggles();
84+
DrawFooter();
7485
//DrawTrailsConfig();
7586
}
7687

@@ -80,7 +91,7 @@ void DrawLoggerTextView(){
8091
DrawTextView("Not running");
8192
return;
8293
}
83-
if(!useSelection || model.selection == null){
94+
if(!Config.useSelection || model.selection == null){
8495
DrawTextView("No selection");
8596
return;
8697
}
@@ -122,7 +133,7 @@ void ConfigTextAreaStyle(){
122133
style.focused.textColor = Color.white;
123134
}
124135

125-
void DrawToggles(){
136+
void DrawFooter(){
126137
BeginHorizontal();
127138
Config.useSelection = ToggleLeft("Use Selection", Config.useSelection,
128139
GL.MaxWidth(100f));
@@ -132,7 +143,8 @@ void DrawToggles(){
132143
= ToggleLeft("Log to console", Config.logToConsole,
133144
GL.MaxWidth(120));
134145
//
135-
GL.FlexibleSpace();
146+
EndHorizontal();
147+
BeginHorizontal();
136148
//
137149
GL.Label("Trails - offset: ", GL.MaxWidth(88f));
138150
Config.trailOffset = FloatField(Config.trailOffset,
@@ -144,8 +156,19 @@ void DrawToggles(){
144156
// TODO for Prolog update
145157
//if(model.selection){
146158
// GL.Label("→", GL.MaxWidth(25f));
147-
// Config.rtypeIndex = Popup(Config.rtypeIndex, rtypeOptions);
159+
// PCfg.rtypeIndex = Popup(PCfg.rtypeIndex, rtypeOptions);
148160
//}
161+
//EndHorizontal();
162+
//BeginHorizontal();
163+
GL.FlexibleSpace();
164+
if(isPlaying){
165+
EGL.LabelField($"#{cumulatedMessageCount:0,000,000}", GL.MaxWidth(92f));
166+
}else{
167+
EditorGUIUtility.labelWidth = 60;
168+
Config.maxMessages = EGL.IntField("Max msgs", Config.maxMessages);
169+
EditorGUIUtility.labelWidth = 0;
170+
//if(ScrubberButton($"Clear")) Clear();
171+
}
149172
EndHorizontal();
150173
if(!Config.useSelection) model.current = null;
151174
}
@@ -165,9 +188,13 @@ void DrawScrubber(){
165188
if(ScrubberButton(">")) SelectNext();
166189
style.font = normalButtonFont;
167190
GL.FlexibleSpace();
168-
if(!isPlaying && ScrubberButton($"Clear")) Clear();
191+
if(isPlaying){
192+
//EGL.LabelField($"N#{cumulatedMessageCount:0,000,000}", GL.MaxWidth(92f));
193+
}else{
194+
if(ScrubberButton($"Clear")) Clear();
195+
}
169196
// TODO reenable
170-
//Config.step = ToggleLeft("Step", Config.step, GL.MaxWidth(48f));
197+
//PCfg.step = ToggleLeft("Step", PCfg.step, GL.MaxWidth(48f));
171198
EndHorizontal();
172199
}
173200

@@ -176,25 +203,25 @@ bool ScrubberButton(string arg)
176203

177204
// TODO re-enable but move elsewhere
178205
//void DrawPauseModeConfig(){
179-
// Config.enableInjection = ToggleLeft(
206+
// PCfg.enableInjection = ToggleLeft(
180207
// $"Instrument ({Logger.injectionTimeMs}ms)",
181-
// Config.enableInjection, GL.ExpandWidth(true));
208+
// PCfg.enableInjection, GL.ExpandWidth(true));
182209
//}
183210

184211
void ToggleAdvanced(){}
185212

186213
void DrawConfigManager(){
187214
var selected = EGL.ObjectField(
188215
PrologConfigManager.current,
189-
typeof(PrologConfig),
216+
typeof(PCfg),
190217
allowSceneObjects: false);
191-
PrologConfigManager.current = selected as PrologConfig;
218+
PrologConfigManager.current = (PCfg)selected;
192219
}
193220

194221
// Ref https://tinyurl.com/yyo8c35g which also demonstrates starting a 2D
195222
// GUI at handles location
196223
void OnSceneGUI(SceneView sceneView){
197-
var sel = HistoryGUI.Draw(model.filtered, selectedFrame);
224+
var sel = PrologHistoryGUI.Draw(model.filtered, selectedFrame);
198225
if(Ed.isPaused || !isPlaying){
199226
selectedFrame = sel ?? selectedFrame;
200227
Repaint();
@@ -207,7 +234,7 @@ void OnSelectionChange()
207234
{ if(Ed.isPaused || !isPlaying) Repaint(); }
208235

209236
void Clear(){
210-
Logger.Clear();
237+
PrologLogger.Clear();
211238
model.Clear();
212239
selectedFrame = null;
213240
SceneView.RepaintAll();
@@ -226,10 +253,10 @@ void SelectNext(){
226253
SceneView.RepaintAll();
227254
}
228255

229-
[MenuItem("Window/Activ/Prolog")]
256+
[MenuItem("Window/Activ/Debug-Chan")]
230257
static void Init(){
231258
instance = (LogWindow)EditorWindow
232-
.GetWindow<LogWindow>(title: "Prolog");
259+
.GetWindow<LogWindow>(title: "Debug-Chan");
233260
instance.Show();
234261
}
235262

0 commit comments

Comments
 (0)