Merge "docs: Update install and release docs for DPDK migration support"
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / dpi / sutstatsconsfile.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 from statsconsfile import *
20 from decimal import *
21
22 class SutStatsConsFile:
23     def __init__(self, fileName, offset):
24         self.offset = offset;
25         self.statsConsFile = StatsConsFile(fileName)
26
27     def readNext(self):
28         entry = self._readNextEntry();
29
30         if (entry is None):
31             return None;
32
33         while (entry is not None and entry[-1] <= 0):
34             entry = self._readNextEntry();
35         return entry;
36
37     def getHz(self):
38         return self.statsConsFile.getHz();
39
40     def _readNextEntry(self):
41         entry = self.statsConsFile.readNext();
42         if (entry is None):
43             return None;
44
45         rx = 0;
46         tx = 0;
47         drop = 0;
48         last_tsc = 0;
49
50         for i in range(0, len(entry), 2):
51             rx += entry[i][2]
52             tx += entry[i][3]
53             drop += entry[i][4]
54             last_tsc = entry[i][5]
55
56         last_tsc -= self.offset;
57         last_tsc = Decimal(last_tsc) / self.statsConsFile.getHz();
58         return [rx, tx, drop, last_tsc];
59
60     def close(self):
61         self.statsConsFile.close();