amachanic / sp_whoisactive

sp_whoisactive
GNU General Public License v3.0
1.13k stars 281 forks source link

Add column to show object (stored procedure) name from dm_exec_sql_text #91

Closed aroques closed 1 year ago

aroques commented 1 year ago

Is your feature request related to a problem? Please describe. I'm not able to see what stored procedure that running queries belong to.

Describe the solution you'd like I'd like a column to show object (stored procedure) name from dm_exec_sql_text.

See the object_name column from the query below for example:

SELECT TOP 10
       s.session_id,
       r.status,
       r.cpu_time,
       r.logical_reads,
       r.reads,
       r.writes,
       r.total_elapsed_time / (1000 * 60) 'Elaps M',
       SUBSTRING(st.text, (r.statement_start_offset / 2) + 1, ((CASE r.statement_end_offset
                                                                    WHEN -1 THEN DATALENGTH(st.text)
                                                                    ELSE r.statement_end_offset
                                                                END - r.statement_start_offset
                                                               ) / 2
                                                              ) + 1
       ) AS statement_text,
       COALESCE(CONCAT(DB_NAME(st.[dbid]), 
                N'.', OBJECT_SCHEMA_NAME(st.objectid, st.[dbid]), 
                N'.', OBJECT_NAME(st.objectid, st.[dbid])), '') AS [object_name],
       r.command,
       s.login_name,
       s.host_name,
       s.program_name,
       s.last_request_end_time,
       s.login_time,
       r.open_transaction_count
FROM sys.dm_exec_sessions AS s
JOIN sys.dm_exec_requests AS r ON r.session_id = s.session_id
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS st
WHERE r.session_id != @@Spid
ORDER BY r.cpu_time DESC;

Describe alternatives you've considered N/A.

erikdarlingdata commented 1 year ago

Does this get what you want?

EXEC sp_WhoIsActive 
    @get_outer_command = 1;
aroques commented 1 year ago

Yes, that is perfect. I didn't know that was there, thank you!