-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.py
More file actions
67 lines (51 loc) · 1.29 KB
/
memory.py
File metadata and controls
67 lines (51 loc) · 1.29 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
import subprocess, sys, time, pylab, numpy
N = 3
def getMemory():
p = subprocess.Popen(["ps", "-C", "MORPH", "v"], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = p.communicate()
data = out.split()
#if len(data) > 10:
return numpy.array(data[18:-1:10]).astype(float)
#else:
# return -1
p = subprocess.Popen(["mpirun", "-n", str(N), "./MORPH"])
data = []
try:
deltaT = float(sys.argv[1])
except:
deltaT = 1
t = []
i = 0
while p.poll() == None:
tmpdata = getMemory();
if len(tmpdata) > 0:
data.append(getMemory())
time.sleep(deltaT)
t.append(i*deltaT)
i +=1
#dataArray = numpy.zeros((N,len(data)))
#i = 0
#for array in data:
# for j in range(N):
# dataArray[j][i] = array[j]
# i+=1
data = numpy.array(data[:-1])
t = numpy.array(t[:-1])
legend = []
numpy.save("memory", data)
numpy.save("time", t)
pylab.figure(1)
pylab.plot(t,data[:,0])
pylab.xlabel("Time [s]")
pylab.ylabel("% Memory usage")
pylab.savefig("master.png")
pylab.figure(2)
for i in xrange(1,N):
pylab.plot(t,data[:,i])
legend.append("Processor nr: " + str(i))
#pylab.plot(t,data[:,1])
pylab.legend(legend,loc=2)
pylab.xlabel("Time [s]")
pylab.ylabel("% Memory usage")
pylab.savefig("slaves.png")