aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/scripts/python/export-to-postgresql.py
diff options
context:
space:
mode:
authorTony Jones <tonyj@suse.de>2019-03-08 19:05:18 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2019-03-11 15:13:02 -0400
commit49f93bbf17e6267eb34e0c12a9813f3a8723749e (patch)
tree7536067e5052a0e408babe7874d22705f75c4c42 /tools/perf/scripts/python/export-to-postgresql.py
parentebf6c5c181abe9309788c6241d39602a1ce18723 (diff)
perf script python: Add printdate function to SQL exporters
Introduce a printdate function to eliminate the repetitive use of datetime.datetime.today() in the SQL exporting scripts. Signed-off-by: Tony Jones <tonyj@suse.de> Acked-by: Adrian Hunter <adrian.hunter@intel.com> Link: http://lkml.kernel.org/r/20190309000518.2438-5-tonyj@suse.de Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/scripts/python/export-to-postgresql.py')
-rw-r--r--tools/perf/scripts/python/export-to-postgresql.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/tools/perf/scripts/python/export-to-postgresql.py b/tools/perf/scripts/python/export-to-postgresql.py
index 00ab972a2eba..c3eae1d77d36 100644
--- a/tools/perf/scripts/python/export-to-postgresql.py
+++ b/tools/perf/scripts/python/export-to-postgresql.py
@@ -251,6 +251,9 @@ perf_db_export_callchains = False
251def printerr(*args, **kw_args): 251def printerr(*args, **kw_args):
252 print(*args, file=sys.stderr, **kw_args) 252 print(*args, file=sys.stderr, **kw_args)
253 253
254def printdate(*args, **kw_args):
255 print(datetime.datetime.today(), *args, sep=' ', **kw_args)
256
254def usage(): 257def usage():
255 printerr("Usage is: export-to-postgresql.py <database name> [<columns>] [<calls>] [<callchains>]") 258 printerr("Usage is: export-to-postgresql.py <database name> [<columns>] [<calls>] [<callchains>]")
256 printerr("where: columns 'all' or 'branches'") 259 printerr("where: columns 'all' or 'branches'")
@@ -289,7 +292,7 @@ def do_query(q, s):
289 return 292 return
290 raise Exception("Query failed: " + q.lastError().text()) 293 raise Exception("Query failed: " + q.lastError().text())
291 294
292print(datetime.datetime.today(), "Creating database...") 295printdate("Creating database...")
293 296
294db = QSqlDatabase.addDatabase('QPSQL') 297db = QSqlDatabase.addDatabase('QPSQL')
295query = QSqlQuery(db) 298query = QSqlQuery(db)
@@ -582,7 +585,7 @@ if perf_db_export_calls:
582 call_file = open_output_file("call_table.bin") 585 call_file = open_output_file("call_table.bin")
583 586
584def trace_begin(): 587def trace_begin():
585 print(datetime.datetime.today(), "Writing to intermediate files...") 588 printdate("Writing to intermediate files...")
586 # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs 589 # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs
587 evsel_table(0, "unknown") 590 evsel_table(0, "unknown")
588 machine_table(0, 0, "unknown") 591 machine_table(0, 0, "unknown")
@@ -598,7 +601,7 @@ def trace_begin():
598unhandled_count = 0 601unhandled_count = 0
599 602
600def trace_end(): 603def trace_end():
601 print(datetime.datetime.today(), "Copying to database...") 604 printdate("Copying to database...")
602 copy_output_file(evsel_file, "selected_events") 605 copy_output_file(evsel_file, "selected_events")
603 copy_output_file(machine_file, "machines") 606 copy_output_file(machine_file, "machines")
604 copy_output_file(thread_file, "threads") 607 copy_output_file(thread_file, "threads")
@@ -613,7 +616,7 @@ def trace_end():
613 if perf_db_export_calls: 616 if perf_db_export_calls:
614 copy_output_file(call_file, "calls") 617 copy_output_file(call_file, "calls")
615 618
616 print(datetime.datetime.today(), "Removing intermediate files...") 619 printdate("Removing intermediate files...")
617 remove_output_file(evsel_file) 620 remove_output_file(evsel_file)
618 remove_output_file(machine_file) 621 remove_output_file(machine_file)
619 remove_output_file(thread_file) 622 remove_output_file(thread_file)
@@ -628,7 +631,7 @@ def trace_end():
628 if perf_db_export_calls: 631 if perf_db_export_calls:
629 remove_output_file(call_file) 632 remove_output_file(call_file)
630 os.rmdir(output_dir_name) 633 os.rmdir(output_dir_name)
631 print(datetime.datetime.today(), "Adding primary keys") 634 printdate("Adding primary keys")
632 do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)') 635 do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)')
633 do_query(query, 'ALTER TABLE machines ADD PRIMARY KEY (id)') 636 do_query(query, 'ALTER TABLE machines ADD PRIMARY KEY (id)')
634 do_query(query, 'ALTER TABLE threads ADD PRIMARY KEY (id)') 637 do_query(query, 'ALTER TABLE threads ADD PRIMARY KEY (id)')
@@ -643,7 +646,7 @@ def trace_end():
643 if perf_db_export_calls: 646 if perf_db_export_calls:
644 do_query(query, 'ALTER TABLE calls ADD PRIMARY KEY (id)') 647 do_query(query, 'ALTER TABLE calls ADD PRIMARY KEY (id)')
645 648
646 print(datetime.datetime.today(), "Adding foreign keys") 649 printdate("Adding foreign keys")
647 do_query(query, 'ALTER TABLE threads ' 650 do_query(query, 'ALTER TABLE threads '
648 'ADD CONSTRAINT machinefk FOREIGN KEY (machine_id) REFERENCES machines (id),' 651 'ADD CONSTRAINT machinefk FOREIGN KEY (machine_id) REFERENCES machines (id),'
649 'ADD CONSTRAINT processfk FOREIGN KEY (process_id) REFERENCES threads (id)') 652 'ADD CONSTRAINT processfk FOREIGN KEY (process_id) REFERENCES threads (id)')
@@ -679,8 +682,8 @@ def trace_end():
679 do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)') 682 do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)')
680 683
681 if (unhandled_count): 684 if (unhandled_count):
682 print(datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events") 685 printdate("Warning: ", unhandled_count, " unhandled events")
683 print(datetime.datetime.today(), "Done") 686 printdate("Done")
684 687
685def trace_unhandled(event_name, context, event_fields_dict): 688def trace_unhandled(event_name, context, event_fields_dict):
686 global unhandled_count 689 global unhandled_count