Skip to contentSkip to conversation

scripts: Add Python 3 support to tracing/draw_functrace.py

PATCH Superseded Jeremy Cline 2 participants 4 messages Jul 20, 2018 – Jul 28, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts: Add Python 3 support to tracing/draw_functrace.py

Use the print function. This maintains Python 2 support and should have no functional change.

---
 scripts/tracing/draw_functrace.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/tracing/draw_functrace.py +2 -1
index db40fa04cd51..7d44e796d362 100755
@@ -20,6 +20,7 @@ Usage:
 	$ scripts/draw_functrace.py < raw_trace_func > draw_functrace
 	Then you have your drawn trace in draw_functrace
 """
+from __future__ import print_function
 
 
 import sys, re
@@ -123,7 +124,7 @@ def main():
 		tree = tree.getParent(caller)
 		tree = tree.calls(callee, calltime)
 
-	print CallTree.ROOT
+	print(CallTree.ROOT)
 
 if __name__ == "__main__":
 	main()
Signature · 1 line
2.17.1
#1 lore raw

2018-07-21 4:35 GMT+09:00 Jeremy Cline <[email protected]>:

Quoted 13 lines

Use the print function. This maintains Python 2 support and should have no functional change.

---
 scripts/tracing/draw_functrace.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/tracing/draw_functrace.py +0 -0
index db40fa04cd51..7d44e796d362 100755

scripts/tracing/draw_functrace.py Usage: · line 23

Quoted 4 lines
scripts/tracing/draw_functrace.py +1 -0
@@ -20,6 +20,7 @@ Usage:
        $ scripts/draw_functrace.py < raw_trace_func > draw_functrace
        Then you have your drawn trace in draw_functrace
 """
+from __future__ import print_function

What do you need this line for?

I have not tested this,
but I guess print(CallTree.ROOT) will work for Python 2.

Quoted 14 lines
scripts/tracing/draw_functrace.py +1 -2
 import sys, re
@@ -123,7 +124,7 @@ def main():
                tree = tree.getParent(caller)
                tree = tree.calls(callee, calltime)
 
-       print CallTree.ROOT
+       print(CallTree.ROOT)
 
 if __name__ == "__main__":
        main()
--

2.17.1

Signature · 2 lines
Best Regards
Masahiro Yamada
#2 lore raw
Quoted 21 lines · Masahiro Yamada

2018-07-21 4:35 GMT+09:00 Jeremy Cline <[email protected]>:

Quoted 13 lines

Use the print function. This maintains Python 2 support and should have no functional change.

---
 scripts/tracing/draw_functrace.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/tracing/draw_functrace.py +0 -0
index db40fa04cd51..7d44e796d362 100755

scripts/tracing/draw_functrace.py Usage: · line 23

Quoted 4 lines
scripts/tracing/draw_functrace.py +1 -0
@@ -20,6 +20,7 @@ Usage:
        $ scripts/draw_functrace.py < raw_trace_func > draw_functrace
        Then you have your drawn trace in draw_functrace
 """
+from __future__ import print_function

What do you need this line for?

Quoted 2 lines

I have not tested this,
but I guess print(CallTree.ROOT) will work for Python 2.

Although "print(CallTree.ROOT)" (as a statement) works in Python 2, its behavior is different than print (as a function) in Python 3. In this case, there's no additional arguments being provided so the behavior will match, but if someone added an argument it would work differently on Python 2 vs Python 3:

Python 2.7.15

Quoted 1 line

scripts/tracing/draw_functrace.py Usage: · line 24

Quoted 1 line
scripts/tracing/draw_functrace.py +0 -0
 > print("hello", "world")

('hello', 'world')

Python 3.6.6

Quoted 1 line

scripts/tracing/draw_functrace.py Usage: · line 25

Quoted 1 line
scripts/tracing/draw_functrace.py +0 -0
 > print("hello, "world")

File "<stdin>", line 1

    print("hello, "world")
                       ^

SyntaxError: invalid syntax

Importing the print_function works on Python 2.6+[0] and changes print to be a function in Python 2 so it'll behave the same in 2 and 3. Given that this script doesn't appear to change much it's probably not going to save anyone from making that mistake, though. Would you prefer a patch without it?

[0] https://docs.python.org/3/library/__future__.html

Regards,
Jeremy

Quoted 20 lines
Quoted 17 lines
scripts/tracing/draw_functrace.py +1 -2
 import sys, re
@@ -123,7 +124,7 @@ def main():
                tree = tree.getParent(caller)
                tree = tree.calls(callee, calltime)
 
-       print CallTree.ROOT
+       print(CallTree.ROOT)
 
 if __name__ == "__main__":
        main()
--

2.17.1

#3 lore raw

2018-07-26 0:01 GMT+09:00 Jeremy Cline <[email protected]>:

Quoted 33 lines · Masahiro Yamada
Quoted 21 lines

2018-07-21 4:35 GMT+09:00 Jeremy Cline <[email protected]>:

Quoted 13 lines

Use the print function. This maintains Python 2 support and should have no functional change.

---
 scripts/tracing/draw_functrace.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/tracing/draw_functrace.py +0 -0
index db40fa04cd51..7d44e796d362 100755

scripts/tracing/draw_functrace.py Usage: · line 23

Quoted 4 lines
scripts/tracing/draw_functrace.py +1 -0
@@ -20,6 +20,7 @@ Usage:
        $ scripts/draw_functrace.py < raw_trace_func > draw_functrace
        Then you have your drawn trace in draw_functrace
 """
+from __future__ import print_function

What do you need this line for?

Quoted 2 lines

I have not tested this,
but I guess print(CallTree.ROOT) will work for Python 2.

Although "print(CallTree.ROOT)" (as a statement) works in Python 2, its behavior is different than print (as a function) in Python 3. In this case, there's no additional arguments being provided so the behavior will match, but if someone added an argument it would work differently on Python 2 vs Python 3:

Python 2.7.15

Quoted 1 line

scripts/tracing/draw_functrace.py Usage: · line 24

Quoted 1 line
scripts/tracing/draw_functrace.py +0 -0
 > print("hello", "world")
Quoted 8 lines

('hello', 'world')

Python 3.6.6

Quoted 1 line

scripts/tracing/draw_functrace.py Usage: · line 25

Quoted 1 line
scripts/tracing/draw_functrace.py +0 -0
 > print("hello, "world")

File "<stdin>", line 1

    print("hello, "world")
                       ^

SyntaxError: invalid syntax

Yes, I know this.

Quoted 5 lines

Importing the print_function works on Python 2.6+[0] and changes print to be a function in Python 2 so it'll behave the same in 2 and 3. Given that this script doesn't appear to change much it's probably not going to save anyone from making that mistake, though. Would you prefer a patch without it?

Either will do.
If it is tedious to respin, I will pick this up.

I saw only one simple print statement in this script, so I wanted to ask you if this had some reason I might be missing.

Anyway, we will remove 'from __future__ import print_function' when Python 2 retires.

Quoted 29 lines

[0] https://docs.python.org/3/library/__future__.html

Regards,
Jeremy

Quoted 9 lines
Quoted 9 lines
scripts/tracing/draw_functrace.py +0 -0
 import sys, re
@@ -123,7 +124,7 @@ def main():
                tree = tree.getParent(caller)
                tree = tree.calls(callee, calltime)
 
Quoted 11 lines
Quoted 8 lines
scripts/tracing/draw_functrace.py +1 -2
-       print CallTree.ROOT
+       print(CallTree.ROOT)
 
 if __name__ == "__main__":
        main()
--

2.17.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Best Regards
Masahiro Yamada