Example #1
0
 protected unsafe void WriteEventCore(int eventId, int eventDataCount, EventData *data)
 {
 }
        /// <summary>
        /// Writes an extended event, where the values of the event have already
        /// been serialized in "data".
        /// </summary>
        /// <param name="eventName">
        /// The name for the event. If null, the name from eventTypes is used.
        /// (Note that providing the event name via the name parameter is slightly
        /// less efficient than using the name from eventTypes.)
        /// </param>
        /// <param name="options">
        /// Optional overrides for the event, such as the level, keyword, opcode,
        /// activityId, and relatedActivityId. Any settings not specified by options
        /// are obtained from eventTypes.
        /// </param>
        /// <param name="eventTypes">
        /// Information about the event and the types of the values in the event.
        /// Must not be null. Note that the eventTypes object should be created once and
        /// saved. It should not be recreated for each event.
        /// </param>
        /// <param name="activityID">
        /// A pointer to the activity ID GUID to log
        /// </param>
        /// <param name="childActivityID">
        /// A pointer to the child activity ID to log (can be null)
        /// </param>
        /// <param name="data">
        /// The previously serialized values to include in the event. Must not be null.
        /// The number and types of the values must match the number and types of the
        /// fields described by the eventTypes parameter.
        /// </param>
        internal unsafe void WriteMultiMerge(
            string eventName,
            ref EventSourceOptions options,
            TraceLoggingEventTypes eventTypes,
            Guid *activityID,
            Guid *childActivityID,
            EventData *data)
        {
#if FEATURE_MANAGED_ETW
            if (!this.IsEnabled())
            {
                return;
            }

            fixed(EventSourceOptions *pOptions = &options)
            {
                EventDescriptor descriptor;
                var             nameInfo = this.UpdateDescriptor(eventName, eventTypes, ref options, out descriptor);

                if (nameInfo == null)
                {
                    return;
                }

#if FEATURE_PERFTRACING
                IntPtr eventHandle = nameInfo.GetOrCreateEventHandle(m_eventPipeProvider, m_eventHandleTable, descriptor, eventTypes);
                Debug.Assert(eventHandle != IntPtr.Zero);
#else
                IntPtr eventHandle = IntPtr.Zero;
#endif

                // We make a descriptor for each EventData, and because we morph strings to counted strings
                // we may have 2 for each arg, so we allocate enough for this.
                var descriptorsLength = eventTypes.dataCount + eventTypes.typeInfos.Length * 2 + 3;
                var descriptors       = stackalloc EventData[descriptorsLength];
                for (int i = 0; i < descriptorsLength; i++)
                {
                    descriptors[i] = default;

                    fixed(byte *
                          pMetadata0 = this.providerMetadata,
                          pMetadata1 = nameInfo.nameMetadata,
                          pMetadata2 = eventTypes.typeMetadata)
                    {
                        descriptors[0].SetMetadata(pMetadata0, this.providerMetadata.Length, 2);
                        descriptors[1].SetMetadata(pMetadata1, nameInfo.nameMetadata.Length, 1);
                        descriptors[2].SetMetadata(pMetadata2, eventTypes.typeMetadata.Length, 1);
                        int numDescrs = 3;

                        for (int i = 0; i < eventTypes.typeInfos.Length; i++)
                        {
                            descriptors[numDescrs].m_Ptr  = data[i].m_Ptr;
                            descriptors[numDescrs].m_Size = data[i].m_Size;

                            // old conventions for bool is 4 bytes, but meta-data assumes 1.
                            if (data[i].m_Size == 4 && eventTypes.typeInfos[i].DataType == typeof(bool))
                            {
                                descriptors[numDescrs].m_Size = 1;
                            }

                            numDescrs++;
                        }

                        this.WriteEventRaw(
                            eventName,
                            ref descriptor,
                            eventHandle,
                            activityID,
                            childActivityID,
                            numDescrs,
                            (IntPtr)descriptors);
                    }
            }
#endif // FEATURE_MANAGED_ETW
        }
Example #3
0
 internal static extern unsafe uint EventWrite(
     [In] long registrationHandle,
     [In] ref EventDescriptor eventDescriptor,
     [In] uint userDataCount,
     [In] EventData *userData
     );
Example #4
0
 internal unsafe abstract uint EventWrite(EventTrace.Event eventID, EventTrace.Keyword keywords, EventTrace.Level level, int argc, EventData *argv);
Example #5
0
        void ActorMessage(
            string actorType,
            string actorId,
            string applicationTypeName,
            string applicationName,
            string serviceTypeName,
            string serviceName,
            Guid partitionId,
            long replicaOrInstanceId,
            string nodeName,
            string message)
        {
    #if !UNSAFE
            WriteEvent(
                ActorMessageEventId,
                actorType,
                actorId,
                applicationTypeName,
                applicationName,
                serviceTypeName,
                serviceName,
                partitionId,
                replicaOrInstanceId,
                nodeName,
                message);
    #else
            const int numArgs = 10;
            fixed(char *pActorType = actorType, pActorId = actorId, pApplicationTypeName = applicationTypeName, pApplicationName = applicationName, pServiceTypeName = serviceTypeName, pServiceName = serviceName, pNodeName = nodeName, pMessage = message)
            {
                EventData *eventData = stackalloc EventData[numArgs];

                eventData[0] = new EventData {
                    DataPointer = (IntPtr)pActorType, Size = SizeInBytes(actorType)
                };
                eventData[1] = new EventData {
                    DataPointer = (IntPtr)pActorId, Size = SizeInBytes(actorId)
                };
                eventData[2] = new EventData {
                    DataPointer = (IntPtr)pApplicationTypeName, Size = SizeInBytes(applicationTypeName)
                };
                eventData[3] = new EventData {
                    DataPointer = (IntPtr)pApplicationName, Size = SizeInBytes(applicationName)
                };
                eventData[4] = new EventData {
                    DataPointer = (IntPtr)pServiceTypeName, Size = SizeInBytes(serviceTypeName)
                };
                eventData[5] = new EventData {
                    DataPointer = (IntPtr)pServiceName, Size = SizeInBytes(serviceName)
                };
                eventData[6] = new EventData {
                    DataPointer = (IntPtr)(&partitionId), Size = sizeof(Guid)
                };
                eventData[7] = new EventData {
                    DataPointer = (IntPtr)(&replicaOrInstanceId), Size = sizeof(long)
                };
                eventData[8] = new EventData {
                    DataPointer = (IntPtr)pNodeName, Size = SizeInBytes(nodeName)
                };
                eventData[9] = new EventData {
                    DataPointer = (IntPtr)pMessage, Size = SizeInBytes(message)
                };

                WriteEventCore(ActorMessageEventId, numArgs, eventData);
            }
    #endif
        }
Example #6
0
        internal unsafe void WriteMultiMerge(
            string eventName,
            ref EventSourceOptions options,
            TraceLoggingEventTypes eventTypes,
            Guid *activityID,
            Guid *childActivityID,
            EventData *data)
        {
#if FEATURE_MANAGED_ETW
            if (!this.IsEnabled())
            {
                return;
            }

            fixed(EventSourceOptions *pOptions = &options)
            {
                EventDescriptor descriptor;
                var             nameInfo = this.UpdateDescriptor(eventName, eventTypes, ref options, out descriptor);

                if (nameInfo == null)
                {
                    return;
                }

                // We make a descriptor for each EventData, and because we morph strings to counted strings
                // we may have 2 for each arg, so we allocate enough for this.
                var descriptors = stackalloc EventData[eventTypes.dataCount + eventTypes.typeInfos.Length * 2 + 3];

                fixed(byte *
                      pMetadata0 = this.providerMetadata,
                      pMetadata1 = nameInfo.nameMetadata,
                      pMetadata2 = eventTypes.typeMetadata)
                {
                    descriptors[0].SetMetadata(pMetadata0, this.providerMetadata.Length, 2);
                    descriptors[1].SetMetadata(pMetadata1, nameInfo.nameMetadata.Length, 1);
                    descriptors[2].SetMetadata(pMetadata2, eventTypes.typeMetadata.Length, 1);
                    int numDescrs = 3;

                    for (int i = 0; i < eventTypes.typeInfos.Length; i++)
                    {
                        // Until M3, we need to morph strings to a counted representation
                        // When TDH supports null terminated strings, we can remove this.
                        if (eventTypes.typeInfos[i].DataType == typeof(string))
                        {
                            // Write out the size of the string
                            descriptors[numDescrs].m_Ptr  = (long)&descriptors[numDescrs + 1].m_Size;
                            descriptors[numDescrs].m_Size = 2;
                            numDescrs++;

                            descriptors[numDescrs].m_Ptr  = data[i].m_Ptr;
                            descriptors[numDescrs].m_Size = data[i].m_Size - 2;   // Remove the null terminator
                            numDescrs++;
                        }
                        else
                        {
                            descriptors[numDescrs].m_Ptr  = data[i].m_Ptr;
                            descriptors[numDescrs].m_Size = data[i].m_Size;

                            // old conventions for bool is 4 bytes, but meta-data assumes 1.
                            if (data[i].m_Size == 4 && eventTypes.typeInfos[i].DataType == typeof(bool))
                            {
                                descriptors[numDescrs].m_Size = 1;
                            }

                            numDescrs++;
                        }
                    }

                    this.WriteEventRaw(
                        eventName,
                        ref descriptor,
                        activityID,
                        childActivityID,
                        numDescrs,
                        (IntPtr)descriptors);
                }
            }
#endif // FEATURE_MANAGED_ETW
        }
Example #7
0
        private static unsafe string EncodeObject(ref object data, EventData *dataDescriptor, byte *dataBuffer)

        /*++
         *
         * Routine Description:
         *
         * This routine is used by WriteEvent to unbox the object type and
         * to fill the passed in ETW data descriptor.
         *
         * Arguments:
         *
         * data - argument to be decoded
         *
         * dataDescriptor - pointer to the descriptor to be filled
         *
         * dataBuffer - storage buffer for storing user data, needed because cant get the address of the object
         *
         * Return Value:
         *
         * null if the object is a basic type other than string. String otherwise
         *
         * --*/
        {
            dataDescriptor->Reserved = 0;

            string sRet = data as string;

            if (sRet != null)
            {
                dataDescriptor->Size = (uint)((sRet.Length + 1) * 2);
                return(sRet);
            }

            // If the data is an enum we'll convert it to it's underlying type
            Type dataType = data.GetType();

            if (dataType.IsEnum)
            {
                data = Convert.ChangeType(data, Enum.GetUnderlyingType(dataType), CultureInfo.InvariantCulture);
            }

            if (data is IntPtr)
            {
                dataDescriptor->Size = (uint)sizeof(IntPtr);
                IntPtr *intptrPtr = (IntPtr *)dataBuffer;
                *       intptrPtr = (IntPtr)data;
                dataDescriptor->Ptr = (ulong)intptrPtr;
            }
            else if (data is int)
            {
                dataDescriptor->Size = (uint)sizeof(int);
                int *intptrPtr = (int *)dataBuffer;
                *    intptrPtr = (int)data;
                dataDescriptor->Ptr = (ulong)intptrPtr;
            }
            else if (data is long)
            {
                dataDescriptor->Size = (uint)sizeof(long);
                long *longptr = (long *)dataBuffer;
                *     longptr = (long)data;
                dataDescriptor->Ptr = (ulong)longptr;
            }
            else if (data is uint)
            {
                dataDescriptor->Size = (uint)sizeof(uint);
                uint *uintptr = (uint *)dataBuffer;
                *     uintptr = (uint)data;
                dataDescriptor->Ptr = (ulong)uintptr;
            }
            else if (data is UInt64)
            {
                dataDescriptor->Size = (uint)sizeof(ulong);
                ulong *ulongptr = (ulong *)dataBuffer;
                *      ulongptr = (ulong)data;
                dataDescriptor->Ptr = (ulong)ulongptr;
            }
            else if (data is char)
            {
                dataDescriptor->Size = (uint)sizeof(char);
                char *charptr = (char *)dataBuffer;
                *     charptr = (char)data;
                dataDescriptor->Ptr = (ulong)charptr;
            }
            else if (data is byte)
            {
                dataDescriptor->Size = (uint)sizeof(byte);
                byte *byteptr = (byte *)dataBuffer;
                *     byteptr = (byte)data;
                dataDescriptor->Ptr = (ulong)byteptr;
            }
            else if (data is short)
            {
                dataDescriptor->Size = (uint)sizeof(short);
                short *shortptr = (short *)dataBuffer;
                *      shortptr = (short)data;
                dataDescriptor->Ptr = (ulong)shortptr;
            }
            else if (data is sbyte)
            {
                dataDescriptor->Size = (uint)sizeof(sbyte);
                sbyte *sbyteptr = (sbyte *)dataBuffer;
                *      sbyteptr = (sbyte)data;
                dataDescriptor->Ptr = (ulong)sbyteptr;
            }
            else if (data is ushort)
            {
                dataDescriptor->Size = (uint)sizeof(ushort);
                ushort *ushortptr = (ushort *)dataBuffer;
                *       ushortptr = (ushort)data;
                dataDescriptor->Ptr = (ulong)ushortptr;
            }
            else if (data is float)
            {
                dataDescriptor->Size = (uint)sizeof(float);
                float *floatptr = (float *)dataBuffer;
                *      floatptr = (float)data;
                dataDescriptor->Ptr = (ulong)floatptr;
            }
            else if (data is double)
            {
                dataDescriptor->Size = (uint)sizeof(double);
                double *doubleptr = (double *)dataBuffer;
                *       doubleptr = (double)data;
                dataDescriptor->Ptr = (ulong)doubleptr;
            }
            else if (data is bool)
            {
                dataDescriptor->Size = (uint)sizeof(bool);
                bool *boolptr = (bool *)dataBuffer;
                *     boolptr = (bool)data;
                dataDescriptor->Ptr = (ulong)boolptr;
            }
            else if (data is Guid)
            {
                dataDescriptor->Size = (uint)sizeof(Guid);
                Guid *guidptr = (Guid *)dataBuffer;
                *     guidptr = (Guid)data;
                dataDescriptor->Ptr = (ulong)guidptr;
            }
            else if (data is decimal)
            {
                dataDescriptor->Size = (uint)sizeof(decimal);
                decimal *decimalptr = (decimal *)dataBuffer;
                *        decimalptr = (decimal)data;
                dataDescriptor->Ptr = (ulong)decimalptr;
            }
            else if (data is Boolean)
            {
                dataDescriptor->Size = (uint)sizeof(Boolean);
                Boolean *booleanptr = (Boolean *)dataBuffer;
                *        booleanptr = (Boolean)data;
                dataDescriptor->Ptr = (ulong)booleanptr;
            }
            else
            {
                //To our eyes, everything else is a just a string
                sRet = data.ToString();
                dataDescriptor->Size = (uint)((sRet.Length + 1) * 2);
                return(sRet);
            }

            return(null);
        }
 private unsafe void WriteEventCore(int eventId, int eventDataCount, EventData *data)
 {
 }
Example #9
0
        public unsafe bool WriteTransferEvent(ref System.Diagnostics.Eventing.EventDescriptor eventDescriptor, Guid relatedActivityId, params object[] eventPayload)
        {
            uint num = 0;

            if (this.IsEnabled(eventDescriptor.Level, eventDescriptor.Keywords))
            {
                Guid       activityId     = GetActivityId();
                int        length         = 0;
                EventData *dataDescriptor = null;
                if ((eventPayload != null) && (eventPayload.Length != 0))
                {
                    length = eventPayload.Length;
                    if (length > 0x20)
                    {
                        throw new ArgumentOutOfRangeException("eventPayload", System.SR.GetString("ArgumentOutOfRange_MaxArgExceeded", new object[] { 0x20 }));
                    }
                    uint       num3     = 0;
                    int        index    = 0;
                    int[]      numArray = new int[8];
                    string[]   strArray = new string[8];
                    EventData *dataPtr2 = (EventData *)stackalloc byte[(((IntPtr)length) * sizeof(EventData))];
                    dataDescriptor = dataPtr2;
                    byte *dataBuffer = stackalloc byte[(IntPtr)(0x10 * length)];
                    for (int i = 0; i < eventPayload.Length; i++)
                    {
                        string str = EncodeObject(ref eventPayload[i], dataDescriptor, dataBuffer);
                        dataBuffer += 0x10;
                        num3       += dataDescriptor->Size;
                        dataDescriptor++;
                        if (str != null)
                        {
                            if (index >= 8)
                            {
                                throw new ArgumentOutOfRangeException("eventPayload", System.SR.GetString("ArgumentOutOfRange_MaxStringsExceeded", new object[] { 8 }));
                            }
                            strArray[index] = str;
                            numArray[index] = i;
                            index++;
                        }
                    }
                    if (num3 > 0xffca)
                    {
                        Thread.SetData(s_returnCodeSlot, 2);
                        return(false);
                    }

                    fixed(char *str2 = ((char *)strArray[0]))
                    {
                        char *chPtr = str2;

                        fixed(char *str3 = ((char *)strArray[1]))
                        {
                            char *chPtr2 = str3;

                            fixed(char *str4 = ((char *)strArray[2]))
                            {
                                char *chPtr3 = str4;

                                fixed(char *str5 = ((char *)strArray[3]))
                                {
                                    char *chPtr4 = str5;

                                    fixed(char *str6 = ((char *)strArray[4]))
                                    {
                                        char *chPtr5 = str6;

                                        fixed(char *str7 = ((char *)strArray[5]))
                                        {
                                            char *chPtr6 = str7;

                                            fixed(char *str8 = ((char *)strArray[6]))
                                            {
                                                char *chPtr7 = str8;

                                                fixed(char *str9 = ((char *)strArray[7]))
                                                {
                                                    char *chPtr8 = str9;

                                                    dataDescriptor = dataPtr2;
                                                    if (strArray[0] != null)
                                                    {
                                                        dataDescriptor[numArray[0]].DataPointer = (ulong)chPtr;
                                                    }
                                                    if (strArray[1] != null)
                                                    {
                                                        dataDescriptor[numArray[1]].DataPointer = (ulong)chPtr2;
                                                    }
                                                    if (strArray[2] != null)
                                                    {
                                                        dataDescriptor[numArray[2]].DataPointer = (ulong)chPtr3;
                                                    }
                                                    if (strArray[3] != null)
                                                    {
                                                        dataDescriptor[numArray[3]].DataPointer = (ulong)chPtr4;
                                                    }
                                                    if (strArray[4] != null)
                                                    {
                                                        dataDescriptor[numArray[4]].DataPointer = (ulong)chPtr5;
                                                    }
                                                    if (strArray[5] != null)
                                                    {
                                                        dataDescriptor[numArray[5]].DataPointer = (ulong)chPtr6;
                                                    }
                                                    if (strArray[6] != null)
                                                    {
                                                        dataDescriptor[numArray[6]].DataPointer = (ulong)chPtr7;
                                                    }
                                                    if (strArray[7] != null)
                                                    {
                                                        dataDescriptor[numArray[7]].DataPointer = (ulong)chPtr8;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    str4 = null;
                    str5 = null;
                    str6 = null;
                    str7 = null;
                    str8 = null;
                    str9 = null;
                }
                if ((relatedActivityId == Guid.Empty) && s_preWin7)
                {
                    num = Microsoft.Win32.UnsafeNativeMethods.EventWrite(this.m_regHandle, ref eventDescriptor, (uint)length, (void *)dataDescriptor);
                }
                else
                {
                    num = Microsoft.Win32.UnsafeNativeMethods.EventWriteTransfer(this.m_regHandle, ref eventDescriptor, (activityId == Guid.Empty) ? null : &activityId, ((relatedActivityId == Guid.Empty) && !s_preWin7) ? null : &relatedActivityId, (uint)length, (void *)dataDescriptor);
                }
            }
            if (num != 0)
            {
                SetLastError((int)num);
                return(false);
            }
            return(true);
        }
        unsafe void WriteStandardLogEvent(int eventId, Guid traceId, string computerName, int processId, string systemName, string componentName, string message, string errorMessage, string memberName, string fileName, int lineNumber)
        {
            const int    ArgumentCount = 10;
            const string NullString    = "";

            if (systemName == null)
            {
                systemName = NullString;
            }
            if (componentName == null)
            {
                componentName = NullString;
            }
            if (message == null)
            {
                message = NullString;
            }
            if (errorMessage == null)
            {
                errorMessage = NullString;
            }
            if (fileName == null)
            {
                fileName = NullString;
            }
            if (memberName == null)
            {
                memberName = NullString;

                fixed(char *pMessage = message, pMemberName = memberName, pFileName = fileName, pSystemName = systemName, pComponentName = componentName, pErrorMessage = errorMessage,
                      pComputerName  = computerName)
                {
                    EventData *eventData = stackalloc EventData[ArgumentCount];

                    eventData[0] = new EventData {
                        DataPointer = (IntPtr)(&traceId), Size = sizeof(Guid)
                    };
                    eventData[1] = new EventData {
                        DataPointer = (IntPtr)pComputerName, Size = this.SizeInBytes(computerName)
                    };
                    eventData[2] = new EventData {
                        DataPointer = (IntPtr)(&processId), Size = sizeof(int)
                    };
                    eventData[3] = new EventData {
                        DataPointer = (IntPtr)pSystemName, Size = this.SizeInBytes(systemName)
                    };


                    eventData[4] = new EventData {
                        DataPointer = (IntPtr)pComponentName, Size = this.SizeInBytes(componentName)
                    };
                    eventData[5] = new EventData {
                        DataPointer = (IntPtr)pMessage, Size = this.SizeInBytes(message)
                    };
                    eventData[6] = new EventData {
                        DataPointer = (IntPtr)pErrorMessage, Size = this.SizeInBytes(errorMessage)
                    };
                    eventData[7] = new EventData {
                        DataPointer = (IntPtr)pMemberName, Size = this.SizeInBytes(memberName)
                    };
                    eventData[8] = new EventData {
                        DataPointer = (IntPtr)pFileName, Size = this.SizeInBytes(fileName)
                    };
                    eventData[9] = new EventData {
                        DataPointer = (IntPtr)(&lineNumber), Size = sizeof(int)
                    };

                    this.WriteEventCore(eventId, ArgumentCount, eventData);
                }
        }
        public unsafe void VariantWrite(
            ref GenericEventDescriptor genericEventDescriptor,
            int argCount,
            Variant v0  = default(Variant),
            Variant v1  = default(Variant),
            Variant v2  = default(Variant),
            Variant v3  = default(Variant),
            Variant v4  = default(Variant),
            Variant v5  = default(Variant),
            Variant v6  = default(Variant),
            Variant v7  = default(Variant),
            Variant v8  = default(Variant),
            Variant v9  = default(Variant),
            Variant v10 = default(Variant),
            Variant v11 = default(Variant),
            Variant v12 = default(Variant),
            Variant v13 = default(Variant))
        {
            EventDescriptor eventDesc = new EventDescriptor(genericEventDescriptor.EventId, genericEventDescriptor.Version, genericEventDescriptor.Channel, genericEventDescriptor.Level, genericEventDescriptor.Opcode, genericEventDescriptor.Task, genericEventDescriptor.Keywords);

            if (argCount == 0)
            {
                this.WriteEvent(ref eventDesc, argCount, null);
                return;
            }

            EventData *eventSourceData = stackalloc EventData[argCount]; // allocation for the data descriptors
            byte *     dataBuffer      = stackalloc byte[EventDataArrayBuilder.BasicTypeAllocationBufferSize * argCount];

            // 16 byte for non-string argument
            var edb = new EventDataArrayBuilder(eventSourceData, dataBuffer);

            if (!edb.AddEventDataWithTruncation(argCount, ref v0, ref v1, ref v2, ref v3, ref v4, ref v5, ref v6, ref v7, ref v8, ref v9, ref v10, ref v11, ref v12, ref v13))
            {
                Debug.Fail(string.Format("EventData for eventid {0} is invalid. Check the total size of the event.",
                                         eventDesc.EventId));
                return;
            }

            fixed(
                char *s0 = v0.ConvertToString(),
                s1       = v1.ConvertToString(),
                s2       = v2.ConvertToString(),
                s3       = v3.ConvertToString(),
                s4       = v4.ConvertToString(),
                s5       = v5.ConvertToString(),
                s6       = v6.ConvertToString(),
                s7       = v7.ConvertToString(),
                s8       = v8.ConvertToString(),
                s9       = v9.ConvertToString(),
                s10      = v10.ConvertToString(),
                s11      = v11.ConvertToString(),
                s12      = v12.ConvertToString(),
                s13      = v13.ConvertToString())
            {
                var eventDataPtr = edb.ToEventDataArray(
                    s0,
                    s1,
                    s2,
                    s3,
                    s4,
                    s5,
                    s6,
                    s7,
                    s8,
                    s9,
                    s10,
                    s11,
                    s12,
                    s13);

                this.WriteEvent(ref eventDesc, argCount, (IntPtr)eventDataPtr);
            }
        }
Example #12
0
 internal static extern unsafe uint EventWriteTransfer([In] long registrationHandle, [In] ref System.Diagnostics.Eventing.EventDescriptor eventDescriptor, [In] ref Guid activityId, [In] ref Guid relatedActivityId, [In] uint userDataCount, [In] EventData *userData);
Example #13
0
 internal static extern unsafe uint EventWrite([In] long registrationHandle, [In] ref System.Diagnostics.Eventing.EventDescriptor eventDescriptor, [In] uint userDataCount, [In] EventData *userData);
        private unsafe void Request(
            Guid activityId,
            Guid localId,
            string uri,
            string resourceType,
            // the following parameters are request headers
            string accept,
            string authorization,
            string consistencyLevel,
            string contentType,
            string contentEncoding,
            string contentLength,
            string contentLocation,
            string continuation,
            string emitVerboseTracesInQuery,
            string enableScanInQuery,
            string eTag,
            string httpDate,
            string ifMatch,
            string ifNoneMatch,
            string indexingDirective,
            string keepAlive,
            string offerType,
            string pageSize,
            string preTriggerExclude,
            string preTriggerInclude,
            string postTriggerExclude,
            string postTriggerInclude,
            string profileRequest,
            string resourceTokenExpiry,
            string sessionToken,
            string setCookie,
            string slug,
            string userAgent,
            string xDate)
        {
            if (uri == null)
            {
                throw new ArgumentException("uri");
            }
            if (resourceType == null)
            {
                throw new ArgumentException("resourceType");
            }

            if (accept == null)
            {
                throw new ArgumentException("accept");
            }
            if (authorization == null)
            {
                throw new ArgumentException("authorization");
            }
            if (consistencyLevel == null)
            {
                throw new ArgumentException("consistencyLevel");
            }
            if (contentType == null)
            {
                throw new ArgumentException("contentType");
            }
            if (contentEncoding == null)
            {
                throw new ArgumentException("contentEncoding");
            }
            if (contentLength == null)
            {
                throw new ArgumentException("contentLength");
            }
            if (contentLocation == null)
            {
                throw new ArgumentException("contentLocation");
            }
            if (continuation == null)
            {
                throw new ArgumentException("continuation");
            }
            if (emitVerboseTracesInQuery == null)
            {
                throw new ArgumentException("emitVerboseTracesInQuery");
            }
            if (enableScanInQuery == null)
            {
                throw new ArgumentException("enableScanInQuery");
            }
            if (eTag == null)
            {
                throw new ArgumentException("eTag");
            }
            if (httpDate == null)
            {
                throw new ArgumentException("httpDate");
            }
            if (ifMatch == null)
            {
                throw new ArgumentException("ifMatch");
            }
            if (ifNoneMatch == null)
            {
                throw new ArgumentException("ifNoneMatch");
            }
            if (indexingDirective == null)
            {
                throw new ArgumentException("indexingDirective");
            }
            if (keepAlive == null)
            {
                throw new ArgumentException("keepAlive");
            }
            if (offerType == null)
            {
                throw new ArgumentException("offerType");
            }
            if (pageSize == null)
            {
                throw new ArgumentException("pageSize");
            }
            if (preTriggerExclude == null)
            {
                throw new ArgumentException("preTriggerExclude");
            }
            if (preTriggerInclude == null)
            {
                throw new ArgumentException("preTriggerInclude");
            }
            if (postTriggerExclude == null)
            {
                throw new ArgumentException("postTriggerExclude");
            }
            if (postTriggerInclude == null)
            {
                throw new ArgumentException("postTriggerInclude");
            }
            if (profileRequest == null)
            {
                throw new ArgumentException("profileRequest");
            }
            if (resourceTokenExpiry == null)
            {
                throw new ArgumentException("resourceTokenExpiry");
            }
            if (sessionToken == null)
            {
                throw new ArgumentException("sessionToken");
            }
            if (setCookie == null)
            {
                throw new ArgumentException("setCookie");
            }
            if (slug == null)
            {
                throw new ArgumentException("slug");
            }
            if (userAgent == null)
            {
                throw new ArgumentException("userAgent");
            }
            if (xDate == null)
            {
                throw new ArgumentException("xDate");
            }

            byte[] guidBytes    = activityId.ToByteArray();
            byte[] localIdBytes = localId.ToByteArray();
            fixed(byte *fixedGuidBytes = guidBytes)
            fixed(byte *fixedLocalIdBytes             = localIdBytes)
            fixed(char *fixedUri                      = uri)
            fixed(char *fixedResourceType             = resourceType)
            fixed(char *fixedAccept                   = accept)
            fixed(char *fixedAuthorization            = authorization)
            fixed(char *fixedConsistencyLevel         = consistencyLevel)
            fixed(char *fixedContentType              = contentType)
            fixed(char *fixedContentEncoding          = contentEncoding)
            fixed(char *fixedContentLength            = contentLength)
            fixed(char *fixedContentLocation          = contentLocation)
            fixed(char *fixedContinuation             = continuation)
            fixed(char *fixedEmitVerboseTracesInQuery = emitVerboseTracesInQuery)
            fixed(char *fixedEnableScanInQuery        = enableScanInQuery)
            fixed(char *fixedETag                     = eTag)
            fixed(char *fixedHttpDate                 = httpDate)
            fixed(char *fixedIfMatch                  = ifMatch)
            fixed(char *fixedIfNoneMatch              = ifNoneMatch)
            fixed(char *fixedIndexingDirective        = indexingDirective)
            fixed(char *fixedKeepAlive                = keepAlive)
            fixed(char *fixedOfferType                = offerType)
            fixed(char *fixedPageSize                 = pageSize)
            fixed(char *fixedPreTriggerExclude        = preTriggerExclude)
            fixed(char *fixedPreTriggerInclude        = preTriggerInclude)
            fixed(char *fixedPostTriggerExclude       = postTriggerExclude)
            fixed(char *fixedPostTriggerInclude       = postTriggerInclude)
            fixed(char *fixedProfileRequest           = profileRequest)
            fixed(char *fixedResourceTokenExpiry      = resourceTokenExpiry)
            fixed(char *fixedSessionToken             = sessionToken)
            fixed(char *fixedSetCookie                = setCookie)
            fixed(char *fixedSlug                     = slug)
            fixed(char *fixedUserAgent                = userAgent)
            fixed(char *fixedXDate                    = xDate)
            {
                const int eventDataCount          = 33;
                const int UnicodeEncodingCharSize = CustomTypeExtensions.UnicodeEncodingCharSize;

                EventData *dataDesc = stackalloc EventData[eventDataCount];

                dataDesc[0].DataPointer = (IntPtr)(fixedGuidBytes);
                dataDesc[0].Size        = guidBytes.Length;

                dataDesc[1].DataPointer = (IntPtr)(fixedLocalIdBytes);
                dataDesc[1].Size        = localIdBytes.Length;

                dataDesc[2].DataPointer = (IntPtr)(fixedUri);
                dataDesc[2].Size        = (uri.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[3].DataPointer = (IntPtr)(fixedResourceType);
                dataDesc[3].Size        = (resourceType.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[4].DataPointer = (IntPtr)(fixedAccept);
                dataDesc[4].Size        = (accept.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[5].DataPointer = (IntPtr)(fixedAuthorization);
                dataDesc[5].Size        = (authorization.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[6].DataPointer = (IntPtr)(fixedConsistencyLevel);
                dataDesc[6].Size        = (consistencyLevel.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[7].DataPointer = (IntPtr)(fixedContentType);
                dataDesc[7].Size        = (contentType.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[8].DataPointer = (IntPtr)(fixedContentEncoding);
                dataDesc[8].Size        = (contentEncoding.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[9].DataPointer = (IntPtr)(fixedContentLength);
                dataDesc[9].Size        = (contentLength.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[10].DataPointer = (IntPtr)(fixedContentLocation);
                dataDesc[10].Size        = (contentLocation.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[11].DataPointer = (IntPtr)(fixedContinuation);
                dataDesc[11].Size        = (continuation.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[12].DataPointer = (IntPtr)(fixedEmitVerboseTracesInQuery);
                dataDesc[12].Size        = (emitVerboseTracesInQuery.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[13].DataPointer = (IntPtr)(fixedEnableScanInQuery);
                dataDesc[13].Size        = (enableScanInQuery.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[14].DataPointer = (IntPtr)(fixedETag);
                dataDesc[14].Size        = (eTag.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[15].DataPointer = (IntPtr)(fixedHttpDate);
                dataDesc[15].Size        = (httpDate.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[16].DataPointer = (IntPtr)(fixedIfMatch);
                dataDesc[16].Size        = (ifMatch.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[17].DataPointer = (IntPtr)(fixedIfNoneMatch);
                dataDesc[17].Size        = (ifNoneMatch.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[18].DataPointer = (IntPtr)(fixedIndexingDirective);
                dataDesc[18].Size        = (indexingDirective.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[19].DataPointer = (IntPtr)(fixedKeepAlive);
                dataDesc[19].Size        = (keepAlive.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[20].DataPointer = (IntPtr)(fixedOfferType);
                dataDesc[20].Size        = (offerType.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[21].DataPointer = (IntPtr)(fixedPageSize);
                dataDesc[21].Size        = (pageSize.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[22].DataPointer = (IntPtr)(fixedPreTriggerExclude);
                dataDesc[22].Size        = (preTriggerExclude.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[23].DataPointer = (IntPtr)(fixedPreTriggerInclude);
                dataDesc[23].Size        = (preTriggerInclude.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[24].DataPointer = (IntPtr)(fixedPostTriggerExclude);
                dataDesc[24].Size        = (postTriggerExclude.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[25].DataPointer = (IntPtr)(fixedPostTriggerInclude);
                dataDesc[25].Size        = (postTriggerInclude.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[26].DataPointer = (IntPtr)(fixedProfileRequest);
                dataDesc[26].Size        = (profileRequest.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[27].DataPointer = (IntPtr)(fixedResourceTokenExpiry);
                dataDesc[27].Size        = (resourceTokenExpiry.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[28].DataPointer = (IntPtr)(fixedSessionToken);
                dataDesc[28].Size        = (sessionToken.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[29].DataPointer = (IntPtr)(fixedSetCookie);
                dataDesc[29].Size        = (setCookie.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[30].DataPointer = (IntPtr)(fixedSlug);
                dataDesc[30].Size        = (slug.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[31].DataPointer = (IntPtr)(fixedUserAgent);
                dataDesc[31].Size        = (userAgent.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[32].DataPointer = (IntPtr)(fixedXDate);
                dataDesc[32].Size        = (xDate.Length + 1) * UnicodeEncodingCharSize;

                this.WriteEventCoreWithActivityId(activityId, 1, eventDataCount, dataDesc);
            }
        }
Example #15
0
        internal unsafe bool Templatet1(
            ref EventDescriptor eventDescriptor,
            string Process,
            uint Samples,
            uint ProcessorCount,
            uint DiskCount,
            string Processors,
            string Disks,
            string ComputerManufacturer,
            string ComputerModel,
            string ComputerProcessorNum,
            string RamSize,
            double ProcessorTimePercentMinimum,
            double ProcessorTimePercentMaximum,
            double ProcessorTimePercentAverage,
            long WorkingSetMinimum,
            long WorkingSetMaximum,
            long WorkingSetAverage,
            long PrivateBytesMinimum,
            long PrivateBytesMaximum,
            long PrivateBytesAverage,
            long DiskBytesReadTotal,
            long DiskBytesReadMinimum,
            long DiskBytesReadMaximum,
            long DiskBytesReadAverage,
            long DiskBytesWrittenTotal,
            long DiskBytesWrittenMinimum,
            long DiskBytesWrittenMaximum,
            long DiskBytesWrittenAverage,
            long DiskReadOperationTotal,
            long DiskReadOperationMinimum,
            long DiskReadOperationMaximum,
            double DiskReadOperationAverage,
            long DiskWriteOperationTotal,
            long DiskWriteOperationMinimum,
            long DiskWriteOperationMaximum,
            double DiskWriteOperationAverage,
            long TcpBytesReceivedTotal,
            long TcpBytesReceivedMinimum,
            long TcpBytesReceivedMaximum,
            long TcpBytesReceivedAverage,
            long TcpBytesSentTotal,
            long TcpBytesSentMinimum,
            long TcpBytesSentMaximum,
            long TcpBytesSentAverage,
            long UdpBytesReceivedTotal,
            long UdpBytesReceivedMinimum,
            long UdpBytesReceivedMaximum,
            long UdpBytesReceivedAverage,
            long UdpBytesSentTotal,
            long UdpBytesSentMinimum,
            long UdpBytesSentMaximum,
            long UdpBytesSentAverage,
            uint TcpConnectionCount,
            string TcpConnections
            )
        {
            int  argumentCount = 53;
            bool status        = true;

            if (IsEnabled(eventDescriptor.Level, eventDescriptor.Keywords))
            {
                byte *     userData    = stackalloc byte[sizeof(EventData) * argumentCount];
                EventData *userDataPtr = (EventData *)userData;

                // Value is a nul-terminated string (assume no embedded nuls):
                userDataPtr[0].Size = (uint)(Process.Length + 1) * sizeof(char);

                userDataPtr[1].DataPointer = (UInt64)(&Samples);
                userDataPtr[1].Size        = (uint)(sizeof(int));

                userDataPtr[2].DataPointer = (UInt64)(&ProcessorCount);
                userDataPtr[2].Size        = (uint)(sizeof(int));

                userDataPtr[3].DataPointer = (UInt64)(&DiskCount);
                userDataPtr[3].Size        = (uint)(sizeof(int));

                // Value contains ProcessorCount concatenated null-terminated strings (embedded null between each one - use something like string.Join("\0", array) to generate this value):
                userDataPtr[4].Size = (uint)(ProcessorCount == 0 ? 0 : sizeof(char) * (Processors.Length + 1));

                // Value contains DiskCount concatenated null-terminated strings (embedded null between each one - use something like string.Join("\0", array) to generate this value):
                userDataPtr[5].Size = (uint)(DiskCount == 0 ? 0 : sizeof(char) * (Disks.Length + 1));

                // Value is a nul-terminated string (assume no embedded nuls):
                userDataPtr[6].Size = (uint)(ComputerManufacturer.Length + 1) * sizeof(char);

                // Value is a nul-terminated string (assume no embedded nuls):
                userDataPtr[7].Size = (uint)(ComputerModel.Length + 1) * sizeof(char);

                // Value is a nul-terminated string (assume no embedded nuls):
                userDataPtr[8].Size = (uint)(ComputerProcessorNum.Length + 1) * sizeof(char);

                // Value is a nul-terminated string (assume no embedded nuls):
                userDataPtr[9].Size = (uint)(RamSize.Length + 1) * sizeof(char);

                userDataPtr[10].DataPointer = (UInt64)(&ProcessorTimePercentMinimum);
                userDataPtr[10].Size        = (uint)(sizeof(double));

                userDataPtr[11].DataPointer = (UInt64)(&ProcessorTimePercentMaximum);
                userDataPtr[11].Size        = (uint)(sizeof(double));

                userDataPtr[12].DataPointer = (UInt64)(&ProcessorTimePercentAverage);
                userDataPtr[12].Size        = (uint)(sizeof(double));

                userDataPtr[13].DataPointer = (UInt64)(&WorkingSetMinimum);
                userDataPtr[13].Size        = (uint)(sizeof(long));

                userDataPtr[14].DataPointer = (UInt64)(&WorkingSetMaximum);
                userDataPtr[14].Size        = (uint)(sizeof(long));

                userDataPtr[15].DataPointer = (UInt64)(&WorkingSetAverage);
                userDataPtr[15].Size        = (uint)(sizeof(long));

                userDataPtr[16].DataPointer = (UInt64)(&PrivateBytesMinimum);
                userDataPtr[16].Size        = (uint)(sizeof(long));

                userDataPtr[17].DataPointer = (UInt64)(&PrivateBytesMaximum);
                userDataPtr[17].Size        = (uint)(sizeof(long));

                userDataPtr[18].DataPointer = (UInt64)(&PrivateBytesAverage);
                userDataPtr[18].Size        = (uint)(sizeof(long));

                userDataPtr[19].DataPointer = (UInt64)(&DiskBytesReadTotal);
                userDataPtr[19].Size        = (uint)(sizeof(long));

                userDataPtr[20].DataPointer = (UInt64)(&DiskBytesReadMinimum);
                userDataPtr[20].Size        = (uint)(sizeof(long));

                userDataPtr[21].DataPointer = (UInt64)(&DiskBytesReadMaximum);
                userDataPtr[21].Size        = (uint)(sizeof(long));

                userDataPtr[22].DataPointer = (UInt64)(&DiskBytesReadAverage);
                userDataPtr[22].Size        = (uint)(sizeof(long));

                userDataPtr[23].DataPointer = (UInt64)(&DiskBytesWrittenTotal);
                userDataPtr[23].Size        = (uint)(sizeof(long));

                userDataPtr[24].DataPointer = (UInt64)(&DiskBytesWrittenMinimum);
                userDataPtr[24].Size        = (uint)(sizeof(long));

                userDataPtr[25].DataPointer = (UInt64)(&DiskBytesWrittenMaximum);
                userDataPtr[25].Size        = (uint)(sizeof(long));

                userDataPtr[26].DataPointer = (UInt64)(&DiskBytesWrittenAverage);
                userDataPtr[26].Size        = (uint)(sizeof(long));

                userDataPtr[27].DataPointer = (UInt64)(&DiskReadOperationTotal);
                userDataPtr[27].Size        = (uint)(sizeof(long));

                userDataPtr[28].DataPointer = (UInt64)(&DiskReadOperationMinimum);
                userDataPtr[28].Size        = (uint)(sizeof(long));

                userDataPtr[29].DataPointer = (UInt64)(&DiskReadOperationMaximum);
                userDataPtr[29].Size        = (uint)(sizeof(long));

                userDataPtr[30].DataPointer = (UInt64)(&DiskReadOperationAverage);
                userDataPtr[30].Size        = (uint)(sizeof(double));

                userDataPtr[31].DataPointer = (UInt64)(&DiskWriteOperationTotal);
                userDataPtr[31].Size        = (uint)(sizeof(long));

                userDataPtr[32].DataPointer = (UInt64)(&DiskWriteOperationMinimum);
                userDataPtr[32].Size        = (uint)(sizeof(long));

                userDataPtr[33].DataPointer = (UInt64)(&DiskWriteOperationMaximum);
                userDataPtr[33].Size        = (uint)(sizeof(long));

                userDataPtr[34].DataPointer = (UInt64)(&DiskWriteOperationAverage);
                userDataPtr[34].Size        = (uint)(sizeof(double));

                userDataPtr[35].DataPointer = (UInt64)(&TcpBytesReceivedTotal);
                userDataPtr[35].Size        = (uint)(sizeof(long));

                userDataPtr[36].DataPointer = (UInt64)(&TcpBytesReceivedMinimum);
                userDataPtr[36].Size        = (uint)(sizeof(long));

                userDataPtr[37].DataPointer = (UInt64)(&TcpBytesReceivedMaximum);
                userDataPtr[37].Size        = (uint)(sizeof(long));

                userDataPtr[38].DataPointer = (UInt64)(&TcpBytesReceivedAverage);
                userDataPtr[38].Size        = (uint)(sizeof(long));

                userDataPtr[39].DataPointer = (UInt64)(&TcpBytesSentTotal);
                userDataPtr[39].Size        = (uint)(sizeof(long));

                userDataPtr[40].DataPointer = (UInt64)(&TcpBytesSentMinimum);
                userDataPtr[40].Size        = (uint)(sizeof(long));

                userDataPtr[41].DataPointer = (UInt64)(&TcpBytesSentMaximum);
                userDataPtr[41].Size        = (uint)(sizeof(long));

                userDataPtr[42].DataPointer = (UInt64)(&TcpBytesSentAverage);
                userDataPtr[42].Size        = (uint)(sizeof(long));

                userDataPtr[43].DataPointer = (UInt64)(&UdpBytesReceivedTotal);
                userDataPtr[43].Size        = (uint)(sizeof(long));

                userDataPtr[44].DataPointer = (UInt64)(&UdpBytesReceivedMinimum);
                userDataPtr[44].Size        = (uint)(sizeof(long));

                userDataPtr[45].DataPointer = (UInt64)(&UdpBytesReceivedMaximum);
                userDataPtr[45].Size        = (uint)(sizeof(long));

                userDataPtr[46].DataPointer = (UInt64)(&UdpBytesReceivedAverage);
                userDataPtr[46].Size        = (uint)(sizeof(long));

                userDataPtr[47].DataPointer = (UInt64)(&UdpBytesSentTotal);
                userDataPtr[47].Size        = (uint)(sizeof(long));

                userDataPtr[48].DataPointer = (UInt64)(&UdpBytesSentMinimum);
                userDataPtr[48].Size        = (uint)(sizeof(long));

                userDataPtr[49].DataPointer = (UInt64)(&UdpBytesSentMaximum);
                userDataPtr[49].Size        = (uint)(sizeof(long));

                userDataPtr[50].DataPointer = (UInt64)(&UdpBytesSentAverage);
                userDataPtr[50].Size        = (uint)(sizeof(long));

                userDataPtr[51].DataPointer = (UInt64)(&TcpConnectionCount);
                userDataPtr[51].Size        = (uint)(sizeof(int));

                // Value contains TcpConnectionsCount concatenated null-terminated strings (embedded null between each one - use something like string.Join("\0", array) to generate this value):
                userDataPtr[52].Size = (uint)(TcpConnectionCount == 0 ? 0 : sizeof(char) * (TcpConnections.Length + 1));

                fixed(char *a0 = Process, a1 = Processors, a2 = Disks, a3 = ComputerManufacturer, a4 = ComputerModel, a5 = ComputerProcessorNum, a6 = RamSize, a7 = TcpConnections)
                {
                    userDataPtr[0].DataPointer  = (ulong)a0;
                    userDataPtr[4].DataPointer  = (ulong)a1;
                    userDataPtr[5].DataPointer  = (ulong)a2;
                    userDataPtr[6].DataPointer  = (ulong)a3;
                    userDataPtr[7].DataPointer  = (ulong)a4;
                    userDataPtr[8].DataPointer  = (ulong)a5;
                    userDataPtr[9].DataPointer  = (ulong)a6;
                    userDataPtr[52].DataPointer = (ulong)a7;
                    status = WriteEvent(ref eventDescriptor, argumentCount, (IntPtr)(userData));
                }
            }

            return(status);
        }
Example #16
0
        private static unsafe string EncodeObject(ref object data, EventData *dataDescriptor, byte *dataBuffer)
        {
            dataDescriptor.Reserved = 0;
            string str = data as string;

            if (str != null)
            {
                dataDescriptor.Size = (uint)((str.Length + 1) * 2);
                return(str);
            }
            if (data == null)
            {
                dataDescriptor.Size        = 0;
                dataDescriptor.DataPointer = 0L;
            }
            else if (data is IntPtr)
            {
                dataDescriptor.Size = (uint)sizeof(IntPtr);
                IntPtr *ptrPtr = (IntPtr *)dataBuffer;
                ptrPtr[0] = (IntPtr)data;
                dataDescriptor.DataPointer = (ulong)ptrPtr;
            }
            else if (data is int)
            {
                dataDescriptor.Size = 4;
                int *numPtr = (int *)dataBuffer;
                numPtr[0] = (int)data;
                dataDescriptor.DataPointer = (ulong)numPtr;
            }
            else if (data is long)
            {
                dataDescriptor.Size = 8;
                long *numPtr2 = (long *)dataBuffer;
                numPtr2[0] = (long)data;
                dataDescriptor.DataPointer = (ulong)numPtr2;
            }
            else if (data is uint)
            {
                dataDescriptor.Size = 4;
                uint *numPtr3 = (uint *)dataBuffer;
                numPtr3[0] = (uint)data;
                dataDescriptor.DataPointer = (ulong)numPtr3;
            }
            else if (data is ulong)
            {
                dataDescriptor.Size = 8;
                ulong *numPtr4 = (ulong *)dataBuffer;
                numPtr4[0] = (ulong)data;
                dataDescriptor.DataPointer = (ulong)numPtr4;
            }
            else if (data is char)
            {
                dataDescriptor.Size = 2;
                char *chPtr = (char *)dataBuffer;
                chPtr[0] = (char)data;
                dataDescriptor.DataPointer = (ulong)chPtr;
            }
            else if (data is byte)
            {
                dataDescriptor.Size = 1;
                byte *numPtr5 = dataBuffer;
                numPtr5[0] = (byte)data;
                dataDescriptor.DataPointer = (ulong)numPtr5;
            }
            else if (data is short)
            {
                dataDescriptor.Size = 2;
                short *numPtr6 = (short *)dataBuffer;
                numPtr6[0] = (short)data;
                dataDescriptor.DataPointer = (ulong)numPtr6;
            }
            else if (data is sbyte)
            {
                dataDescriptor.Size = 1;
                sbyte *numPtr7 = (sbyte *)dataBuffer;
                numPtr7[0] = (sbyte)data;
                dataDescriptor.DataPointer = (ulong)numPtr7;
            }
            else if (data is ushort)
            {
                dataDescriptor.Size = 2;
                ushort *numPtr8 = (ushort *)dataBuffer;
                numPtr8[0] = (ushort)data;
                dataDescriptor.DataPointer = (ulong)numPtr8;
            }
            else if (data is float)
            {
                dataDescriptor.Size = 4;
                float *numPtr9 = (float *)dataBuffer;
                numPtr9[0] = (float)data;
                dataDescriptor.DataPointer = (ulong)numPtr9;
            }
            else if (data is double)
            {
                dataDescriptor.Size = 8;
                double *numPtr10 = (double *)dataBuffer;
                numPtr10[0] = (double)data;
                dataDescriptor.DataPointer = (ulong)numPtr10;
            }
            else if (data is bool)
            {
                dataDescriptor.Size = 1;
                bool *flagPtr = (bool *)dataBuffer;
                *((sbyte *)flagPtr)        = (bool)data;
                dataDescriptor.DataPointer = (ulong)flagPtr;
            }
            else if (data is Guid)
            {
                dataDescriptor.Size = (uint)sizeof(Guid);
                Guid *guidPtr = (Guid *)dataBuffer;
                guidPtr[0] = (Guid)data;
                dataDescriptor.DataPointer = (ulong)guidPtr;
            }
            else if (data is decimal)
            {
                dataDescriptor.Size = 0x10;
                decimal *numPtr11 = (decimal *)dataBuffer;
                numPtr11[0] = (decimal)data;
                dataDescriptor.DataPointer = (ulong)numPtr11;
            }
            else if (data is bool)
            {
                dataDescriptor.Size = 1;
                bool *flagPtr2 = (bool *)dataBuffer;
                *((sbyte *)flagPtr2)       = (bool)data;
                dataDescriptor.DataPointer = (ulong)flagPtr2;
            }
            else
            {
                str = data.ToString();
                dataDescriptor.Size = (uint)((str.Length + 1) * 2);
                return(str);
            }
            return(null);
        }
Example #17
0
        public bool WriteTransferEvent(ref EventDescriptor eventDescriptor, Guid relatedActivityId, params object[] eventPayload)
        {
            uint status = 0;

            if (IsEnabled(eventDescriptor.Level, eventDescriptor.Keywords))
            {
                Guid activityId = GetActivityId();

                unsafe
                {
                    int        argCount    = 0;
                    EventData *userDataPtr = null;

                    if ((eventPayload != null) && (eventPayload.Length != 0))
                    {
                        argCount = eventPayload.Length;
                        if (argCount > s_etwMaxNumberArguments)
                        {
                            //
                            // too many arguments to log
                            //
                            throw new ArgumentOutOfRangeException("eventPayload",
                                                                  string.Format(CultureInfo.CurrentCulture, DotNetEventingStrings.ArgumentOutOfRange_MaxArgExceeded, s_etwMaxNumberArguments));
                        }

                        uint       totalEventSize = 0;
                        int        index;
                        int        stringIndex    = 0;
                        int[]      stringPosition = new int[s_etwAPIMaxStringCount];                       // used to keep the position of strings in the eventPayload parameter
                        string[]   dataString     = new string[s_etwAPIMaxStringCount];                    // string arrays from the eventPayload parameter
                        EventData *userData       = stackalloc EventData[argCount];                        // allocation for the data descriptors
                        userDataPtr = (EventData *)userData;
                        byte *dataBuffer    = stackalloc byte[s_basicTypeAllocationBufferSize * argCount]; // 16 byte for unboxing non-string argument
                        byte *currentBuffer = dataBuffer;

                        //
                        // The loop below goes through all the arguments and fills in the data
                        // descriptors. For strings save the location in the dataString array.
                        // Calculates the total size of the event by adding the data descriptor
                        // size value set in EncodeObjec method.
                        //
                        for (index = 0; index < eventPayload.Length; index++)
                        {
                            string isString;
                            isString        = EncodeObject(ref eventPayload[index], userDataPtr, currentBuffer);
                            currentBuffer  += s_basicTypeAllocationBufferSize;
                            totalEventSize += userDataPtr->Size;
                            userDataPtr++;
                            if (isString != null)
                            {
                                if (stringIndex < s_etwAPIMaxStringCount)
                                {
                                    dataString[stringIndex]     = isString;
                                    stringPosition[stringIndex] = index;
                                    stringIndex++;
                                }
                                else
                                {
                                    throw new ArgumentOutOfRangeException("eventPayload",
                                                                          string.Format(CultureInfo.CurrentCulture, DotNetEventingStrings.ArgumentOutOfRange_MaxStringsExceeded, s_etwAPIMaxStringCount));
                                }
                            }
                        }

                        if (totalEventSize > s_traceEventMaximumSize)
                        {
                            t_returnCode = WriteEventErrorCode.EventTooBig;
                            return(false);
                        }

                        fixed(char *v0 = dataString[0], v1 = dataString[1], v2 = dataString[2], v3 = dataString[3],
                              v4       = dataString[4], v5 = dataString[5], v6 = dataString[6], v7 = dataString[7])
                        {
                            userDataPtr = (EventData *)userData;
                            if (dataString[0] != null)
                            {
                                userDataPtr[stringPosition[0]].DataPointer = (ulong)v0;
                            }

                            if (dataString[1] != null)
                            {
                                userDataPtr[stringPosition[1]].DataPointer = (ulong)v1;
                            }

                            if (dataString[2] != null)
                            {
                                userDataPtr[stringPosition[2]].DataPointer = (ulong)v2;
                            }

                            if (dataString[3] != null)
                            {
                                userDataPtr[stringPosition[3]].DataPointer = (ulong)v3;
                            }

                            if (dataString[4] != null)
                            {
                                userDataPtr[stringPosition[4]].DataPointer = (ulong)v4;
                            }

                            if (dataString[5] != null)
                            {
                                userDataPtr[stringPosition[5]].DataPointer = (ulong)v5;
                            }

                            if (dataString[6] != null)
                            {
                                userDataPtr[stringPosition[6]].DataPointer = (ulong)v6;
                            }

                            if (dataString[7] != null)
                            {
                                userDataPtr[stringPosition[7]].DataPointer = (ulong)v7;
                            }
                        }
                    }

                    status = UnsafeNativeMethods.EventWriteTransfer(_regHandle,
                                                                    ref eventDescriptor,
                                                                    (activityId == Guid.Empty) ? null : &activityId,
                                                                    (relatedActivityId == Guid.Empty) ? null : &relatedActivityId,
                                                                    (uint)argCount,
                                                                    userDataPtr);
                }
            }

            if (status != 0)
            {
                SetLastError((int)status);
                return(false);
            }

            return(true);
        }
Example #18
0
 protected unsafe void WriteEventCore(int eventId, int eventDataCount, EventData *data)
 {
     throw new NotImplementedException();
 }
Example #19
0
        internal unsafe uint TraceEvent(EventTrace.Event eventID, EventTrace.Keyword keywords, EventTrace.Level level, params object[] eventPayload)
        {
            // It is the responsibility of the caller to check that flags/keywords are enabled before calling this method
            Debug.Assert(IsEnabled(keywords, level));

            int argCount = eventPayload.Length;

            Debug.Assert(argCount <= s_etwMaxNumberArguments);

            uint totalEventSize = 0;
            int  stringIndex    = 0;

            int[]      stringPosition = new int[s_etwAPIMaxStringCount];
            string []  dataString     = new string[s_etwAPIMaxStringCount];
            EventData *userData       = stackalloc EventData[argCount];
            EventData *userDataPtr    = userData;
            byte *     dataBuffer     = stackalloc byte[s_basicTypeAllocationBufferSize * argCount];
            byte *     currentBuffer  = dataBuffer;


            for (int index = 0; index < argCount; index++)
            {
                if (eventPayload[index] != null)
                {
                    string isString = EncodeObject(ref eventPayload[index], userDataPtr, currentBuffer);
                    currentBuffer += s_basicTypeAllocationBufferSize;
                    totalEventSize = userDataPtr->Size;
                    userDataPtr++;
                    if (isString != null)
                    {
                        Debug.Assert(stringIndex < s_etwAPIMaxStringCount); // need to increase string count or emit fewer strings
                        dataString[stringIndex]     = isString;
                        stringPosition[stringIndex] = index;
                        stringIndex++;
                    }
                }
            }

            if (totalEventSize > s_traceEventMaximumSize)
            {
                return(ErrorEventTooBig);
            }

            fixed(char *s0 = dataString[0], s1 = dataString[1], s2 = dataString[2], s3 = dataString[3],
                  s4       = dataString[4], s5 = dataString[5], s6 = dataString[6], s7 = dataString[7])
            {
                userDataPtr = userData;
                if (dataString[0] != null)
                {
                    userDataPtr[stringPosition[0]].Ptr = (ulong)s0;
                }
                if (dataString[1] != null)
                {
                    userDataPtr[stringPosition[1]].Ptr = (ulong)s1;
                }
                if (dataString[2] != null)
                {
                    userDataPtr[stringPosition[2]].Ptr = (ulong)s2;
                }
                if (dataString[3] != null)
                {
                    userDataPtr[stringPosition[3]].Ptr = (ulong)s3;
                }
                if (dataString[4] != null)
                {
                    userDataPtr[stringPosition[4]].Ptr = (ulong)s4;
                }
                if (dataString[5] != null)
                {
                    userDataPtr[stringPosition[5]].Ptr = (ulong)s5;
                }
                if (dataString[6] != null)
                {
                    userDataPtr[stringPosition[6]].Ptr = (ulong)s6;
                }
                if (dataString[7] != null)
                {
                    userDataPtr[stringPosition[7]].Ptr = (ulong)s7;
                }

                return(EventWrite(eventID, keywords, level, argCount, userData));
            }
        }
Example #20
0
        private unsafe void WriteEvent(int eventId, string?arg1, string?arg2, int arg3, string?arg4, byte arg5, byte arg6, HttpVersionPolicy arg7)
        {
            if (IsEnabled())
            {
                if (arg1 == null)
                {
                    arg1 = "";
                }
                if (arg2 == null)
                {
                    arg2 = "";
                }
                if (arg4 == null)
                    arg4 = "";

                fixed(char *arg1Ptr = arg1)
                fixed(char *arg2Ptr = arg2)
                fixed(char *arg4Ptr = arg4)
                {
                    const int  NumEventDatas = 7;
                    EventData *descrs        = stackalloc EventData[NumEventDatas];

                    descrs[0] = new EventData
                    {
                        DataPointer = (IntPtr)(arg1Ptr),
                        Size        = (arg1.Length + 1) * sizeof(char)
                    };
                    descrs[1] = new EventData
                    {
                        DataPointer = (IntPtr)(arg2Ptr),
                        Size        = (arg2.Length + 1) * sizeof(char)
                    };
                    descrs[2] = new EventData
                    {
                        DataPointer = (IntPtr)(&arg3),
                        Size        = sizeof(int)
                    };
                    descrs[3] = new EventData
                    {
                        DataPointer = (IntPtr)(arg4Ptr),
                        Size        = (arg4.Length + 1) * sizeof(char)
                    };
                    descrs[4] = new EventData
                    {
                        DataPointer = (IntPtr)(&arg5),
                        Size        = sizeof(byte)
                    };
                    descrs[5] = new EventData
                    {
                        DataPointer = (IntPtr)(&arg6),
                        Size        = sizeof(byte)
                    };
                    descrs[6] = new EventData
                    {
                        DataPointer = (IntPtr)(&arg7),
                        Size        = sizeof(HttpVersionPolicy)
                    };

                    WriteEventCore(eventId, NumEventDatas, descrs);
                }
            }
        }
Example #21
0
        internal unsafe override uint EventWrite(EventTrace.Event eventID, EventTrace.Keyword keywords, EventTrace.Level level, int argc, EventData *argv)
        {
            ClassicEtw.EVENT_HEADER header;
            header.Header.ClientContext = 0;
            header.Header.Flags         = ClassicEtw.WNODE_FLAG_TRACED_GUID | ClassicEtw.WNODE_FLAG_USE_MOF_PTR;
            header.Header.Guid          = EventTrace.GetGuidForEvent(eventID);
            header.Header.Level         = (byte)level;
            header.Header.Type          = (byte)EventTrace.GetOpcodeForEvent(eventID);
            header.Header.Version       = (ushort)EventTrace.GetVersionForEvent(eventID);
            // Extra copy on XP to move argv to the end of the EVENT_HEADER
            EventData *eventData = &header.Data;

            if (argc > ClassicEtw.MAX_MOF_FIELDS)
            {
                // Data will be lost on XP
                argc = ClassicEtw.MAX_MOF_FIELDS;
            }

            header.Header.Size = (ushort)(argc * sizeof(EventData) + 48);
            for (int x = 0; x < argc; x++)
            {
                eventData[x].Ptr  = argv[x].Ptr;
                eventData[x].Size = argv[x].Size;
            }

            return(ClassicEtw.TraceEvent(_traceHandle, &header));
        }
Example #22
0
 private unsafe static void FillInEventData(EventData *pEventData, Guid *pGuid)
 {
     Debug.Assert(pGuid != null);
     pEventData->DataPointer = (IntPtr)pGuid;
     pEventData->Size        = sizeof(Guid);
 }
Example #23
0
        internal unsafe override uint EventWrite(EventTrace.Event eventID, EventTrace.Keyword keywords, EventTrace.Level level, int argc, EventData *argv)
        {
            ManifestEtw.EventDescriptor eventDescriptor;
            eventDescriptor.Id       = (ushort)eventID;
            eventDescriptor.Version  = EventTrace.GetVersionForEvent(eventID);
            eventDescriptor.Channel  = 0x10; // Since Channel isn't supported on XP we only use a single default channel.
            eventDescriptor.Level    = (byte)level;
            eventDescriptor.Opcode   = EventTrace.GetOpcodeForEvent(eventID);
            eventDescriptor.Task     = EventTrace.GetTaskForEvent(eventID);
            eventDescriptor.Keywords = (long)keywords;
            if (argc == 0)
            {
                argv = null;
            }

            return(ManifestEtw.EventWrite(_registrationHandle.Value, ref eventDescriptor, (uint)argc, argv));
        }
Example #24
0
        private unsafe void WriteEvent(
            int eventId,
            [CanBeNull] string arg1,
            [CanBeNull] string arg2,
            [CanBeNull] string arg3,
            [CanBeNull] string arg4,
            [CanBeNull] string arg5)
        {
            if (!this.IsEnabled())
            {
                return;
            }

            if (arg1 == null)
            {
                arg1 = string.Empty;
            }

            if (arg2 == null)
            {
                arg2 = string.Empty;
            }

            if (arg3 == null)
            {
                arg3 = string.Empty;
            }

            if (arg4 == null)
            {
                arg4 = string.Empty;
            }

            if (arg5 == null)
            {
                arg5 = string.Empty;
            }

            fixed(char *cp1 = arg1)
            {
                fixed(char *cp2 = arg2)
                {
                    fixed(char *cp3 = arg3)
                    {
                        fixed(char *cp4 = arg4)
                        {
                            fixed(char *cp5 = arg5)
                            {
                                EventData *data = stackalloc EventData[5];

                                data[0].DataPointer = (IntPtr)cp1;
                                data[0].Size        = (arg1.Length + 1) * 2;
                                data[1].DataPointer = (IntPtr)cp2;
                                data[1].Size        = (arg2.Length + 1) * 2;
                                data[2].DataPointer = (IntPtr)cp3;
                                data[2].Size        = (arg3.Length + 1) * 2;
                                data[3].DataPointer = (IntPtr)cp4;
                                data[3].Size        = (arg4.Length + 1) * 2;
                                data[4].DataPointer = (IntPtr)cp5;
                                data[4].Size        = (arg5.Length + 1) * 2;
                                this.WriteEventCore(eventId, 5, data);
                            }
                        }
                    }
                }
            }
        }
Example #25
0
        private unsafe void Response(Guid activityId,
                                     Guid localId,
                                     short statusCode,
                                     double milliseconds,
                                     // the following parameters are response headers
                                     string contentType,
                                     string contentEncoding,
                                     string contentLength,
                                     string contentLocation,
                                     string currentMediaStorageUsageInMB,
                                     string currentResourceQuotaUsage,
                                     string databaseAccountConsumedDocumentStorageInMB,
                                     string databaseAccountProvisionedDocumentStorageInMB,
                                     string databaseAccountReservedDocumentStorageInMB,
                                     string gatewayVersion,
                                     string indexingDirective,
                                     string itemCount,
                                     string lastStateChangeUtc,
                                     string maxMediaStorageUsageInMB,
                                     string maxResourceQuota,
                                     string newResourceId,
                                     string ownerFullName,
                                     string ownerId,
                                     string requestCharge,
                                     string requestValidationFailure,
                                     string retryAfter,
                                     string retryAfterInMilliseconds,
                                     string serverVersion,
                                     string schemaVersion,
                                     string sessionToken,
                                     string version)
        {
            if (contentType == null)
            {
                throw new ArgumentException("contentType");
            }
            if (contentEncoding == null)
            {
                throw new ArgumentException("contentEncoding");
            }
            if (contentLength == null)
            {
                throw new ArgumentException("contentLength");
            }
            if (contentLocation == null)
            {
                throw new ArgumentException("contentLocation");
            }
            if (currentMediaStorageUsageInMB == null)
            {
                throw new ArgumentException("currentMediaStorageUsageInMB");
            }
            if (currentResourceQuotaUsage == null)
            {
                throw new ArgumentException("currentResourceQuotaUsage");
            }
            if (databaseAccountConsumedDocumentStorageInMB == null)
            {
                throw new ArgumentException("databaseAccountConsumedDocumentStorageInMB");
            }
            if (databaseAccountProvisionedDocumentStorageInMB == null)
            {
                throw new ArgumentException("databaseAccountProvisionedDocumentStorageInMB");
            }
            if (databaseAccountReservedDocumentStorageInMB == null)
            {
                throw new ArgumentException("databaseAccountReservedDocumentStorageInMB");
            }
            if (gatewayVersion == null)
            {
                throw new ArgumentException("gatewayVersion");
            }
            if (indexingDirective == null)
            {
                throw new ArgumentException("indexingDirective");
            }
            if (itemCount == null)
            {
                throw new ArgumentException("itemCount");
            }
            if (lastStateChangeUtc == null)
            {
                throw new ArgumentException("lastStateChangeUtc");
            }
            if (maxMediaStorageUsageInMB == null)
            {
                throw new ArgumentException("maxMediaStorageUsageInMB");
            }
            if (maxResourceQuota == null)
            {
                throw new ArgumentException("maxResourceQuota");
            }
            if (newResourceId == null)
            {
                throw new ArgumentException("newResourceId");
            }
            if (ownerFullName == null)
            {
                throw new ArgumentException("ownerFullName");
            }
            if (ownerId == null)
            {
                throw new ArgumentException("ownerId");
            }
            if (requestCharge == null)
            {
                throw new ArgumentException("requestCharge");
            }
            if (requestValidationFailure == null)
            {
                throw new ArgumentException("requestValidationFailure");
            }
            if (retryAfter == null)
            {
                throw new ArgumentException("retryAfter");
            }
            if (retryAfterInMilliseconds == null)
            {
                throw new ArgumentException("retryAfterInMilliseconds");
            }
            if (serverVersion == null)
            {
                throw new ArgumentException("serverVersion");
            }
            if (schemaVersion == null)
            {
                throw new ArgumentException("schemaVersion");
            }
            if (sessionToken == null)
            {
                throw new ArgumentException("sessionToken");
            }
            if (version == null)
            {
                throw new ArgumentException("version");
            }

            byte[] guidBytes    = activityId.ToByteArray();
            byte[] localIdBytes = localId.ToByteArray();
            fixed(byte *fixedGuidBytes = guidBytes)
            fixed(byte *fixedLocalIdBytes    = localIdBytes)
            fixed(char *fixedContentType     = contentType)
            fixed(char *fixedContentEncoding = contentEncoding)
            fixed(char *fixedContentLength   = contentLength)
            fixed(char *fixedContentLocation = contentLocation)
            fixed(char *fixedCurrentMediaStorageUsageInMB = currentMediaStorageUsageInMB)
            fixed(char *fixedCurrentResourceQuotaUsage    = currentResourceQuotaUsage)
            fixed(char *fixedDatabaseAccountConsumedDocumentStorageInMB    = databaseAccountConsumedDocumentStorageInMB)
            fixed(char *fixedDatabaseAccountProvisionedDocumentStorageInMB = databaseAccountProvisionedDocumentStorageInMB)
            fixed(char *fixedDatabaseAccountReservedDocumentStorageInMB    = databaseAccountReservedDocumentStorageInMB)
            fixed(char *fixedGatewayVersion           = gatewayVersion)
            fixed(char *fixedIndexingDirective        = indexingDirective)
            fixed(char *fixedItemCount                = itemCount)
            fixed(char *fixedLastStateChangeUtc       = lastStateChangeUtc)
            fixed(char *fixedMaxMediaStorageUsageInMB = maxMediaStorageUsageInMB)
            fixed(char *fixedMaxResourceQuota         = maxResourceQuota)
            fixed(char *fixedNewResourceId            = newResourceId)
            fixed(char *fixedOwnerFullName            = ownerFullName)
            fixed(char *fixedOwnerId                  = ownerId)
            fixed(char *fixedRequestCharge            = requestCharge)
            fixed(char *fixedRequestValidationFailure = requestValidationFailure)
            fixed(char *fixedRetryAfter               = retryAfter)
            fixed(char *fixedRetryAfterInMilliseconds = retryAfterInMilliseconds)
            fixed(char *fixedServerVersion            = serverVersion)
            fixed(char *fixedSchemaVersion            = schemaVersion)
            fixed(char *fixedSessionToken             = sessionToken)
            fixed(char *fixedVersion                  = version)
            {
                const int eventDataCount          = 30;
                const int UnicodeEncodingCharSize = CustomTypeExtensions.UnicodeEncodingCharSize;

                EventData *dataDesc = stackalloc EventData[eventDataCount];

                dataDesc[0].DataPointer = (IntPtr)(fixedGuidBytes);
                dataDesc[0].Size        = guidBytes.Length;

                dataDesc[1].DataPointer = (IntPtr)(fixedLocalIdBytes);
                dataDesc[1].Size        = localIdBytes.Length;

                dataDesc[2].DataPointer = (IntPtr)(&statusCode);
                dataDesc[2].Size        = 2;

                dataDesc[3].DataPointer = (IntPtr)(&milliseconds);
                dataDesc[3].Size        = 8;

                dataDesc[4].DataPointer = (IntPtr)(fixedContentType);
                dataDesc[4].Size        = (contentType.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[5].DataPointer = (IntPtr)(fixedContentEncoding);
                dataDesc[5].Size        = (contentEncoding.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[6].DataPointer = (IntPtr)(fixedContentLength);
                dataDesc[6].Size        = (contentLength.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[7].DataPointer = (IntPtr)(fixedContentLocation);
                dataDesc[7].Size        = (contentLocation.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[8].DataPointer = (IntPtr)(fixedCurrentMediaStorageUsageInMB);
                dataDesc[8].Size        = (currentMediaStorageUsageInMB.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[9].DataPointer = (IntPtr)(fixedCurrentResourceQuotaUsage);
                dataDesc[9].Size        = (currentResourceQuotaUsage.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[10].DataPointer = (IntPtr)(fixedDatabaseAccountConsumedDocumentStorageInMB);
                dataDesc[10].Size        = (databaseAccountConsumedDocumentStorageInMB.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[11].DataPointer = (IntPtr)(fixedDatabaseAccountProvisionedDocumentStorageInMB);
                dataDesc[11].Size        = (databaseAccountProvisionedDocumentStorageInMB.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[12].DataPointer = (IntPtr)(fixedDatabaseAccountReservedDocumentStorageInMB);
                dataDesc[12].Size        = (databaseAccountReservedDocumentStorageInMB.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[13].DataPointer = (IntPtr)(fixedGatewayVersion);
                dataDesc[13].Size        = (gatewayVersion.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[14].DataPointer = (IntPtr)(fixedIndexingDirective);
                dataDesc[14].Size        = (indexingDirective.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[15].DataPointer = (IntPtr)(fixedItemCount);
                dataDesc[15].Size        = (itemCount.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[16].DataPointer = (IntPtr)(fixedLastStateChangeUtc);
                dataDesc[16].Size        = (lastStateChangeUtc.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[17].DataPointer = (IntPtr)(fixedMaxMediaStorageUsageInMB);
                dataDesc[17].Size        = (maxMediaStorageUsageInMB.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[18].DataPointer = (IntPtr)(fixedMaxResourceQuota);
                dataDesc[18].Size        = (maxResourceQuota.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[19].DataPointer = (IntPtr)(fixedNewResourceId);
                dataDesc[19].Size        = (newResourceId.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[20].DataPointer = (IntPtr)(fixedOwnerFullName);
                dataDesc[20].Size        = (ownerFullName.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[21].DataPointer = (IntPtr)(fixedOwnerId);
                dataDesc[21].Size        = (ownerId.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[22].DataPointer = (IntPtr)(fixedRequestCharge);
                dataDesc[22].Size        = (requestCharge.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[23].DataPointer = (IntPtr)(fixedRequestValidationFailure);
                dataDesc[23].Size        = (requestValidationFailure.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[24].DataPointer = (IntPtr)(fixedRetryAfter);
                dataDesc[24].Size        = (retryAfter.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[25].DataPointer = (IntPtr)(fixedRetryAfterInMilliseconds);
                dataDesc[25].Size        = (retryAfterInMilliseconds.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[26].DataPointer = (IntPtr)(fixedServerVersion);
                dataDesc[26].Size        = (serverVersion.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[27].DataPointer = (IntPtr)(fixedSchemaVersion);
                dataDesc[27].Size        = (schemaVersion.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[28].DataPointer = (IntPtr)(fixedSessionToken);
                dataDesc[28].Size        = (sessionToken.Length + 1) * UnicodeEncodingCharSize;

                dataDesc[29].DataPointer = (IntPtr)(fixedVersion);
                dataDesc[29].Size        = (version.Length + 1) * UnicodeEncodingCharSize;

                this.WriteEventCoreWithActivityId(activityId, 2, eventDataCount, dataDesc);
            }
        }
        private unsafe void VariantWrite(
            int eventId,
            int argCount,
            Variant v0 = default(Variant),
            Variant v1 = default(Variant),
            Variant v2 = default(Variant),
            Variant v3 = default(Variant),
            Variant v4 = default(Variant),
            Variant v5 = default(Variant),
            Variant v6 = default(Variant),
            Variant v7 = default(Variant),
            Variant v8 = default(Variant))
        {
            if (this.eventDescriptors[eventId].IsEventSinkEnabled())
            {
                if (argCount == 0)
                {
                    this.WriteEventCore(eventId, argCount, null);
                }
                else
                {
                    EventData *eventSourceData = stackalloc EventData[argCount]; // allocation for the data descriptors
                    byte *     dataBuffer      = stackalloc byte[EventDataArrayBuilder.BasicTypeAllocationBufferSize * argCount];

                    // 16 byte for non-string argument
                    var edb = new EventDataArrayBuilder((Writer.EventData *)eventSourceData, dataBuffer);

                    // The block below goes through all the arguments and fills in the data
                    // descriptors.
                    edb.AddEventData(v0);
                    if (argCount > 1)
                    {
                        edb.AddEventData(v1);
                        if (argCount > 2)
                        {
                            edb.AddEventData(v2);
                            if (argCount > 3)
                            {
                                edb.AddEventData(v3);
                                if (argCount > 4)
                                {
                                    edb.AddEventData(v4);
                                    if (argCount > 5)
                                    {
                                        edb.AddEventData(v5);
                                        if (argCount > 6)
                                        {
                                            edb.AddEventData(v6);
                                            if (argCount > 7)
                                            {
                                                edb.AddEventData(v7);
                                                if (argCount > 8)
                                                {
                                                    edb.AddEventData(v8);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (!edb.IsValid())
                    {
                        Debug.Fail(string.Format(
                                       "EventData for eventid {0} is invalid. Check the total size of the event.", eventId));
                        return;
                    }

                    fixed(
                        char *s0 = v0.ConvertToString(),
                        s1       = v1.ConvertToString(),
                        s2       = v2.ConvertToString(),
                        s3       = v3.ConvertToString(),
                        s4       = v4.ConvertToString(),
                        s5       = v5.ConvertToString(),
                        s6       = v6.ConvertToString(),
                        s7       = v7.ConvertToString(),
                        s8       = v8.ConvertToString())
                    {
                        var eventDataPtr = edb.ToEventDataArray(
                            s0,
                            s1,
                            s2,
                            s3,
                            s4,
                            s5,
                            s6,
                            s7,
                            s8);

                        this.WriteEventCore(eventId, argCount, (EventData *)eventDataPtr);
                    }
                }
            }
#if DotNetCoreClrLinux
            this.VariantWriteViaNative(eventId, 9, v0, v1, v2, v3, v4, v5, v6, v7, v8);
#endif
        }