Skip to content

Commit fbc7942

Browse files
authored
Merge pull request #415 from VladDBA/dev
Updated non-sp Blitz scripts and HTML report enhancements
2 parents 8bc9841 + dd558b4 commit fbc7942

12 files changed

+798
-237
lines changed

PSBlitz.ps1

Lines changed: 182 additions & 20 deletions
Large diffs are not rendered by default.

Resources/GetBlitzWhoData.sql

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ CREATE NONCLUSTERED INDEX [IX_AGG]
1717

1818
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
1919

20-
DECLARE @DatabaseName NVARCHAR(128);
20+
DECLARE @DatabaseName NVARCHAR(128),
21+
@IsAzureSQLDB BIT;
2122

2223
SET @DatabaseName = N'';
2324

25+
SELECT @IsAzureSQLDB = CASE WHEN SERVERPROPERTY('EngineEdition') = 5 THEN 1 ELSE 0 END;
26+
2427
/*Standard RAW output*/
2528
SELECT CONVERT(VARCHAR(25),CAST([CheckDate] AS DATETIME),120) AS [CheckDate],
2629
CONVERT(VARCHAR(25),[start_time],120) AS [start_time],
@@ -75,7 +78,12 @@ WHERE [database_name] = CASE
7578
WHEN @DatabaseName = N'' THEN [database_name]
7679
ELSE @DatabaseName
7780
END
78-
AND [program_name] NOT LIKE N'PSBlitz%';
81+
AND [program_name] NOT LIKE N'PSBlitz%'
82+
/*ignore the session running on master on Azure SQL DB*/
83+
AND [database_name] <> CASE
84+
WHEN @IsAzureSQLDB = 1 THEN N'master'
85+
ELSE N''
86+
END;
7987

8088
/*Aggregate output*/
8189
;WITH agg ( ID, [session_id], [query_hash], start_time, [TotalExecTime],[first_seen],[last_seen])
@@ -92,6 +100,10 @@ AND [program_name] NOT LIKE N'PSBlitz%';
92100
ELSE @DatabaseName
93101
END
94102
AND [program_name] NOT LIKE N'PSBlitz%'
103+
AND [database_name] <> CASE
104+
WHEN @IsAzureSQLDB = 1 THEN N'master'
105+
ELSE N''
106+
END
95107
GROUP BY [session_id],
96108
[query_hash],
97109
[start_time])

Resources/GetTempDBUsageInfo.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,5 @@ FROM [sys].[dm_db_task_space_usage] [tsu]
6565
WHERE [tsu].[session_id] > 50
6666
AND ( [tsu].[user_objects_alloc_page_count] > 0
6767
OR [tsu].[internal_objects_alloc_page_count] > 0 )
68-
ORDER BY [total_allocation_MB] DESC;
68+
AND [tsu].[session_id] <> @@SPID
69+
ORDER BY [total_allocation_MB] DESC;

Resources/copy.js

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
1-
document.addEventListener('DOMContentLoaded', function() {
1+
/* ------------------------------------------------------------------
2+
copy.js – unified copy handling for:
3+
1Column-wide copy (your original implementation)
4+
2Row-specific copy (button inside the Query Name cell)
5+
------------------------------------------------------------------ */
6+
7+
document.addEventListener('DOMContentLoaded', function () {
28
const messageElement = document.getElementById('message');
39

10+
/* --------------------------------------------------------------
11+
Helper: show the temporary "Copied!" tooltip near a button
12+
-------------------------------------------------------------- */
13+
function showCopyMessage(btn) {
14+
const rect = btn.getBoundingClientRect();
15+
messageElement.style.left = `${rect.left + window.scrollX}px`;
16+
messageElement.style.top = `${rect.bottom + window.scrollY + 10}px`;
17+
messageElement.classList.add('show');
18+
setTimeout(() => messageElement.classList.remove('show'), 1000);
19+
}
20+
21+
/* --------------------------------------------------------------
22+
1Column-wide copy - keep your original logic unchanged
23+
-------------------------------------------------------------- */
424
document.querySelectorAll('.copyButton').forEach(button => {
5-
button.addEventListener('click', function(event) {
25+
button.addEventListener('click', function () {
626
const tableId = button.getAttribute('data-table-id');
727
const columnIndex = parseInt(button.getAttribute('data-column-index'), 10);
8-
928
const table = document.getElementById(tableId);
29+
1030
if (!table) {
1131
console.error('Table not found:', tableId);
1232
return;
1333
}
1434

1535
const rows = table.getElementsByTagName('tr');
16-
let columnValues = [];
36+
const columnValues = [];
1737

1838
for (let row of rows) {
1939
const cell = row.getElementsByTagName('td')[columnIndex];
@@ -23,20 +43,46 @@ document.addEventListener('DOMContentLoaded', function() {
2343
}
2444

2545
const columnText = columnValues.join('\n');
26-
console.log('Text to copy:', columnText); // Log the text to be copied
27-
28-
navigator.clipboard.writeText(columnText).then(function() {
29-
// Position the message near the clicked button
30-
const buttonRect = button.getBoundingClientRect();
31-
messageElement.style.left = `${buttonRect.left + window.scrollX}px`;
32-
messageElement.style.top = `${buttonRect.bottom + window.scrollY + 10}px`;
33-
messageElement.classList.add('show');
34-
setTimeout(() => {
35-
messageElement.classList.remove('show');
36-
}, 1000); // Hide the message after 2 seconds
37-
}).catch(function(err) {
38-
console.error('Could not copy text: ', err);
39-
});
46+
console.log('Text to copy (column):', columnText);
47+
48+
navigator.clipboard.writeText(columnText)
49+
.then(() => showCopyMessage(button))
50+
.catch(err => console.error('Could not copy column text:', err));
51+
});
52+
});
53+
54+
/* --------------------------------------------------------------
55+
2Row-specific copy – new logic for the button inside the name cell
56+
Use class "copyBtnRow" (or reuse "copyButton" if you prefer)
57+
-------------------------------------------------------------- */
58+
document.querySelectorAll('.copyBtnRow').forEach(button => {
59+
button.addEventListener('click', function () {
60+
// Find the row that contains this button
61+
const row = button.closest('tr');
62+
if (!row) {
63+
console.error('Button not inside a table row');
64+
return;
65+
}
66+
67+
// Assuming the query text is in the second cell (index 1)
68+
const queryCell = row.cells[1];
69+
if (!queryCell) {
70+
console.error('Expected query text cell missing');
71+
return;
72+
}
73+
74+
const queryText = queryCell.textContent.trim();
75+
console.log('Text to copy (row):', queryText);
76+
77+
navigator.clipboard.writeText(queryText)
78+
.then(() => {
79+
const originalLabel = button.textContent;
80+
button.textContent = 'Copied!';
81+
setTimeout(() => {
82+
button.textContent = originalLabel;
83+
}, 750);
84+
})
85+
.catch(err => console.error('Could not copy row text:', err));
4086
});
4187
});
4288
});

Resources/searchtable.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,29 @@ function SearchTable(tableId, columnIndex) {
77
table = document.getElementById(tableId);
88
tr = table.getElementsByTagName("tr");
99

10+
// Loop through all table rows, and hide those who don't match the search query
11+
for (i = 0; i < tr.length; i++) {
12+
td = tr[i].getElementsByTagName("td")[columnIndex];
13+
if (td) {
14+
txtValue = td.textContent || td.innerText;
15+
if (txtValue.toUpperCase().indexOf(filter) > -1) {
16+
tr[i].style.display = "";
17+
} else {
18+
tr[i].style.display = "none";
19+
}
20+
}
21+
}
22+
}
23+
24+
// for second search box
25+
function SearchTable(tableId, columnIndex) {
26+
// Declare variables
27+
var input, filter, table, tr, td, i, txtValue;
28+
input = document.getElementById("SearchBox1");
29+
filter = input.value.toUpperCase();
30+
table = document.getElementById(tableId);
31+
tr = table.getElementsByTagName("tr");
32+
1033
// Loop through all table rows, and hide those who don't match the search query
1134
for (i = 0; i < tr.length; i++) {
1235
td = tr[i].getElementsByTagName("td")[columnIndex];

Resources/spBlitzCache_NonSPLatest.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ SET NOCOUNT ON;
117117
SET STATISTICS XML OFF;
118118
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
119119

120-
SELECT @Version = '8.26', @VersionDate = '20251002';
120+
SELECT @Version = '8.28', @VersionDate = '20251124';
121121
SET @OutputType = UPPER(@OutputType);
122122

123123
IF(@VersionCheckMode = 1)
@@ -5023,6 +5023,7 @@ BEGIN
50235023
CASE WHEN select_with_writes > 0 THEN '', 66'' ELSE '''' END
50245024
, 3, 200000) AS opserver_warning , ' + @nl ;
50255025
END;
5026+
50265027
/*Vlad - column list, datetime and varbinary to varchar conversions changes for PSBlitz*/
50275028
SET @columns += N'
50285029
CONVERT(NVARCHAR(30), CAST((ExecutionCount) AS BIGINT), 1) AS [# Executions],
@@ -6262,7 +6263,7 @@ BEGIN
62626263
END;
62636264

62646265

6265-
/*Vlad - column changes for PSBlitz*/
6266+
/*Vlad - column changes for PSBlitz*/
62666267
SELECT [Priority],
62676268
FindingsGroup,
62686269
Finding,

0 commit comments

Comments
 (0)