--²é¿´CPUÀûÓÃÂÊ
-- CREATE PROCEDURE sp_GetTop10_CPU () AS
BEGIN
SET NOCOUNT ON
DECLARE @cinterval char(8)
DECLARE @interval int
SET @cinterval = '00:00:10'
CREATE TABLE #thread
(
RUN INT NOT NULL,
SPID INT NOT NULL,
THREAD INT NULL,
STATUS varchar(30) NOT NULL,
[IO] INT NOT NULL,
CPU INT NOT NULL,
MEM INT NOT NULL,
LOCKS int NOT NULL,
BLK INT NOT NULL,
hostname varchar(30) NOT NULL,
hostprocess INT NOT NULL
CONSTRAINT PK_thread1 PRIMARY KEY CLUSTERED (RUN,SPID)
)
INSERT #thread
SELECT 1,pr.spid,pr.kpid,pr.status,pr.physical_io,pr.cpu, pr.memusage,ISNULL(count(lk.spid),0),pr.blocked , max(pr.hostname), max(pr.hostprocess)
from master.dbo.sysprocesses pr
LEFT OUTER JOIN master.dbo.syslocks lk
ON pr.spid = lk.spid
WHERE pr.spid>=50 AND pr.spid<>@@SPID
GROUP BY pr.spid,pr.kpid,pr.status,pr.physical_io, pr.cpu,pr.memusage,pr.blocked
WAITFOR DELAY @cinterval
INSERT #thread
SELECT 2,pr.spid,pr.kpid,pr.status,pr.physical_io,pr.cpu, pr.memusage,ISNULL(count(lk.spid),0),pr.blocked , max(pr.hostname), max(pr.hostprocess)
from master.dbo.sysprocesses pr
LEFT OUTER JOIN master.dbo.syslocks lk
ON pr.spid = lk.spid
WHERE pr.spid>=50 AND pr.spid<>@@SPID
GROUP BY pr.spid,pr.kpid,pr.status,pr.physical_io, pr.cpu,pr.memusage,pr.blocked
SELECT TOP 10 T.*
from
(
SELECT a.SPID, a.hostname, b.hostprocess, b.STATUS, (b.CPU-a.CPU) as 'CPU'
from #thread a
JOIN #thread b
ON a.SPID=b.SP
ÍâÁ¬½ÓÈ¡Êý¾ÝÈç¹ûΪ¿Õ£¬²»´æÔÚASʱ¿ÉÄÜÈ¡µ½Êý¾Ý£¬µ«¼ÓÁËAS¾Í»á±¨´í¡£±ÈÈçSelect Top 10 a.*,b.Class AS ClassId
,b.DeviceName from AuxBusInfo a Left Join DeviceCandidate b On a.InitialDeviceRscId = b.DeviceRscId Order By AuxBusId£¬µ± ......
Õ⼸ÌìÓÃÁËÒ»ÏÂMicrosoft SQL Server 200µÄ·ÖÎö·þÎñ£¬Ìù³öÀ´¸ø´ó¼Ò·ÖÏíһϡ£
Çë¶à¶àÖ¸Õý¡£Ð»Ð»¡£
Ò»¡¢ÐèÇó£º
½¨Á¢Ò»¸öͼÊ鶩µ¥Í³¼Æϵͳ
1¡¢Í³¼Æ¸÷¸öͼÊé¹Ý¶©µ¥ÊýÁ¿¡£
2¡¢Í³¼Æ¸÷¸öͼÊé¹Ý¶©µ¥µÄ¸÷¸ö״̬µÄÊýÁ¿Õ¼¸ÃͼÊé¹ÝµÄ¶©µ¥ÊýÁ¿µÄ°Ù·Ö±È¡£
3¡¢Í¬Ê±Í³¼ÆÔʼÊýÁ¿ºÍ´¢ÔËÊýÁ¿
¶þ¡¢Êý¾Ý±í
Ö ......