-
Notifications
You must be signed in to change notification settings - Fork 1
/
monsoon.py
executable file
·116 lines (89 loc) · 2.65 KB
/
monsoon.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
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
#!/usr/bin/python
import sys
import Monsoon.HVPM as HVPM
import Monsoon.sampleEngine as sampleEngine
import Monsoon.Operations as op
import Monsoon.reflash as reflash
import os
import time
# /home/carlnues/.local/lib/python2.7/site-packages/Monsoon/
def main():
output_file = "" # file handle
output_filename = "monsoonout.txt"
log_file = "" # file handle
log_filename = "monsoonlog.txt"
sample_count = 5000 * 60 * 30 # 5000 per second, i.e. set to 5000 for 1 second
Mon = "" # HVPM object
engine = "" # sampleEngine object
samples = [[]]
sample_metadata = ""
voltage = 3.8
timing_dict = {}
print("Monsoon: Start sampling")
# Hardcode sampling to fixed time for null workloads:
timing_dict = {"userspace_300000":1000000, "userspace_1267200":700000, "userspace_2649600":700000, "interactive_none":750000, "ondemand_none":750000}
if (sys.argv[2] == "N"):
sample_count = timing_dict[sys.argv[4] + "_" + sys.argv[5]]
#end_if
'''
print(os.getpid())
time.sleep(1)
print("Now")
'''
Mon = HVPM.Monsoon()
Mon.setup_usb()
'''
Mon.setVout(0)
print("done")
sys.exit(0)
'''
Mon.setVout(voltage)
engine = sampleEngine.SampleEngine(Mon)
'''
engine.enableCSVOutput("testfoobar.csv")
engine.ConsoleOutput(True)
engine.startSampling(sample_count)
'''
#'''
engine.disableCSVOutput()
#engine.ConsoleOutput(True)
engine.ConsoleOutput(False)
engine.startSampling(sample_count)
samples = engine.getSamples()
#'''
#Mon.setVout(0.0)
'''
for e in range(len(samples[sampleEngine.channels.timeStamp])):
timeStamp = samples[sampleEngine.channels.timeStamp][e]
Current = samples[sampleEngine.channels.MainCurrent][e]
print("current at t " + repr(timeStamp) + " is " + repr(Current) + "mA")
#end_for
'''
# samples[x]: 0 = time; 1 = current; 4 = voltage
# Save out results:
output_file = open(output_filename, "w")
sample_metadata = "{\"Dropped\":" + str(engine.dropped) + ", \"Events\":" + str(len(samples[0])) + ", \"Voltage\":" + str(voltage) + "}"
output_file.write(sample_metadata + "\n")
for i in range(len(samples[0])):
output_file.write(repr(samples[0][i]))
output_file.write("\t")
output_file.write(repr(samples[1][i]))
output_file.write("\t")
output_file.write(repr(samples[4][i]))
#output_file.write("\t")
#output_file.write(repr(samples[6][i]))
output_file.write("\n")
#end_for
output_file.close()
# Record metadata to progress logfile:
log_file = open(log_filename, "a")
log_file.write(sample_metadata + "\n")
log_file.close()
print("Monsoon: Stopped sampling. Metadata: " + sample_metadata)
# Return error if we had dropped events:
if (engine.dropped != 0):
sys.exit(1)
#end_if
sys.exit(0)
#end_def
main()