コード例 #1
0
        private bool GetWinFabIdParts(string winfabId, out string taskName, out string eventType, out string id)
        {
            taskName  = null;
            eventType = null;
            id        = null;

            // WinFab ID is of the following format:
            //      <TaskName>.<EventType>[@<id>]
            // The '@<id>' part above is optional
            string[] winfabIdParts = winfabId.Split(new[] { '.', '@' }, (int)WinFabIdParts.MaxCount);
            if (winfabIdParts.Length < (int)WinFabIdParts.MinCount)
            {
                this.traceSource.WriteError(
                    this.logSourceId,
                    "The event has invalid event identifier (TaskName/EventType/ID) {0}.",
                    winfabId);
                return(false);
            }

            taskName  = winfabIdParts[(int)WinFabIdParts.TaskName];
            eventType = winfabIdParts[(int)WinFabIdParts.EventType];

            // The DTR file in V3+ has the full event type name. However, we want to display
            // only the event group name in the MDS table.
            string eventGroupName = EventDefinition.GetEventGroupName(eventType);

            if (false == string.IsNullOrEmpty(eventGroupName))
            {
                eventType = eventGroupName;
            }

            if (winfabIdParts.Length == (int)WinFabIdParts.MinCount)
            {
                // This event does not have an ID field
                id = string.Empty;
            }
            else
            {
                // This event has an ID field
                id = winfabIdParts[(int)WinFabIdParts.Id];
            }

            return(true);
        }
コード例 #2
0
        private static void VerifyEvents(string logDirectory)
        {
            // Get merged lines from expected output
            var allLines = TestUtility.GetMergedDtrLines("fabric", expectedOutputDataFolderPath);

            // Calculate number of records from output dtr file
            List <string> allEventRecords = new List <string>();
            StringBuilder strb            = new StringBuilder();

            foreach (var line in allLines)
            {
                var lineParts = line.Split(',');
                if (lineParts.Length > 0)
                {
                    var      dateString = lineParts[0];
                    DateTime result     = DateTime.MinValue;
                    if (DateTime.TryParse(dateString, out result))
                    {
                        if (strb.Length > 0)
                        {
                            allEventRecords.Add(strb.ToString());
                            strb.Clear();
                        }
                        strb.Append(line);
                    }
                    else
                    {
                        strb.Append(line);
                    }
                }
            }

            // Write out the last record
            if (strb.Length > 0)
            {
                allEventRecords.Add(strb.ToString());
                strb.Clear();
            }

            // Get records from MDS table
            string tablePath = Path.Combine(logDirectory, "Fabric");
            string tableName = String.Concat(
                TableName,
                MdsFileProducer.TableSchemaVersion,
                DefaultTableNonce);

            QueryLocalTable tableQuery      = new QueryLocalTable(tableName, tablePath);
            var             allTableRecords = tableQuery.ReadRecords(DateTime.MinValue, DateTime.MaxValue).ToArray();

            Assert.AreEqual(allEventRecords.Count, allTableRecords.Count(), "Total number of records in the dtr files should be the same as in the MDS files");

            // Compare records
            for (int i = 0; i < allEventRecords.Count; i++)
            {
                string[] eventParts          = allEventRecords[i].Split(new char[] { ',' }, (int)MdsFileProducer.EtwEventParts.Count);
                object[] expectedTableFields = new object[(int)MdsFileProducer.MdsTableFields.Count];
                expectedTableFields[(int)MdsFileProducer.MdsTableFields.Timestamp] = DateTime.Parse(eventParts[(int)MdsFileProducer.EtwEventParts.Timestamp]);
                expectedTableFields[(int)MdsFileProducer.MdsTableFields.Level]     = eventParts[(int)MdsFileProducer.EtwEventParts.Level];
                expectedTableFields[(int)MdsFileProducer.MdsTableFields.ThreadId]  = Int32.Parse(eventParts[(int)MdsFileProducer.EtwEventParts.ThreadId]);
                expectedTableFields[(int)MdsFileProducer.MdsTableFields.ProcessId] = Int32.Parse(eventParts[(int)MdsFileProducer.EtwEventParts.ProcessId]);

                var      winFabId      = eventParts[(int)MdsFileProducer.EtwEventParts.WinFabId];
                string[] winFabIdParts = winFabId.Split(new[] { '.', '@' }, (int)MdsFileProducer.WinFabIdParts.MaxCount);
                if (winFabIdParts.Length >= (int)MdsFileProducer.WinFabIdParts.MinCount)
                {
                    expectedTableFields[(int)MdsFileProducer.MdsTableFields.TaskName] = winFabIdParts[(int)MdsFileProducer.WinFabIdParts.TaskName];

                    var    eventType      = winFabIdParts[(int)MdsFileProducer.WinFabIdParts.EventType];
                    string eventGroupName = EventDefinition.GetEventGroupName(eventType);
                    if (!string.IsNullOrEmpty(eventGroupName))
                    {
                        eventType = eventGroupName;
                    }

                    expectedTableFields[(int)MdsFileProducer.MdsTableFields.EventType] = eventType;

                    expectedTableFields[(int)MdsFileProducer.MdsTableFields.Id] = (winFabIdParts.Length == (int)MdsFileProducer.WinFabIdParts.MinCount) ? (string.Empty) : (winFabIdParts[(int)MdsFileProducer.WinFabIdParts.Id]);
                }

                expectedTableFields[(int)MdsFileProducer.MdsTableFields.Text] = eventParts[(int)MdsFileProducer.EtwEventParts.Text];

                Assert.AreEqual(1 + expectedTableFields.Length, allTableRecords[i].FieldData.Length, "Schema mismatch between dtr file and mds table record");

                bool match = true;
                for (int j = 0; j < expectedTableFields.Length; j++)
                {
                    // for text fields compare after stripping CR and tabs
                    if (j == (int)MdsFileProducer.MdsTableFields.Text)
                    {
                        var expectedText = ((string)expectedTableFields[(int)MdsFileProducer.MdsTableFields.Text]).Replace("\r", "").Replace("\t", "");
                        var mdsText      = ((string)allTableRecords[i].FieldData[j + 1]).Replace("\r", "").Replace("\t", "");
                        if (expectedText.Equals(mdsText) == false)
                        {
                            match = false;
                            break;
                        }
                    }
                    else
                    {
                        if (expectedTableFields[j].Equals(allTableRecords[i].FieldData[j + 1]) == false)
                        {
                            match = false;
                            break;
                        }
                    }
                }

                Assert.IsTrue(match, "Event record values differ between the dtr file and mds table record");
            }
        }