History

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

Tony Jones committed 7 years ago

Commit ebf6c5c1 parent 1937b051 file · +14 −9Browse files

Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all

Unified · Split

tools/perf/scripts/python/export-to-sqlite.py+14−9
@@ -10,6 +10,8 @@ · 9 unmodified lines
10# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for10# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11# more details.11# more details.
12 12
13from __future__ import print_function
14
13import os15import os
14import sys16import sys
15import struct17import struct
@@ -60,11 +62,14 @@ perf_db_export_mode = True · 44 unmodified lines
60perf_db_export_calls = False62perf_db_export_calls = False
61perf_db_export_callchains = False63perf_db_export_callchains = False
62 64
65def printerr(*args, **keyword_args):
66 print(*args, file=sys.stderr, **keyword_args)
67
63def usage():68def 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
70if (len(sys.argv) < 2):75if (len(sys.argv) < 2):
@@ -100,7 +105,7 @@ def do_query_(q): · 29 unmodified lines
100 return105 return
101 raise Exception("Query failed: " + q.lastError().text())106 raise Exception("Query failed: " + q.lastError().text())
102 107
103print datetime.datetime.today(), "Creating database..."108print(datetime.datetime.today(), "Creating database ...")
104 109
105db_exists = False110db_exists = False
106try:111try:
@@ -378,7 +383,7 @@ if perf_db_export_calls: · 271 unmodified lines
378 call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")383 call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
379 384
380def trace_begin():385def 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 NULLs388 # 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 · 12 unmodified lines
397def trace_end():402def 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
409def trace_unhandled(event_name, context, event_fields_dict):414def trace_unhandled(event_name, context, event_fields_dict):
410 global unhandled_count415 global unhandled_count

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t