Skip to content

Commit

Permalink
Add temporary test
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Dec 22, 2024
1 parent efb3412 commit bf13c46
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions src/Ultra.Tests/UltraSamplerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);


}
}

0 comments on commit bf13c46

Please sign in to comment.