-
-
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.
Add Thread Start/Stop and samplingId
- Loading branch information
Showing
8 changed files
with
254 additions
and
30 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
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,79 @@ | ||
// 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; | ||
using Ultra.Sampler; | ||
|
||
namespace Ultra.Core; | ||
|
||
internal sealed class UltraNativeThreadStartTraceEvent : TraceEvent | ||
{ | ||
private static readonly string[] _payloadNames = | ||
[ | ||
nameof(SamplingId), | ||
nameof(FrameThreadId), | ||
nameof(ThreadNameSize), | ||
nameof(ThreadName), | ||
]; | ||
|
||
private Action<UltraNativeThreadStartTraceEvent>? _target; | ||
|
||
internal UltraNativeThreadStartTraceEvent(Action<UltraNativeThreadStartTraceEvent>? 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 SamplingId => (ulong)GetInt64At(0); | ||
|
||
public ulong FrameThreadId => (ulong)GetInt64At(8); | ||
|
||
public int ThreadNameSize => GetInt32At(16); | ||
|
||
public unsafe byte* ThreadNamePointer => (byte*)DataStart + 24 + ThreadNameSize; | ||
|
||
public unsafe string ThreadName => Encoding.UTF8.GetString(new ReadOnlySpan<byte>(ThreadNamePointer, ThreadNameSize)); | ||
|
||
/// <inheritdoc /> | ||
|
||
public override object PayloadValue(int index) | ||
{ | ||
switch (index) | ||
{ | ||
case 0: | ||
return SamplingId; | ||
case 1: | ||
return FrameThreadId; | ||
case 2: | ||
return ThreadNameSize; | ||
case 3: | ||
unsafe | ||
{ | ||
return new ReadOnlySpan<byte>(ThreadNamePointer, ThreadNameSize).ToArray(); | ||
} | ||
default: | ||
throw new ArgumentOutOfRangeException(nameof(index)); | ||
} | ||
} | ||
|
||
public override string[] PayloadNames => _payloadNames; | ||
|
||
/// <inheritdoc /> | ||
protected override Delegate? Target | ||
{ | ||
get => _target; | ||
set => _target = (Action<UltraNativeThreadStartTraceEvent>?)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,62 @@ | ||
// 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; | ||
|
||
namespace Ultra.Core; | ||
|
||
internal sealed class UltraNativeThreadStopTraceEvent : TraceEvent | ||
{ | ||
private static readonly string[] _payloadNames = | ||
[ | ||
nameof(SamplingId), | ||
nameof(FrameThreadId), | ||
]; | ||
|
||
private Action<UltraNativeThreadStopTraceEvent>? _target; | ||
|
||
internal UltraNativeThreadStopTraceEvent(Action<UltraNativeThreadStopTraceEvent>? 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 SamplingId => (ulong)GetInt64At(0); | ||
|
||
public ulong FrameThreadId => (ulong)GetInt64At(8); | ||
|
||
/// <inheritdoc /> | ||
|
||
public override object PayloadValue(int index) | ||
{ | ||
switch (index) | ||
{ | ||
case 0: | ||
return SamplingId; | ||
case 1: | ||
return FrameThreadId; | ||
default: | ||
throw new ArgumentOutOfRangeException(nameof(index)); | ||
} | ||
} | ||
|
||
public override string[] PayloadNames => _payloadNames; | ||
|
||
/// <inheritdoc /> | ||
protected override Delegate? Target | ||
{ | ||
get => _target; | ||
set => _target = (Action<UltraNativeThreadStopTraceEvent>?)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
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
Oops, something went wrong.