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
Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all
Unified · Split
| @@ -10,6 +10,8 @@ · 9 unmodified lines | ||
| 10 | 10 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | 11 | # more details. |
| 12 | 12 | |
| 13 | +from __future__ import print_function | |
| 14 | + | |
| 13 | 15 | import os |
| 14 | 16 | import sys |
| 15 | 17 | import struct |
| @@ -60,11 +62,14 @@ perf_db_export_mode = True · 44 unmodified lines | ||
| 60 | 62 | perf_db_export_calls = False |
| 61 | 63 | perf_db_export_callchains = False |
| 62 | 64 | |
| 65 | +def printerr(*args, **keyword_args): | |
| 66 | + print(*args, file=sys.stderr, **keyword_args) | |
| 67 | + | |
| 63 | 68 | def usage(): |
| 64 | − print >> sys.stderr, "Usage is: export-to-sqlite.py <database name> [<columns>] [<calls>] [<callchains>]" | |
| 65 | − print >> sys.stderr, "where: columns 'all' or 'branches'" | |
| 66 | − print >> sys.stderr, " calls 'calls' => create calls and call_paths table" | |
| 67 | − print >> sys.stderr, " callchains 'callchains' => create call_paths table" | |
| 69 | + printerr("Usage is: export-to-sqlite.py <database name> [<columns>] [<calls>] [<callchains>]"); | |
| 70 | + printerr("where: columns 'all' or 'branches'"); | |
| 71 | + printerr(" calls 'calls' => create calls and call_paths table"); | |
| 72 | + printerr(" callchains 'callchains' => create call_paths table"); | |
| 68 | 73 | raise Exception("Too few arguments") |
| 69 | 74 | |
| 70 | 75 | if (len(sys.argv) < 2): |
| @@ -100,7 +105,7 @@ def do_query_(q): · 29 unmodified lines | ||
| 100 | 105 | return |
| 101 | 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 | 110 | db_exists = False |
| 106 | 111 | try: |
| @@ -378,7 +383,7 @@ if perf_db_export_calls: · 271 unmodified lines | ||
| 378 | 383 | call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") |
| 379 | 384 | |
| 380 | 385 | def trace_begin(): |
| 381 | − print datetime.datetime.today(), "Writing records..." | |
| 386 | + print(datetime.datetime.today(), "Writing records...") | |
| 382 | 387 | do_query(query, 'BEGIN TRANSACTION') |
| 383 | 388 | # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs |
| 384 | 389 | evsel_table(0, "unknown") |
| @@ -397,14 +402,14 @@ unhandled_count = 0 · 12 unmodified lines | ||
| 397 | 402 | def trace_end(): |
| 398 | 403 | do_query(query, 'END TRANSACTION') |
| 399 | 404 | |
| 400 | − print datetime.datetime.today(), "Adding indexes" | |
| 405 | + print(datetime.datetime.today(), "Adding indexes") | |
| 401 | 406 | if perf_db_export_calls: |
| 402 | 407 | do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)') |
| 403 | 408 | do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)') |
| 404 | 409 | |
| 405 | 410 | if (unhandled_count): |
| 406 | − print datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events" | |
| 407 | − print datetime.datetime.today(), "Done" | |
| 411 | + print(datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events") | |
| 412 | + print(datetime.datetime.today(), "Done") | |
| 408 | 413 | |
| 409 | 414 | def trace_unhandled(event_name, context, event_fields_dict): |
| 410 | 415 | global unhandled_count |