-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProcessResourceStatistics.cpp
85 lines (74 loc) · 1.52 KB
/
ProcessResourceStatistics.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "stdafx.h"
#include "ProcessResourceStatistics.h"
#include <psapi.h>
#pragma comment(lib,"Psapi.lib")
ProcessResourceStatistics::ProcessResourceStatistics(int pid) : m_hProcess(NULL)
{
m_hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
if (m_hProcess!=NULL)
m_cpu.Init(m_hProcess);
}
ProcessResourceStatistics::~ProcessResourceStatistics()
{
if (m_hProcess != NULL)
{
CloseHandle(m_hProcess);
m_hProcess = NULL;
}
}
int ProcessResourceStatistics::IsRunning()
{
int iRet = -1;
if (m_hProcess != NULL)
{
DWORD exitcode;
GetExitCodeProcess(m_hProcess, &exitcode);
if (exitcode != STILL_ACTIVE)
{
CloseHandle(m_hProcess);
m_hProcess = 0;
}
else
{
iRet = 0;
}
}
return iRet;
}
double ProcessResourceStatistics::GetCPUInfo()
{
double cpuUsaeRate = 0.0;
if (m_hProcess != NULL && m_cpu.IsNormal())
{
cpuUsaeRate = m_cpu.GetCpuUsageRate();
}
return cpuUsaeRate;
}
double ProcessResourceStatistics::GetMemoryInfo()
{
double memMB = 0;
if (m_hProcess != NULL)
{
PROCESS_MEMORY_COUNTERS pmc;
::GetProcessMemoryInfo(m_hProcess, &pmc, sizeof(pmc));
memMB = pmc.WorkingSetSize / 1024.00 / 1024.00; //MByte
}
return memMB;
}
double ProcessResourceStatistics::GetHandleInfo()
{
DWORD dwHandleCount = 0;
if (m_hProcess != NULL)
{
GetProcessHandleCount(m_hProcess, &dwHandleCount);
}
return (double)dwHandleCount;
}
double ProcessResourceStatistics::GetThreadInfo()
{
DWORD dwThreadCount = 0;
if (m_hProcess != NULL)
{
}
return (double)dwThreadCount;
}