diff --git a/Lite/Services/RemoteCollectorService.FileIo.cs b/Lite/Services/RemoteCollectorService.FileIo.cs index f7438627..0039422a 100644 --- a/Lite/Services/RemoteCollectorService.FileIo.cs +++ b/Lite/Services/RemoteCollectorService.FileIo.cs @@ -59,7 +59,7 @@ LEFT JOIN sys.database_files AS df SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; SELECT - database_name = DB_NAME(vfs.database_id), + database_name = ISNULL(d.name, N'Unknown'), file_name = mf.name, file_type = mf.type_desc, physical_name = mf.physical_name, @@ -78,6 +78,8 @@ FROM sys.dm_io_virtual_file_stats(NULL, NULL) AS vfs LEFT JOIN sys.master_files AS mf ON mf.database_id = vfs.database_id AND mf.file_id = vfs.file_id +LEFT JOIN sys.databases AS d + ON d.database_id = vfs.database_id WHERE (vfs.database_id > 4 OR vfs.database_id = 2) AND vfs.database_id < 32761 AND vfs.database_id <> ISNULL(DB_ID(N'PerformanceMonitor'), 0) diff --git a/Lite/Services/RemoteCollectorService.ProcedureStats.cs b/Lite/Services/RemoteCollectorService.ProcedureStats.cs index a4503236..349e2518 100644 --- a/Lite/Services/RemoteCollectorService.ProcedureStats.cs +++ b/Lite/Services/RemoteCollectorService.ProcedureStats.cs @@ -76,9 +76,10 @@ CROSS APPLY FROM sys.dm_exec_plan_attributes(s.plan_handle) AS pa WHERE pa.attribute = N''dbid'' ) AS pa -LEFT JOIN sys.databases AS d +INNER JOIN sys.databases AS d ON pa.dbid = d.database_id -WHERE pa.dbid NOT IN (1, 3, 4, 32761, 32767, ISNULL(DB_ID(N''PerformanceMonitor''), 0)) +WHERE d.state = 0 +AND pa.dbid NOT IN (1, 3, 4, 32761, 32767, ISNULL(DB_ID(N''PerformanceMonitor''), 0)) AND s.last_execution_time >= DATEADD(MINUTE, -10, GETDATE()) UNION ALL @@ -130,9 +131,10 @@ CROSS APPLY FROM sys.dm_exec_plan_attributes(s.plan_handle) AS pa WHERE pa.attribute = N''dbid'' ) AS pa -LEFT JOIN sys.databases AS d +INNER JOIN sys.databases AS d ON pa.dbid = d.database_id -WHERE pa.dbid NOT IN (1, 3, 4, 32761, 32767, ISNULL(DB_ID(N''PerformanceMonitor''), 0)) +WHERE d.state = 0 +AND pa.dbid NOT IN (1, 3, 4, 32761, 32767, ISNULL(DB_ID(N''PerformanceMonitor''), 0)) AND s.last_execution_time >= DATEADD(MINUTE, -10, GETDATE()) UNION ALL @@ -171,9 +173,10 @@ CROSS APPLY FROM sys.dm_exec_plan_attributes(s.plan_handle) AS pa WHERE pa.attribute = N''dbid'' ) AS pa -LEFT JOIN sys.databases AS d +INNER JOIN sys.databases AS d ON pa.dbid = d.database_id -WHERE pa.dbid NOT IN (1, 3, 4, 32761, 32767, ISNULL(DB_ID(N''PerformanceMonitor''), 0)) +WHERE d.state = 0 +AND pa.dbid NOT IN (1, 3, 4, 32761, 32767, ISNULL(DB_ID(N''PerformanceMonitor''), 0)) AND s.last_execution_time >= DATEADD(MINUTE, -10, GETDATE()) ) AS combined ORDER BY total_elapsed_time DESC diff --git a/Lite/Services/RemoteCollectorService.QuerySnapshots.cs b/Lite/Services/RemoteCollectorService.QuerySnapshots.cs index 9fc2b2a2..b85500c1 100644 --- a/Lite/Services/RemoteCollectorService.QuerySnapshots.cs +++ b/Lite/Services/RemoteCollectorService.QuerySnapshots.cs @@ -25,7 +25,7 @@ public partial class RemoteCollectorService SELECT /* PerformanceMonitorLite */ der.session_id, - database_name = DB_NAME(der.database_id), + database_name = d.name, elapsed_time_formatted = CASE WHEN der.total_elapsed_time < 0 @@ -72,6 +72,8 @@ JOIN sys.dm_exec_sessions AS des ON des.session_id = der.session_id OUTER APPLY sys.dm_exec_sql_text(COALESCE(der.sql_handle, der.plan_handle)) AS dest OUTER APPLY sys.dm_exec_text_query_plan(der.plan_handle, der.statement_start_offset, der.statement_end_offset) AS deqp +LEFT JOIN sys.databases AS d + ON d.database_id = der.database_id {1} WHERE der.session_id <> @@SPID AND der.session_id >= 50 diff --git a/Lite/Services/RemoteCollectorService.WaitingTasks.cs b/Lite/Services/RemoteCollectorService.WaitingTasks.cs index e3b31f70..d68fc1ee 100644 --- a/Lite/Services/RemoteCollectorService.WaitingTasks.cs +++ b/Lite/Services/RemoteCollectorService.WaitingTasks.cs @@ -32,10 +32,12 @@ private async Task CollectWaitingTasksAsync(ServerConnection server, Cancel wait_type = wt.wait_type, wait_duration_ms = wt.wait_duration_ms, blocking_session_id = wt.blocking_session_id, - database_name = DB_NAME(er.database_id) + database_name = d.name FROM sys.dm_os_waiting_tasks AS wt LEFT JOIN sys.dm_exec_requests AS er ON er.session_id = wt.session_id +LEFT JOIN sys.databases AS d + ON d.database_id = er.database_id WHERE wt.session_id >= 50 AND wt.session_id <> @@SPID AND wt.wait_type IS NOT NULL