Skip to content

Commit

Permalink
Add uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Dec 16, 2024
1 parent 4383eb3 commit d8b357f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/Ultra.Core/Parser/UltraSamplerParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public override object PayloadValue(int index)

public override string[] PayloadNames => _payloadNames;

/// <inheritdoc />
protected override Delegate? Target
{
get => _target;
Expand Down
2 changes: 1 addition & 1 deletion src/Ultra.Sampler/MacOS/MacOSLibSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -444,4 +444,4 @@ public enum TH_FLAGS
public const uint LC_UUID = 0x1b;
public const uint LC_SEGMENT_64 = 0x19;

}
}
5 changes: 3 additions & 2 deletions src/Ultra.Sampler/MacOS/MacOSUltraSampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ private void AddModuleEvent(UltraSamplerNativeModuleEventKind kind, nint loadAdd
evt.Path = path.ToArray();
evt.TimestampUtc = DateTime.UtcNow;
evt.Size = GetDyldCodeSize(loadAddress);
TryGetUuidFromMacHeader(loadAddress, out evt.Uuid);

lock (_moduleEventLock)
{
Expand All @@ -230,7 +231,7 @@ private void NotifyPendingNativeModuleEvents()
for(; _nextModuleEventIndexToLog < events.Length; _nextModuleEventIndexToLog++)
{
var evt = events[_nextModuleEventIndexToLog];
UltraSamplerSource.Log.NativeModuleEvent((int)evt.Kind, evt.LoadAddress, evt.Size, evt.TimestampUtc, evt.Path);
UltraSamplerSource.Log.NativeModuleEvent((int)evt.Kind, evt.LoadAddress, evt.Size, evt.TimestampUtc, evt.Uuid, evt.Path);
}
}
}
Expand Down Expand Up @@ -425,7 +426,7 @@ private int ComputeSameFrameCount(ulong threadId, int frameCount, ulong* frames)

int sameFrameCount = 0;

ref var allCompressedFrames = ref _allCompressedFrames[0];
ref var allCompressedFrames = ref MemoryMarshal.GetArrayDataReference(_allCompressedFrames);
var indexInCompressedFrames = index * MaximumCompressedFrameTotalCount;
ref ulong previousFrame = ref Unsafe.Add(ref allCompressedFrames, indexInCompressedFrames);

Expand Down
1 change: 1 addition & 0 deletions src/Ultra.Sampler/MacOS/NativeModuleEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal struct NativeModuleEvent
public ulong LoadAddress;
public ulong Size;
public byte[]? Path;
public Guid Uuid;
public DateTime TimestampUtc;

public override string ToString()
Expand Down
20 changes: 11 additions & 9 deletions src/Ultra.Sampler/UltraSamplerSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ private UltraSamplerSource()

[Event(UltraSamplerConstants.NativeModuleEventId, Level = EventLevel.Informational, Task = (EventTask)UltraSamplerConstants.TaskNativeModuleEventId)]
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
public unsafe void NativeModuleEvent(int nativeModuleEventKind, ulong loadAddress, ulong size, DateTime timestampUtc, byte[]? modulePathUtf8) // byte[] is last to allow perfview to visualize previous fixed size arguments
public unsafe void NativeModuleEvent(int nativeModuleEventKind, ulong loadAddress, ulong size, DateTime timestampUtc, Guid uuid, byte[]? modulePathUtf8) // byte[] is last to allow perfview to visualize previous fixed size arguments
{
var evt = stackalloc EventData[6];
var evt = stackalloc EventData[7];
evt[0].DataPointer = (nint)(void*)&nativeModuleEventKind;
evt[0].Size = sizeof(int);
evt[1].DataPointer = (nint)(void*)&loadAddress;
Expand All @@ -51,24 +51,26 @@ private UltraSamplerSource()
var utcFileTime = timestampUtc.ToFileTimeUtc();
evt[3].DataPointer = (nint)(void*)&utcFileTime;
evt[3].Size = sizeof(long);
evt[4].DataPointer = (nint)(void*)&uuid;
evt[4].Size = sizeof(Guid);
fixed (byte* evtPathPtr = modulePathUtf8)
{
var modulePathUtf8Size = modulePathUtf8?.Length ?? 0;
evt[4].DataPointer = (nint)(void*)&modulePathUtf8Size;
evt[4].Size = sizeof(int);
evt[5].DataPointer = (nint)(void*)&modulePathUtf8Size;
evt[5].Size = sizeof(int);

if (modulePathUtf8Size > 0)
{
evt[5].DataPointer = (nint)evtPathPtr;
evt[5].Size = modulePathUtf8Size;
evt[6].DataPointer = (nint)evtPathPtr;
evt[6].Size = modulePathUtf8Size;
}
else
{
evt[5].DataPointer = (nint)(void*)&loadAddress;
evt[5].Size = 0;
evt[6].DataPointer = (nint)(void*)&loadAddress;
evt[6].Size = 0;
}

WriteEventCore(UltraSamplerConstants.NativeModuleEventId, 6, evt);
WriteEventCore(UltraSamplerConstants.NativeModuleEventId, 7, evt);
}
}

Expand Down

0 comments on commit d8b357f

Please sign in to comment.