diff options
| author | Tony Jones <tonyj@suse.de> | 2019-03-08 19:05:18 -0500 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-03-11 15:13:02 -0400 |
| commit | 49f93bbf17e6267eb34e0c12a9813f3a8723749e (patch) | |
| tree | 7536067e5052a0e408babe7874d22705f75c4c42 /tools/perf/scripts/python | |
| parent | ebf6c5c181abe9309788c6241d39602a1ce18723 (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')
| -rw-r--r-- | tools/perf/scripts/python/export-to-postgresql.py | 19 | ||||
| -rw-r--r-- | tools/perf/scripts/python/export-to-sqlite.py | 13 |
2 files changed, 19 insertions, 13 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 | |||
| 251 | def printerr(*args, **kw_args): | 251 | def printerr(*args, **kw_args): |
| 252 | print(*args, file=sys.stderr, **kw_args) | 252 | print(*args, file=sys.stderr, **kw_args) |
| 253 | 253 | ||
| 254 | def printdate(*args, **kw_args): | ||
| 255 | print(datetime.datetime.today(), *args, sep=' ', **kw_args) | ||
| 256 | |||
| 254 | def usage(): | 257 | def 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 | ||
| 292 | print(datetime.datetime.today(), "Creating database...") | 295 | printdate("Creating database...") |
| 293 | 296 | ||
| 294 | db = QSqlDatabase.addDatabase('QPSQL') | 297 | db = QSqlDatabase.addDatabase('QPSQL') |
| 295 | query = QSqlQuery(db) | 298 | query = 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 | ||
| 584 | def trace_begin(): | 587 | def 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(): | |||
| 598 | unhandled_count = 0 | 601 | unhandled_count = 0 |
| 599 | 602 | ||
| 600 | def trace_end(): | 603 | def 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 | ||
| 685 | def trace_unhandled(event_name, context, event_fields_dict): | 688 | def trace_unhandled(event_name, context, event_fields_dict): |
| 686 | global unhandled_count | 689 | global unhandled_count |
diff --git a/tools/perf/scripts/python/export-to-sqlite.py b/tools/perf/scripts/python/export-to-sqlite.py index 3da338243aed..3b71902a5a21 100644 --- a/tools/perf/scripts/python/export-to-sqlite.py +++ b/tools/perf/scripts/python/export-to-sqlite.py | |||
| @@ -65,6 +65,9 @@ perf_db_export_callchains = False | |||
| 65 | def printerr(*args, **keyword_args): | 65 | def printerr(*args, **keyword_args): |
| 66 | print(*args, file=sys.stderr, **keyword_args) | 66 | print(*args, file=sys.stderr, **keyword_args) |
| 67 | 67 | ||
| 68 | def printdate(*args, **kw_args): | ||
| 69 | print(datetime.datetime.today(), *args, sep=' ', **kw_args) | ||
| 70 | |||
| 68 | def usage(): | 71 | def usage(): |
| 69 | printerr("Usage is: export-to-sqlite.py <database name> [<columns>] [<calls>] [<callchains>]"); | 72 | printerr("Usage is: export-to-sqlite.py <database name> [<columns>] [<calls>] [<callchains>]"); |
| 70 | printerr("where: columns 'all' or 'branches'"); | 73 | printerr("where: columns 'all' or 'branches'"); |
| @@ -105,7 +108,7 @@ def do_query_(q): | |||
| 105 | return | 108 | return |
| 106 | raise Exception("Query failed: " + q.lastError().text()) | 109 | raise Exception("Query failed: " + q.lastError().text()) |
| 107 | 110 | ||
| 108 | print(datetime.datetime.today(), "Creating database ...") | 111 | printdate("Creating database ...") |
| 109 | 112 | ||
| 110 | db_exists = False | 113 | db_exists = False |
| 111 | try: | 114 | try: |
| @@ -383,7 +386,7 @@ if perf_db_export_calls: | |||
| 383 | call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") | 386 | call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") |
| 384 | 387 | ||
| 385 | def trace_begin(): | 388 | def trace_begin(): |
| 386 | print(datetime.datetime.today(), "Writing records...") | 389 | printdate("Writing records...") |
| 387 | do_query(query, 'BEGIN TRANSACTION') | 390 | do_query(query, 'BEGIN TRANSACTION') |
| 388 | # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs | 391 | # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs |
| 389 | evsel_table(0, "unknown") | 392 | evsel_table(0, "unknown") |
| @@ -402,14 +405,14 @@ unhandled_count = 0 | |||
| 402 | def trace_end(): | 405 | def trace_end(): |
| 403 | do_query(query, 'END TRANSACTION') | 406 | do_query(query, 'END TRANSACTION') |
| 404 | 407 | ||
| 405 | print(datetime.datetime.today(), "Adding indexes") | 408 | printdate("Adding indexes") |
| 406 | if perf_db_export_calls: | 409 | if perf_db_export_calls: |
| 407 | do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)') | 410 | do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)') |
| 408 | do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)') | 411 | do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)') |
| 409 | 412 | ||
| 410 | if (unhandled_count): | 413 | if (unhandled_count): |
| 411 | print(datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events") | 414 | printdate("Warning: ", unhandled_count, " unhandled events") |
| 412 | print(datetime.datetime.today(), "Done") | 415 | printdate("Done") |
| 413 | 416 | ||
| 414 | def trace_unhandled(event_name, context, event_fields_dict): | 417 | def trace_unhandled(event_name, context, event_fields_dict): |
| 415 | global unhandled_count | 418 | global unhandled_count |
