Skip to content

Commit

Permalink
Rename processor
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Dec 27, 2024
1 parent bbb1669 commit 4f223f1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ namespace Ultra.Core;
/// <summary>
/// Internal class to process events from an EventPipe session (Sampler and CLR)
/// </summary>
internal class UltraEventPipeProcessor
internal class UltraEventProcessor
{
private readonly EventPipeEventSource _samplerEventSource;
private readonly TraceEventDispatcher _samplerEventSource;
private readonly UltraSamplerParser _samplerParser;
private ProcessState? _currentProcessState;

private readonly UTraceSession _session = new();

private readonly UnsafeDictionary<int, ProcessState> _processes = new(1);

private readonly EventPipeEventSource? _clrEventSource;
private readonly TraceEventDispatcher? _clrEventSource;
private readonly ClrRundownTraceEventParser? _clrRundownTraceEventParser;

public UltraEventPipeProcessor(EventPipeEventSource samplerEventSource)
public UltraEventProcessor(TraceEventDispatcher samplerEventSource)
{
_samplerEventSource = samplerEventSource;
_samplerParser = new UltraSamplerParser(samplerEventSource);
Expand All @@ -41,7 +41,7 @@ public UltraEventPipeProcessor(EventPipeEventSource samplerEventSource)
_samplerParser.Source.Dynamic.AddCallbackForProviderEvent("Microsoft-DotNETCore-EventPipe", "ProcessInfo", SamplerProcessInfo);
}

public UltraEventPipeProcessor(EventPipeEventSource samplerEventSource, EventPipeEventSource clrEventSource) : this(samplerEventSource)
public UltraEventProcessor(TraceEventDispatcher samplerEventSource, TraceEventDispatcher clrEventSource) : this(samplerEventSource)
{
_clrEventSource = clrEventSource;
_clrRundownTraceEventParser = new ClrRundownTraceEventParser(clrEventSource);
Expand Down Expand Up @@ -95,6 +95,27 @@ public UltraEventPipeProcessor(EventPipeEventSource samplerEventSource, EventPip
_clrRundownTraceEventParser.MethodILToNativeMapDCStop += ProcessMethodILToNativeMap;
}

public UTraceSession Run()
{
// Run CLR if available
_clrEventSource?.Process();

foreach (var process in _session.Processes)
{
process.ManagedMethods.SortMethodAddressRanges();
}

// Run sampler before CLR
_samplerEventSource.Process();

_session.NumberOfProcessors = _samplerEventSource.NumberOfProcessors;
_session.StartTime = _samplerEventSource.SessionStartTime;
_session.Duration = _samplerEventSource.SessionDuration;
_session.CpuSpeedMHz = _samplerEventSource.CpuSpeedMHz;

return _session;
}

private void SamplerParserOnEventNativeProcessStart(UltraNativeProcessStartTraceEvent processStartEvent)
{
var processState = GetProcessState(processStartEvent);
Expand Down Expand Up @@ -365,27 +386,6 @@ private void SamplerParserOnEventNativeThreadStop(UltraNativeThreadStopTraceEven
thread.StopTime = UTimeSpan.FromMilliseconds(obj.TimeStampRelativeMSec);
}

public UTraceSession Run()
{
// Run CLR if available
_clrEventSource?.Process();

foreach (var process in _session.Processes)
{
process.ManagedMethods.SortMethodAddressRanges();
}

// Run sampler before CLR
_samplerEventSource.Process();

_session.NumberOfProcessors = _samplerEventSource.NumberOfProcessors;
_session.StartTime = _samplerEventSource.SessionStartTime;
_session.Duration = _samplerEventSource.SessionDuration;
_session.CpuSpeedMHz = _samplerEventSource.CpuSpeedMHz;

return _session;
}

private void SamplerProcessInfo(TraceEvent obj)
{
var osInformation = obj.PayloadByName("OSInformation") as string;
Expand Down
12 changes: 6 additions & 6 deletions src/Ultra.Tests/UltraSamplerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ 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");
using var samplerEventSource = new EventPipeEventSource(@"/Users/xoofx/code/captures/ultra_Ultra_2024-12-25_12_46_29_8804_sampler.nettrace");
using var clrEventSource = new EventPipeEventSource(@"/Users/xoofx/code/captures/ultra_Ultra_2024-12-25_12_46_29_8804_clr.nettrace");

var processor = new UltraEventPipeProcessor(samplerEventSource, clrEventSource);
var processor = new UltraEventProcessor(samplerEventSource, clrEventSource);

var session = processor.Run();

Expand All @@ -60,7 +60,7 @@ public void TestProcessor()

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("----------------------------------------------------------------------------------------");
Expand Down Expand Up @@ -111,10 +111,10 @@ public void TestProcessor()
}
}
//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");
Expand Down

0 comments on commit 4f223f1

Please sign in to comment.