goo

CPUの使用率取得

◆一覧リスト
HSP Ver3.0
HSP Ver2.61
ブログ関連
その他
★人気blogランキング

「CPUの使用率取得」
CPUの使用率の取得について。

以下、メモです。
2008/01/28 訂正
1000ms毎にCPUの使用率(%)を測定
左ドラッグでウィンドウ移動
右クリックで終了
/* ----------------------------------------------------------------------------
	CPU使用率取得モジュール
	GetPerCPU time
		time:取得時間
		戻り値:使用率(実数値)
   ---------------------------------------------------------------------------- */
#module GetCPUPer
#uselib "pdh.dll"
#func PdhOpenQuery "PdhOpenQuery" int,int,var
#func PdhAddCounter "PdhAddCounterA" int,var,int,var
#func PdhCollectQueryData "PdhCollectQueryData" int
#func PdhGetFormattedCounterValue "PdhGetFormattedCounterValue" int,int,int,var
#func PdhCloseQuery "PdhCloseQuery" int
#func PdhBrowseCounters "PdhBrowseCountersA" var

#define 	PDH_FMT_DOUBLE		0x200

#defcfunc GetPerCPU int time
	dim FmtValue,4 : cpu = 0f
	PdhOpenQuery 0, 0, hQuery
	s="¥¥Processor(_Total)¥¥% Processor Time"
	PdhAddCounter hQuery, s, 0, hCounter
	PdhCollectQueryData hQuery
	await time
	PdhCollectQueryData hQuery
	PdhGetFormattedCounterValue hCounter, PDH_FMT_DOUBLE, NULL, FmtValue
	dupptr cpu,varptr(FmtValue)+8,8,3
	PdhCloseQuery hQuery
return cpu
#global
/* end of GetCPUPer ----------------------------------------------------------- */

#define		WM_LBUTTONDOWN		0x0201
#define		WM_RBUTTONDOWN		0x0204
#define		WM_NCLBUTTONDOWN	0x00A1
#define		HTCAPTION		2

	bgscr 0,104,20 : gsel 0,2
	oncmd gosub *LBUTTONDOWN,WM_LBUTTONDOWN
	oncmd *RBUTTONDOWN,WM_RBUTTONDOWN
	//dim PDH_BROWSE_DLG_CONFIG,10
	//PdhBrowseCounters PDH_BROWSE_DLG_CONFIG
	font "",12
	repeat
       	redraw 0
		time = GetPerCPU(1000)
		color : boxf
		color 0,0,255 : boxf 2,2,time,16
		color 255,255,255: pos 3,3: mes strf("%7.2f %%",time)
		redraw 1
	loop

//マウス左ドラッグでウィンドウを移動
*LBUTTONDOWN
	sendmsg hwnd,WM_NCLBUTTONDOWN,HTCAPTION,0
return

//右クリックで終了
*RBUTTONDOWN
end
コメント ( 4 ) | Trackback ( 0 )