未验证 提交 d0916fbd 编写于 作者: J John Salem 提交者: GitHub

Fix in-process decoding of DateTime in EventSource (#67557)

上级 f00615cf
......@@ -1841,7 +1841,7 @@ private static unsafe void DecodeObjects(object?[] decodedObjects, Type[] parame
}
else if (typeCode == TypeCode.DateTime)
{
decoded = *(DateTime*)dataPointer;
decoded = DateTime.FromFileTimeUtc(*(long*)dataPointer);
}
else if (IntPtr.Size == 8 && dataType == typeof(IntPtr))
{
......
......@@ -15,6 +15,20 @@ class SimpleEventSource : EventSource
[Event(1)]
internal void MathResult(int x, int y, int z, string formula) { this.WriteEvent(1, x, y, z, formula); }
[Event(2)]
internal void DateTimeEvent(DateTime dateTime) => WriteEvent(2, dateTime);
[NonEvent]
private unsafe void WriteEvent(int eventId, DateTime dateTime)
{
EventData* desc = stackalloc EventData[1];
long fileTime = dateTime.ToFileTimeUtc();
desc[0].DataPointer = (IntPtr)(&fileTime);
desc[0].Size = 8;
WriteEventCore(eventId, 1, desc);
}
}
internal sealed class SimpleEventListener : EventListener
......@@ -23,6 +37,7 @@ internal sealed class SimpleEventListener : EventListener
private readonly EventLevel _level;
public int EventCount { get; private set; } = 0;
public DateTime DateObserved { get; private set; } = DateTime.MinValue;
public SimpleEventListener(string targetSourceName, EventLevel level)
{
......@@ -41,13 +56,19 @@ protected override void OnEventSourceCreated(EventSource source)
protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
EventCount++;
if (eventData.EventId == 2)
{
DateObserved = (DateTime)eventData.Payload[0];
}
else
EventCount++;
}
}
class EventPipeSmoke
{
private static int messageIterations = 100;
private static readonly DateTime ThePast = DateTime.UtcNow;
static int Main(string[] args)
{
......@@ -68,10 +89,12 @@ static int Main(string[] args)
eventSource.MathResult(x, y, x+y, formula);
}
eventSource.DateTimeEvent(ThePast);
Console.WriteLine("\tEnd: Messaging.\n");
Console.WriteLine($"\tEventListener received {listener.EventCount} event(s)\n");
pass = listener.EventCount == messageIterations;
Console.WriteLine($"\tEventListener received {listener.DateObserved} vs {ThePast}\n");
pass = listener.EventCount == messageIterations && ThePast == listener.DateObserved;
}
return pass ? 100 : -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册