-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdataCollection.py
135 lines (115 loc) · 5.41 KB
/
dataCollection.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python3
import os
import argparse
import subprocess
class resultMaker:
def __init__(self, testFileDir, outputFile):
self.outputFile = outputFile
self.testFileDir = testFileDir
self.numberOfIterations = 5
self.numberOfGraphTypes = 4
# self.numberOfTestTypes = 1
def runFiles(self):
with open(self.outputFile, "w") as outputFile:
for i in range(0,self.numberOfIterations):
for fileName in os.listdir(self.testFileDir):
for test in range(0, 2):
for graph in range(1, self.numberOfGraphTypes):
rawStats = self.getStatistics(test, graph, self.testFileDir, fileName, test)
timeMemStats = self.parseData(rawStats)
outputFile.write(fileName)
outputFile.write("\t")
outputFile.write(str(test))
outputFile.write("\t")
outputFile.write(str(graph))
outputFile.write("\t")
for stat in timeMemStats:
outputFile.write(str(stat))
outputFile.write("\t")
outputFile.write("\n")
for i in range(0, self.numberOfIterations):
for fileName in os.listdir(self.testFileDir+"created/"):
for test in range(2, 6):
graphName = fileName[-3:]
if graphName == ".vg":
graphType = 1
elif graphName == ".pg":
graphType = 2
elif graphName == ".hg":
graphType = 3
elif graphName == ".og":
graphType = 4
if graphType:
rawStats = self.getStatistics(test, graphType, self.testFileDir+"created/", fileName)
timeMemStats = self.parseData(rawStats)
outputFile.write(fileName)
outputFile.write("\t")
outputFile.write(str(test))
outputFile.write("\t")
outputFile.write(str(graphType))
outputFile.write("\t")
for stat in timeMemStats:
outputFile.write(str(stat))
outputFile.write("\t")
outputFile.write("\n")
def getStatistics(self, testType, graphType, directory, file, serialize=False):
print(testType, graphType, directory, file, serialize)
print("/usr/bin/time","-l","./bin/project", str(testType), str(graphType), directory+file)
if serialize:
graphName = None
if graphType == 1:
graphName = ".vg"
elif graphType == 2:
graphName = ".pg"
elif graphType == 3:
graphName = ".hg"
elif graphType == 4:
graphName = ".og"
if len(graphName)==3:
with open(directory+"created/"+file[:-3]+graphName, "w") as outFile:
p = subprocess.Popen( ["/usr/bin/time", "-l", "./bin/project", str(testType), str(graphType), directory + file], stdout=outFile, stderr=subprocess.PIPE, encoding='utf8')
out, err = p.communicate()
else:
p = subprocess.Popen( ["/usr/bin/time", "-l", "./bin/project", str(testType), str(graphType), directory + file], stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf8')
out, err = p.communicate()
return err
def parseData(self, rawStats):
rawStats = str(rawStats).split("\n")
numberItems = None
accessTime = None
for line in rawStats:
line = line.rstrip()
line = line.split()
if len(line) > 3:
if line[1] == "real":
realTime = line[0]
usrTime = line[2]
sysTime = line[4]
elif line[1] == "maximum" and line[2] == "resident":
memoryUsage = line[0]
elif line[0] == "number":
if line[4] == "graph:":
if numberItems:
assert(numberItems == line[-1])
numberItems = line[-1]
elif line[3] == "accessed:":
numberItems = line[-1]
if len(line) >2:
if line[0] == "elapsed":
accessTime = line[-1]
return (realTime, usrTime, sysTime, memoryUsage, numberItems, accessTime)
def argParser():
parser=argparse.ArgumentParser(add_help=True)
parser.add_argument("--outputFile","-o",
type=str,
help="specify the file name of the output file")
parser.add_argument("--testFileDir","-i",
type=str,
help="specify the directory name of the input files")
return vars(parser.parse_args())
def main():
args = argParser()
myResultMaker = resultMaker(args["testFileDir"],args["outputFile"])
myResultMaker.runFiles()
if __name__ == "__main__":
main()