-
Notifications
You must be signed in to change notification settings - Fork 72
/
cpumem.ahk
98 lines (74 loc) · 3.16 KB
/
cpumem.ahk
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
GetProcessMemory_CommitSize(ProcID, Units="K") {
Process, Exist, %ProcID%
pid := Errorlevel
; get process handle
hProcess := DllCall( "OpenProcess", UInt, 0x10|0x400, Int, false, UInt, pid )
; get memory info
PROCESS_MEMORY_COUNTERS_EX := VarSetCapacity(memCounters, 44, 0)
DllCall( "psapi.dll\GetProcessMemoryInfo", UInt, hProcess, UInt, &memCounters, UInt, PROCESS_MEMORY_COUNTERS_EX )
DllCall( "CloseHandle", UInt, hProcess )
SetFormat, Float, 0.0 ; round up K
PrivateBytes := NumGet(memCounters, 40, "UInt")
if (Units == "B")
return PrivateBytes
if (Units == "K")
Return PrivateBytes / 1024
if (Units == "M")
Return PrivateBytes / 1024 / 1024
}
GetProcessMemory_PeakWorkingSet(ProcID, Units="K") {
Process, Exist, %ProcID%
pid := Errorlevel
; get process handle
hProcess := DllCall( "OpenProcess", UInt, 0x10|0x400, Int, false, UInt, pid )
; get memory info
PROCESS_MEMORY_COUNTERS_EX := VarSetCapacity(memCounters, 44, 0)
DllCall( "psapi.dll\GetProcessMemoryInfo", UInt, hProcess, UInt, &memCounters, UInt, PROCESS_MEMORY_COUNTERS_EX )
DllCall( "CloseHandle", UInt, hProcess )
SetFormat, Float, 0.0 ; round up K
PrivateBytes := NumGet(memCounters, 8, "UInt")
if (Units == "B")
return PrivateBytes
if (Units == "K")
Return PrivateBytes / 1024
if (Units == "M")
Return PrivateBytes / 1024 / 1024
}
GetProcessMemory_WorkingSet(ProcID, Units="K") {
Process, Exist, %ProcID%
pid := Errorlevel
; get process handle
hProcess := DllCall( "OpenProcess", UInt, 0x10|0x400, Int, false, UInt, pid )
; get memory info
PROCESS_MEMORY_COUNTERS_EX := VarSetCapacity(memCounters, 44, 0)
DllCall( "psapi.dll\GetProcessMemoryInfo", UInt, hProcess, UInt, &memCounters, UInt, PROCESS_MEMORY_COUNTERS_EX )
DllCall( "CloseHandle", UInt, hProcess )
SetFormat, Float, 0.0 ; round up K
PrivateBytes := NumGet(memCounters, 12, "UInt")
if (Units == "B")
return PrivateBytes
if (Units == "K")
Return PrivateBytes / 1024
if (Units == "M")
Return PrivateBytes / 1024 / 1024
}
GetServerProcessTimes(pid) { ; Individual CPU Load of the process with pid
Static soldKrnlTime, soldUserTime
Static snewKrnlTime, snewUserTime
soldKrnlTime := snewKrnlTime
soldUserTime := snewUserTime
hProc := DllCall("OpenProcess", "Uint", 0x400, "int", 0, "Uint", pid)
DllCall("GetProcessTimes", "Uint", hProc, "int64P", CreationTime, "int64P", ExitTime, "int64P", snewKrnlTime, "int64P", snewUserTime)
DllCall("CloseHandle", "Uint", hProc)
Return (snewKrnlTime-soldKrnlTime + snewUserTime-soldUserTime)/10000000 * 100 ; 1sec: 10**7
}
GetGUIProcessTimes(pid) { ; Individual CPU Load of the process with pid
Static goldKrnlTime, goldUserTime
Static gnewKrnlTime, gnewUserTime
goldKrnlTime := gnewKrnlTime
goldUserTime := gnewUserTime
hProc := DllCall("OpenProcess", "Uint", 0x400, "int", 0, "Uint", pid)
DllCall("GetProcessTimes", "Uint", hProc, "int64P", CreationTime, "int64P", ExitTime, "int64P", gnewKrnlTime, "int64P", gnewUserTime)
DllCall("CloseHandle", "Uint", hProc)
Return (gnewKrnlTime-goldKrnlTime + gnewUserTime-goldUserTime)/10000000 * 100 ; 1sec: 10**7
}