-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatitemp
executable file
·119 lines (83 loc) · 3.43 KB
/
atitemp
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
#!/usr/bin/python
import os, sys
from adl3 import *
import collections
class ADLError(Exception):
pass
adapters = []
def initialize():
# check for unset DISPLAY, assume :0
if "DISPLAY" not in os.environ:
os.environ["DISPLAY"] = ":0"
# the '1' means only retrieve info for active adapters
if ADL_Main_Control_Create(ADL_Main_Memory_Alloc, 1) != ADL_OK:
raise ADLError("Couldn't initialize ADL interface.")
def shutdown():
if ADL_Main_Control_Destroy() != ADL_OK:
raise ADLError("Couldn't destroy ADL interface global pointers.")
def get_adapter_info():
adapter_info = []
num_adapters = c_int(-1)
if ADL_Adapter_NumberOfAdapters_Get(byref(num_adapters)) != ADL_OK:
raise ADLError("ADL_Adapter_NumberOfAdapters_Get failed.")
# allocate an array of AdapterInfo, see ctypes docs for more info
AdapterInfoArray = (AdapterInfo * num_adapters.value)()
# AdapterInfo_Get grabs info for ALL adapters in the system
if ADL_Adapter_AdapterInfo_Get(cast(AdapterInfoArray, LPAdapterInfo), sizeof(AdapterInfoArray)) != ADL_OK:
raise ADLError("ADL_Adapter_AdapterInfo_Get failed.")
deviceAdapter = collections.namedtuple('DeviceAdapter', ['AdapterIndex', 'AdapterID', 'BusNumber', 'UDID'])
devices = []
for adapter in AdapterInfoArray:
index = adapter.iAdapterIndex
busNum = adapter.iBusNumber
udid = adapter.strUDID
adapterID = c_int(-1)
#status = c_int(-1)
if ADL_Adapter_ID_Get(index, byref(adapterID)) != ADL_OK:
raise ADLError("ADL_Adapter_Active_Get failed.")
found = False
for device in devices:
if (device.AdapterID.value == adapterID.value):
found = True
break
# save it in our list if it's the first controller of the adapter
if (found == False):
devices.append(deviceAdapter(index,adapterID,busNum,udid))
for device in devices:
adapter_info.append(AdapterInfoArray[device.AdapterIndex])
return adapter_info
def show_status(adapter_list=None):
adapter_info = get_adapter_info()
for index, info in enumerate(adapter_info):
if adapter_list is None or index in adapter_list:
#print "%d. %s (%s)" % (index, info.strAdapterName, info.strDisplayName)
temperature = ADLTemperature()
temperature.iSize = sizeof(temperature)
if ADL_Overdrive5_Temperature_Get(info.iAdapterIndex, 0, byref(temperature)) != ADL_OK:
raise ADLError("ADL_Overdrive5_Temperature_Get failed.")
print "gpu%s.value %g" % (index, temperature.iTemperature/1000.0)
def print_config():
print 'graph_title ATI GPU Temperatures'
print 'graph_vlabel Celcius'
print 'graph_args --base 1000 --lower-limit 0'
print 'graph_category system'
adapter_info = get_adapter_info()
for index, info in enumerate(adapter_info):
print 'gpu%s.label gpu %s' % (index, index)
print 'gpu%s.draw LINE2' % (index)
if __name__ == "__main__":
try:
initialize()
if len(sys.argv)>1 :
if sys.argv[1]=="config":
print_config()
sys.exit(0)
elif sys.argv[1]!="" :
verboselog('unknown argument "'+sys.argv[1]+'"')
sys.exit(1)
show_status()
except ADLError, err:
result = 1
print err
finally:
shutdown()