SQL SERVER 檢視CPU利用率

2021-05-10 15:29:48 字數 2159 閱讀 9965

--檢視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.spid and a.run=1 and b.run=2

) torder by cpu desc

drop table #thread

return

endgo

declare @handle binary(20)

select @handle = sql_handle from master..sysprocesses where spid = 53

select 'current statement'= text from ::fn_get_sql(@handle)

select @handle = sql_handle from master..sysprocesses where spid = 57

select 'current statement'= text from ::fn_get_sql(@handle)

system_function_schema

SQL SERVER 檢視CPU利用率

檢視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 th...

檢視CPU資訊

cpu總核數 物理cpu個數 每顆物理cpu的核數 總邏輯cpu數 物理cpu個數 每顆物理cpu的核數 超執行緒數 檢視cpu資訊 型號 root aaa cat proc cpuinfo grep name cut f2 d uniq c 24 intel r xeon r cpu e5 263...

檢視cpu資訊

1 cat proc cpuinfo 2 判斷物理cpu的個數可以檢視physical id 的值,相同則為同乙個物理cpu cat proc cpuinfo grep physical uniq c 4 physical id 0 說明實際上是一顆4核的cpu 3 getconf long bit...