@@ -1627,6 +1627,7 @@ static int python_generate_script(struct pevent *pevent, const char *outfile)
1627
1627
fprintf (ofp , "# See the perf-script-python Documentation for the list "
1628
1628
"of available functions.\n\n" );
1629
1629
1630
+ fprintf (ofp , "from __future__ import print_function\n\n" );
1630
1631
fprintf (ofp , "import os\n" );
1631
1632
fprintf (ofp , "import sys\n\n" );
1632
1633
@@ -1636,10 +1637,10 @@ static int python_generate_script(struct pevent *pevent, const char *outfile)
1636
1637
fprintf (ofp , "from Core import *\n\n\n" );
1637
1638
1638
1639
fprintf (ofp , "def trace_begin():\n" );
1639
- fprintf (ofp , "\tprint \"in trace_begin\"\n\n" );
1640
+ fprintf (ofp , "\tprint( \"in trace_begin\") \n\n" );
1640
1641
1641
1642
fprintf (ofp , "def trace_end():\n" );
1642
- fprintf (ofp , "\tprint \"in trace_end\"\n\n" );
1643
+ fprintf (ofp , "\tprint( \"in trace_end\") \n\n" );
1643
1644
1644
1645
while ((event = trace_find_next_event (pevent , event ))) {
1645
1646
fprintf (ofp , "def %s__%s(" , event -> system , event -> name );
@@ -1675,7 +1676,7 @@ static int python_generate_script(struct pevent *pevent, const char *outfile)
1675
1676
"common_secs, common_nsecs,\n\t\t\t"
1676
1677
"common_pid, common_comm)\n\n" );
1677
1678
1678
- fprintf (ofp , "\t\tprint \"" );
1679
+ fprintf (ofp , "\t\tprint( \"" );
1679
1680
1680
1681
not_first = 0 ;
1681
1682
count = 0 ;
@@ -1736,31 +1737,31 @@ static int python_generate_script(struct pevent *pevent, const char *outfile)
1736
1737
fprintf (ofp , "%s" , f -> name );
1737
1738
}
1738
1739
1739
- fprintf (ofp , ")\n\n" );
1740
+ fprintf (ofp , ")) \n\n" );
1740
1741
1741
- fprintf (ofp , "\t\tprint 'Sample: {'+"
1742
- "get_dict_as_string(perf_sample_dict['sample'], ', ')+'}'\n\n" );
1742
+ fprintf (ofp , "\t\tprint( 'Sample: {'+"
1743
+ "get_dict_as_string(perf_sample_dict['sample'], ', ')+'}') \n\n" );
1743
1744
1744
1745
fprintf (ofp , "\t\tfor node in common_callchain:" );
1745
1746
fprintf (ofp , "\n\t\t\tif 'sym' in node:" );
1746
- fprintf (ofp , "\n\t\t\t\tprint \"\\t[%%x] %%s\" %% (node['ip'], node['sym']['name'])" );
1747
+ fprintf (ofp , "\n\t\t\t\tprint( \"\\t[%%x] %%s\" %% (node['ip'], node['sym']['name']) )" );
1747
1748
fprintf (ofp , "\n\t\t\telse:" );
1748
- fprintf (ofp , "\n\t\t\t\tprint \"\t[%%x]\" %% (node['ip'])\n\n" );
1749
- fprintf (ofp , "\t\tprint \"\\n\" \n\n" );
1749
+ fprintf (ofp , "\n\t\t\t\tprint( \"\t[%%x]\" %% (node['ip']) )\n\n" );
1750
+ fprintf (ofp , "\t\tprint() \n\n" );
1750
1751
1751
1752
}
1752
1753
1753
1754
fprintf (ofp , "def trace_unhandled(event_name, context, "
1754
1755
"event_fields_dict, perf_sample_dict):\n" );
1755
1756
1756
- fprintf (ofp , "\t\tprint get_dict_as_string(event_fields_dict)\n" );
1757
- fprintf (ofp , "\t\tprint 'Sample: {'+"
1758
- "get_dict_as_string(perf_sample_dict['sample'], ', ')+'}'\n\n" );
1757
+ fprintf (ofp , "\t\tprint( get_dict_as_string(event_fields_dict) )\n" );
1758
+ fprintf (ofp , "\t\tprint( 'Sample: {'+"
1759
+ "get_dict_as_string(perf_sample_dict['sample'], ', ')+'}') \n\n" );
1759
1760
1760
1761
fprintf (ofp , "def print_header("
1761
1762
"event_name, cpu, secs, nsecs, pid, comm):\n"
1762
- "\tprint \"%%-20s %%5u %%05u.%%09u %%8u %%-20s \" %% \\\n\t"
1763
- "(event_name, cpu, secs, nsecs, pid, comm),\n\n" );
1763
+ "\tprint( \"%%-20s %%5u %%05u.%%09u %%8u %%-20s \" %% \\\n\t"
1764
+ "(event_name, cpu, secs, nsecs, pid, comm), end=\"\") \n\n" );
1764
1765
1765
1766
fprintf (ofp , "def get_dict_as_string(a_dict, delimiter=' '):\n"
1766
1767
"\treturn delimiter.join"
0 commit comments