code review comments and PROX commit ID
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / dpi / ratedistribution.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 decimal import *
21
22 def usage(progName):
23     print "usage: " + progName + " config [up|down]"
24     print " The script reads a lua configuration "
25     print " and outputs a histogram wit 21 buckets."
26     print " The first 20 buckets contain 70th percentile."
27     print " The last bucket contains the remaining items."
28     exit(-1);
29
30 if (len(sys.argv) != 3):
31     usage(sys.argv[0])
32
33 if (sys.argv[2] == "down"):
34     match = "dn_bps"
35 elif (sys.argv[2] == "up"):
36     match = "up_bps"
37 else:
38     usage(sys.argv[0])
39
40 values = []
41 for line in open(sys.argv[1]).readlines():
42     line = line.strip();
43
44     if line.find(match) != -1:
45         v = line.split(" = ")[1].strip(",")
46         values.append(Decimal(v));
47
48 values = sorted(values)
49
50 treshold = values[int(len(values)*0.7)]
51
52 buckets = [0]*21;
53
54 for v in values:
55     if (v > treshold):
56         buckets[20] += 1
57     else:
58         buckets[int(v * 20 / treshold)] += 1
59
60 stepSize = treshold / 20;
61
62 print "# bucket range, count"
63 for i in range(len(buckets) - 1):
64     beg = str(int(i * stepSize))
65     end = str(int((i + 1) * stepSize - 1))
66     print beg + "-" + end + "," + str(buckets[i])
67
68 i = len(buckets) - 1
69 print beg + "+," + str(buckets[i])