diff options
Diffstat (limited to 'tools/perf/util/scripting-engines/trace-event-python.c')
-rw-r--r-- | tools/perf/util/scripting-engines/trace-event-python.c | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 46e9e19ab1ac..bc32e57d17be 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c | |||
@@ -908,14 +908,11 @@ static void python_process_tracepoint(struct perf_sample *sample, | |||
908 | if (_PyTuple_Resize(&t, n) == -1) | 908 | if (_PyTuple_Resize(&t, n) == -1) |
909 | Py_FatalError("error resizing Python tuple"); | 909 | Py_FatalError("error resizing Python tuple"); |
910 | 910 | ||
911 | if (!dict) { | 911 | if (!dict) |
912 | call_object(handler, t, handler_name); | 912 | call_object(handler, t, handler_name); |
913 | } else { | 913 | else |
914 | call_object(handler, t, default_handler_name); | 914 | call_object(handler, t, default_handler_name); |
915 | Py_DECREF(dict); | ||
916 | } | ||
917 | 915 | ||
918 | Py_XDECREF(all_entries_dict); | ||
919 | Py_DECREF(t); | 916 | Py_DECREF(t); |
920 | } | 917 | } |
921 | 918 | ||
@@ -1235,7 +1232,6 @@ static void python_process_general_event(struct perf_sample *sample, | |||
1235 | 1232 | ||
1236 | call_object(handler, t, handler_name); | 1233 | call_object(handler, t, handler_name); |
1237 | 1234 | ||
1238 | Py_DECREF(dict); | ||
1239 | Py_DECREF(t); | 1235 | Py_DECREF(t); |
1240 | } | 1236 | } |
1241 | 1237 | ||
@@ -1627,6 +1623,7 @@ static int python_generate_script(struct pevent *pevent, const char *outfile) | |||
1627 | fprintf(ofp, "# See the perf-script-python Documentation for the list " | 1623 | fprintf(ofp, "# See the perf-script-python Documentation for the list " |
1628 | "of available functions.\n\n"); | 1624 | "of available functions.\n\n"); |
1629 | 1625 | ||
1626 | fprintf(ofp, "from __future__ import print_function\n\n"); | ||
1630 | fprintf(ofp, "import os\n"); | 1627 | fprintf(ofp, "import os\n"); |
1631 | fprintf(ofp, "import sys\n\n"); | 1628 | fprintf(ofp, "import sys\n\n"); |
1632 | 1629 | ||
@@ -1636,10 +1633,10 @@ static int python_generate_script(struct pevent *pevent, const char *outfile) | |||
1636 | fprintf(ofp, "from Core import *\n\n\n"); | 1633 | fprintf(ofp, "from Core import *\n\n\n"); |
1637 | 1634 | ||
1638 | fprintf(ofp, "def trace_begin():\n"); | 1635 | fprintf(ofp, "def trace_begin():\n"); |
1639 | fprintf(ofp, "\tprint \"in trace_begin\"\n\n"); | 1636 | fprintf(ofp, "\tprint(\"in trace_begin\")\n\n"); |
1640 | 1637 | ||
1641 | fprintf(ofp, "def trace_end():\n"); | 1638 | fprintf(ofp, "def trace_end():\n"); |
1642 | fprintf(ofp, "\tprint \"in trace_end\"\n\n"); | 1639 | fprintf(ofp, "\tprint(\"in trace_end\")\n\n"); |
1643 | 1640 | ||
1644 | while ((event = trace_find_next_event(pevent, event))) { | 1641 | while ((event = trace_find_next_event(pevent, event))) { |
1645 | fprintf(ofp, "def %s__%s(", event->system, event->name); | 1642 | fprintf(ofp, "def %s__%s(", event->system, event->name); |
@@ -1675,7 +1672,7 @@ static int python_generate_script(struct pevent *pevent, const char *outfile) | |||
1675 | "common_secs, common_nsecs,\n\t\t\t" | 1672 | "common_secs, common_nsecs,\n\t\t\t" |
1676 | "common_pid, common_comm)\n\n"); | 1673 | "common_pid, common_comm)\n\n"); |
1677 | 1674 | ||
1678 | fprintf(ofp, "\t\tprint \""); | 1675 | fprintf(ofp, "\t\tprint(\""); |
1679 | 1676 | ||
1680 | not_first = 0; | 1677 | not_first = 0; |
1681 | count = 0; | 1678 | count = 0; |
@@ -1736,31 +1733,31 @@ static int python_generate_script(struct pevent *pevent, const char *outfile) | |||
1736 | fprintf(ofp, "%s", f->name); | 1733 | fprintf(ofp, "%s", f->name); |
1737 | } | 1734 | } |
1738 | 1735 | ||
1739 | fprintf(ofp, ")\n\n"); | 1736 | fprintf(ofp, "))\n\n"); |
1740 | 1737 | ||
1741 | fprintf(ofp, "\t\tprint 'Sample: {'+" | 1738 | fprintf(ofp, "\t\tprint('Sample: {'+" |
1742 | "get_dict_as_string(perf_sample_dict['sample'], ', ')+'}'\n\n"); | 1739 | "get_dict_as_string(perf_sample_dict['sample'], ', ')+'}')\n\n"); |
1743 | 1740 | ||
1744 | fprintf(ofp, "\t\tfor node in common_callchain:"); | 1741 | fprintf(ofp, "\t\tfor node in common_callchain:"); |
1745 | fprintf(ofp, "\n\t\t\tif 'sym' in node:"); | 1742 | 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'])"); | 1743 | fprintf(ofp, "\n\t\t\t\tprint(\"\\t[%%x] %%s\" %% (node['ip'], node['sym']['name']))"); |
1747 | fprintf(ofp, "\n\t\t\telse:"); | 1744 | fprintf(ofp, "\n\t\t\telse:"); |
1748 | fprintf(ofp, "\n\t\t\t\tprint \"\t[%%x]\" %% (node['ip'])\n\n"); | 1745 | fprintf(ofp, "\n\t\t\t\tprint(\"\t[%%x]\" %% (node['ip']))\n\n"); |
1749 | fprintf(ofp, "\t\tprint \"\\n\"\n\n"); | 1746 | fprintf(ofp, "\t\tprint()\n\n"); |
1750 | 1747 | ||
1751 | } | 1748 | } |
1752 | 1749 | ||
1753 | fprintf(ofp, "def trace_unhandled(event_name, context, " | 1750 | fprintf(ofp, "def trace_unhandled(event_name, context, " |
1754 | "event_fields_dict, perf_sample_dict):\n"); | 1751 | "event_fields_dict, perf_sample_dict):\n"); |
1755 | 1752 | ||
1756 | fprintf(ofp, "\t\tprint get_dict_as_string(event_fields_dict)\n"); | 1753 | fprintf(ofp, "\t\tprint(get_dict_as_string(event_fields_dict))\n"); |
1757 | fprintf(ofp, "\t\tprint 'Sample: {'+" | 1754 | fprintf(ofp, "\t\tprint('Sample: {'+" |
1758 | "get_dict_as_string(perf_sample_dict['sample'], ', ')+'}'\n\n"); | 1755 | "get_dict_as_string(perf_sample_dict['sample'], ', ')+'}')\n\n"); |
1759 | 1756 | ||
1760 | fprintf(ofp, "def print_header(" | 1757 | fprintf(ofp, "def print_header(" |
1761 | "event_name, cpu, secs, nsecs, pid, comm):\n" | 1758 | "event_name, cpu, secs, nsecs, pid, comm):\n" |
1762 | "\tprint \"%%-20s %%5u %%05u.%%09u %%8u %%-20s \" %% \\\n\t" | 1759 | "\tprint(\"%%-20s %%5u %%05u.%%09u %%8u %%-20s \" %% \\\n\t" |
1763 | "(event_name, cpu, secs, nsecs, pid, comm),\n\n"); | 1760 | "(event_name, cpu, secs, nsecs, pid, comm), end=\"\")\n\n"); |
1764 | 1761 | ||
1765 | fprintf(ofp, "def get_dict_as_string(a_dict, delimiter=' '):\n" | 1762 | fprintf(ofp, "def get_dict_as_string(a_dict, delimiter=' '):\n" |
1766 | "\treturn delimiter.join" | 1763 | "\treturn delimiter.join" |