Refactor GetManifestForRegisteredProvider to use XmlWriter#2353
Refactor GetManifestForRegisteredProvider to use XmlWriter#2353
Conversation
|
@copilot, the new test is failing with the following error: |
... Fixed in commit c485a84. The issue was that stringIds (like |
|
@copilot, I've made a bunch of changes locally. Please update the PR description. |
Updated the PR description to reflect the changes made in commits 657a433, ab5f160, and 554069f: Key updates:
The new description better reflects the current state of the PR with your improvements. |
Replace hand-crafted XML string concatenation with XmlWriter for proper XML generation. Add comparison tests against a copy of the legacy implementation to validate output equivalence. Changes: - New XmlWriter-based implementation using structured data classes (EventData, TemplateData, DataField, MapData, MapEntry, StringTableEntry) - Fix: events with multiple versions are now all preserved (List<EventData>) - Fix: proper XML escaping via XmlWriter instead of manual escaping - Legacy implementation preserved in test file for comparison testing - Tests for Microsoft-JScript, Microsoft-Windows-Ntfs, and Microsoft-Windows-DotNETRuntime providers
554069f to
d08077e
Compare
marklio
left a comment
There was a problem hiding this comment.
This seems "reasonable", but it is a little "strange". Now, instead of writing out the data, a new set of data structures is produced to represent the data and then that is transformed into the Xml. It seems like it would be simpler to replace the stringbuilder output to the equivalent XmlWriter methods. I think it probably "works", but it is definitely harder to understand what the code is doing.
| string valueName = new string((char*)(&enumBuffer[mapEntries[k].NameOffset])).Trim(); | ||
| string escapedValueName = XmlUtilities.XmlEscape(valueName); | ||
| string stringId = XmlUtilities.XmlEscape($"map_{enumName}{valueName}"); | ||
| enumWriter.WriteLine(" <map value=\"0x{0:x}\" message=\"$(string.{1})\"/>", value, stringId); |
There was a problem hiding this comment.
I would have expected this to be replaced with a WriteStartElement, two WriteAttributeStrings and a WriteEndElement.
…ering Address reviewer feedback to use XmlWriter more directly. Instead of collecting into intermediate data classes (EventData, TemplateData, DataField, TemplateKey, MapData, MapEntry, StringTableEntry) and then serializing in a second pass, use XmlWriter fragment buffers to render events, templates, and maps inline during enumeration. The main document writer uses WriteRaw to inject the pre-rendered sections. - Removed 7 helper classes (EventData, TemplateData, DataField, TemplateKey, MapData, MapEntry, StringTableEntry) - Template dedup uses rendered XML content as key (collision-free) - Map dedup uses mapName key with rendered XML and display name - Preserved map-reuse bug fix (display name lookup for all map refs) - TaskInfo retained (pre-existing, used for task/opcode tracking) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add tracking of string table entries that contain XML-special characters in the semantic comparison loop. This surfaces whether the test data actually exercises the escaping path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
marklio
left a comment
There was a problem hiding this comment.
Looks reasonable. Took me a while to wrap my head around the up-front fragment rendering and realize this is what was happening before as well.
The
GetManifestForRegisteredProvidermethod hand-crafted XML through string concatenation and manual escaping. This refactoring replaces it withXmlWriterfor better maintainability while ensuring identical output to the original implementation.Changes
RegisteredTraceEventParser.cs
EventData,TemplateData,DataField,MapData,MapEntry,StringTableEntry) to collect manifest data before serialization.StringWriter-based XML concatenation withXmlWriter, which handles element nesting, attribute escaping, and namespace declarations automatically.XmlUtilities.XmlEscapecalls that would have caused double-escaping when combined withXmlWriter.mapattribute (only the first field to discover a map received it).TemplateKeyclass implementingIEquatable<TemplateKey>for collision-free template deduplication.usingdirectives (System.Linq,Microsoft.Diagnostics.Utilities).RegisteredTraceEventParserTests.cs
GetManifestForRegisteredProvider_NoDoubleEscapedEntities: verifies no double-escaped XML entities in output and semantically compares string table entries between new and legacyimplementations.
GetManifestForRegisteredProvider_NewAndLegacyImplementationsProduceSameOutput: normalizes and compares full XML output against a legacy reference implementation(Microsoft-JScript provider).
GetManifestForRegisteredProvider_DotNETRuntime_NewAndLegacyMatch: same comparison for the complex Microsoft-Windows-DotNETRuntime provider.NormalizeTemplateNames,RemoveNonSignificantTextNodes,SortAttributes) to handle formatting differences and template naming order betweenimplementations.