diff options
author | Tony Jones <tonyj@suse.de> | 2019-03-08 19:05:17 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-03-11 15:12:59 -0400 |
commit | ebf6c5c181abe9309788c6241d39602a1ce18723 (patch) | |
tree | a24d4087ffcc875d251be75c4f7bb70ac8c0d158 /tools/perf/scripts/python/export-to-sqlite.py | |
parent | 1937b0560c3ea43b1b0f7d3617949ca50de8f8c0 (diff) |
perf script python: Add Python3 support to export-to-sqlite.py
Support both Python2 and Python3 in the export-to-sqlite.py script
The use of 'from __future__' implies the minimum supported Python2 version
is now v2.6
Signed-off-by: Tony Jones <tonyj@suse.de>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
Link: http://lkml.kernel.org/r/20190309000518.2438-4-tonyj@suse.de
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/scripts/python/export-to-sqlite.py')
-rw-r--r-- | tools/perf/scripts/python/export-to-sqlite.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/tools/perf/scripts/python/export-to-sqlite.py b/tools/perf/scripts/python/export-to-sqlite.py index eb63e6c7107f..3da338243aed 100644 --- a/tools/perf/scripts/python/export-to-sqlite.py +++ b/tools/perf/scripts/python/export-to-sqlite.py | |||
@@ -10,6 +10,8 @@ | |||
10 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | 10 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
11 | # more details. | 11 | # more details. |
12 | 12 | ||
13 | from __future__ import print_function | ||
14 | |||
13 | import os | 15 | import os |
14 | import sys | 16 | import sys |
15 | import struct | 17 | import struct |
@@ -60,11 +62,14 @@ perf_db_export_mode = True | |||
60 | perf_db_export_calls = False | 62 | perf_db_export_calls = False |
61 | perf_db_export_callchains = False | 63 | perf_db_export_callchains = False |
62 | 64 | ||
65 | def printerr(*args, **keyword_args): | ||
66 | print(*args, file=sys.stderr, **keyword_args) | ||
67 | |||
63 | def usage(): | 68 | def usage(): |
64 | print >> sys.stderr, "Usage is: export-to-sqlite.py <database name> [<columns>] [<calls>] [<callchains>]" | 69 | printerr("Usage is: export-to-sqlite.py <database name> [<columns>] [<calls>] [<callchains>]"); |
65 | print >> sys.stderr, "where: columns 'all' or 'branches'" | 70 | printerr("where: columns 'all' or 'branches'"); |
66 | print >> sys.stderr, " calls 'calls' => create calls and call_paths table" | 71 | printerr(" calls 'calls' => create calls and call_paths table"); |
67 | print >> sys.stderr, " callchains 'callchains' => create call_paths table" | 72 | printerr(" callchains 'callchains' => create call_paths table"); |
68 | raise Exception("Too few arguments") | 73 | raise Exception("Too few arguments") |
69 | 74 | ||
70 | if (len(sys.argv) < 2): | 75 | if (len(sys.argv) < 2): |
@@ -100,7 +105,7 @@ def do_query_(q): | |||
100 | return | 105 | return |
101 | raise Exception("Query failed: " + q.lastError().text()) | 106 | raise Exception("Query failed: " + q.lastError().text()) |
102 | 107 | ||
103 | print datetime.datetime.today(), "Creating database..." | 108 | print(datetime.datetime.today(), "Creating database ...") |
104 | 109 | ||
105 | db_exists = False | 110 | db_exists = False |
106 | try: | 111 | try: |
@@ -378,7 +383,7 @@ if perf_db_export_calls: | |||
378 | call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") | 383 | call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") |
379 | 384 | ||
380 | def trace_begin(): | 385 | def trace_begin(): |
381 | print datetime.datetime.today(), "Writing records..." | 386 | print(datetime.datetime.today(), "Writing records...") |
382 | do_query(query, 'BEGIN TRANSACTION') | 387 | do_query(query, 'BEGIN TRANSACTION') |
383 | # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs | 388 | # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs |
384 | evsel_table(0, "unknown") | 389 | evsel_table(0, "unknown") |
@@ -397,14 +402,14 @@ unhandled_count = 0 | |||
397 | def trace_end(): | 402 | def trace_end(): |
398 | do_query(query, 'END TRANSACTION') | 403 | do_query(query, 'END TRANSACTION') |
399 | 404 | ||
400 | print datetime.datetime.today(), "Adding indexes" | 405 | print(datetime.datetime.today(), "Adding indexes") |
401 | if perf_db_export_calls: | 406 | if perf_db_export_calls: |
402 | do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)') | 407 | do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)') |
403 | do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)') | 408 | do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)') |
404 | 409 | ||
405 | if (unhandled_count): | 410 | if (unhandled_count): |
406 | print datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events" | 411 | print(datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events") |
407 | print datetime.datetime.today(), "Done" | 412 | print(datetime.datetime.today(), "Done") |
408 | 413 | ||
409 | def trace_unhandled(event_name, context, event_fields_dict): | 414 | def trace_unhandled(event_name, context, event_fields_dict): |
410 | global unhandled_count | 415 | global unhandled_count |