Skip to content

Commit

Permalink
Trim code and tests (#21)
Browse files Browse the repository at this point in the history
* Skip proactively loading PDBs for well-known modules. There is no
  impact on perf, as the associated DIA session cache is still present.

* Eliminate a redundant test, and add some "fuzz" to an existing test.

* Remove all repeated whitespace, not just spaces, for single-line
  input.
  • Loading branch information
arvindshmicrosoft authored Jan 19, 2022
1 parent c6e3801 commit d548ba5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 31 deletions.
11 changes: 2 additions & 9 deletions Engine/StackResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -559,15 +559,8 @@ private void ProcessCallStack(Object obj) {
// process any frames which are purely virtual address (in such cases, the caller should have specified base addresses)
var callStackLines = PreProcessVAs(ordinalResolvedFrames, rgxVAOnly);

// locate PDBs for well-known modules, and populate their DIA session helper classes
if (DiaUtil.LocateandLoadPDBs(_diautils, tp.symPath, tp.searchPDBsRecursively, wellKnownModuleNames.ToList(), tp.cachePDB, modulesToIgnore)) {
// resolve symbols by using DIA
currstack.Resolvedstack = ResolveSymbols(_diautils, callStackLines, tp.includeSourceInfo, tp.relookupSource, tp.includeOffsets, tp.showInlineFrames, rgxAlreadySymbolizedFrame, rgxModuleName, modulesToIgnore, tp);
}
else {
currstack.Resolvedstack = string.Empty;
break;
}
// resolve symbols by using DIA
currstack.Resolvedstack = ResolveSymbols(_diautils, callStackLines, tp.includeSourceInfo, tp.relookupSource, tp.includeOffsets, tp.showInlineFrames, rgxAlreadySymbolizedFrame, rgxModuleName, modulesToIgnore, tp);

var localCounter = Interlocked.Increment(ref this.globalCounter);
this.PercentComplete = (int)((double)localCounter / tp.listOfCallStacks.Count * 100.0);
Expand Down
2 changes: 1 addition & 1 deletion Engine/StackWithCount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class StackWithCount {
public StackWithCount(string callStack, bool framesOnSingleLine, int count) {
this._framesOnSingleLine = framesOnSingleLine;
if (framesOnSingleLine) {
this._callStack = System.Text.RegularExpressions.Regex.Replace(callStack, @" {2,}", " ");
this._callStack = System.Text.RegularExpressions.Regex.Replace(callStack, @"\s{2,}", " ");
}
else {
this._callStack = callStack;
Expand Down
27 changes: 6 additions & 21 deletions Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ public void BlockResolution() {
}
}

/// Test the resolution of OrdinalNNN symbols to their actual names.
/// Test the resolution of OrdinalNNN symbols to their actual names. We throw in some frames containing non-relevant info for good measure.
[Fact][Trait("Category", "Unit")]
public void OrdinalBasedSymbol() {
using (var csr = new StackResolver()) {
var dllPaths = new List<string>{@"..\..\..\Tests\TestCases\TestOrdinal"};
var ret = csr.ResolveCallstacks("sqldk!Ordinal298+00000000000004A5", @"..\..\..\Tests\TestCases\TestOrdinal", false, dllPaths, false, false, false, false, true, false, false, null);
Assert.Equal("sqldk!SOS_Scheduler::SwitchContext+941", ret.Trim());
var ret = csr.ResolveCallstacks(@"sqldk!Ordinal298+00000000000004A5
00007FF818405E70 Module(sqldk+0000000000003505) (Ordinal298 + 00000000000004A5)", @"..\..\..\Tests\TestCases\TestOrdinal", false, dllPaths, false, false, false, false, true, false, false, null);
Assert.Equal("sqldk!SOS_Scheduler::SwitchContext+941\r\nsqldk!SOS_Scheduler::SwitchContext+941", ret.Trim());
}
}

Expand All @@ -53,22 +54,6 @@ public void RegularSymbolVirtualAddress() {
}
}

/// Test the resolution of a "regular" symbol with virtual address as input.
[Fact]
[Trait("Category", "Unit")]
public void RegularSymbolVirtualAddressMultipleFramesInSingleLine() {
using (var csr = new StackResolver()) {
var moduleAddressesGood = @"c:\mssql\binn\sqldk.dll 00000001`00400000";
Assert.True(csr.ProcessBaseAddresses(moduleAddressesGood));
var ret = csr.ResolveCallstacks("prologue 0x000000010042249f 0x0000000100440609 epilogue", @"..\..\..\Tests\TestCases\TestOrdinal", false, null, false, true, false, false, true, false, false, null);
var expectedSymbol = @"prologue
sqldk!Spinlock<244,2,1>::SpinToAcquireWithExponentialBackoff+349
sqldk!MemoryClerkInternal::AllocatePagesWithFailureMode+644
epilogue";
Assert.Equal(expectedSymbol, ret.Trim());
}
}

/// Perf / scale test. We randomly generate 750K XEvents each with 25 frame callstacks, and then resolve them.
[Fact][Trait("Category", "Perf")]
public void LargeXEventsInput() {
Expand Down Expand Up @@ -370,8 +355,8 @@ public void SingleLineCallStack() {
csr.ProcessBaseAddresses(File.ReadAllText(@"..\..\..\Tests\TestCases\ImportXEL\base_addresses.txt"));
Assert.Equal(31, csr.LoadedModules.Count);
var pdbPath = @"..\..\..\Tests\TestCases\sqlsyms\13.0.4001.0\x64";
var callStack = @"callstack 0x00007FFEABD0D919 0x00007FFEABC4D45D 0x00007FFEAC0F7EE0 0x00007FFEAC0F80CF 0x00007FFEAC1EE447 0x00007FFEAC1EE6F5 0x00007FFEAC1D48B0 0x00007FFEAC71475A 0x00007FFEA9A708F1 0x00007FFEA9991FB9 0x00007FFEA9993D21 0x00007FFEA99B59F1 0x00007FFEA99B5055 0x00007FFEA99B2B8F 0x00007FFEA9675AD1 0x00007FFEA9671EFB 0x00007FFEAA37D83D 0x00007FFEAA37D241 0x00007FFEAA379F98 0x00007FFEA96719CA 0x00007FFEA9672933 0x00007FFEA9672041 0x00007FFEA967A82B 0x00007FFEA9681542 ";
var symres = csr.ResolveCallstacks(callStack, pdbPath, false, null, false, true, true, false, true, false, false, null);
var callStack = @"callstack 0x00007FFEABD0D919 0x00007FFEABC4D45D 0x00007FFEAC0F7EE0 0x00007FFEAC0F80CF 0x00007FFEAC1EE447 0x00007FFEAC1EE6F5 0x00007FFEAC1D48B0 0x00007FFEAC71475A 0x00007FFEA9A708F1 0x00007FFEA9991FB9 0x00007FFEA9993D21 0x00007FFEA99B59F1 0x00007FFEA99B5055 0x00007FFEA99B2B8F 0x00007FFEA9675AD1 0x00007FFEA9671EFB 0x00007FFEAA37D83D 0x00007FFEAA37D241 0x00007FFEAA379F98 0x00007FFEA96719CA 0x00007FFEA9672933 0x00007FFEA9672041 0x00007FFEA967A82B 0x00007FFEA9681542 ";
var symres = csr.ResolveCallstacks(callStack, pdbPath, false, null, false, true, false, false, true, false, false, null);
Assert.Equal(@"callstack
sqldk!XeSosPkg::spinlock_backoff::Publish+425
sqldk!SpinlockBase::Sleep+182
Expand Down

0 comments on commit d548ba5

Please sign in to comment.