社区
嵌入开发(WinCE)
帖子详情
How could I know whether a window process is idle or not?
lifeis
2003-08-22 11:19:14
thanx
...全文
33
3
打赏
收藏
How could I know whether a window process is idle or not?
thanx
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
3 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
lifeis
2003-08-26
打赏
举报
回复
thanks
lifeis
2003-08-26
打赏
举报
回复
up
WaterUsage
2003-08-22
打赏
举报
回复
这是偶保存的一个文章(使用BCB),不知道是哪位大虾写的
——————————————————
一句话:在一个特定时间段内计算特定进程的总时间和所有进程的总时间,它们的比值就是那个特定进程的确CPU占有率,这里我采用1秒种。
====================================================================
typedef struct _THREAD_INFO
{
LARGE_INTEGER CreateTime;
DWORD dwUnknown1;
DWORD dwStartAddress;
DWORD StartEIP;
DWORD dwOwnerPID;
DWORD dwThreadId;
DWORD dwCurrentPriority;
DWORD dwBasePriority;
DWORD dwContextSwitches;
DWORD Unknown;
DWORD WaitReason;
}THREADINFO, *PTHREADINFO;
typedef struct _UNICODE_STRING
{
USHORT Length;
USHORT MaxLength;
PWSTR Buffer;
} UNICODE_STRING;
typedef struct _PROCESS_INFO
{
DWORD dwOffset;
DWORD dwThreadsCount;
DWORD dwUnused1[6];
LARGE_INTEGER CreateTime;
LARGE_INTEGER UserTime;
LARGE_INTEGER KernelTime;
UNICODE_STRING ProcessName;
DWORD dwBasePriority;
DWORD dwProcessID;
DWORD dwParentProcessId;
DWORD dwHandleCount;
DWORD dwUnused3[2];
DWORD dwVirtualBytesPeak;
DWORD dwVirtualBytes;
ULONG dwPageFaults;
DWORD dwWorkingSetPeak;
DWORD dwWorkingSet;
DWORD dwQuotaPeakPagedPoolUsage;
DWORD dwQuotaPagedPoolUsage;
DWORD dwQuotaPeakNonPagedPoolUsage;
DWORD dwQuotaNonPagedPoolUsage;
DWORD dwPageFileUsage;
DWORD dwPageFileUsagePeak;
DWORD dCommitCharge;
THREADINFO ThreadSysInfo[1];
} PROCESSINFO, *PPROCESSINFO;
//每秒钟查询一次
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Button2Click(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
PVOID pProcInfo = NULL;
DWORD dwInfoSize = 0x20000;
PPROCESSINFO pProcessInfo;
DWORD dwWorkingSet;
long ( __stdcall *NtQuerySystemInformation )( DWORD, PVOID, DWORD, DWORD );
static __int64 LastTotalProcessCPUUsage = 0;
static __int64 LastCurrentProcessCPUUsage = 0;
int CurrentDelta;
int TotalDelta;
__int64 TotalProcessCPUUsage = 0;
__int64 CurrentProcessCPUUsage = 0;
/////////////////////////////////
pProcInfo = (PVOID)(new byte[dwInfoSize]);
NtQuerySystemInformation = (long(__stdcall*)(DWORD,PVOID,DWORD,DWORD))
GetProcAddress( GetModuleHandle( "ntdll.dll" ),"NtQuerySystemInformation" );
NtQuerySystemInformation(5,pProcInfo,dwInfoSize,0);
pProcessInfo = (PPROCESSINFO)pProcInfo;
do
{
TotalProcessCPUUsage += (__int64)pProcessInfo->KernelTime.QuadPart + (__int64)pProcessInfo->UserTime.QuadPart;
if(pProcessInfo->dwProcessID == GetCurrentProcessId())
{
dwWorkingSet = pProcessInfo->dwWorkingSet;
CurrentProcessCPUUsage += (__int64)pProcessInfo->KernelTime.QuadPart + (__int64)pProcessInfo->UserTime.QuadPart;
}
/////////
if(pProcessInfo->dwOffset == 0)
{
break;
}
pProcessInfo = (PPROCESSINFO)((byte*)pProcessInfo + pProcessInfo->dwOffset);
}
while(true);
TotalDelta = TotalProcessCPUUsage - LastTotalProcessCPUUsage;
CurrentDelta = CurrentProcessCPUUsage - LastCurrentProcessCPUUsage;
if(TotalDelta != 0)
this->Caption = "CPU = " + IntToStr(100 * CurrentDelta / TotalDelta) +
"Memory = "+ IntToStr(dwWorkingSet / 1024) " K";
LastTotalProcessCPUUsage = TotalProcessCPUUsage;
LastCurrentProcessCPUUsage = CurrentProcessCPUUsage;
delete[] pProcInfo;
}
ViewPager 放大缩小左右移动
* Indicates that the pager is in the
process
of settling to a final * position. */ public static final int SCROLL_STATE_SETTLING = 2; private int mScrollState = SCROLL_STATE_
IDLE
; /** * ...
PostgreSQL数据库事务系统——三层系统举例
Internally, a backend needs a way to identify subtransactions whether or not they have XIDs; but this need only lasts as long as the parent top transaction endures. Therefore, we have ...
node.js运行js_在将自己埋在包中之前,请学习Node.js运行时本身
node.js运行jsby Samer Buna 通过Samer Buna 在将自己埋在包中之前,请学习Node.js运行时本身 (Before you bury yourself in packages, learn ...Update: This article is now part of my book “Node.js Beyond ...
2-
PROCESS
ES AND THREADS
Please indicate the source: http://blog.csdn.net/gaoxiangnumber1 Welcome to my github: https://github.com/gaoxiangnumber12.1
PROCESS
ES In any multiprogramming system, the CPU switches from
process
to
新视野大学英语(第三版)视听说4必修答案(全)
I mean, we both work, we both live in the house, we agreed that housework is … is both of our responsibility. I don’t like to have to keep reminding you about it. M: What’s the matter with you ...
嵌入开发(WinCE)
19,504
社区成员
41,569
社区内容
发帖
与我相关
我的任务
嵌入开发(WinCE)
硬件/嵌入开发 嵌入开发(WinCE)
复制链接
扫一扫
分享
社区描述
硬件/嵌入开发 嵌入开发(WinCE)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章