Example #1
0
        public ProviderDefinitionDescription(IXPathNavigable inputProvider, StringTable strings)
        {
            if (strings == null)
            {
                throw new ArgumentNullException("strings");
            }

            if (inputProvider == null)
            {
                throw new ArgumentNullException("inputProvider");
            }

            XmlElement provider = inputProvider as XmlElement;

            if (provider == null)
            {
                throw new ArgumentException(StringResources.ETLReaderError_InvalidXmlElement_InputProvider);
            }

            this.guid = new Guid(provider.GetAttribute("guid"));
            bool wellKnownProviderId = WellKnownProviderList.IsWellKnownProvider(this.guid);
            bool dynamicManifest     = WellKnownProviderList.IsDynamicProvider(this.guid);

            this.name   = provider.GetAttribute("name");
            this.events = new Dictionary <int, EventDefinitionDescription>();

            XmlElement mapElements = provider["maps"];

            this.valueMaps = new ValueMaps(mapElements, strings);

            XmlElement eventElements   = provider["events"];
            XmlElement templates       = provider["templates"];
            string     eventSourceName = dynamicManifest ? this.name : null;

            foreach (XmlElement evt in eventElements.GetElementsByTagName("event"))
            {
                string     tid      = evt.GetAttribute("template");
                XmlElement template = null;

                foreach (XmlElement t in templates.GetElementsByTagName("template"))
                {
                    if (tid == t.GetAttribute("tid"))
                    {
                        template = t;
                        break;
                    }
                }

                var eventDef = new EventDefinitionDescription(evt, template, strings, wellKnownProviderId, eventSourceName);

                // We are not using Version information as key here. This is intentional while we make some structural changes
                // to handle scenarios where a single file can have events with multiple versions. Till these changes can materialize,
                // we have to handle scenario where we have same events with multiple versions in the same .etl file.
                this.events.Add(eventDef.Id, eventDef);
            }
        }
Example #2
0
 internal string FormatEvent(EventRecord eventRecord, ValueMaps valueMaps, out string eventType, out string eventText, int formatVersion)
 {
     return(this.description.FormatEvent(this.stack, eventRecord, valueMaps, out eventType, out eventText, formatVersion));
 }
Example #3
0
        public string FormatField(IFormatProvider provider, ApplicationDataReader reader, ValueMaps valueMaps)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (valueMaps == null)
            {
                throw new ArgumentNullException("valueMaps");
            }

            if (this.skipFormatting)
            {
                return("");
            }

            try
            {
                switch (this.inType)
                {
                case FieldType.UnicodeString:
                    return(reader.ReadUnicodeString());

                case FieldType.AnsiString:
                    return(reader.ReadAnsiString());

                case FieldType.Boolean:
                    return(reader.ReadBoolean().ToString());

                case FieldType.UInt8:
                    return(reader.ReadUInt8().ToString(provider));

                case FieldType.UInt16:
                    return(reader.ReadUInt16().ToString(provider));

                case FieldType.UInt32:
                    uint key = reader.ReadUInt32();

                    if (!string.IsNullOrEmpty(this.mapName))
                    {
                        string stringValue = null;
                        if (valueMaps.TryGetValue(this.mapName, key, out stringValue))
                        {
                            return(stringValue);
                        }
                    }

                    return(key.ToString(provider));

                case FieldType.UInt64:
                    UInt64 value = reader.ReadUInt64();

                    if (this.omitIfZero && value == 0)
                    {
                        return(System.String.Empty);
                    }

                    return(value.ToString(provider));

                case FieldType.Int8:
                    return(reader.ReadInt8().ToString(provider));

                case FieldType.Int16:
                    return(reader.ReadInt16().ToString(provider));

                case FieldType.Int32:
                    return(reader.ReadInt32().ToString(provider));

                case FieldType.Int64:
                    return(reader.ReadInt64().ToString(provider));

                case FieldType.HexInt32:
                    return(reader.ReadUInt32().ToString("x", provider));

                case FieldType.HexInt64:
                    value = reader.ReadUInt64();

                    if (this.omitIfZero && value == 0)
                    {
                        return(System.String.Empty);
                    }

                    return(value.ToString("x", provider));

                case FieldType.Float:
                    return(reader.ReadFloat().ToString(provider));

                case FieldType.Double:
                    return(reader.ReadDouble().ToString(provider));

                case FieldType.DateTime:
                    return(reader.ReadFileTime().ToString("yyyy-M-d HH:mm:ss.fff", provider));

                case FieldType.Guid:
                    return(reader.ReadGuid().ToString("D"));

                case FieldType.LargeInteger:
                    UInt64 highValue = reader.ReadUInt64();
                    UInt64 lowValue  = reader.ReadUInt64();

                    if (highValue == 0)
                    {
                        return(lowValue.ToString("x", provider));
                    }

                    return(highValue.ToString("x", provider) + lowValue.ToString("x16", provider));

                default:
                    return("<unknown type " + this.inType + ">");
                }
            }
            catch (OverflowException)
            {
                return("<unknown " + this.inType + " value>");
            }
            catch (ArgumentException e)
            {
                if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WeakETLReader")))
                {
                    return(string.Format("(!!! Invalid value for field {0}: {1} !!!)", this.Name, e.Message));
                }
                throw;
            }
        }
Example #4
0
 public string FormatField(ApplicationDataReader reader, ValueMaps valueMaps)
 {
     return(this.FormatField(CultureInfo.InvariantCulture, reader, valueMaps));
 }
        internal string FormatEvent(EventStack stack, EventRecord eventRecord, ValueMaps valueMaps, out string eventType, out string eventText, int formatVersion)
        {
            try
            {
                // This inefficient code is only a placeholder
                // once we make it work on all primitive types this will be
                // pre-compiled Linq Expression EventRecord->String
                ApplicationDataReader reader = new ApplicationDataReader(eventRecord.UserData, eventRecord.UserDataLength);

                eventType = this.eventName;
                string type = this.originalEventName;
                string id   = string.Empty;

                string[] values = new string[fields.Count];
                for (int i = 0; i < this.fields.Count; i++)
                {
                    FieldDefinition fieldDef = this.fields[i];
                    values[i] = fieldDef.FormatField(CultureInfo.InvariantCulture, reader, valueMaps);
                }

                if (this.isParentEvent)
                {
                    for (int i = this.fields.Count - 1; i >= 0; i--)
                    {
                        if (this.fields[i].IsContextField)
                        {
                            values[i] = stack.Pop(eventRecord.EventHeader.ProcessId, eventRecord.EventHeader.ThreadId, values[i], this.firstContextFieldIndex == i);
                            if (values[i] == null)
                            {
                                values[i] = " !!!Context Data Not Found!!! ";
                            }
                        }
                    }
                }

                if (this.typeFieldIndex != -1)
                {
                    type = eventType = values[typeFieldIndex];
                }

                eventText = FormatWithFieldValues(values, out id);

                if (id.Length > 0)
                {
                    type += "@" + id;
                }

                if (this.isChildEvent)
                {
                    stack.Push(eventRecord.EventHeader.ProcessId, eventRecord.EventHeader.ThreadId, values[0], eventText);
                    return(null);
                }

                return(EventFormatter.FormatEvent(
                           string.IsNullOrEmpty(this.eventSourceName) ? (EventFormatter.FormatVersion)formatVersion : EventFormatter.FormatVersion.EventSourceBasedFormatting,
                           CultureInfo.InvariantCulture,
                           eventRecord,
                           this.eventSourceName,
                           this.level,
                           this.taskName,
                           this.opcodeName,
                           this.keywordsName,
                           type,
                           eventText));
            }
            catch (Exception e)
            {
                throw new InvalidDataException(
                          string.Format(CultureInfo.InvariantCulture, "Unable to parse event {0}.{1} id {2} eventsource {3}", this.TaskName, this.EventName, this.id, this.eventSourceName),
                          e);
            }
        }