-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update native UltraNativeModuleTraceEvent with uuid
- Loading branch information
Showing
4 changed files
with
178 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright (c) Alexandre Mutel. All rights reserved. | ||
// Licensed under the BSD-Clause 2 license. | ||
// See license.txt file in the project root for full license information. | ||
|
||
using Microsoft.Diagnostics.Tracing; | ||
using Ultra.Sampler; | ||
|
||
namespace Ultra.Core; | ||
|
||
internal sealed class UltraNativeCallstackTraceEvent : TraceEvent | ||
{ | ||
private static readonly string[] _payloadNames = | ||
[ | ||
nameof(FrameThreadId), | ||
nameof(ThreadState), | ||
nameof(ThreadCpuUsage), | ||
nameof(PreviousFrameCount), | ||
nameof(FrameSize), | ||
nameof(FrameAddresses) | ||
]; | ||
|
||
private Action<UltraNativeCallstackTraceEvent>? _target; | ||
|
||
internal UltraNativeCallstackTraceEvent(Action<UltraNativeCallstackTraceEvent>? target, int eventID, int task, string taskName, Guid taskGuid, int opcode, string opcodeName, Guid providerGuid, string providerName) : base(eventID, task, taskName, taskGuid, opcode, opcodeName, providerGuid, providerName) | ||
{ | ||
_target = target; | ||
} | ||
|
||
public ulong FrameThreadId => (ulong)GetInt64At(0); | ||
|
||
public UltraSamplerThreadState ThreadState => (UltraSamplerThreadState)GetInt32At(8); | ||
|
||
public double ThreadCpuUsage => GetInt32At(12) / 1000.0; | ||
|
||
public int PreviousFrameCount => GetInt32At(16); | ||
|
||
public int FrameSize => GetInt32At(20); | ||
|
||
public unsafe ReadOnlySpan<ulong> FrameAddresses => new((byte*)DataStart + 24, FrameSize / sizeof(ulong)); | ||
|
||
/// <inheritdoc /> | ||
|
||
public override object PayloadValue(int index) | ||
{ | ||
switch (index) | ||
{ | ||
case 0: | ||
return FrameThreadId; | ||
case 1: | ||
return (int)ThreadState; | ||
case 2: | ||
return GetInt32At(12); | ||
case 3: | ||
return PreviousFrameCount; | ||
case 4: | ||
return FrameSize; | ||
case 5: | ||
return FrameAddresses.ToArray(); | ||
default: | ||
throw new ArgumentOutOfRangeException(nameof(index)); | ||
} | ||
} | ||
|
||
public override string[] PayloadNames => _payloadNames; | ||
|
||
/// <inheritdoc /> | ||
protected override Delegate? Target | ||
{ | ||
get => _target; | ||
set => _target = (Action<UltraNativeCallstackTraceEvent>?)value; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Dispatch() | ||
{ | ||
_target?.Invoke(this); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Validate() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright (c) Alexandre Mutel. All rights reserved. | ||
// Licensed under the BSD-Clause 2 license. | ||
// See license.txt file in the project root for full license information. | ||
|
||
using System.Text; | ||
using Microsoft.Diagnostics.Tracing; | ||
|
||
namespace Ultra.Core; | ||
|
||
internal sealed class UltraNativeModuleTraceEvent : TraceEvent | ||
{ | ||
private static readonly string[] _payloadNames = | ||
[ | ||
nameof(NativeModuleEventKind), | ||
nameof(LoadAddress), | ||
nameof(Size), | ||
nameof(TimestampUtc), | ||
nameof(Uuid), | ||
nameof(ModulePathUtf8Length), | ||
nameof(ModulePath) | ||
]; | ||
|
||
private Action<UltraNativeModuleTraceEvent>? _target; | ||
|
||
internal UltraNativeModuleTraceEvent(Action<UltraNativeModuleTraceEvent>? target, int eventID, int task, string taskName, Guid taskGuid, int opcode, string opcodeName, Guid providerGuid, string providerName) : base(eventID, task, taskName, taskGuid, opcode, opcodeName, | ||
providerGuid, | ||
providerName) | ||
{ | ||
_target = target; | ||
} | ||
|
||
public UltraSamplerNativeModuleEventKind NativeModuleEventKind => (UltraSamplerNativeModuleEventKind)GetInt32At(0); | ||
|
||
public ulong LoadAddress => (ulong)GetInt64At(4); | ||
|
||
public ulong Size => (ulong)GetInt64At(12); | ||
|
||
public DateTime TimestampUtc => DateTime.FromFileTimeUtc(GetInt64At(20)); | ||
|
||
public unsafe Guid Uuid => *(Guid*)(DataStart + 28); | ||
|
||
public unsafe int ModulePathUtf8Length => GetInt32At(44); | ||
|
||
public unsafe ReadOnlySpan<byte> ModulePathUtf8 => ModulePathUtf8Length == 0 ? ReadOnlySpan<byte>.Empty : new((byte*)DataStart + 48, ModulePathUtf8Length); | ||
|
||
public unsafe string? ModulePath => ModulePathUtf8Length == 0 ? null : Encoding.UTF8.GetString(ModulePathUtf8); | ||
|
||
/// <inheritdoc /> | ||
public override object? PayloadValue(int index) | ||
{ | ||
switch (index) | ||
{ | ||
case 0: | ||
return (int)NativeModuleEventKind; | ||
case 1: | ||
return LoadAddress; | ||
case 2: | ||
return Size; | ||
case 3: | ||
return TimestampUtc; | ||
case 4: | ||
return Uuid; | ||
case 5: | ||
return ModulePathUtf8Length; | ||
case 6: | ||
return ModulePathUtf8.ToArray(); | ||
default: | ||
throw new ArgumentOutOfRangeException(nameof(index)); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override string[] PayloadNames => _payloadNames; | ||
|
||
/// <inheritdoc /> | ||
protected override Delegate? Target | ||
{ | ||
get => _target; | ||
set => _target = (Action<UltraNativeModuleTraceEvent>?)value; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Dispatch() | ||
{ | ||
_target?.Invoke(this); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Validate() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters