Mich Talebzadeh createdImage may be NSFW.
Clik here to view. the sp__monrunning stored procedure for displaying the procedures that are running for more than 100 ms as part of the excellent Extended Stored Procedures by Ed Barlow (AKA the Ed Barlow Stored Procedures).
I’ve cleaned up the format output and added the dont_format option:
$ diff sp__monrunning.old sp__monrunning.15 9c9,10 < create procedure sp__monrunning --- > create procedure sp__monrunning( > @dont_format char(1)=NULL) 11,16c12,18 < ------------------------------------------------------------------------------------------------ < -- Vers| Date | Who | DA | Description < -------+--------+--------------------+----+----------------------------------------------------- < -- 1.0 |07/04/06| Mich Talebzadeh | | Statistics on processes currently being executed < -- | | | | with Elapsed time > 100ms < -------+--------+--------------------+----+----------------------------------------------------- --- > -------------------------------------------------------------------------------------------------- > -- Vers| Date | Who | DA | Description > -------+----------+--------------------+----+----------------------------------------------------- > -- 1.1 |11/20/2013| Jason Froebe | | Cleaned up the report format, added dont_format option > -- 1.0 |07/04/2006| Mich Talebzadeh | | Statistics on processes currently being executed > -- | | | | with Elapsed time > 100ms > -------+-- ------+--------------------+----+----------------------------------------------------- 18,22c20,24 < declare @time datetime < select @time = getdate() < --print "" < --print "Stats for various procedures at %1!. Server up since %2!", @time, @@boottime < --print "" --- > declare @max_loginname_size varchar(3) > declare @max_procname_size varchar(3) > declare @max_dbname_size varchar(3) > declare @exec_str varchar(2000) > 35c37 < "Name" = substring(suser_name(p.suid),1,20), --- > "Name" = suser_name(p.suid), 37,39c39,42 < "Procedure" = ProcName, < "Database" = DBNAME, < "Elapsed Time/ms" = TimeMs --- > ProcName, > DBNAME, > TimeMs > into #proc_report 43c46,75 < order by TimeMs asc --- > > select @max_loginname_size = convert(varchar(3), isnull( max(char_length(Name)), 1)), > @max_procname_size = convert(varchar(3), isnull( max(char_length(ProcName)), 1)), > @max_dbname_size = convert(varchar(3), isnull( max(char_length(DBNAME)), 1)) > from #proc_report > > if @dont_format is null > begin > select @exec_str = 'select > "Name" = convert(varchar(' + @max_loginname_size + '), Name), > SPID, > "Procedure" = convert(varchar(' + @max_procname_size + '), ProcName), > "Database" = convert(varchar(' + @max_dbname_size + '), DBNAME), > "Elapsed Time/ms" = TimeMs > from #proc_report > order by TimeMs asc' > > exec (@exec_str) > end > else > begin > select > "Name" = Name, > SPID, > "Procedure" = ProcName, > "Database" = DBNAME, > "Elapsed Time/ms" = TimeMs > from #proc_report > order by TimeMs asc > end
Full SQL code of sp__monrunning:
use sybsystemprocs go IF EXISTS (SELECT * FROM sysobjects WHERE name = "sp__monrunning" AND type = "P") DROP PROC sp__monrunning go create procedure sp__monrunning( @dont_format char(1)=NULL) as -------------------------------------------------------------------------------------------------- -- Vers| Date | Who | DA | Description -------+----------+--------------------+----+----------------------------------------------------- -- 1.1 |11/20/2013| Jason Froebe | | Cleaned up the report format, added dont_format option -- 1.0 |07/04/2006| Mich Talebzadeh | | Statistics on processes currently being executed -- | | | | with Elapsed time > 100ms -------+-- ------+--------------------+----+----------------------------------------------------- begin declare @max_loginname_size varchar(3) declare @max_procname_size varchar(3) declare @max_dbname_size varchar(3) declare @exec_str varchar(2000) select SPID, ProcName = isnull(object_name(ProcedureID, DBID),"UNKNOWN"), DBNAME = isnull(db_name(DBID), "UNKNOWN"), TimeMs = datediff(ms, min(StartTime), max(EndTime)) into #performance from master..monSysStatement m where db_name(DBID) != 'sybsystemprocs' group by SPID, DBID, ProcedureID, BatchID having ProcedureID != 0 select distinct "Name" = suser_name(p.suid), SPID, ProcName, DBNAME, TimeMs into #proc_report from #performance t, master..sysprocesses p where t.SPID = p.spid and TimeMs >= 100 select @max_loginname_size = convert(varchar(3), isnull( max(char_length(Name)), 1)), @max_procname_size = convert(varchar(3), isnull( max(char_length(ProcName)), 1)), @max_dbname_size = convert(varchar(3), isnull( max(char_length(DBNAME)), 1)) from #proc_report if @dont_format is null begin select @exec_str = 'select "Name" = convert(varchar(' + @max_loginname_size + '), Name), SPID, "Procedure" = convert(varchar(' + @max_procname_size + '), ProcName), "Database" = convert(varchar(' + @max_dbname_size + '), DBNAME), "Elapsed Time/ms" = TimeMs from #proc_report order by TimeMs asc' exec (@exec_str) end else begin select "Name" = Name, SPID, "Procedure" = ProcName, "Database" = DBNAME, "Elapsed Time/ms" = TimeMs from #proc_report order by TimeMs asc end end go grant exec on sp__monrunning to public go exit