internal IList <PropertyItem> GetProperties(EventRecord eventRecord)
        {
            // We only support top level properties and simple types
            IList <PropertyItem> properties = new List <PropertyItem>();

            if (this._hasProperties)
            {
                int offset = 0;

                for (int i = 0; i < _traceEventInfo.TopLevelPropertyCount; i++)
                {
                    EventPropertyInfo info = _eventPropertyInfoArray[i];

                    // Read the current property name
                    string propertyName = Marshal.PtrToStringUni(new IntPtr(_address.ToInt64() + info.NameOffset));

                    object value;
                    string mapName;
                    int    length;

                    if (eventRecord.UserData == IntPtr.Zero)
                    {
                        mapName = string.Empty;
                        value   = string.Empty;
                        length  = info.LengthPropertyIndex;
                    }
                    else
                    {
                        IntPtr dataPtr = new IntPtr(eventRecord.UserData.ToInt64() + offset);
                        value = ReadPropertyValue(info, dataPtr, out mapName, out length);
                    }

                    // If we have a map name, return both map name and map value as a pair.
                    if (!string.IsNullOrEmpty(mapName))
                    {
                        value = new KeyValuePair <string, object>(mapName, value);
                    }

                    offset += length;
                    properties.Add(new PropertyItem(propertyName, value));
                }

                if (offset < eventRecord.UserDataLength)
                {
                    //
                    // There is some extra information not mapped.
                    //
                    IntPtr dataPtr = new IntPtr(eventRecord.UserData.ToInt64() + offset);
                    int    length  = eventRecord.UserDataLength - offset;
                    byte[] array   = new byte[length];

                    for (int index = 0; index < length; index++)
                    {
                        array[index] = Marshal.ReadByte(dataPtr, index);
                    }

                    properties.Add(new PropertyItem("__ExtraPayload", array));
                }
            }
            else
            {
                // NOTE: It is just a guess that this is an Unicode string
                string str = Marshal.PtrToStringUni(eventRecord.UserData);

                properties.Add(new PropertyItem("EventData", str));
            }

            return(properties);
        }
Example #2
0
 internal static extern int TdhGetEventInformation(
     ref EventRecord Event,
     uint TdhContextCount,
     IntPtr TdhContext,
     [Out] IntPtr eventInfoPtr,
     ref int BufferSize);
 internal TraceEventInfoWrapper(EventRecord eventRecord)
 {
     Initialize(eventRecord);
 }