[PATCH] perf scripts python: Add Python 3 support to export-to-postgresql.py

From: Seeteena Thoufeek
Date: Wed Jan 16 2019 - 11:25:03 EST


Support both Python 2 and Python 3 in export-to-postgresql.py. ``print``
is now a function rather than a statement. This should have no functional
change.

Signed-off-by: Seeteena Thoufeek <s1seetee@xxxxxxxxxxxxxxxxxx>
Reviewed-by: Ravi Bangoria <ravi.bangoria@xxxxxxxxxxxxx>
---
tools/perf/scripts/python/export-to-postgresql.py | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/tools/perf/scripts/python/export-to-postgresql.py b/tools/perf/scripts/python/export-to-postgresql.py
index 0564dd7..6774909 100644
--- a/tools/perf/scripts/python/export-to-postgresql.py
+++ b/tools/perf/scripts/python/export-to-postgresql.py
@@ -273,7 +273,7 @@ def do_query(q, s):
return
raise Exception("Query failed: " + q.lastError().text())

-print datetime.datetime.today(), "Creating database..."
+print(datetime.datetime.today(), "Creating database...")

db = QSqlDatabase.addDatabase('QPSQL')
query = QSqlQuery(db)
@@ -564,7 +564,7 @@ if perf_db_export_calls:
call_file = open_output_file("call_table.bin")

def trace_begin():
- print datetime.datetime.today(), "Writing to intermediate files..."
+ print(datetime.datetime.today(), "Writing to intermediate files...")
# id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs
evsel_table(0, "unknown")
machine_table(0, 0, "unknown")
@@ -579,7 +579,7 @@ def trace_begin():
unhandled_count = 0

def trace_end():
- print datetime.datetime.today(), "Copying to database..."
+ print(datetime.datetime.today(), "Copying to database...")
copy_output_file(evsel_file, "selected_events")
copy_output_file(machine_file, "machines")
copy_output_file(thread_file, "threads")
@@ -594,7 +594,7 @@ def trace_end():
if perf_db_export_calls:
copy_output_file(call_file, "calls")

- print datetime.datetime.today(), "Removing intermediate files..."
+ print(datetime.datetime.today(), "Removing intermediate files...")
remove_output_file(evsel_file)
remove_output_file(machine_file)
remove_output_file(thread_file)
@@ -609,7 +609,7 @@ def trace_end():
if perf_db_export_calls:
remove_output_file(call_file)
os.rmdir(output_dir_name)
- print datetime.datetime.today(), "Adding primary keys"
+ print(datetime.datetime.today(), "Adding primary keys")
do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)')
do_query(query, 'ALTER TABLE machines ADD PRIMARY KEY (id)')
do_query(query, 'ALTER TABLE threads ADD PRIMARY KEY (id)')
@@ -624,7 +624,7 @@ def trace_end():
if perf_db_export_calls:
do_query(query, 'ALTER TABLE calls ADD PRIMARY KEY (id)')

- print datetime.datetime.today(), "Adding foreign keys"
+ print(datetime.datetime.today(), "Adding foreign keys")
do_query(query, 'ALTER TABLE threads '
'ADD CONSTRAINT machinefk FOREIGN KEY (machine_id) REFERENCES machines (id),'
'ADD CONSTRAINT processfk FOREIGN KEY (process_id) REFERENCES threads (id)')
@@ -659,8 +659,8 @@ def trace_end():
do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)')

if (unhandled_count):
- print datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events"
- print datetime.datetime.today(), "Done"
+ print(datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events")
+ print(datetime.datetime.today(), "Done")

def trace_unhandled(event_name, context, event_fields_dict):
global unhandled_count
--
1.8.3.1