Skip to content

Commit

Permalink
Merge pull request #73 from VladDBA/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
VladDBA authored Apr 20, 2023
2 parents 46bf1a7 + 6bcf2c6 commit 1b4e52f
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 212 deletions.
41 changes: 27 additions & 14 deletions PSBlitz.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ param(

###Internal params
#Version
$Vers = "3.0.0"
$VersDate = "20230411"
$Vers = "3.0.1"
$VersDate = "20230421"
#Get script path
$ScriptPath = split-path -parent $MyInvocation.MyCommand.Definition
#Set resources path
Expand Down Expand Up @@ -729,6 +729,30 @@ if (!(Test-Path $XDLOutDir)) {
New-Item -ItemType Directory -Force -Path $XDLOutDir | Out-Null
}

#Initiate Excel app here
if ($ToHTML -ne "Y") {
###Open Excel
if ($DebugInfo) {
$ErrorActionPreference = "Continue"
Write-Host "Opening excel file" -fore yellow
}
else {
#Do not display the occasional "out of memory" errors
$ErrorActionPreference = "SilentlyContinue"
}

try {
$ExcelApp = New-Object -comobject Excel.Application -ErrorAction Stop
}
catch {
Write-Host "Could not open Excel." -fore Red
Write-Host "->Switching to HTML output."
$ToHTML = "Y"
$ErrorActionPreference = "Continue"
}

}

if ($ToHTML -eq "Y") {
#Set HTML files output directory
$HTMLOutDir = $OutDir + "\" + "HTMLFiles"
Expand Down Expand Up @@ -793,23 +817,12 @@ else {
Copy-Item $OrigExcelF -Destination $OutExcelF
}
#Set output table for sp_BlitzWho
#$BlitzWhoOut = "BlitzWho_" + $DirDate
#Set replace strings
$OldBlitzWhoOut = "@OutputTableName = 'BlitzWho_..PSBlitzReplace..',"
$NewBlitzWhoOut = "@OutputTableName = 'BlitzWho_$DirDate',"

if ($ToHTML -ne "Y") {
###Open Excel
if ($DebugInfo) {
$ErrorActionPreference = "Continue"
Write-Host "Opening excel file" -fore yellow
}
else {
#Do not display the occasional "out of memory" errors
$ErrorActionPreference = "SilentlyContinue"
}

$ExcelApp = New-Object -comobject Excel.Application
###Open Excel FIle
if ($DebugInfo) {
$ExcelApp.visible = $True
}
Expand Down
7 changes: 6 additions & 1 deletion Resources/spBlitzCache_NonSPLatest.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
sp_BlitzCache non-stored procedure
Part of https://github.com/VladDBA/PSBlitz
*/

DECLARE
@Help BIT,
@UseTriggersAnyway BIT,
Expand Down Expand Up @@ -98,7 +103,7 @@ SET NOCOUNT ON;
SET STATISTICS XML OFF;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

SELECT @Version = '8.13', @VersionDate = '20230215';
SELECT @Version = '8.14', @VersionDate = '20230420';
SET @OutputType = UPPER(@OutputType);

IF(@VersionCheckMode = 1)
Expand Down
380 changes: 197 additions & 183 deletions Resources/spBlitzFirst_NonSPLatest.sql

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions Resources/spBlitzIndex_NonSPLatest.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/*sp_BlitzIndex non-stored procedure*/
/*
sp_BlitzIndex non-stored procedure
Part of https://github.com/VladDBA/PSBlitz
*/

DECLARE
@DatabaseName NVARCHAR(128) ,
Expand Down Expand Up @@ -78,7 +81,7 @@ SET NOCOUNT ON;
SET STATISTICS XML OFF;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

SELECT @Version = '8.13', @VersionDate = '20230215';
SELECT @Version = '8.14', @VersionDate = '20230420';
SET @OutputType = UPPER(@OutputType);

IF(@VersionCheckMode = 1)
Expand Down
12 changes: 8 additions & 4 deletions Resources/spBlitzLock_NonSPLatest.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/*sp_BlitzLock non-stored procedure*/
/*
sp_BlitzLock non-stored procedure
Part of https://github.com/VladDBA/PSBlitz
*/

DECLARE @Top INT,
@DatabaseName NVARCHAR(256),
Expand Down Expand Up @@ -84,7 +87,7 @@ without the otuermost BEGIN and END and with the dr.deadlock_graph column still
SET NOCOUNT, XACT_ABORT ON;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

SELECT @Version = '8.13', @VersionDate = '20230215';
SELECT @Version = '8.14', @VersionDate = '20230420';

IF @VersionCheckMode = 1
BEGIN
Expand Down Expand Up @@ -954,12 +957,13 @@ without the otuermost BEGIN and END and with the dr.deadlock_graph column still
SELECT
deadlock_xml =
TRY_CAST(fx.event_data AS xml)
FROM sys.fn_xe_file_target_read_file('system_health*.xel', NULL, NULL, NULL) AS fx
FROM sys.fn_xe_file_target_read_file(N'system_health*.xel', NULL, NULL, NULL) AS fx
LEFT JOIN #t AS t
ON 1 = 1
WHERE fx.object_name = N'xml_deadlock_report'
) AS xml
CROSS APPLY xml.deadlock_xml.nodes('/event') AS e(x)
WHERE e.x.exist('@name[ . = "xml_deadlock_report"]') = 1
WHERE 1 = 1
AND e.x.exist('@timestamp[. >= sql:variable("@StartDate")]') = 1
AND e.x.exist('@timestamp[. < sql:variable("@EndDate")]') = 1
OPTION(RECOMPILE);
Expand Down
13 changes: 8 additions & 5 deletions Resources/spBlitzWho_NonSPLatest.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/*sp_BlitzWho non-stored procedure*/
/*
sp_BlitzWho non-stored procedure
Part of https://github.com/VladDBA/PSBlitz
*/

DECLARE
@Help TINYINT ,
Expand Down Expand Up @@ -50,12 +53,12 @@ DECLARE
@SortOrder = N'elapsed time'


/* Everything from here down is straight out of sp_BlitzWho without the GO at the end: */
/* Everything from here down is straight out of sp_BlitzWho without the GO at the end and without the block that creates the view at line 344*/
SET NOCOUNT ON;
SET STATISTICS XML OFF;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

SELECT @Version = '8.13', @VersionDate = '20230215';
SELECT @Version = '8.14', @VersionDate = '20230420';

IF(@VersionCheckMode = 1)
BEGIN
Expand Down Expand Up @@ -464,7 +467,7 @@ BEGIN
/* Think of the StringToExecute as starting with this, but we'll set this up later depending on whether we're doing an insert or a select:
SELECT @StringToExecute = N'SELECT GETDATE() AS run_date ,
*/
SET @StringToExecute = N'COALESCE( RIGHT(''00'' + CONVERT(VARCHAR(20), (ABS(r.total_elapsed_time) / 1000) / 86400), 2) + '':'' + CONVERT(VARCHAR(20), (DATEADD(SECOND, (r.total_elapsed_time / 1000), 0) + DATEADD(MILLISECOND, (r.total_elapsed_time % 1000), 0)), 114), RIGHT(''00'' + CONVERT(VARCHAR(20), DATEDIFF(SECOND, s.last_request_start_time, GETDATE()) / 86400), 2) + '':'' + CONVERT(VARCHAR(20), DATEADD(SECOND, DATEDIFF(SECOND, s.last_request_start_time, GETDATE()), 0), 114) ) AS [elapsed_time] ,
SET @StringToExecute = N' CASE WHEN YEAR(s.last_request_start_time) = 1900 THEN NULL ELSE COALESCE( RIGHT(''00'' + CONVERT(VARCHAR(20), (ABS(r.total_elapsed_time) / 1000) / 86400), 2) + '':'' + CONVERT(VARCHAR(20), (DATEADD(SECOND, (r.total_elapsed_time / 1000), 0) + DATEADD(MILLISECOND, (r.total_elapsed_time % 1000), 0)), 114), RIGHT(''00'' + CONVERT(VARCHAR(20), DATEDIFF(SECOND, s.last_request_start_time, GETDATE()) / 86400), 2) + '':'' + CONVERT(VARCHAR(20), DATEADD(SECOND, DATEDIFF(SECOND, s.last_request_start_time, GETDATE()), 0), 114) ) END AS [elapsed_time] ,
s.session_id ,
CASE WHEN r.blocking_session_id <> 0 AND blocked.session_id IS NULL
THEN r.blocking_session_id
Expand Down Expand Up @@ -682,7 +685,7 @@ IF @ProductVersionMajor >= 11
/* Think of the StringToExecute as starting with this, but we'll set this up later depending on whether we're doing an insert or a select:
SELECT @StringToExecute = N'SELECT GETDATE() AS run_date ,
*/
SELECT @StringToExecute = N'COALESCE( RIGHT(''00'' + CONVERT(VARCHAR(20), (ABS(r.total_elapsed_time) / 1000) / 86400), 2) + '':'' + CONVERT(VARCHAR(20), (DATEADD(SECOND, (r.total_elapsed_time / 1000), 0) + DATEADD(MILLISECOND, (r.total_elapsed_time % 1000), 0)), 114), RIGHT(''00'' + CONVERT(VARCHAR(20), DATEDIFF(SECOND, s.last_request_start_time, GETDATE()) / 86400), 2) + '':'' + CONVERT(VARCHAR(20), DATEADD(SECOND, DATEDIFF(SECOND, s.last_request_start_time, GETDATE()), 0), 114) ) AS [elapsed_time] ,
SELECT @StringToExecute = N' CASE WHEN YEAR(s.last_request_start_time) = 1900 THEN NULL ELSE COALESCE( RIGHT(''00'' + CONVERT(VARCHAR(20), (ABS(r.total_elapsed_time) / 1000) / 86400), 2) + '':'' + CONVERT(VARCHAR(20), (DATEADD(SECOND, (r.total_elapsed_time / 1000), 0) + DATEADD(MILLISECOND, (r.total_elapsed_time % 1000), 0)), 114), RIGHT(''00'' + CONVERT(VARCHAR(20), DATEDIFF(SECOND, s.last_request_start_time, GETDATE()) / 86400), 2) + '':'' + CONVERT(VARCHAR(20), DATEADD(SECOND, DATEDIFF(SECOND, s.last_request_start_time, GETDATE()), 0), 114) ) END AS [elapsed_time] ,
s.session_id ,
CASE WHEN r.blocking_session_id <> 0 AND blocked.session_id IS NULL
THEN r.blocking_session_id
Expand Down
9 changes: 6 additions & 3 deletions Resources/spBlitz_NonSPLatest.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/*sp_Blitz non-stored procedure*/
/*
sp_BlitzFirst non-stored procedure
Part of https://github.com/VladDBA/PSBlitz
*/

DECLARE
@Help TINYINT ,
Expand Down Expand Up @@ -70,7 +73,7 @@ without the GO at the end
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;


SELECT @Version = '8.13', @VersionDate = '20230215';
SELECT @Version = '8.14', @VersionDate = '20230420';
SET @OutputType = UPPER(@OutputType);

IF(@VersionCheckMode = 1)
Expand Down Expand Up @@ -6902,7 +6905,7 @@ IF @ProductVersionMajor >= 10
Details = '[' + DBName + '].[' + SPSchema + '].[' + ProcName + '] has WITH RECOMPILE in the stored procedure code, which may cause increased CPU usage due to constant recompiles of the code.',
CheckID = '78'
FROM #Recompile AS TR
WHERE ProcName NOT LIKE 'sp_AllNightLog%' AND ProcName NOT LIKE 'sp_AskBrent%' AND ProcName NOT LIKE 'sp_Blitz%'
WHERE ProcName NOT LIKE 'sp_AllNightLog%' AND ProcName NOT LIKE 'sp_AskBrent%' AND ProcName NOT LIKE 'sp_Blitz%' AND ProcName NOT LIKE 'sp_PressureDetector'
AND DBName NOT IN ('master', 'model', 'msdb', 'tempdb');
DROP TABLE #Recompile;
END;
Expand Down

0 comments on commit 1b4e52f

Please sign in to comment.