Skip to content

Commit 7c7b8ed

Browse files
Get-DbaWaitStatistic - Add ExcludeWaitType and IncludeWaitType parameters (#10276)
1 parent 27f3fef commit 7c7b8ed

2 files changed

Lines changed: 66 additions & 1 deletion

File tree

public/Get-DbaWaitStatistic.ps1

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ function Get-DbaWaitStatistic {
3939
Includes wait types that are typically benign and can be safely ignored during troubleshooting, such as Service Broker idle waits and background task waits.
4040
Use this when you need to see all wait activity or when investigating unusual issues with specific features like mirroring or Availability Groups.
4141
42+
.PARAMETER ExcludeWaitType
43+
Additional wait types to exclude beyond the default ignorable list. Provide an array of wait type names (e.g., "CXPACKET", "CXCONSUMER").
44+
Use this when you want to filter out specific waits that may not be relevant to your analysis.
45+
46+
.PARAMETER IncludeWaitType
47+
Wait types to always include in results, even if they appear in the ignorable list. Provide an array of wait type names.
48+
Use this to ensure specific waits are shown regardless of the -IncludeIgnorable switch setting.
49+
4250
.PARAMETER EnableException
4351
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
4452
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
@@ -108,6 +116,16 @@ function Get-DbaWaitStatistic {
108116
109117
Displays the output then loads the associated sqlskills website for each result. Opens one tab per unique URL.
110118
119+
.EXAMPLE
120+
PS C:\> Get-DbaWaitStatistic -SqlInstance sql2016 -ExcludeWaitType "CXPACKET", "CXCONSUMER"
121+
122+
Gets wait statistics excluding parallelism waits (CXPACKET and CXCONSUMER) in addition to the default ignorable waits.
123+
124+
.EXAMPLE
125+
PS C:\> Get-DbaWaitStatistic -SqlInstance sql2016 -IncludeWaitType "BROKER_RECEIVE_WAITFOR"
126+
127+
Gets wait statistics and ensures BROKER_RECEIVE_WAITFOR is included even though it's in the default ignorable list.
128+
111129
#>
112130
[CmdletBinding()]
113131
param (
@@ -116,6 +134,8 @@ function Get-DbaWaitStatistic {
116134
[PSCredential]$SqlCredential,
117135
[int]$Threshold = 95,
118136
[switch]$IncludeIgnorable,
137+
[string[]]$ExcludeWaitType,
138+
[string[]]$IncludeWaitType,
119139
[switch]$EnableException
120140
)
121141

@@ -808,7 +828,7 @@ function Get-DbaWaitStatistic {
808828
XE_TIMER_TASK_DONE = 'Other'
809829
}
810830

811-
$ignorable = 'BROKER_EVENTHANDLER', 'BROKER_RECEIVE_WAITFOR', 'BROKER_TASK_STOP',
831+
$defaultIgnorable = 'BROKER_EVENTHANDLER', 'BROKER_RECEIVE_WAITFOR', 'BROKER_TASK_STOP',
812832
'BROKER_TO_FLUSH', 'BROKER_TRANSMITTER', 'CHECKPOINT_QUEUE',
813833
'CHKPT', 'CLR_AUTO_EVENT', 'CLR_MANUAL_EVENT', 'CLR_SEMAPHORE', 'CXCONSUMER',
814834
'DBMIRROR_DBM_EVENT', 'DBMIRROR_EVENTS_QUEUE', 'DBMIRROR_WORKER_QUEUE',
@@ -844,6 +864,28 @@ function Get-DbaWaitStatistic {
844864
'XE_BUFFERMGR_ALLPROCESSED_EVENT', 'XE_DISPATCHER_JOIN',
845865
'XE_DISPATCHER_WAIT', 'XE_LIVE_TARGET_TVF', 'XE_TIMER_EVENT'
846866

867+
# Build the effective ignorable list
868+
$ignorable = New-Object System.Collections.ArrayList
869+
$ignorable.AddRange($defaultIgnorable)
870+
871+
# Add user-specified exclusions
872+
if ($ExcludeWaitType) {
873+
foreach ($waitType in $ExcludeWaitType) {
874+
if ($ignorable -notcontains $waitType) {
875+
$null = $ignorable.Add($waitType)
876+
}
877+
}
878+
}
879+
880+
# Remove user-specified inclusions from ignorable list
881+
if ($IncludeWaitType) {
882+
foreach ($waitType in $IncludeWaitType) {
883+
if ($ignorable -contains $waitType) {
884+
$null = $ignorable.Remove($waitType)
885+
}
886+
}
887+
}
888+
847889
if ($IncludeIgnorable) {
848890
$sql = "WITH [Waits] AS
849891
(SELECT

tests/Get-DbaWaitStatistic.Tests.ps1

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Describe $CommandName -Tag UnitTests {
1515
"SqlCredential",
1616
"Threshold",
1717
"IncludeIgnorable",
18+
"ExcludeWaitType",
19+
"IncludeWaitType",
1820
"EnableException"
1921
)
2022
Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $hasParameters | Should -BeNullOrEmpty
@@ -64,4 +66,25 @@ Describe $CommandName -Tag IntegrationTests {
6466
}
6567
}
6668
}
69+
70+
Context "ExcludeWaitType parameter filters out additional wait types" {
71+
BeforeAll {
72+
$filteredResults = Get-DbaWaitStatistic -SqlInstance $TestConfig.InstanceSingle -Threshold 100 -IncludeIgnorable -ExcludeWaitType "CXPACKET", "CXCONSUMER"
73+
}
74+
75+
It "excludes specified wait types" {
76+
$filteredResults.WaitType | Should -Not -Contain "CXPACKET"
77+
$filteredResults.WaitType | Should -Not -Contain "CXCONSUMER"
78+
}
79+
}
80+
81+
Context "IncludeWaitType parameter includes wait types from ignorable list" {
82+
BeforeAll {
83+
$resultsWith = Get-DbaWaitStatistic -SqlInstance $TestConfig.InstanceSingle -Threshold 100 -IncludeWaitType "CHKPT"
84+
}
85+
86+
It "includes specified wait type that would normally be ignored" {
87+
$resultsWith.WaitType | Should -Contain "CHKPT"
88+
}
89+
}
6790
}

0 commit comments

Comments
 (0)