Skip to content

Commit

Permalink
Use print function for Python 3 compatibility (iovisor#1748)
Browse files Browse the repository at this point in the history
and add `from __future__ import print_function` where needed for Python3
print semantics in Python2
  • Loading branch information
javierhonduco authored and yonghong-song committed May 10, 2018
1 parent 0a43633 commit fe966bb
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
3 changes: 2 additions & 1 deletion examples/tracing/bitehist.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#
# 15-Aug-2015 Brendan Gregg Created this.

from __future__ import print_function
from bcc import BPF
from time import sleep

Expand All @@ -37,7 +38,7 @@
try:
sleep(99999999)
except KeyboardInterrupt:
print
print()

# output
b["dist"].print_log2_hist("kbytes")
3 changes: 2 additions & 1 deletion examples/tracing/trace_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# run in project examples directory with:
# sudo ./trace_fields.py"

from __future__ import print_function
from bcc import BPF

prog = """
Expand All @@ -16,5 +17,5 @@
"""
b = BPF(text=prog)
b.attach_kprobe(event=b.get_syscall_fnname("clone"), fn_name="hello")
print "PID MESSAGE"
print("PID MESSAGE")
b.trace_print(fmt="{1} {5}")
3 changes: 2 additions & 1 deletion examples/tracing/vfsreadlat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#
# 15-Aug-2015 Brendan Gregg Created this.

from __future__ import print_function
from bcc import BPF
from ctypes import c_ushort, c_int, c_ulonglong
from time import sleep
Expand Down Expand Up @@ -58,7 +59,7 @@ def usage():
except KeyboardInterrupt:
pass; do_exit = 1

print
print()
b["dist"].print_log2_hist("usecs")
b["dist"].clear()
if do_exit:
Expand Down
3 changes: 2 additions & 1 deletion src/cc/frontends/p4/compiler/topoSorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

# -*- coding: utf-8 -*-

from __future__ import print_function

class Node(object):
def __init__(self, n):
Expand Down Expand Up @@ -55,7 +56,7 @@ def visit(node, topo_sorting, sequence=None):
sequence += [str(node)]
if node._behavioral_topo_sorting_mark == 1:
if sequence is not None:
print "cycle", sequence
print("cycle", sequence)
return False
if node._behavioral_topo_sorting_mark != 2:
node._behavioral_topo_sorting_mark = 1
Expand Down
15 changes: 8 additions & 7 deletions src/cc/frontends/p4/test/testP4toEbpf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Runs the compiler on all files in the 'testprograms' folder
# Writes outputs in the 'testoutputs' folder

from __future__ import print_function
from bcc import BPF
import os, sys
sys.path.append("../compiler") # To get hold of p4toEbpf
Expand Down Expand Up @@ -37,9 +38,9 @@ def main():
errors = 0

if not is_root():
print "Loading EBPF programs requires root privilege."
print "Will only test compilation, not loading."
print "(Run with sudo to test program loading.)"
print("Loading EBPF programs requires root privilege.")
print("Will only test compilation, not loading.")
print("(Run with sudo to test program loading.)")

for f in files:
path = os.path.join(testpath, f)
Expand All @@ -57,7 +58,7 @@ def main():
result = p4toEbpf.process(args)
if result.kind != "OK":
errors += 1
print path, result.error
print(path, result.error)
set_error(result.kind, path, result.error)
else:
# Try to load the compiled function
Expand All @@ -72,11 +73,11 @@ def main():

filesDone += 1

print "Compiled", filesDone, "files", errors, "errors"
print("Compiled", filesDone, "files", errors, "errors")
for key in sorted(filesFailed):
print key, ":", len(filesFailed[key]), "programs"
print(key, ":", len(filesFailed[key]), "programs")
for v in filesFailed[key]:
print "\t", v
print("\t", v)
exit(len(filesFailed) != 0)


Expand Down

0 comments on commit fe966bb

Please sign in to comment.