linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scripts: Add Python 3 support to tracing/draw_functrace.py
@ 2018-07-20 19:35 Jeremy Cline
  2018-07-25 14:39 ` Masahiro Yamada
  0 siblings, 1 reply; 4+ messages in thread
From: Jeremy Cline @ 2018-07-20 19:35 UTC (permalink / raw)
  To: Masahiro Yamada, Michal Marek
  Cc: Frederic Weisbecker, linux-kbuild, linux-kernel, Jeremy Cline

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

Signed-off-by: Jeremy Cline <jcline@redhat.com>
---
 scripts/tracing/draw_functrace.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/scripts/tracing/draw_functrace.py b/scripts/tracing/draw_functrace.py
index db40fa04cd51..7d44e796d362 100755
--- a/scripts/tracing/draw_functrace.py
+++ b/scripts/tracing/draw_functrace.py
@@ -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()
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] scripts: Add Python 3 support to tracing/draw_functrace.py
  2018-07-20 19:35 [PATCH] scripts: Add Python 3 support to tracing/draw_functrace.py Jeremy Cline
@ 2018-07-25 14:39 ` Masahiro Yamada
  2018-07-25 15:01   ` Jeremy Cline
  0 siblings, 1 reply; 4+ messages in thread
From: Masahiro Yamada @ 2018-07-25 14:39 UTC (permalink / raw)
  To: Jeremy Cline
  Cc: Michal Marek, Frederic Weisbecker, Linux Kbuild mailing list,
	Linux Kernel Mailing List

2018-07-21 4:35 GMT+09:00 Jeremy Cline <jcline@redhat.com>:
> Use the print function. This maintains Python 2 support and should have
> no functional change.
>
> Signed-off-by: Jeremy Cline <jcline@redhat.com>
> ---
>  scripts/tracing/draw_functrace.py | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/tracing/draw_functrace.py b/scripts/tracing/draw_functrace.py
> index db40fa04cd51..7d44e796d362 100755
> --- a/scripts/tracing/draw_functrace.py
> +++ b/scripts/tracing/draw_functrace.py
> @@ -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.



>
>  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
>



-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] scripts: Add Python 3 support to tracing/draw_functrace.py
  2018-07-25 14:39 ` Masahiro Yamada
@ 2018-07-25 15:01   ` Jeremy Cline
  2018-07-28  5:41     ` Masahiro Yamada
  0 siblings, 1 reply; 4+ messages in thread
From: Jeremy Cline @ 2018-07-25 15:01 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: Michal Marek, Frederic Weisbecker, Linux Kbuild mailing list,
	Linux Kernel Mailing List

On 07/25/2018 10:39 AM, Masahiro Yamada wrote:
> 2018-07-21 4:35 GMT+09:00 Jeremy Cline <jcline@redhat.com>:
>> Use the print function. This maintains Python 2 support and should have
>> no functional change.
>>
>> Signed-off-by: Jeremy Cline <jcline@redhat.com>
>> ---
>>  scripts/tracing/draw_functrace.py | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/scripts/tracing/draw_functrace.py b/scripts/tracing/draw_functrace.py
>> index db40fa04cd51..7d44e796d362 100755
>> --- a/scripts/tracing/draw_functrace.py
>> +++ b/scripts/tracing/draw_functrace.py
>> @@ -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.

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
>>> print("hello", "world")
('hello', 'world')

Python 3.6.6
>>> 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

> 
> 
> 
>>
>>  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
>>
> 
> 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] scripts: Add Python 3 support to tracing/draw_functrace.py
  2018-07-25 15:01   ` Jeremy Cline
@ 2018-07-28  5:41     ` Masahiro Yamada
  0 siblings, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2018-07-28  5:41 UTC (permalink / raw)
  To: Jeremy Cline
  Cc: Michal Marek, Frederic Weisbecker, Linux Kbuild mailing list,
	Linux Kernel Mailing List

2018-07-26 0:01 GMT+09:00 Jeremy Cline <jcline@redhat.com>:
> On 07/25/2018 10:39 AM, Masahiro Yamada wrote:
>> 2018-07-21 4:35 GMT+09:00 Jeremy Cline <jcline@redhat.com>:
>>> Use the print function. This maintains Python 2 support and should have
>>> no functional change.
>>>
>>> Signed-off-by: Jeremy Cline <jcline@redhat.com>
>>> ---
>>>  scripts/tracing/draw_functrace.py | 3 ++-
>>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/scripts/tracing/draw_functrace.py b/scripts/tracing/draw_functrace.py
>>> index db40fa04cd51..7d44e796d362 100755
>>> --- a/scripts/tracing/draw_functrace.py
>>> +++ b/scripts/tracing/draw_functrace.py
>>> @@ -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.
>
> 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
>>>> print("hello", "world")
> ('hello', 'world')
>
> Python 3.6.6
>>>> print("hello, "world")
>   File "<stdin>", line 1
>     print("hello, "world")
>                        ^
> SyntaxError: invalid syntax

Yes, I know this.


> 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.



> [0] https://docs.python.org/3/library/__future__.html
>
> Regards,
> Jeremy
>
>>
>>
>>
>>>
>>>  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
>>>
>>
>>
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-07-28  5:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-20 19:35 [PATCH] scripts: Add Python 3 support to tracing/draw_functrace.py Jeremy Cline
2018-07-25 14:39 ` Masahiro Yamada
2018-07-25 15:01   ` Jeremy Cline
2018-07-28  5:41     ` Masahiro Yamada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).