4 ## Copyright (c) 2010-2017 Intel Corporation
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
10 ## http://www.apache.org/licenses/LICENSE-2.0
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.
26 def __init__(self, value, tsc):
30 def measure_tx(prox_instance, port_id):
31 port_tx_pkt = "port(" + str(port_id) + ").tx.packets"
32 port_tsc = "port(" + str(port_id) + ").tsc";
33 cmd = "stats " + port_tx_pkt + "," + port_tsc;
34 reply = prox_instance.send(cmd).recv().split(",");
36 return data_point(int(reply[0]), int(reply[1]));
38 def get_rate(first, second, hz):
39 tsc_diff = second.tsc - first.tsc;
40 value_diff = second.value - first.value;
42 return int(Decimal(value_diff * hz) / tsc_diff)
44 # make sure that prox has been started with the -t parameter
45 prox_instance = prox("127.0.0.1")
46 print "Connected to prox"
48 hz = int(prox_instance.send("stats hz").recv());
50 print "System is running at " + str(hz) + " Hz"
52 print "Showing TX pps on port 0"
56 print "Requesting new data every " + str(update_interval) + "s"
58 measure = measure_tx(prox_instance, 0);
60 sleep(update_interval)
61 measure2 = measure_tx(prox_instance, 0);
63 # since PROX takes measurements at a configured rate (through
64 # update interval command or throw -r command line parameter), it
65 # might be possible that two consecutive measurements report the
66 # same. To get updates at a frequency higher than 1 Hz,
67 # reconfigure prox as mentioned above.
69 if (measure.tsc == measure2.tsc):
72 print get_rate(measure, measure2, hz);