-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
executable file
·81 lines (60 loc) · 1.67 KB
/
test.py
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
#!/usr/bin/env python
import powerMeterDaemon as pm
import time
import datetime
import os
def run(cmd):
f=os.popen(cmd)
buf=""
for i in f.readlines():
buf+=i
return buf.strip()
# Lets get a powerMeter without the GUI and dont start monitoring immediately
meter = pm.powerMeter(plotGraph=False,powerLogFile="",MonitorOnStart=False, verbose=False)
# testMachine
testHostname = "user@testmachine"
testKeys = "~/.ssh/test"
# path to test on testMachine
testPath = "./Code/Benchmark/test.sh"
# start the monitor and give it time to record a baseline power consumption
meter.startMonitoring()
time.sleep(10)
# run test on remote machine
cmd = "ssh -i " + testKeys + " " + testHostname + " '" + testPath + "'"
#print cmd
run(cmd)
# make sure the test is done then stop monitoring
time.sleep(10)
meter.stopMonitoring()
# Get get the power consumption log
log = meter.getDataLog()
now = datetime.datetime.now()
nowstr = now.strftime("%Y%m%d_%H%M%S")
curdir = "./logs/"+nowstr
os.mkdir(curdir)
# write out power consumption in CSV
logFile = curdir+"/powerlog.csv"
f = open(logFile,"a")
f.write(testHostname+"\n")
for k in log:
f.write(k[0]+","+str(k[3])+"\n")
f.close()
# copy back test log from testMachines
cmd = "scp -i " + testKeys + " "+testHostname+":~/Code/Benchmark/test.log "+curdir+"/test.log"
#print cmd
run(cmd)
# record power consumption of testMachine at idle
#print "Idle run log"
meter.clearData()
meter.startMonitoring()
#print "logging..."
time.sleep(130)
meter.stopMonitoring()
log = meter.getDataLog()
logFile = curdir+"/idlePowerlog.csv"
f = open(logFile,"a")
f.write(testHostname+"\n")
for k in log:
f.write(k[0]+","+str(k[3])+"\n")
f.close()
print "all done.."