code review comments and PROX commit ID
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / dpi / maketable.py
1 #!/bin/env python
2
3 ##
4 ## Copyright (c) 2010-2017 Intel Corporation
5 ##
6 ## Licensed under the Apache License, Version 2.0 (the "License");
7 ## you may not use this file except in compliance with the License.
8 ## You may obtain a copy of the License at
9 ##
10 ##     http://www.apache.org/licenses/LICENSE-2.0
11 ##
12 ## Unless required by applicable law or agreed to in writing, software
13 ## distributed under the License is distributed on an "AS IS" BASIS,
14 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ## See the License for the specific language governing permissions and
16 ## limitations under the License.
17 ##
18
19 import sys
20 from config import *
21 from csvreader import *
22 from sets import Set
23 from csvwriter import *
24
25 class ResultEntry:
26     def __init__(self):
27         self.boundary = None;
28         self.cores = {}
29
30     def setBoundary(self, val):
31         self.boundary = val;
32
33     def addCoreResult(self, core, val):
34         self.cores[core] = val
35
36     def getCoreResult(self, core):
37         if (core in self.cores):
38             return self.cores[core];
39         return None;
40
41     def getBoundary(self):
42         return self.boundary;
43
44     def getCores(self):
45         return self.cores
46
47     def getMsr(self):
48         return self.msr;
49
50 class DictEntry:
51     def __init__(self, key):
52         self.dictionary = {}
53         self.entries = []
54         self.key = key;
55
56 config = Config();
57 config.parse(sys.argv[0], sys.argv[1:])
58
59 err = config.getErrorMakeTable();
60
61 if (err is not None):
62     print err
63     exit(-1);
64
65 if (config._debug):
66     print "Performance data: " + config.getInputFileName2()
67     print "Boundaries: " + config.getInputFileName()
68
69 allData = {}
70
71 infileFields = []
72 infileFields += [("msr", "int")]
73 infileFields += [("conn", "int")]
74 infileFields += [("ss", "Decimal")]
75 infileFields += [("bw", "Decimal")]
76
77 boundariesFile = CsvReader(infileFields)
78 boundariesFile.open(config.getInputFileName());
79 boundaries = boundariesFile.readAll();
80
81 cores = Set()
82
83 orderedResults = []
84 finalResults = {}
85
86 for a in boundaries:
87     key = a["conn"]
88     if (key not in finalResults):
89         newDict = DictEntry(key)
90         finalResults[key] = newDict
91         orderedResults.append(newDict)
92
93 for a in boundaries:
94     table = finalResults[a["conn"]]
95     key = a["msr"]
96     value = ResultEntry()
97     value.msr = a["msr"]
98     value.conn = a["conn"]
99     value.boundary = a["bw"]
100     table.dictionary[key] = value
101     table.entries.append(value)
102
103 infileFields2 = []
104 infileFields2 += [("cores", "int")]
105 infileFields2 += [("msr", "int")]
106 infileFields2 += [("conn", "int")]
107 infileFields2 += [("ss", "Decimal")]
108 infileFields2 += [("down", "Decimal")]
109
110 resultsFile = CsvReader(infileFields2)
111 resultsFile.open(config.getInputFileName2())
112
113 for a in resultsFile.readAll():
114     table = finalResults[a["conn"]]
115     key = a["msr"]
116     table.dictionary[key].addCoreResult(a["cores"], a["down"])
117     cores.add(a["cores"]);
118
119
120 outputFile = CsvWriter()
121
122 outputFile.open(config._output_file_name)
123
124 title = ["setup rate", "maximum"]
125 for e in sorted(cores):
126     title += [str(e)]
127
128 for a in orderedResults:
129     outputFile.write(["connections = " + str(a.key)])
130     outputFile.write(title)
131
132     for e in a.entries:
133         line = [str(e.getMsr())]
134         line += [str(e.getBoundary())]
135         for c in sorted(cores):
136             if (e.getCoreResult(c) is not None):
137                 line += [str(e.getCoreResult(c))]
138             else:
139                 line += [""]
140         outputFile.write(line)