lkml.org 
[lkml]   [2019]   [Jan]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v3] perf scripts python: Add Python 3 support to export-to-postgresql.py
Date
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.

Also, handles the conversion of "print >> sys.stderr".

Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Reviewed-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
---
tools/perf/scripts/python/export-to-postgresql.py | 25 ++++++++++++-----------
1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/tools/perf/scripts/python/export-to-postgresql.py b/tools/perf/scripts/python/export-to-postgresql.py
index 0564dd7..b2ff375 100644
--- a/tools/perf/scripts/python/export-to-postgresql.py
+++ b/tools/perf/scripts/python/export-to-postgresql.py
@@ -9,6 +9,7 @@
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
+from __future__ import print_function

import os
import sys
@@ -236,10 +237,10 @@ perf_db_export_callchains = False


def usage():
- print >> sys.stderr, "Usage is: export-to-postgresql.py <database name> [<columns>] [<calls>] [<callchains>]"
- print >> sys.stderr, "where: columns 'all' or 'branches'"
- print >> sys.stderr, " calls 'calls' => create calls and call_paths table"
- print >> sys.stderr, " callchains 'callchains' => create call_paths table"
+ sys.stderr.write("Usage is: export-to-postgresql.py <database name> [<columns>] [<calls>] [<callchains>]");
+ sys.stderr.write("where: columns 'all' or 'branches'");
+ sys.stderr.write(" calls 'calls' => create calls and call_paths table");
+ sys.stderr.write(" callchains 'callchains' => create call_paths table");
raise Exception("Too few arguments")

if (len(sys.argv) < 2):
@@ -273,7 +274,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 +565,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 +580,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 +595,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 +610,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 +625,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 +660,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
\
 
 \ /
  Last update: 2019-01-21 11:40    [W:0.027 / U:0.416 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site