diff --git a/src/Ultra.Tests/UltraSamplerTests.cs b/src/Ultra.Tests/UltraSamplerTests.cs index 9eeb48f..1b6827e 100644 --- a/src/Ultra.Tests/UltraSamplerTests.cs +++ b/src/Ultra.Tests/UltraSamplerTests.cs @@ -2,7 +2,10 @@ // Licensed under the BSD-Clause 2 license. // See license.txt file in the project root for full license information. +using Microsoft.Diagnostics.Tracing; +using Microsoft.Diagnostics.Tracing.StackSources; using Ultra.Core; +using Ultra.Core.Model; using Ultra.Sampler; using Ultra.Sampler.MacOS; @@ -32,4 +35,99 @@ public void TestEventSource() Assert.AreEqual(UltraSamplerConstants.ProviderName, sampler.Name); Assert.AreEqual(UltraSamplerConstants.ProviderGuid, sampler.Guid); } + + [TestMethod] + public void TestProcessor() + { + return; // Disabled + + using var samplerEventSource = new EventPipeEventSource(@"C:\code\Captures\ultra_Ultra_2024-12-22_15_00_14_2860_sampler.nettrace"); + using var clrEventSource = new EventPipeEventSource(@"C:\code\Captures\ultra_Ultra_2024-12-22_15_00_14_2860_clr.nettrace"); + + var processor = new UltraEventPipeProcessor(samplerEventSource, clrEventSource); + + var session = processor.Run(); + + Console.WriteLine("----------------------------------------------------------------------------------------"); + Console.WriteLine("Modules"); + Console.WriteLine("----------------------------------------------------------------------------------------"); + + var process = session.Processes[0]; + foreach (var traceModule in process.Modules.Items) + { + Console.WriteLine(traceModule); + } + + Console.WriteLine($"CodeAddresses: {process.CodeAddresses.Items.Length} items"); + Console.WriteLine($"CallStacks: {process.CallStacks.Items.Length} items"); + + Console.WriteLine("----------------------------------------------------------------------------------------"); + Console.WriteLine($"Threads {process.Threads.Items.Length} items"); + Console.WriteLine("----------------------------------------------------------------------------------------"); + + foreach (var thread in process.Threads.Items) + { + Console.WriteLine(thread); + } + + //return; + + var modules = process.Modules; + var managedMethods = process.ManagedMethods; + + foreach (var thread in process.Threads) + { + Console.WriteLine(thread); + + + foreach (var callstack in thread.Samples) + { + Console.WriteLine($" CallStack: {callstack}"); + + UCallStackIndex parentIndex = callstack.CallStackIndex; + while (true) + { + var frameInfo = process.CallStacks[parentIndex]; + parentIndex = frameInfo.ParentCallStackIndex; + if (parentIndex == UCallStackIndex.Invalid) + { + break; + } + + var frame = process.CodeAddresses[frameInfo.CodeAddressIndex]; + if (modules.TryFindNativeModuleByAddress(frame, out var module)) + { + Console.WriteLine($" {module.ModuleFile.FilePath}+{frame - module.BaseAddress} (Module: {module.BaseAddress} Address: {frame})"); + } + else + { + if (managedMethods.TryFindMethodByAddress(frame, out var method)) + { + Console.WriteLine($" {method.MethodNamespace}.{method.MethodName}+{frame - method.MethodStartAddress} (Method: {method.MethodStartAddress} Address: {frame})"); + } + else + { + Console.WriteLine($" {frame}"); + } + } + //Console.WriteLine($" {addressIndex}"); + } + } + } + + //EventPipeEventSource + //TraceLog.CreateFromEventPipeDataFile(@"C:\code\Captures\ultra_Ultra_2024-12-17_08_13_37_34101_sampler.nettrace"); + //TraceLog.CreateFromEventPipeDataFile(@"C:\code\Captures\ultra_Ultra_2024-12-17_08_13_37_34101_clr.nettrace"); + + + + //TraceEventSession.Merge([@"C:\code\Captures\ultra_Ultra_2024-12-17_08_13_37_34101_sampler.nettrace.etlx", @"C:\code\Captures\ultra_Ultra_2024-12-17_08_13_37_34101_sampler.nettrace.etlx"], @"C:\code\Captures\test.etlx"); + //TraceLog.M + + //UAddress x = (UAddress)0x15; + + //Console.WriteLine(x); + + + } } \ No newline at end of file