Skip to content

Commit

Permalink
Remove Opcode Validation When Specifying a RelatedActivityId (dotnet#…
Browse files Browse the repository at this point in the history
…38347)

* Remove opcode validation when specifying relatedActivityId.

* Remove test that is no longer needed.
  • Loading branch information
brianrob authored and github-actions committed Aug 17, 2020
1 parent 244bcf3 commit cbf4e83
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,17 +328,6 @@
// source.UnregisterEventTemplate(value, 30, ProviderGuid);
// }
// }
// public event Action<EmptyTraceData> LogTransferNoOpcode
// {
// add
// {
// source.RegisterEventTemplate(LogTransferNoOpcodeTemplate(value));
// }
// remove
// {
// source.UnregisterEventTemplate(value, 28, ProviderGuid);
// }
// }
// public event Action<MessageArgs> Message
// {
// add
Expand Down Expand Up @@ -535,10 +524,6 @@
// { // action, eventid, taskid, taskName, taskGuid, opcode, opcodeName, providerGuid, providerName
// return new EventWithWeirdArgsArgs(action, 30, 65504, "EventWithWeirdArgs", Guid.Empty, 0, "", ProviderGuid, ProviderName);
// }
// private static EmptyTraceData LogTransferNoOpcodeTemplate(Action<EmptyTraceData> action)
// { // action, eventid, taskid, taskName, taskGuid, opcode, opcodeName, providerGuid, providerName
// return new EmptyTraceData(action, 28, 65506, "LogTransferNoOpcode", Guid.Empty, 0, "", ProviderGuid, ProviderName);
// }
// private static MessageArgs MessageTemplate(Action<MessageArgs> action)
// { // action, eventid, taskid, taskName, taskGuid, opcode, opcodeName, providerGuid, providerName
// return new MessageArgs(action, 14, 65520, "Message", Guid.Empty, 0, "", ProviderGuid, ProviderName);
Expand Down Expand Up @@ -577,7 +562,7 @@
// {
// if (s_templates == null)
// {
// var templates = new TraceEvent[35];
// var templates = new TraceEvent[34];
// templates[0] = Event0Template(null);
// templates[1] = EventITemplate(null);
// templates[2] = EventIITemplate(null);
Expand Down Expand Up @@ -605,14 +590,13 @@
// templates[24] = EventWithManyTypeArgsTemplate(null);
// templates[25] = EventWith7StringsTemplate(null);
// templates[26] = EventWith9StringsTemplate(null);
// templates[27] = LogTransferNoOpcodeTemplate(null);
// templates[28] = WorkManyArgsSendTemplate(null);
// templates[29] = EventWithWeirdArgsTemplate(null);
// templates[30] = WorkWeirdArgsSendTemplate(null);
// templates[31] = EventWithEscapingMessageTemplate(null);
// templates[32] = EventWithMoreEscapingMessageTemplate(null);
// templates[33] = EventWithByteArrArgTemplate(null);
// templates[34] = EventWithBytePtrArgTemplate(null);
// templates[27] = WorkManyArgsSendTemplate(null);
// templates[28] = EventWithWeirdArgsTemplate(null);
// templates[29] = WorkWeirdArgsSendTemplate(null);
// templates[30] = EventWithEscapingMessageTemplate(null);
// templates[31] = EventWithMoreEscapingMessageTemplate(null);
// templates[32] = EventWithByteArrArgTemplate(null);
// templates[33] = EventWithBytePtrArgTemplate(null);
// s_templates = templates;
// }
// foreach (var template in s_templates)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ public void Test_WriteEvent_TransferEvents()
Assert.True((bool)LoudListener.LastEvent.Payload[1]);
Assert.Equal(MyLongEnum.LongVal1, (MyLongEnum)LoudListener.LastEvent.Payload[2]);
// Assert.Equal(9999999999999999999999999999m, (decimal)LoudListener.LastEvent.Payload[3]);

actid = Guid.NewGuid();
Assert.Throws<EventSourceException>(() => log.LogTransferNoOpcode(actid));
}
}
TestUtilities.CheckNoEventSourcesRunning("Stop");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,6 @@ public void EventWith7Strings(string s0, string s1, string s2, string s3, string
public void EventWith9Strings(string s0, string s1, string s2, string s3, string s4, string s5, string s6, string s7, string s8)
{ WriteEvent(27, s0, s1, s2, s3, s4, s5, s6, s7, s8); }

[Event(28, Keywords = Keywords.Transfer | Keywords.HasNoArgs)]
public void LogTransferNoOpcode(Guid RelatedActivityId)
{
unsafe
{
WriteEventWithRelatedActivityIdCore(28, &RelatedActivityId, 0, null);
}
}

[Event(29, Keywords = Keywords.Transfer | Keywords.HasNoArgs, Level = EventLevel.Informational, Opcode = EventOpcode.Send, Task = Tasks.WorkManyArgs)]
public void EventWithXferManyTypeArgs(Guid RelatedActivityId, long l, uint ui, ulong ui64, char ch,
byte b, sbyte sb, short sh, ushort ush,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1195,9 +1195,6 @@ protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, Guid* rel
Debug.Assert(m_eventData != null); // You must have initialized this if you enabled the source.
try
{
if (relatedActivityId != null)
ValidateEventOpcodeForTransfer(ref m_eventData[eventId], m_eventData[eventId].Name);

EventOpcode opcode = (EventOpcode)m_eventData[eventId].Descriptor.Opcode;
EventActivityOptions activityOptions = m_eventData[eventId].ActivityOptions;
Guid* pActivityId = null;
Expand Down Expand Up @@ -1870,8 +1867,6 @@ private unsafe void WriteEventVarargs(int eventId, Guid* childActivityID, object
{
if (childActivityID != null)
{
ValidateEventOpcodeForTransfer(ref m_eventData[eventId], m_eventData[eventId].Name);

// If you use WriteEventWithRelatedActivityID you MUST declare the first argument to be a GUID
// with the name 'relatedActivityID, and NOT pass this argument to the WriteEvent method.
// During manifest creation we modify the ParameterInfo[] that we store to strip out any
Expand Down Expand Up @@ -2337,16 +2332,6 @@ private void ThrowEventSourceException(string? eventName, Exception? innerEx = n
}
}

private void ValidateEventOpcodeForTransfer(ref EventMetadata eventData, string? eventName)
{
if ((EventOpcode)eventData.Descriptor.Opcode != EventOpcode.Send &&
(EventOpcode)eventData.Descriptor.Opcode != EventOpcode.Receive &&
(EventOpcode)eventData.Descriptor.Opcode != EventOpcode.Start)
{
ThrowEventSourceException(eventName);
}
}

internal static EventOpcode GetOpcodeWithDefault(EventOpcode opcode, string? eventName)
{
if (opcode == EventOpcode.Info && eventName != null)
Expand Down

0 comments on commit cbf4e83

Please sign in to comment.