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
1010 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
1111 # more details.
1212
13+from __future__ import print_function
14+
1315 import os
1416 import sys
1517 import struct
@@ -60,11 +62,14 @@ perf_db_export_mode = True · 44 unmodified lines
6062 perf_db_export_calls = False
6163 perf_db_export_callchains = False
6264
65+def printerr(*args, **keyword_args):
66+ print(*args, file=sys.stderr, **keyword_args)
67+
6368 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");
6873 raise Exception("Too few arguments")
6974
7075 if (len(sys.argv) < 2):
@@ -100,7 +105,7 @@ def do_query_(q): · 29 unmodified lines
100105 return
101106 raise Exception("Query failed: " + q.lastError().text())
102107
103−print datetime.datetime.today(), "Creating database..."
108+print(datetime.datetime.today(), "Creating database ...")
104109
105110 db_exists = False
106111 try:
@@ -378,7 +383,7 @@ if perf_db_export_calls: · 271 unmodified lines
378383 call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
379384
380385 def trace_begin():
381− print datetime.datetime.today(), "Writing records..."
386+ print(datetime.datetime.today(), "Writing records...")
382387 do_query(query, 'BEGIN TRANSACTION')
383388 # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs
384389 evsel_table(0, "unknown")
@@ -397,14 +402,14 @@ unhandled_count = 0 · 12 unmodified lines
397402 def trace_end():
398403 do_query(query, 'END TRANSACTION')
399404
400− print datetime.datetime.today(), "Adding indexes"
405+ print(datetime.datetime.today(), "Adding indexes")
401406 if perf_db_export_calls:
402407 do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)')
403408 do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)')
404409
405410 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")
408413
409414 def trace_unhandled(event_name, context, event_fields_dict):
410415 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