Skip to content

Commit

Permalink
fix netqtop python3 compatible (iovisor#3140)
Browse files Browse the repository at this point in the history
* fix netqtop python3 compatible
* delete import types
  • Loading branch information
NPC51129 committed Oct 19, 2020
1 parent 6ba4dc1 commit ec3747e
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions tools/netqtop.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/python

from __future__ import print_function
from bcc import BPF
from ctypes import *
import argparse
import os
from time import sleep,time,localtime,asctime
import types

# pre defines -------------------------------
ROOT_PATH = "/sys/class/net"
Expand All @@ -28,7 +28,7 @@ def to_str(num):
elif num > 1000:
return str(round(num/1024.0, 2)) + 'K'
else:
if type(num) == types.FloatType:
if isinstance(num, float):
return str(round(num, 2))
else:
return str(num)
Expand All @@ -50,9 +50,10 @@ def print_table(table, qnum):
headers.append("BPS")
headers.append("PPS")

print(" ", end="")
for hd in headers:
print(hd.center(COL_WIDTH))
print
print( "%-11s" % hd, end="")
print()

# ------- calculates --------------
qids=[]
Expand Down Expand Up @@ -97,42 +98,42 @@ def print_table(table, qnum):
avg = 0
if data[2] != 0:
avg = data[1] / data[2]
print("%5d %11s %10s %10s %10s %10s %10s" % (
print(" %-11d%-11s%-11s%-11s%-11s%-11s%-11s" % (
data[0],
to_str(avg),
to_str(data[3]),
to_str(data[4]),
to_str(data[5]),
to_str(data[6]),
to_str(data[7])
)),
), end="")
if args.throughput:
BPS = data[1] / print_interval
PPS = data[2] / print_interval
print("%10s %10s" % (
print("%-11s%-11s" % (
to_str(BPS),
to_str(PPS)
))
else:
print
print()

# ------- print total --------------
print(" Total %10s %10s %10s %10s %10s %10s" % (
print(" Total %-11s%-11s%-11s%-11s%-11s%-11s" % (
to_str(tAVG),
to_str(tGroup[0]),
to_str(tGroup[1]),
to_str(tGroup[2]),
to_str(tGroup[3]),
to_str(tGroup[4])
)),
), end="")

if args.throughput:
print("%10s %10s" % (
print("%-11s%-11s" % (
to_str(tBPS),
to_str(tPPS)
))
else:
print
print()


def print_result(b):
Expand All @@ -152,7 +153,7 @@ def print_result(b):
if args.throughput:
print("-"*95)
else:
print("-"*76)
print("-"*77)

############## specify network interface #################
parser = argparse.ArgumentParser(description="")
Expand Down

0 comments on commit ec3747e

Please sign in to comment.