-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
154 lines (120 loc) · 3.4 KB
/
main.go
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package main
import (
"bartico.com/nvidia-clock-control/icon"
"bartico.com/nvidia-clock-control/nv_smi"
"bartico.com/nvidia-clock-control/tray"
"github.com/getlantern/systray"
"fmt"
"time"
)
var currentMemoryLimit = -1
var currentCoreLimit = -1
var memoryGroup *tray.MenuGroup
var coreGroup *tray.MenuGroup
var gpuClocks = nv_smi.QuerySupportedClocks()
func printLimit(limit int) string {
if limit == -1 {
return "Unlimited"
}
return fmt.Sprintf("%d MHz", limit)
}
func addLimitsInfo() {
mLimits := systray.AddMenuItem("Limits not available", "Current Limits")
mLimits.Disable()
go func() {
for {
mLimits.SetTitle(fmt.Sprintf("Memory: %s - Core: %s", printLimit(currentMemoryLimit), printLimit(currentCoreLimit)))
time.Sleep(3 * time.Second)
}
}()
}
func addMemControl() {
menuItemMemoryGroup := systray.AddMenuItem("Memory Clock Limit", "Memory Clock Limit")
memoryGroup = new(tray.MenuGroup)
for _, value := range gpuClocks.Memory() {
var memoryClock = printLimit(value)
memoryGroup.Add(menuItemMemoryGroup.AddSubMenuItemCheckbox(memoryClock, memoryClock, false), value, func() {
currentMemoryLimit = value
nv_smi.SetMemoryLimit(gpuClocks.MinimumMemoryClock, currentMemoryLimit)
})
}
}
func addCoreControl() {
menuItemCoreGroup := systray.AddMenuItem("Core Clock Limit", "Core Clock Limit")
coreGroup = new(tray.MenuGroup)
coreClocks := gpuClocks.Core()
for _, value := range coreClocks {
var coreClock = printLimit(value)
coreGroup.Add(menuItemCoreGroup.AddSubMenuItemCheckbox(coreClock, coreClock, false), value, func() {
currentCoreLimit = value
nv_smi.SetCoreLimit(gpuClocks.MinimumCoreClock, currentCoreLimit)
})
}
}
func addResetControls() {
resetAll := systray.AddMenuItem("Reset All Limits", "Reset All Limits")
go func() {
for {
<- resetAll.ClickedCh
currentMemoryLimit = -1
currentCoreLimit = -1
nv_smi.ResetAllLimits()
memoryGroup.UncheckAll()
coreGroup.UncheckAll()
}
}()
}
func hideSomeCoreLimits(coreStepping int) {
allItems := coreGroup.GetAll()
prev := allItems[0].GetValue()
for _, groupItem := range allItems {
groupItem.Show()
value := groupItem.GetValue()
if prev - value < coreStepping {
groupItem.Hide()
} else {
prev = value
}
}
}
func addSettingsControl() {
settingsMenu := systray.AddMenuItem("Settings", "Settings")
hideCoreLimitSubItem := settingsMenu.AddSubMenuItem("Hide Core Limits", "Hide Core Limits")
hideCoreLimitsMenuGroup := new(tray.MenuGroup)
for _, value := range [6]int{250, 200, 150, 100, 50, 30} {
displayValue := fmt.Sprintf("%d MHz Steps", value)
hideCoreLimitsMenuGroup.Add(hideCoreLimitSubItem.AddSubMenuItemCheckbox(displayValue, displayValue, false), value, func() {
hideSomeCoreLimits(value)
})
}
showAllCoreLimits := settingsMenu.AddSubMenuItem("Show All Core Limits", "Show All Core Limits")
go func() {
for {
<-showAllCoreLimits.ClickedCh
hideCoreLimitsMenuGroup.UncheckAll()
coreGroup.ShowAll()
}
}()
}
func onReady() {
systray.SetIcon(icon.Data)
systray.SetTitle("Nvidia Clock Control")
nv_smi.ResetAllLimits()
addLimitsInfo()
systray.AddSeparator()
addMemControl()
addCoreControl()
systray.AddSeparator()
addResetControls()
systray.AddSeparator()
addSettingsControl()
systray.AddSeparator()
mQuit := systray.AddMenuItem("Quit", "Quit")
go func() {
<-mQuit.ClickedCh
systray.Quit()
}()
}
func main() {
systray.Run(onReady, nil)
}