diff options
Diffstat (limited to 'tools/perf/scripts/python/export-to-postgresql.py')
| -rw-r--r-- | tools/perf/scripts/python/export-to-postgresql.py | 52 |
1 files changed, 32 insertions, 20 deletions
diff --git a/tools/perf/scripts/python/export-to-postgresql.py b/tools/perf/scripts/python/export-to-postgresql.py index 1b02cdc0cab6..7656ff8aa066 100644 --- a/tools/perf/scripts/python/export-to-postgresql.py +++ b/tools/perf/scripts/python/export-to-postgresql.py | |||
| @@ -34,10 +34,9 @@ import datetime | |||
| 34 | # | 34 | # |
| 35 | # ubuntu: | 35 | # ubuntu: |
| 36 | # | 36 | # |
| 37 | # $ sudo apt-get install postgresql | 37 | # $ sudo apt-get install postgresql python-pyside.qtsql libqt4-sql-psql |
| 38 | # $ sudo su - postgres | 38 | # $ sudo su - postgres |
| 39 | # $ createuser <your user id here> | 39 | # $ createuser -s <your user id here> |
| 40 | # Shall the new role be a superuser? (y/n) y | ||
| 41 | # | 40 | # |
| 42 | # An example of using this script with Intel PT: | 41 | # An example of using this script with Intel PT: |
| 43 | # | 42 | # |
| @@ -224,11 +223,14 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | |||
| 224 | 223 | ||
| 225 | perf_db_export_mode = True | 224 | perf_db_export_mode = True |
| 226 | perf_db_export_calls = False | 225 | perf_db_export_calls = False |
| 226 | perf_db_export_callchains = False | ||
| 227 | |||
| 227 | 228 | ||
| 228 | def usage(): | 229 | def usage(): |
| 229 | print >> sys.stderr, "Usage is: export-to-postgresql.py <database name> [<columns>] [<calls>]" | 230 | print >> sys.stderr, "Usage is: export-to-postgresql.py <database name> [<columns>] [<calls>] [<callchains>]" |
| 230 | print >> sys.stderr, "where: columns 'all' or 'branches'" | 231 | print >> sys.stderr, "where: columns 'all' or 'branches'" |
| 231 | print >> sys.stderr, " calls 'calls' => create calls table" | 232 | print >> sys.stderr, " calls 'calls' => create calls and call_paths table" |
| 233 | print >> sys.stderr, " callchains 'callchains' => create call_paths table" | ||
| 232 | raise Exception("Too few arguments") | 234 | raise Exception("Too few arguments") |
| 233 | 235 | ||
| 234 | if (len(sys.argv) < 2): | 236 | if (len(sys.argv) < 2): |
| @@ -246,9 +248,11 @@ if columns not in ("all", "branches"): | |||
| 246 | 248 | ||
| 247 | branches = (columns == "branches") | 249 | branches = (columns == "branches") |
| 248 | 250 | ||
| 249 | if (len(sys.argv) >= 4): | 251 | for i in range(3,len(sys.argv)): |
| 250 | if (sys.argv[3] == "calls"): | 252 | if (sys.argv[i] == "calls"): |
| 251 | perf_db_export_calls = True | 253 | perf_db_export_calls = True |
| 254 | elif (sys.argv[i] == "callchains"): | ||
| 255 | perf_db_export_callchains = True | ||
| 252 | else: | 256 | else: |
| 253 | usage() | 257 | usage() |
| 254 | 258 | ||
| @@ -359,14 +363,16 @@ else: | |||
| 359 | 'transaction bigint,' | 363 | 'transaction bigint,' |
| 360 | 'data_src bigint,' | 364 | 'data_src bigint,' |
| 361 | 'branch_type integer,' | 365 | 'branch_type integer,' |
| 362 | 'in_tx boolean)') | 366 | 'in_tx boolean,' |
| 367 | 'call_path_id bigint)') | ||
| 363 | 368 | ||
| 364 | if perf_db_export_calls: | 369 | if perf_db_export_calls or perf_db_export_callchains: |
| 365 | do_query(query, 'CREATE TABLE call_paths (' | 370 | do_query(query, 'CREATE TABLE call_paths (' |
| 366 | 'id bigint NOT NULL,' | 371 | 'id bigint NOT NULL,' |
| 367 | 'parent_id bigint,' | 372 | 'parent_id bigint,' |
| 368 | 'symbol_id bigint,' | 373 | 'symbol_id bigint,' |
| 369 | 'ip bigint)') | 374 | 'ip bigint)') |
| 375 | if perf_db_export_calls: | ||
| 370 | do_query(query, 'CREATE TABLE calls (' | 376 | do_query(query, 'CREATE TABLE calls (' |
| 371 | 'id bigint NOT NULL,' | 377 | 'id bigint NOT NULL,' |
| 372 | 'thread_id bigint,' | 378 | 'thread_id bigint,' |
| @@ -428,7 +434,7 @@ do_query(query, 'CREATE VIEW comm_threads_view AS ' | |||
| 428 | '(SELECT tid FROM threads WHERE id = thread_id) AS tid' | 434 | '(SELECT tid FROM threads WHERE id = thread_id) AS tid' |
| 429 | ' FROM comm_threads') | 435 | ' FROM comm_threads') |
| 430 | 436 | ||
| 431 | if perf_db_export_calls: | 437 | if perf_db_export_calls or perf_db_export_callchains: |
| 432 | do_query(query, 'CREATE VIEW call_paths_view AS ' | 438 | do_query(query, 'CREATE VIEW call_paths_view AS ' |
| 433 | 'SELECT ' | 439 | 'SELECT ' |
| 434 | 'c.id,' | 440 | 'c.id,' |
| @@ -444,6 +450,7 @@ if perf_db_export_calls: | |||
| 444 | '(SELECT dso_id FROM symbols WHERE id = p.symbol_id) AS parent_dso_id,' | 450 | '(SELECT dso_id FROM symbols WHERE id = p.symbol_id) AS parent_dso_id,' |
| 445 | '(SELECT dso FROM symbols_view WHERE id = p.symbol_id) AS parent_dso_short_name' | 451 | '(SELECT dso FROM symbols_view WHERE id = p.symbol_id) AS parent_dso_short_name' |
| 446 | ' FROM call_paths c INNER JOIN call_paths p ON p.id = c.parent_id') | 452 | ' FROM call_paths c INNER JOIN call_paths p ON p.id = c.parent_id') |
| 453 | if perf_db_export_calls: | ||
| 447 | do_query(query, 'CREATE VIEW calls_view AS ' | 454 | do_query(query, 'CREATE VIEW calls_view AS ' |
| 448 | 'SELECT ' | 455 | 'SELECT ' |
| 449 | 'calls.id,' | 456 | 'calls.id,' |
| @@ -541,8 +548,9 @@ dso_file = open_output_file("dso_table.bin") | |||
| 541 | symbol_file = open_output_file("symbol_table.bin") | 548 | symbol_file = open_output_file("symbol_table.bin") |
| 542 | branch_type_file = open_output_file("branch_type_table.bin") | 549 | branch_type_file = open_output_file("branch_type_table.bin") |
| 543 | sample_file = open_output_file("sample_table.bin") | 550 | sample_file = open_output_file("sample_table.bin") |
| 544 | if perf_db_export_calls: | 551 | if perf_db_export_calls or perf_db_export_callchains: |
| 545 | call_path_file = open_output_file("call_path_table.bin") | 552 | call_path_file = open_output_file("call_path_table.bin") |
| 553 | if perf_db_export_calls: | ||
| 546 | call_file = open_output_file("call_table.bin") | 554 | call_file = open_output_file("call_table.bin") |
| 547 | 555 | ||
| 548 | def trace_begin(): | 556 | def trace_begin(): |
| @@ -554,8 +562,8 @@ def trace_begin(): | |||
| 554 | comm_table(0, "unknown") | 562 | comm_table(0, "unknown") |
| 555 | dso_table(0, 0, "unknown", "unknown", "") | 563 | dso_table(0, 0, "unknown", "unknown", "") |
| 556 | symbol_table(0, 0, 0, 0, 0, "unknown") | 564 | symbol_table(0, 0, 0, 0, 0, "unknown") |
| 557 | sample_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) | 565 | sample_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) |
| 558 | if perf_db_export_calls: | 566 | if perf_db_export_calls or perf_db_export_callchains: |
| 559 | call_path_table(0, 0, 0, 0) | 567 | call_path_table(0, 0, 0, 0) |
| 560 | 568 | ||
| 561 | unhandled_count = 0 | 569 | unhandled_count = 0 |
| @@ -571,8 +579,9 @@ def trace_end(): | |||
| 571 | copy_output_file(symbol_file, "symbols") | 579 | copy_output_file(symbol_file, "symbols") |
| 572 | copy_output_file(branch_type_file, "branch_types") | 580 | copy_output_file(branch_type_file, "branch_types") |
| 573 | copy_output_file(sample_file, "samples") | 581 | copy_output_file(sample_file, "samples") |
| 574 | if perf_db_export_calls: | 582 | if perf_db_export_calls or perf_db_export_callchains: |
| 575 | copy_output_file(call_path_file, "call_paths") | 583 | copy_output_file(call_path_file, "call_paths") |
| 584 | if perf_db_export_calls: | ||
| 576 | copy_output_file(call_file, "calls") | 585 | copy_output_file(call_file, "calls") |
| 577 | 586 | ||
| 578 | print datetime.datetime.today(), "Removing intermediate files..." | 587 | print datetime.datetime.today(), "Removing intermediate files..." |
| @@ -585,8 +594,9 @@ def trace_end(): | |||
| 585 | remove_output_file(symbol_file) | 594 | remove_output_file(symbol_file) |
| 586 | remove_output_file(branch_type_file) | 595 | remove_output_file(branch_type_file) |
| 587 | remove_output_file(sample_file) | 596 | remove_output_file(sample_file) |
| 588 | if perf_db_export_calls: | 597 | if perf_db_export_calls or perf_db_export_callchains: |
| 589 | remove_output_file(call_path_file) | 598 | remove_output_file(call_path_file) |
| 599 | if perf_db_export_calls: | ||
| 590 | remove_output_file(call_file) | 600 | remove_output_file(call_file) |
| 591 | os.rmdir(output_dir_name) | 601 | os.rmdir(output_dir_name) |
| 592 | print datetime.datetime.today(), "Adding primary keys" | 602 | print datetime.datetime.today(), "Adding primary keys" |
| @@ -599,8 +609,9 @@ def trace_end(): | |||
| 599 | do_query(query, 'ALTER TABLE symbols ADD PRIMARY KEY (id)') | 609 | do_query(query, 'ALTER TABLE symbols ADD PRIMARY KEY (id)') |
| 600 | do_query(query, 'ALTER TABLE branch_types ADD PRIMARY KEY (id)') | 610 | do_query(query, 'ALTER TABLE branch_types ADD PRIMARY KEY (id)') |
| 601 | do_query(query, 'ALTER TABLE samples ADD PRIMARY KEY (id)') | 611 | do_query(query, 'ALTER TABLE samples ADD PRIMARY KEY (id)') |
| 602 | if perf_db_export_calls: | 612 | if perf_db_export_calls or perf_db_export_callchains: |
| 603 | do_query(query, 'ALTER TABLE call_paths ADD PRIMARY KEY (id)') | 613 | do_query(query, 'ALTER TABLE call_paths ADD PRIMARY KEY (id)') |
| 614 | if perf_db_export_calls: | ||
| 604 | do_query(query, 'ALTER TABLE calls ADD PRIMARY KEY (id)') | 615 | do_query(query, 'ALTER TABLE calls ADD PRIMARY KEY (id)') |
| 605 | 616 | ||
| 606 | print datetime.datetime.today(), "Adding foreign keys" | 617 | print datetime.datetime.today(), "Adding foreign keys" |
| @@ -623,10 +634,11 @@ def trace_end(): | |||
| 623 | 'ADD CONSTRAINT symbolfk FOREIGN KEY (symbol_id) REFERENCES symbols (id),' | 634 | 'ADD CONSTRAINT symbolfk FOREIGN KEY (symbol_id) REFERENCES symbols (id),' |
| 624 | 'ADD CONSTRAINT todsofk FOREIGN KEY (to_dso_id) REFERENCES dsos (id),' | 635 | 'ADD CONSTRAINT todsofk FOREIGN KEY (to_dso_id) REFERENCES dsos (id),' |
| 625 | 'ADD CONSTRAINT tosymbolfk FOREIGN KEY (to_symbol_id) REFERENCES symbols (id)') | 636 | 'ADD CONSTRAINT tosymbolfk FOREIGN KEY (to_symbol_id) REFERENCES symbols (id)') |
| 626 | if perf_db_export_calls: | 637 | if perf_db_export_calls or perf_db_export_callchains: |
| 627 | do_query(query, 'ALTER TABLE call_paths ' | 638 | do_query(query, 'ALTER TABLE call_paths ' |
| 628 | 'ADD CONSTRAINT parentfk FOREIGN KEY (parent_id) REFERENCES call_paths (id),' | 639 | 'ADD CONSTRAINT parentfk FOREIGN KEY (parent_id) REFERENCES call_paths (id),' |
| 629 | 'ADD CONSTRAINT symbolfk FOREIGN KEY (symbol_id) REFERENCES symbols (id)') | 640 | 'ADD CONSTRAINT symbolfk FOREIGN KEY (symbol_id) REFERENCES symbols (id)') |
| 641 | if perf_db_export_calls: | ||
| 630 | do_query(query, 'ALTER TABLE calls ' | 642 | do_query(query, 'ALTER TABLE calls ' |
| 631 | 'ADD CONSTRAINT threadfk FOREIGN KEY (thread_id) REFERENCES threads (id),' | 643 | 'ADD CONSTRAINT threadfk FOREIGN KEY (thread_id) REFERENCES threads (id),' |
| 632 | 'ADD CONSTRAINT commfk FOREIGN KEY (comm_id) REFERENCES comms (id),' | 644 | 'ADD CONSTRAINT commfk FOREIGN KEY (comm_id) REFERENCES comms (id),' |
| @@ -694,11 +706,11 @@ def branch_type_table(branch_type, name, *x): | |||
| 694 | value = struct.pack(fmt, 2, 4, branch_type, n, name) | 706 | value = struct.pack(fmt, 2, 4, branch_type, n, name) |
| 695 | branch_type_file.write(value) | 707 | branch_type_file.write(value) |
| 696 | 708 | ||
| 697 | def sample_table(sample_id, evsel_id, machine_id, thread_id, comm_id, dso_id, symbol_id, sym_offset, ip, time, cpu, to_dso_id, to_symbol_id, to_sym_offset, to_ip, period, weight, transaction, data_src, branch_type, in_tx, *x): | 709 | def sample_table(sample_id, evsel_id, machine_id, thread_id, comm_id, dso_id, symbol_id, sym_offset, ip, time, cpu, to_dso_id, to_symbol_id, to_sym_offset, to_ip, period, weight, transaction, data_src, branch_type, in_tx, call_path_id, *x): |
| 698 | if branches: | 710 | if branches: |
| 699 | value = struct.pack("!hiqiqiqiqiqiqiqiqiqiqiiiqiqiqiqiiiB", 17, 8, sample_id, 8, evsel_id, 8, machine_id, 8, thread_id, 8, comm_id, 8, dso_id, 8, symbol_id, 8, sym_offset, 8, ip, 8, time, 4, cpu, 8, to_dso_id, 8, to_symbol_id, 8, to_sym_offset, 8, to_ip, 4, branch_type, 1, in_tx) | 711 | value = struct.pack("!hiqiqiqiqiqiqiqiqiqiqiiiqiqiqiqiiiBiq", 18, 8, sample_id, 8, evsel_id, 8, machine_id, 8, thread_id, 8, comm_id, 8, dso_id, 8, symbol_id, 8, sym_offset, 8, ip, 8, time, 4, cpu, 8, to_dso_id, 8, to_symbol_id, 8, to_sym_offset, 8, to_ip, 4, branch_type, 1, in_tx, 8, call_path_id) |
| 700 | else: | 712 | else: |
| 701 | value = struct.pack("!hiqiqiqiqiqiqiqiqiqiqiiiqiqiqiqiqiqiqiqiiiB", 21, 8, sample_id, 8, evsel_id, 8, machine_id, 8, thread_id, 8, comm_id, 8, dso_id, 8, symbol_id, 8, sym_offset, 8, ip, 8, time, 4, cpu, 8, to_dso_id, 8, to_symbol_id, 8, to_sym_offset, 8, to_ip, 8, period, 8, weight, 8, transaction, 8, data_src, 4, branch_type, 1, in_tx) | 713 | value = struct.pack("!hiqiqiqiqiqiqiqiqiqiqiiiqiqiqiqiqiqiqiqiiiBiq", 22, 8, sample_id, 8, evsel_id, 8, machine_id, 8, thread_id, 8, comm_id, 8, dso_id, 8, symbol_id, 8, sym_offset, 8, ip, 8, time, 4, cpu, 8, to_dso_id, 8, to_symbol_id, 8, to_sym_offset, 8, to_ip, 8, period, 8, weight, 8, transaction, 8, data_src, 4, branch_type, 1, in_tx, 8, call_path_id) |
| 702 | sample_file.write(value) | 714 | sample_file.write(value) |
| 703 | 715 | ||
| 704 | def call_path_table(cp_id, parent_id, symbol_id, ip, *x): | 716 | def call_path_table(cp_id, parent_id, symbol_id, ip, *x): |
