-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpuPowerExtracter.py
More file actions
161 lines (135 loc) · 5.27 KB
/
gpuPowerExtracter.py
File metadata and controls
161 lines (135 loc) · 5.27 KB
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
155
156
157
158
159
160
161
k].endswith("%"):
metricsRecs[k] = float(metricsRecs[k][:-2]) / 100.0
else:
metricsRecs[k] = float(metricsRecs[k]);
# metricsRecs[k] = str(metricsRecs[k])
dataArray = dataArray + metricsRecs
recStr = '|'
for item in dataArray:
recStr += str(item) + '|'
recStr += '\n'
print recStr
outTxt.write(recStr)
record.append(dataArray)
#cur.execute('insert into gpu_performance_dvfs(App, Kernel,\
# SM_Clock, MEM_Clock,\
# Arguments, Time,\
# Achieved_Occ,\
# Dram_read_throughput, Dram_read_transactions,\
# Dram_write_throughput, Dram_write_transactions,\
# l2_read_throughput, l2_read_transactions,\
# shared_load_throughput, shared_load_transactions,\
# shared_store_throughput, shared_store_transactions\
# ) values(%s, %s, %s, %s, %s, %s, %s, \
# %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)',\
# dataArray)
#cur.execute('insert into gpu_performance_dvfs(App, Kernel,\
# SM_Clock, MEM_Clock,\
# Arguments, Time\
# ) values(%s, %s, %s, %s, %s, %s)',\
# dataArray)
##write a row to csv
#csvWriter.writerow(dataArray)
# print record
# sio.savemat('perfData.mat', {'perfData':np.array(record)})
outTxt.close()
tempf = open('perfData.bin', 'wb')
pickle.dump(record, tempf, 0)
tempf.close()
#conn_localhost.commit()
#cur.close()
#conn_localhost.close()
import time
import datetime
import sys,urllib,urllib2
import csv
import os
import re
import cPickle as pickle
logRoot = 'EPPMiner_DVFS_gtx980/'
# Read log lines
# loglines = [line.strip() for line in open('dvfs.txt').readlines()]
outTxt = open('powerStatistics.txt', 'w')
fileName = [line.strip() for line in open('logList.txt').readlines()]
loglines = []
for i in range(len(fileName)):
try:
myfile = open(logRoot + 'power/' + fileName[i] + '.txt')
tmplines = [line.strip() for line in myfile.readlines()]
loglines.extend(tmplines)
except Exception, e:
print e.args[0], e.args[1], fileName
continue;
# for line in loglines:
# print line
freqInd = [s for s, line in enumerate(loglines) if 'sm_clock:' in line]
# progInd = [s for s, line in enumerate(loglines) if 'program:' in line];
record_count = len(freqInd)
outRec = []
for i in range(record_count):
if i < record_count - 1:
powerSamples = loglines[freqInd[i] : freqInd[i+1]]
else:
powerSamples = loglines[freqInd[i] : ]
# extract clock frequency and program information
clock_info = powerSamples[0]
sm_clock = re.findall('sm_clock:[0-9]*,', clock_info)[0][9:-1]
mem_clock = re.findall('mem_clock:[0-9]*', clock_info)[0][10:]
prog_info = powerSamples[1]
program = re.findall('program:[A-Za-z|(|)|-]*,', prog_info)[0][8:-1]
arg = re.findall('arguments:.*', prog_info)[0][10:]
powerSamples = powerSamples[2:]
powerRecInd = [s for s, line in enumerate(powerSamples) if 'Driver Version:' in line]
tmp_rec_count = len(powerRecInd)
record = [powerSamples[powerRecInd[i]:powerRecInd[i + 1]] if i < tmp_rec_count - 1 \
else powerSamples[powerRecInd[i]:] for i in range(tmp_rec_count)]
idlePowerInfor = []
actPowerInfor = []
# tempInfor = []
appInfor = []
for infor in record:
powerLine = [infor[j + 1] for j, line in enumerate(infor) if 'GTX 980' in line];
if len(powerLine) == 0: # incomplete nvidia-smi returned records
continue
else:
power = powerLine[0].split()[4];
# print power;
#tempLine = [infor[j + 1] for j, line in enumerate(infor) if 'GTX 980' in line][0];
#temp = powerLine.split()[2];
## print temp;
appLine = [infor[k] for k, line in enumerate(infor) if 'Applications' in line];
if len(appLine) == 0:
app = ' '
appInfor.append(app)
idlePowerInfor.append(power)
else:
app = appLine[0].split()[4]
app = app.split('\\')[-1]
appInfor.append(app)
actPowerInfor.append(power)
print app, power
# find most frequent active power
act_p = 0
idle_p = 0
max_count = -1
tmp_set = set(actPowerInfor)
for p in tmp_set:
if actPowerInfor.count(p) > max_count:
max_count = actPowerInfor.count(p)
act_p = p
if act_p == 0 or act_p == '0':
continue
max_count = -1
tmp_set = set(idlePowerInfor)
for p in tmp_set:
if idlePowerInfor.count(p) > max_count:
max_count = idlePowerInfor.count(p)
idle_p = p
outRec.append([int(sm_clock), int(mem_clock), program, arg, int(str(idle_p).replace('W', '')), int(str(act_p).replace('W', ''))])
txt_rec = '%s|%s|%s|%s|%s|%s\n' % (int(sm_clock), int(mem_clock), program, arg, idle_p, act_p)
# print txt_rec
outTxt.write(txt_rec)
outTxt.close()
tempf = open('powerData.bin', 'wb')
pickle.dump(outRec, tempf, 0)
tempf.close()