private void ResumeRuntime(IpcEndpointInfo info) { var client = new DiagnosticsClient(info.Endpoint); _outputHelper.WriteLine($"{info.RuntimeInstanceCookie}: Resuming runtime instance."); try { client.ResumeRuntime(); _outputHelper.WriteLine($"{info.RuntimeInstanceCookie}: Resumed successfully."); } catch (ServerErrorException ex) { // Runtime likely does not understand the ResumeRuntime command. _outputHelper.WriteLine($"{info.RuntimeInstanceCookie}: {ex.Message}"); } }
public void CheckSpecificProcessTest() { TestRunner runner = new TestRunner(CommonHelper.GetTraceePath(), output); runner.Start(3000); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Thread.Sleep(5000); } var client = new DiagnosticsClient(runner.Pid); Assert.True(client.CheckTransport(), $"Unable to verify diagnostics transport for test process {runner.Pid}."); runner.Stop(); }
public void BasicEventPipeSessionTest() { TestRunner runner = new TestRunner(CommonHelper.GetTraceePath(), output); runner.Start(3000); DiagnosticsClient client = new DiagnosticsClient(runner.Pid); using (var session = client.StartEventPipeSession(new List <EventPipeProvider>() { new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Informational) })) { Assert.True(session.EventStream != null); } runner.Stop(); }
private static EventPipeSession CreateSessionFromResponse(IpcEndpoint endpoint, ref IpcResponse?response, string operationName) { try { DiagnosticsClient.ValidateResponseMessage(response.Value.Message, operationName); long sessionId = BitConverter.ToInt64(response.Value.Message.Payload, 0); var session = new EventPipeSession(endpoint, response.Value, sessionId); response = null; return(session); } finally { response?.Dispose(); } }
public async Task StopAsync(CancellationToken cancellationToken) { if (TryCreateStopMessage(out IpcMessage requestMessage)) { try { IpcMessage response = await IpcClient.SendMessageAsync(_endpoint, requestMessage, cancellationToken).ConfigureAwait(false); DiagnosticsClient.ValidateResponseMessage(response, nameof(StopAsync)); } // On non-abrupt exits (i.e. the target process has already exited and pipe is gone, sending Stop command will fail). catch (IOException) { throw new ServerNotAvailableException("Could not send Stop command. The target process may have exited."); } } }
///<summary> /// Stops the given session ///</summary> public void Stop() { if (TryCreateStopMessage(out IpcMessage requestMessage)) { try { IpcMessage response = IpcClient.SendMessage(_endpoint, requestMessage); DiagnosticsClient.ValidateResponseMessage(response, nameof(Stop)); } // On non-abrupt exits (i.e. the target process has already exited and pipe is gone, sending Stop command will fail). catch (IOException) { throw new ServerNotAvailableException("Could not send Stop command. The target process may have exited."); } } }
public void BasicEnvTest() { // as the attribute says, this test requires 5.0-rc1 or newer. This has been tested locally on // an rc1 build and passes. It is equivalent to the dotnet/runtime version of this test. TestRunner runner = new TestRunner(CommonHelper.GetTraceePathWithArgs(targetFramework: "net5.0"), output); string testKey = "FOO"; string testVal = "BAR"; runner.AddEnvVar(testKey, testVal); runner.Start(3000); DiagnosticsClient client = new DiagnosticsClient(runner.Pid); Dictionary <string, string> env = client.GetProcessEnvironment(); Assert.True(env.ContainsKey(testKey) && env[testKey].Equals(testVal)); runner.Stop(); }
public void EventPipeSessionStreamTest() { TestRunner runner = new TestRunner(CommonHelper.GetTraceePathWithArgs(), output); runner.Start(3000); DiagnosticsClient client = new DiagnosticsClient(runner.Pid); runner.PrintStatus(); output.WriteLine($"[{DateTime.Now.ToString()}] Trying to start an EventPipe session on process {runner.Pid}"); using (var session = client.StartEventPipeSession(new List <EventPipeProvider>() { new EventPipeProvider("System.Runtime", EventLevel.Informational, 0, new Dictionary <string, string>() { { "EventCounterIntervalSec", "1" } }) })) { var evntCnt = 0; Task streamTask = Task.Run(() => { var source = new EventPipeEventSource(session.EventStream); source.Dynamic.All += (TraceEvent obj) => { output.WriteLine("Got an event"); evntCnt += 1; }; try { source.Process(); } catch (Exception e) { // This exception can happen if the target process exits while EventPipeEventSource is in the middle of reading from the pipe. Console.WriteLine("Error encountered while processing events"); Console.WriteLine(e.ToString()); } finally { runner.Stop(); } }); output.WriteLine("Waiting for stream Task"); streamTask.Wait(10000); output.WriteLine("Done waiting for stream Task"); Assert.True(evntCnt > 0); } }
public void PublishedProcessTest1() { using TestRunner runner = new TestRunner(CommonHelper.GetTraceePathWithArgs(), output); runner.Start(timeoutInMSPipeCreation: 3000); // On Windows, runner.Start will not wait for named pipe creation since for other tests, NamedPipeClientStream will // just wait until the named pipe is created. // For these tests, we need to sleep an arbitrary time before pipe is created. if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Thread.Sleep(5000); } List <int> publishedProcesses = new List <int>(DiagnosticsClient.GetPublishedProcesses()); foreach (int p in publishedProcesses) { output.WriteLine($"[{DateTime.Now.ToString()}] Saw published process {p}"); } Assert.Contains(publishedProcesses, p => p == runner.Pid); runner.Stop(); }
public void WriteAllDumpTypesTest() { var normalDumpPath = "./myDump-normal.dmp"; var heapDumpPath = "./myDump-heap.dmp"; var triageDumpPath = "./myDump-triage.dmp"; var fullDumpPath = "./myDump-full.dmp"; using TestRunner runner = new TestRunner(CommonHelper.GetTraceePathWithArgs(), output); runner.Start(3000); DiagnosticsClient client = new DiagnosticsClient(runner.Pid); if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { Assert.Throws <PlatformNotSupportedException>(() => client.WriteDump(DumpType.Normal, normalDumpPath)); Assert.Throws <PlatformNotSupportedException>(() => client.WriteDump(DumpType.WithHeap, heapDumpPath)); Assert.Throws <PlatformNotSupportedException>(() => client.WriteDump(DumpType.Triage, triageDumpPath)); Assert.Throws <PlatformNotSupportedException>(() => client.WriteDump(DumpType.Full, fullDumpPath)); } else { // Write each type of dump output.WriteLine($"Requesting dump at {DateTime.Now.ToString()}"); client.WriteDump(DumpType.Normal, normalDumpPath); client.WriteDump(DumpType.WithHeap, heapDumpPath); client.WriteDump(DumpType.Triage, triageDumpPath); client.WriteDump(DumpType.Full, fullDumpPath); // Check they were all created Assert.True(File.Exists(normalDumpPath)); Assert.True(File.Exists(heapDumpPath)); Assert.True(File.Exists(triageDumpPath)); Assert.True(File.Exists(fullDumpPath)); // Remove them File.Delete(normalDumpPath); File.Delete(heapDumpPath); File.Delete(triageDumpPath); File.Delete(fullDumpPath); } runner.Stop(); }
public void BasicWriteDumpTest() { var dumpPath = "./myDump.dmp"; TestRunner runner = new TestRunner(CommonHelper.GetTraceePath(), output); runner.Start(3000); DiagnosticsClient client = new DiagnosticsClient(runner.Pid); if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { Assert.Throws <PlatformNotSupportedException>(() => client.WriteDump(DumpType.Normal, dumpPath)); } else { output.WriteLine($"Requesting dump at {DateTime.Now.ToString()}"); client.WriteDump(DumpType.Normal, dumpPath); Assert.True(File.Exists(dumpPath)); File.Delete(dumpPath); } runner.Stop(); }
public async Task WaitForConnectionTest() { using TestRunner runner = new TestRunner(CommonHelper.GetTraceePathWithArgs(), output); runner.Start(timeoutInMSPipeCreation: 3000); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Thread.Sleep(5000); } var client = new DiagnosticsClient(runner.Pid); using var timeoutSource = new CancellationTokenSource(TimeSpan.FromMilliseconds(250)); try { await client.WaitForConnectionAsync(timeoutSource.Token); } finally { runner.Stop(); } }
public void WriteDumpFailTest() { List <int> pids = new List <int>(DiagnosticsClient.GetPublishedProcesses()); int arbitraryPid = 1; string dumpPath = "./myDump.dmp"; while (pids.Contains(arbitraryPid)) { arbitraryPid += 1; } var client = new DiagnosticsClient(arbitraryPid); if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { Assert.Throws <PlatformNotSupportedException>(() => client.WriteDump(DumpType.Normal, dumpPath)); } else { Assert.Throws <ServerNotAvailableException>(() => client.WriteDump(DumpType.Normal, "./myDump.dmp")); } }
/// <summary> /// Verifies that a client can handle multiple operations simultaneously. /// </summary> private async Task VerifySingleSession(IpcEndpointInfo info) { await VerifyWaitForConnection(info); var client = new DiagnosticsClient(info.Endpoint); _outputHelper.WriteLine($"{info.RuntimeInstanceCookie}: Creating session #1."); var providers = new List <EventPipeProvider>(); providers.Add(new EventPipeProvider( "System.Runtime", EventLevel.Informational, 0, new Dictionary <string, string>() { { "EventCounterIntervalSec", "1" } })); using var session = client.StartEventPipeSession(providers); _outputHelper.WriteLine($"{info.RuntimeInstanceCookie}: Verifying session produces events."); await VerifyEventStreamProvidesEventsAsync(info, session, 1); _outputHelper.WriteLine($"{info.RuntimeInstanceCookie}: Session verification complete."); }
public void BasicWriteDumpTest() { if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { var dumpPath = "./myDump.dmp"; using TestRunner runner = new TestRunner(CommonHelper.GetTraceePathWithArgs(), output); runner.Start(timeoutInMSPipeCreation: 3000); DiagnosticsClient client = new DiagnosticsClient(runner.Pid); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Environment.Version.ToString().StartsWith("3")) { Assert.Throws <UnsupportedCommandException>(() => client.WriteDump(DumpType.Normal, dumpPath)); } else { output.WriteLine($"Requesting dump at {DateTime.Now.ToString()}"); client.WriteDump(DumpType.Normal, dumpPath); Assert.True(File.Exists(dumpPath)); File.Delete(dumpPath); } runner.Stop(); } }
public DiagnosticsClientApiShim(DiagnosticsClient client, bool useAsync) { _client = client; _useAsync = useAsync; }