Skip to content

Commit 1cc2ac4

Browse files
Resolve inconsistency in newline handling
* Ensure consistent newline before each "slot" in histogram cases. * Handle trailing spaces in single-line multiple frames input. * Add new test for histogram fn+offset case; minor update to existing test to reflect the desired outcome.
1 parent e0f1122 commit 1cc2ac4

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

Engine/ModuleInfoHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ await Task.Run(() => Parallel.ForEach(listOfCallStacks, currItem => {
134134
// pass-through this line as it is either non-XML, 0-length or whitespace-only
135135
outCallstack.AppendLine(line);
136136
}
137-
currItem.Callstack = outCallstack.ToString();
137+
currItem.Callstack = outCallstack.ToString().Trim();
138138
}
139139
}));
140140

Engine/StackResolver.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ public async Task<string> ResolveCallstacksAsync(List<StackDetails> listOfCallSt
382382

383383
foreach (var currstack in listOfCallStacks) {
384384
if (cts.IsCancellationRequested) { StatusMessage = OperationCanceled; PercentComplete = 0; return OperationCanceled; }
385-
if (!string.IsNullOrEmpty(currstack.Resolvedstack)) finalCallstack.Append(currstack.Resolvedstack);
385+
if (!string.IsNullOrEmpty(currstack.Resolvedstack)) finalCallstack.AppendLine(currstack.Resolvedstack);
386386
else if (!string.IsNullOrEmpty(currstack.Callstack)) {
387387
finalCallstack = new StringBuilder("WARNING: No output to show. This may indicate an internal error!");
388388
break;
@@ -477,7 +477,7 @@ public async Task<List<StackDetails>> GetListofCallStacksAsync(string inputCalls
477477
string callstackText = string.Empty;
478478
if (reader.ReadToDescendant("value")) {
479479
reader.Read();
480-
if (XmlNodeType.Text == reader.NodeType || XmlNodeType.CDATA == reader.NodeType) callstackText = reader.Value;
480+
if (XmlNodeType.Text == reader.NodeType || XmlNodeType.CDATA == reader.NodeType) callstackText = reader.Value.Trim();
481481
}
482482
if (string.IsNullOrEmpty(callstackText)) throw new XmlException();
483483
allStacks.Add(new StackDetails(callstackText, framesOnSingleLine, annotation, $"Slot_{stacknum}\t[count:{slotcount}]:"));

Tests/Tests.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,18 @@ private string PrepareLargeXEventInput() {
651651
Assert.AreEqual(expected.Trim(), ret.Trim());
652652
}
653653

654+
/// End-to-end test with XE histogram target and module+offset frames.
655+
[TestMethod][TestCategory("Unit")]
656+
public async Task E2EHistogramOffsets() {
657+
using var csr = new StackResolver();
658+
using var cts = new CancellationTokenSource();
659+
var pdbPath = @"..\..\..\Tests\TestCases\TestOrdinal";
660+
var input = "<HistogramTarget truncated=\"0\" buckets=\"256\">\r\n <Slot count=\"108633\">\r\n <value>sqldk.dll+40609\r\nsqldk.dll+40609</value>\r\n </Slot>\r\n<Slot count=\"108631\">\r\n <value>sqldk.dll+40609\r\nsqldk.dll+40609</value>\r\n </Slot>\r\n</HistogramTarget>";
661+
var ret = await csr.ResolveCallstacksAsync(await csr.GetListofCallStacksAsync(input, true, cts), pdbPath, false, null, true, false, false, true, false, false, null, cts);
662+
var expected = "Slot_0 [count:108633]:\r\n\r\nsqldk!MemoryClerkInternal::AllocatePagesWithFailureMode+644\r\nsqldk!MemoryClerkInternal::AllocatePagesWithFailureMode+644\r\n\r\nSlot_1\t[count:108631]:\r\n\r\nsqldk!MemoryClerkInternal::AllocatePagesWithFailureMode+644\r\nsqldk!MemoryClerkInternal::AllocatePagesWithFailureMode+644";
663+
Assert.AreEqual(expected.Trim(), ret.Trim());
664+
}
665+
654666
[TestMethod][TestCategory("Unit")] public async Task E2ESymSrvXMLFramesMultiHistogram() {
655667
using var csr = new StackResolver();
656668
using var cts = new CancellationTokenSource();
@@ -678,7 +690,7 @@ private string PrepareLargeXEventInput() {
678690
"Annotation for histogram #2 <HistogramTarget truncated=\"0\" buckets=\"256\"><Slot count=\"5\"><value>0x00007FFEAC0F80CF 0x00007FFEAC1EE447 0x00007FFEAC1EE6F5</value></Slot></HistogramTarget>";
679691

680692
var ret = await csr.ResolveCallstacksAsync(await csr.GetListofCallStacksAsync(input, true, cts), pdbPath, false, null, false, false, false, true, false, false, null, cts);
681-
var expected = "Annotation for histogram #1\r\nSlot_0 [count:5]:\r\n\r\nsqldk!XeSosPkg::spinlock_backoff::Publish+425\r\nsqldk!SpinlockBase::Sleep+182\r\nsqlmin!Spinlock<143,7,1>::SpinToAcquireWithExponentialBackoff+363\r\nsqlmin!lck_lockInternal+2042\r\nAnnotation for histogram #2\r\nSlot_1 [count:5]:\r\n\r\nsqlmin!lck_lockInternal+2042\r\nsqlmin!MDL::LockGenericLocal+382\r\nsqlmin!MDL::LockGenericIdsLocal+101";
693+
var expected = "Annotation for histogram #1\r\nSlot_0 [count:5]:\r\n\r\nsqldk!XeSosPkg::spinlock_backoff::Publish+425\r\nsqldk!SpinlockBase::Sleep+182\r\nsqlmin!Spinlock<143,7,1>::SpinToAcquireWithExponentialBackoff+363\r\nsqlmin!lck_lockInternal+2042\r\n\r\nAnnotation for histogram #2\r\nSlot_1 [count:5]:\r\n\r\nsqlmin!lck_lockInternal+2042\r\nsqlmin!MDL::LockGenericLocal+382\r\nsqlmin!MDL::LockGenericIdsLocal+101";
682694
Assert.AreEqual(expected.Trim(), ret.Trim());
683695
}
684696

0 commit comments

Comments
 (0)