Skip to content

Commit

Permalink
Merge pull request #398 from erikdarlingdata/dev
Browse files Browse the repository at this point in the history
Update sp_PressureDetector.sql
  • Loading branch information
erikdarlingdata authored Apr 3, 2024
2 parents 06d273c + 4958202 commit 2d8821a
Showing 1 changed file with 116 additions and 26 deletions.
142 changes: 116 additions & 26 deletions sp_PressureDetector/sp_PressureDetector.sql
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,15 @@ OPTION(MAXDOP 1, RECOMPILE);',
database_file_details nvarchar(1000),
file_size_gb decimal(38,2),
total_gb_read decimal(38,2),
total_mb_read decimal(38,2),
total_read_count bigint,
avg_read_stall_ms decimal(38,2),
total_gb_written decimal(38,2),
total_mb_written decimal(38,2),
total_write_count bigint,
avg_write_stall_ms decimal(38,2),
io_stall_read_ms bigint,
io_stall_write_ms bigint,
sample_time datetime
);

Expand Down Expand Up @@ -908,6 +912,16 @@ OPTION(MAXDOP 1, RECOMPILE);',
)
ELSE 0
END,
total_mb_read =
CASE
WHEN vfs.num_of_bytes_read > 0
THEN CONVERT
(
decimal(38, 2),
vfs.num_of_bytes_read / 1048576.
)
ELSE 0
END,
total_read_count =
vfs.num_of_reads,
avg_read_stall_ms =
Expand All @@ -917,7 +931,7 @@ OPTION(MAXDOP 1, RECOMPILE);',
ISNULL
(
vfs.io_stall_read_ms /
(1.0 * NULLIF(vfs.num_of_reads, 0)),
(NULLIF(vfs.num_of_reads, 0)),
0
)
),
Expand All @@ -931,6 +945,16 @@ OPTION(MAXDOP 1, RECOMPILE);',
)
ELSE 0
END,
total_mb_written =
CASE
WHEN vfs.num_of_bytes_written > 0
THEN CONVERT
(
decimal(38, 2),
vfs.num_of_bytes_written / 1048576.
)
ELSE 0
END,
total_write_count =
vfs.num_of_writes,
avg_write_stall_ms =
Expand All @@ -940,10 +964,12 @@ OPTION(MAXDOP 1, RECOMPILE);',
ISNULL
(
vfs.io_stall_write_ms /
(1.0 * NULLIF(vfs.num_of_writes, 0)),
(NULLIF(vfs.num_of_writes, 0)),
0
)
),
io_stall_read_ms,
io_stall_write_ms,
sample_time =
GETDATE()
FROM sys.dm_io_virtual_file_stats(NULL, NULL) AS vfs
Expand All @@ -963,7 +989,7 @@ OPTION(MAXDOP 1, RECOMPILE);',
N'
WHERE
(
vfs.num_of_reads > 0
vfs.num_of_reads > 0
OR vfs.num_of_writes > 0
);'
);
Expand All @@ -983,11 +1009,15 @@ OPTION(MAXDOP 1, RECOMPILE);',
database_file_details,
file_size_gb,
total_gb_read,
total_mb_read,
total_read_count,
avg_read_stall_ms,
total_gb_written,
total_mb_written,
total_write_count,
avg_write_stall_ms,
io_stall_read_ms,
io_stall_write_ms,
sample_time
)
EXEC sys.sp_executesql
Expand Down Expand Up @@ -1102,26 +1132,52 @@ OPTION(MAXDOP 1, RECOMPILE);',
fm.database_file_details,
fm.file_size_gb,
avg_read_stall_ms =
CONVERT
(
decimal(38, 2),
(fm2.avg_read_stall_ms + fm.avg_read_stall_ms) / 2
),
CASE
WHEN (fm2.total_read_count - fm.total_read_count) = 0
THEN 0.00
ELSE
CONVERT
(
decimal(38, 2),
(fm2.io_stall_read_ms - fm.io_stall_read_ms) /
(fm2.total_read_count - fm.total_read_count)
)
END,
avg_write_stall_ms =
CONVERT
(
decimal(38, 2),
(fm2.avg_write_stall_ms + fm.avg_write_stall_ms) / 2
),
CASE
WHEN (fm2.total_write_count - fm.total_write_count) = 0
THEN 0.00
ELSE
CONVERT
(
decimal(38, 2),
(fm2.io_stall_write_ms - fm.io_stall_write_ms) /
(fm2.total_write_count - fm.total_write_count)
)
END,
total_avg_stall =
(
(fm2.avg_read_stall_ms + fm2.avg_write_stall_ms) +
(fm.avg_read_stall_ms + fm.avg_write_stall_ms) / 2
),
total_gb_read =
(fm2.total_gb_read - fm.total_gb_read),
total_gb_written =
(fm2.total_gb_written - fm.total_gb_written),
CASE
WHEN (fm2.total_read_count - fm.total_read_count) +
(fm2.total_write_count - fm.total_write_count) = 0
THEN 0.00
ELSE
CONVERT
(
decimal(38,2),
(
(fm2.io_stall_read_ms - fm.io_stall_read_ms) +
(fm2.io_stall_write_ms - fm.io_stall_write_ms)
) /
(
(fm2.total_read_count - fm.total_read_count) +
(fm2.total_write_count - fm.total_write_count)
)
)
END,
total_mb_read =
(fm2.total_mb_read - fm.total_mb_read),
total_mb_written =
(fm2.total_mb_written - fm.total_mb_written),
total_read_count =
(fm2.total_read_count - fm.total_read_count),
total_write_count =
Expand All @@ -1145,8 +1201,38 @@ OPTION(MAXDOP 1, RECOMPILE);',
f.avg_read_stall_ms,
f.avg_write_stall_ms,
f.total_avg_stall,
f.total_gb_read,
f.total_gb_written,
total_mb_read =
REPLACE
(
CONVERT
(
nvarchar(30),
CONVERT
(
money,
f.total_mb_read
),
1
),
N'.00',
N''
),
total_mb_written =
REPLACE
(
CONVERT
(
nvarchar(30),
CONVERT
(
money,
f.total_mb_written
),
1
),
N'.00',
N''
),
total_read_count =
REPLACE
(
Expand Down Expand Up @@ -1182,8 +1268,11 @@ OPTION(MAXDOP 1, RECOMPILE);',
sample_seconds =
DATEDIFF(SECOND, f.sample_time_o, f.sample_time_t)
FROM f
WHERE f.total_read_count > 0
OR f.total_write_count > 0
WHERE
(
f.total_read_count > 0
OR f.total_write_count > 0
)
ORDER BY
f.total_avg_stall DESC;
END
Expand Down Expand Up @@ -2602,7 +2691,8 @@ OPTION(MAXDOP 1, RECOMPILE);',
x.*
FROM @file_metrics AS x
ORDER BY
x.database_name
x.database_name,
x.sample_time
OPTION(RECOMPILE);

SELECT
Expand Down

0 comments on commit 2d8821a

Please sign in to comment.