private void ParseConfig(DateTime startTime, TraceFileType traceFileType)
        {
            List <TraceFileInfo> fileInfoList = new List <TraceFileInfo>();

            string paramName = configParamNames[traceFileType];

            string[] valuesAsStrings = this.testContext.DataRow[paramName] as string[];
            foreach (string valueAsString in valuesAsStrings)
            {
                string[] valueParts = valueAsString.Split(new char[] { ',' }, (int)TraceFileAttribute.Count);
                Verify.IsTrue(valueParts.Length == (int)TraceFileAttribute.Count);
                TraceFileInfo fileInfo = new TraceFileInfo();
                fileInfo.Name             = valueParts[(int)TraceFileAttribute.Name].Trim();
                fileInfo.IsLastChunkOfEtl = Boolean.Parse(
                    valueParts[(int)TraceFileAttribute.IsLastChunkOfEtl].Trim());
                fileInfo.CreationPass = Int32.Parse(
                    valueParts[(int)TraceFileAttribute.CreationPass].Trim());
                int lastEventTimestampOffsetMinutes = Int32.Parse(
                    valueParts[(int)TraceFileAttribute.LastEventTimestamp].Trim());
                fileInfo.LastEventTimestamp         = startTime.AddSeconds(lastEventTimestampOffsetMinutes);
                fileInfo.AllEventsHaveSameTimestamp = Boolean.Parse(
                    valueParts[(int)TraceFileAttribute.AllEventsHaveSameTimestamp].Trim());
                int lastWriteTimeOffsetMinutes = Int32.Parse(
                    valueParts[(int)TraceFileAttribute.LastWriteTime].Trim());
                fileInfo.LastWriteTime   = startTime.AddSeconds(lastWriteTimeOffsetMinutes);
                fileInfo.ProcessedInPass = Int32.Parse(
                    valueParts[(int)TraceFileAttribute.ProcessedInPass].Trim());
                fileInfo.DeletionPass = Int32.Parse(
                    valueParts[(int)TraceFileAttribute.DeletionPass].Trim());
                fileInfo.EmptyFile = Boolean.Parse(
                    valueParts[(int)TraceFileAttribute.EmptyFile].Trim());
                fileInfoList.Add(fileInfo);
            }

            this.traceFileInfo[traceFileType] = fileInfoList;
        }
Beispiel #2
0
        private void TraceInfoDataTemplateDisplay_MouseDown(object sender, MouseButtonEventArgs e)
        {
            TraceFileInfo traceInfo = (sender as FrameworkElement).DataContext as TraceFileInfo;

            traceInfo.Selected = !traceInfo.Selected;
        }
        private void VerifyEventsFromFile(TraceFileInfo traceFile, QueryLocalTable tableQuery, bool expectProcessed)
        {
            if (traceFile.EmptyFile)
            {
                // We created a file with no events. Nothing to verify here.
                return;
            }

            object[] expectedTableFields = new object[(int)MdsEtwEventUploader.MdsTableFields.Count];

            // Read the events from the table
            TableRecord[] tableRecords = tableQuery.ReadRecords(DateTime.MinValue, DateTime.MaxValue).ToArray();

            // Figure out the full path to the trace file
            string traceFileFullPath;

            if (false == FabricFile.Exists(traceFile.FullName))
            {
                // Maybe the trace file was deleted, i.e. moved to the deleted items folder
                string fileName = Path.GetFileName(traceFile.FullName);
                traceFileFullPath = Path.Combine(this.deletedItemsFolder, fileName);
            }
            else
            {
                traceFileFullPath = traceFile.FullName;
            }

            using (StreamReader reader = new StreamReader(traceFileFullPath))
            {
                // Read event from file
                string eventLine = reader.ReadLine();

                // For this event, get the fields that we expect to see in the table
                string[] eventParts = eventLine.Split(new char[] { ',', '.' });
                expectedTableFields[(int)MdsEtwEventUploader.MdsTableFields.Timestamp] = DateTime.Parse(eventParts[0]);
                expectedTableFields[(int)MdsEtwEventUploader.MdsTableFields.Level]     = eventParts[1];
                expectedTableFields[(int)MdsEtwEventUploader.MdsTableFields.ThreadId]  = Int32.Parse(eventParts[2]);
                expectedTableFields[(int)MdsEtwEventUploader.MdsTableFields.ProcessId] = Int32.Parse(eventParts[3]);
                expectedTableFields[(int)MdsEtwEventUploader.MdsTableFields.TaskName]  = eventParts[4];
                string   eventTypeWithId      = eventParts[5];
                string[] eventTypeWithIdParts = eventTypeWithId.Split('@');
                expectedTableFields[(int)MdsEtwEventUploader.MdsTableFields.EventType] = eventTypeWithIdParts[0];
                expectedTableFields[(int)MdsEtwEventUploader.MdsTableFields.Id]        = (eventTypeWithIdParts.Length > 1) ? eventTypeWithIdParts[1] : String.Empty;
                // ReadLine method removes the '\r' at the end. Add it back.
                expectedTableFields[(int)MdsEtwEventUploader.MdsTableFields.Text] = String.Concat(eventParts[6], "\r");

                // Search the table to see if we have a match
                bool matchFound = false;
                foreach (TableRecord tableRecord in tableRecords)
                {
                    // The timestamp when the event was written to the table (NOT to be confused with
                    // timestamp when the event occurred) also shows up as a field in the record that
                    // we read. However, it is not a field in the record that we write. Looks like MDS
                    // automatically adds the extra field.
                    if ((1 + expectedTableFields.Length) != tableRecord.FieldData.Length)
                    {
                        Utility.TraceSource.WriteError(
                            TraceType,
                            "Found a record in the table whose schema does not match the expected schema. Record field tags are: {0}",
                            String.Join(",", tableRecord.FieldTags));
                        Verify.Fail("Unexpected schema for table record");
                    }

                    bool currentRecordMatchesEvent = true;
                    for (int i = 0; i < expectedTableFields.Length; i++)
                    {
                        if (false == expectedTableFields[i].Equals(tableRecord.FieldData[i + 1]))
                        {
                            currentRecordMatchesEvent = false;
                            break;
                        }
                    }
                    if (currentRecordMatchesEvent)
                    {
                        matchFound = true;
                        break;
                    }
                }

                if (expectProcessed != matchFound)
                {
                    Utility.TraceSource.WriteError(
                        TraceType,
                        "{0} Event info: {1}",
                        expectProcessed ?
                        "An event that we expected to find in the table was not found." :
                        "Event unexpectedly found in table.",
                        eventLine);
                    Verify.Fail("Unexpected event processing status");
                }
            }
        }
        private void CreateTraceFile(TraceFileInfo traceFileToCreate, string traceSubFolderName)
        {
            // Compute file name
            int    differentiator = traceFileToCreate.IsLastChunkOfEtl ? Int32.MaxValue : 0;
            string fileName       = String.Format(
                "{0}_{1}_{2:D20}_{3}.{4}",
                TestFabricNodeId,
                traceFileToCreate.Name,
                traceFileToCreate.LastEventTimestamp.Ticks,
                differentiator.ToString("D10"),
                EtlConsumerConstants.FilteredEtwTraceFileExtension);

            // Compute full path to file
            string fullName = Path.Combine(
                EtwCsvFolder,
                traceSubFolderName,
                fileName);

            // Create the file
            Random random     = new Random();
            int    eventCount = traceFileToCreate.EmptyFile ? 0 : (1 + (random.Next() % MaxPerFileEventCount));

            traceFileToCreate.EventCount = eventCount;
            using (StreamWriter writer = new StreamWriter(fullName))
            {
                for (int i = (eventCount - 1); i >= 0; i--)
                {
                    int      offset         = 0 - i;
                    DateTime eventTimestamp = traceFileToCreate.AllEventsHaveSameTimestamp ?
                                              traceFileToCreate.LastEventTimestamp :
                                              traceFileToCreate.LastEventTimestamp.AddSeconds(offset);
                    string eventLevel = eventLevels[random.Next() % eventLevels.Length];
                    int    processId  = random.Next() % 10000;
                    int    threadId   = random.Next() % 10000;
                    string taskName   = String.Concat(TaskNamePrefix, (random.Next() % 100).ToString());
                    string eventType  = String.Concat(EventTypePrefix, (random.Next() % 100).ToString());
                    string id         = String.Concat(IdPrefix, random.Next().ToString());
                    // Some events have an id field, some don't
                    string eventTypeWithId = ((random.Next() % 2) == 0) ? eventType : String.Concat(eventType, "@", id);
                    string text            = String.Concat(TextPrefix, random.Next().ToString());

                    string eventLine = String.Format(
                        "{0},{1},{2},{3},{4}.{5},{6}",
                        eventTimestamp,
                        eventLevel,
                        threadId,
                        processId,
                        taskName,
                        eventTypeWithId,
                        text);
                    writer.WriteLine(eventLine);
                }
            }

            // Set the last write time of the file as specified in the config
            FileInfo fileInfo = new FileInfo(fullName);

            fileInfo.LastWriteTimeUtc = traceFileToCreate.LastWriteTime;

            // Save the full path to the file for future reference
            traceFileToCreate.FullName = fullName;
        }