Commit fe966bbd authored by Javier Honduvilla Coto's avatar Javier Honduvilla Coto Committed by yonghong-song

Use print function for Python 3 compatibility (#1748)

and add `from __future__ import print_function` where needed for Python3
print semantics in Python2
parent 0a436339
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
# #
# 15-Aug-2015 Brendan Gregg Created this. # 15-Aug-2015 Brendan Gregg Created this.
from __future__ import print_function
from bcc import BPF from bcc import BPF
from time import sleep from time import sleep
...@@ -37,7 +38,7 @@ print("Tracing... Hit Ctrl-C to end.") ...@@ -37,7 +38,7 @@ print("Tracing... Hit Ctrl-C to end.")
try: try:
sleep(99999999) sleep(99999999)
except KeyboardInterrupt: except KeyboardInterrupt:
print print()
# output # output
b["dist"].print_log2_hist("kbytes") b["dist"].print_log2_hist("kbytes")
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
# run in project examples directory with: # run in project examples directory with:
# sudo ./trace_fields.py" # sudo ./trace_fields.py"
from __future__ import print_function
from bcc import BPF from bcc import BPF
prog = """ prog = """
...@@ -16,5 +17,5 @@ int hello(void *ctx) { ...@@ -16,5 +17,5 @@ int hello(void *ctx) {
""" """
b = BPF(text=prog) b = BPF(text=prog)
b.attach_kprobe(event=b.get_syscall_fnname("clone"), fn_name="hello") b.attach_kprobe(event=b.get_syscall_fnname("clone"), fn_name="hello")
print "PID MESSAGE" print("PID MESSAGE")
b.trace_print(fmt="{1} {5}") b.trace_print(fmt="{1} {5}")
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
# #
# 15-Aug-2015 Brendan Gregg Created this. # 15-Aug-2015 Brendan Gregg Created this.
from __future__ import print_function
from bcc import BPF from bcc import BPF
from ctypes import c_ushort, c_int, c_ulonglong from ctypes import c_ushort, c_int, c_ulonglong
from time import sleep from time import sleep
...@@ -58,7 +59,7 @@ while (1): ...@@ -58,7 +59,7 @@ while (1):
except KeyboardInterrupt: except KeyboardInterrupt:
pass; do_exit = 1 pass; do_exit = 1
print print()
b["dist"].print_log2_hist("usecs") b["dist"].print_log2_hist("usecs")
b["dist"].clear() b["dist"].clear()
if do_exit: if do_exit:
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import print_function
class Node(object): class Node(object):
def __init__(self, n): def __init__(self, n):
...@@ -55,7 +56,7 @@ class Graph(object): ...@@ -55,7 +56,7 @@ class Graph(object):
sequence += [str(node)] sequence += [str(node)]
if node._behavioral_topo_sorting_mark == 1: if node._behavioral_topo_sorting_mark == 1:
if sequence is not None: if sequence is not None:
print "cycle", sequence print("cycle", sequence)
return False return False
if node._behavioral_topo_sorting_mark != 2: if node._behavioral_topo_sorting_mark != 2:
node._behavioral_topo_sorting_mark = 1 node._behavioral_topo_sorting_mark = 1
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
# Runs the compiler on all files in the 'testprograms' folder # Runs the compiler on all files in the 'testprograms' folder
# Writes outputs in the 'testoutputs' folder # Writes outputs in the 'testoutputs' folder
from __future__ import print_function
from bcc import BPF from bcc import BPF
import os, sys import os, sys
sys.path.append("../compiler") # To get hold of p4toEbpf sys.path.append("../compiler") # To get hold of p4toEbpf
...@@ -37,9 +38,9 @@ def main(): ...@@ -37,9 +38,9 @@ def main():
errors = 0 errors = 0
if not is_root(): if not is_root():
print "Loading EBPF programs requires root privilege." print("Loading EBPF programs requires root privilege.")
print "Will only test compilation, not loading." print("Will only test compilation, not loading.")
print "(Run with sudo to test program loading.)" print("(Run with sudo to test program loading.)")
for f in files: for f in files:
path = os.path.join(testpath, f) path = os.path.join(testpath, f)
...@@ -57,7 +58,7 @@ def main(): ...@@ -57,7 +58,7 @@ def main():
result = p4toEbpf.process(args) result = p4toEbpf.process(args)
if result.kind != "OK": if result.kind != "OK":
errors += 1 errors += 1
print path, result.error print(path, result.error)
set_error(result.kind, path, result.error) set_error(result.kind, path, result.error)
else: else:
# Try to load the compiled function # Try to load the compiled function
...@@ -72,11 +73,11 @@ def main(): ...@@ -72,11 +73,11 @@ def main():
filesDone += 1 filesDone += 1
print "Compiled", filesDone, "files", errors, "errors" print("Compiled", filesDone, "files", errors, "errors")
for key in sorted(filesFailed): for key in sorted(filesFailed):
print key, ":", len(filesFailed[key]), "programs" print(key, ":", len(filesFailed[key]), "programs")
for v in filesFailed[key]: for v in filesFailed[key]:
print "\t", v print("\t", v)
exit(len(filesFailed) != 0) exit(len(filesFailed) != 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment