-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCPU_Freq_Cores_WIP_Find_Params.ahk
120 lines (106 loc) · 3.6 KB
/
CPU_Freq_Cores_WIP_Find_Params.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
DetectHiddenWindows, On
TARGET_SCHEME := "d740827b-295c-4564-b160-6c98ca38069c" ;GUID того плана энергосбережения, которого будем "мучать" (заранее нужно создать новый Power Scheme в Windows на базе Balanced Power Scheme и к примеру назвать его "CustomFreqAHK", чтобы не портить Balanced план, добавить в автозагрузку комманду установки Balanced плана)
/*
GetCPUCurrentClockSpeed()
{
sWQLQuery := "Select CurrentClockSpeed From Win32_Processor"
oWMI := ComObjGet("winmgmts:")
oQueryEnum := oWMI.ExecQuery(sWQLQuery)._NewEnum()
if (oQueryEnum[oCPU])
return oCPU.CurrentClockSpeed
}
*/
GetCPUData(Name)
{
sWQLQuery := "Select " Name " From Win32_Processor"
oWMI := ComObjGet("winmgmts:")
oQueryEnum := oWMI.ExecQuery(sWQLQuery)._NewEnum()
if (oQueryEnum[oCPU])
return oCPU[Name]
}
GetCPUCurrentClockSpeed()
{
return GetCPUData("CurrentClockSpeed")
}
GetCPUNumberOfCores()
{
return GetCPUData("NumberOfCores")
}
SetMaxProcessorState(Value, Mode)
{
global TARGET_SCHEME
if ((0 <= Value && Value <= 100) && (Mode = "AC" || Mode = "DC")) ;for strings: logical equal (=), case-sensitive-equal (==) ;for digits both are logical equal
{
RunWait, %ComSpec% /c powercfg -set%Mode%valueindex %TARGET_SCHEME% SUB_PROCESSOR PROCTHROTTLEMAX %Value%,, Hide
RunWait, %ComSpec% /c powercfg -setactive %TARGET_SCHEME%,, Hide
}
else
throw Exception("Bad Value or Mode", -1)
}
SetMinProcessorState(Value, Mode)
{
global TARGET_SCHEME
if ((0 <= Value && Value <= 100) && (Mode = "AC" || Mode = "DC")) ;for strings: logical equal (=), case-sensitive-equal (==) ;for digits both are logical equal
{
RunWait, %ComSpec% /c powercfg -set%Mode%valueindex %TARGET_SCHEME% SUB_PROCESSOR PROCTHROTTLEMIN %Value%,, Hide
RunWait, %ComSpec% /c powercfg -setactive %TARGET_SCHEME%,, Hide
}
else
throw Exception("Bad Value or Mode", -1)
}
CreateAssocArray(m)
{
obj := {}
len := m.Length() / 2
Loop, % len {
i := A_Index * 2 - 1
obj[m[i]] := m[i + 1]
obj[m[i + 1]] := m[i]
obj[A_Index + 100] := [m[i], m[i + 1]]
}
return obj
}
obj := CreateAssocArray([1, 0.8, 31, 1.0, 34, 1.3])
;MsgBox % obj[31] " " obj[1.3] " " obj[101][2]
StartDummyLoad()
{
Code := "
(LTrim
#NoTrayIcon
#Persistent
SetBatchLines, -1
while (true)
{}
)"
return ExecScript(Code, false)
}
FindProcessorState(StartPosition := 0, DummyLoadStartPosition := 95)
{
;WMI not detect Intel Turbo Boost frequency :(
Loop, 100 {
if (A_Index < StartPosition)
Continue
SetMaxProcessorState(A_Index, "AC")
SetMinProcessorState(A_Index, "AC")
;if (A_Index >= DummyLoadStartPosition && !Load) {
;Load := true
;DummyLoadPID := StartDummyLoad()
;}
Freq := GetCPUCurrentClockSpeed()
if (Freq != FreqPrev) {
FreqPrev := Freq
;sToolTip .= Format("{:3i}% -> {:4i}MHz`n", A_Index, Freq)
sToolTip .= A_Index "% -> " Freq "MHz`n"
;sToolTip .= A_Index "% -> " Round(Freq / 1000, 1) "GHz`n"
sResult .= A_Index "," Round(Freq / 1000, 1) ","
}
ToolTip % "CPU State = " A_Index "%`n" sToolTip
}
;WinClose, ahk_pid %DummyLoadPID%
SetMinProcessorState(0, "AC")
Clipboard := "[" SubStr(sResult, 1, -1) "]" ; trim last comma
}
FindProcessorState(9)
MsgBox Done
!x:: ExitApp
!z:: Reload