Offer visual cues for monitor status (#301)
authorSung Yoon Whang <suwhang@microsoft.com>
Tue, 4 Jun 2019 22:58:44 +0000 (15:58 -0700)
committerGitHub <noreply@github.com>
Tue, 4 Jun 2019 22:58:44 +0000 (15:58 -0700)
* Offer visual cues for monitor status

* Offer visual cue when user specifies a nonexistent EventSource

* Change the initial message to something more helpful than 'Running'

src/Tools/dotnet-counters/ConsoleWriter.cs
src/Tools/dotnet-counters/CounterMonitor.cs

index e4237aa1f9e83f794999b8790b989f1c6e7e6090..2ae447641500832d1f522c2b97cf7b67bab7f37b 100644 (file)
@@ -15,9 +15,19 @@ namespace Microsoft.Diagnostics.Tools.Counters
         private int origCol;
         private int maxRow;  // Running maximum of row number
         private int maxCol;  // Running maximum of col number
+        private int STATUS_ROW; // Row # of where we print the status of dotnet-counters
+        private bool paused = false;
         private Dictionary<string, int> knownProvidersRowNum;
         private Dictionary<string, int> unknownProvidersRowNum;
 
+        private void UpdateStatus(string msg)
+        {
+            Console.SetCursorPosition(0, STATUS_ROW);
+            Console.Write(new String(' ', 20));
+            Console.SetCursorPosition(0, STATUS_ROW);
+            Console.Write(msg);
+        }
+
         public ConsoleWriter()
         {
             displayPosition = new Dictionary<string, (int, int)>();
@@ -36,13 +46,42 @@ namespace Microsoft.Diagnostics.Tools.Counters
             origRow = Console.CursorTop;
             origCol = Console.CursorLeft;
             Console.WriteLine("Press p to pause, r to resume, q to quit.");
+            Console.WriteLine("    Status: Waiting for initial payload...");
 
-            maxRow = origRow+1;
+            STATUS_ROW = origRow+1;
+            maxRow = origRow+2;
             maxCol = origCol;
         }
 
-        public void Update(string providerName, ICounterPayload payload)
+        public void ToggleStatus(bool pauseCmdSet)
         {
+            if (paused == pauseCmdSet)
+            {
+                return;
+            }
+            else if (pauseCmdSet)
+            {
+                UpdateStatus("    Status: Paused");
+            }
+            else
+            {
+                UpdateStatus("    Status: Running");
+            }
+            paused = pauseCmdSet;
+        }
+
+        public void Update(string providerName, ICounterPayload payload, bool pauseCmdSet)
+        {
+            if (paused != pauseCmdSet)
+            {
+                ToggleStatus(pauseCmdSet);
+            }
+
+            if (pauseCmdSet)
+            {
+                return;
+            }
+
             string name = payload.GetName();
 
             // We already know what this counter is! Just update the value string on the console.
@@ -108,4 +147,4 @@ namespace Microsoft.Diagnostics.Tools.Counters
             }
         }
     }
-}
\ No newline at end of file
+}
index bace03216fc2cac05a88555121978b7f9fb49245..ff626d9fe38cb3cf5754edb695ba252f70d8dbf8 100644 (file)
@@ -41,7 +41,7 @@ namespace Microsoft.Diagnostics.Tools.Counters
             // There's a potential race here between the two tasks but not a huge deal if we miss by one event.
             if (pauseCmdSet) 
             {
-                return;
+                writer.ToggleStatus(pauseCmdSet);
             }
 
             if (obj.EventName.Equals("EventCounters"))
@@ -64,7 +64,7 @@ namespace Microsoft.Diagnostics.Tools.Counters
                 {
                     payload = payloadFields.Count == 6 ? (ICounterPayload)new IncrementingCounterPayload(payloadFields) : (ICounterPayload)new CounterPayload(payloadFields);
                 }
-                writer.Update(obj.ProviderName, payload);
+                writer.Update(obj.ProviderName, payload, pauseCmdSet);
             }
         }
 
@@ -157,6 +157,7 @@ namespace Microsoft.Diagnostics.Tools.Counters
 
             var shouldExit = new ManualResetEvent(false);
             var terminated = false;
+            writer.InitializeDisplay();
 
             Task monitorTask = new Task(() => {
                 try
@@ -168,7 +169,6 @@ namespace Microsoft.Diagnostics.Tools.Counters
 
                     var binaryReader = EventPipeClient.CollectTracing(_processId, configuration, out _sessionId);
                     EventPipeEventSource source = new EventPipeEventSource(binaryReader);
-                    writer.InitializeDisplay();
                     source.Dynamic.All += Dynamic_All;
                     source.Process();
                 }