5134d2252a3e4c29bee9bb5d6cb8001201822af7
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / rapid / rapid_irqtest.py
1 #!/usr/bin/python
2
3 ##
4 ## Copyright (c) 2020 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 ##
11 ##     http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19
20 from past.utils import old_div
21 import sys
22 import time
23 from rapid_log import RapidLog
24 from rapid_test import RapidTest
25
26 class IrqTest(RapidTest):
27     """
28     Class to manage the irq testing
29     """
30     def __init__(self, runtime, machines):
31         self.runtime = runtime
32         self.machines = machines
33
34     def run(self):
35         RapidLog.info("+----------------------------------------------------------------------------------------------------------------------------")
36         RapidLog.info("| Measuring time probably spent dealing with an interrupt. Interrupting DPDK cores for more than 50us might be problematic   ")
37         RapidLog.info("| and result in packet loss. The first row shows the interrupted time buckets: first number is the bucket between 0us and    ")
38         RapidLog.info("| that number expressed in us and so on. The numbers in the other rows show how many times per second, the program was       ")
39         RapidLog.info("| interrupted for a time as specified by its bucket. '0' is printed when there are no interrupts in this bucket throughout   ")
40         RapidLog.info("| the duration of the test. 0.00 means there were interrupts in this bucket but very few. Due to rounding this shows as 0.00 ") 
41         RapidLog.info("+----------------------------------------------------------------------------------------------------------------------------")
42         sys.stdout.flush()
43         for machine in self.machines:
44             buckets=machine.socket.show_irq_buckets(1)
45             print('Measurement ongoing ... ',end='\r')
46             machine.stop()
47             old_irq = [[0 for x in range(len(buckets)+1)] for y in range(len(machine.get_cores())+1)] 
48             irq = [[0 for x in range(len(buckets)+1)] for y in range(len(machine.get_cores())+1)]
49             irq[0][0] = 'bucket us' 
50             for j,bucket in enumerate(buckets,start=1):
51                 irq[0][j] = '<'+ bucket
52             irq[0][-1] = '>'+ buckets [-2]
53             machine.start()
54             time.sleep(2)
55             for j,bucket in enumerate(buckets,start=1):
56                 for i,irqcore in enumerate(machine.get_cores(),start=1):
57                     old_irq[i][j] = machine.socket.irq_stats(irqcore,j-1)
58             time.sleep(float(self.runtime))
59             machine.stop()
60             for i,irqcore in enumerate(machine.get_cores(),start=1):
61                 irq[i][0]='core %s '%irqcore
62                 for j,bucket in enumerate(buckets,start=1):
63                     diff =  machine.socket.irq_stats(irqcore,j-1) - old_irq[i][j]
64                     if diff == 0:
65                         irq[i][j] = '0'
66                     else:
67                         irq[i][j] = str(round(old_div(diff,float(self.runtime)), 2))
68             RapidLog.info('Results for PROX instance %s'%machine.name)
69             for row in irq:
70                 RapidLog.info(''.join(['{:>12}'.format(item) for item in row]))
71         return (True)