diff options
author | Adrian Hunter <adrian.hunter@intel.com> | 2019-07-10 04:58:10 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-07-10 12:05:12 -0400 |
commit | 56789f3dc127d4f8c07ce2bb48629ba75e8ef16c (patch) | |
tree | 177bed32c37f15171b90c0bcf1c182d86065ec36 /tools | |
parent | 37c1f991b1bcdbe268b99b22e265738f4209f4f4 (diff) |
perf scripts python: export-to-postgresql.py: Export switch events
Export switch events to a new table 'context_switches' and create a view
'context_switches_view'. The table and view will show automatically in the
exported-sql-viewer.py script.
If the table ends up empty, then it and the view are dropped.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/20190710085810.1650-22-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/scripts/python/export-to-postgresql.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tools/perf/scripts/python/export-to-postgresql.py b/tools/perf/scripts/python/export-to-postgresql.py index 13205e4e5b3b..7bd73a904b4e 100644 --- a/tools/perf/scripts/python/export-to-postgresql.py +++ b/tools/perf/scripts/python/export-to-postgresql.py | |||
@@ -482,6 +482,17 @@ do_query(query, 'CREATE TABLE pwrx (' | |||
482 | 'last_cstate integer,' | 482 | 'last_cstate integer,' |
483 | 'wake_reason integer)') | 483 | 'wake_reason integer)') |
484 | 484 | ||
485 | do_query(query, 'CREATE TABLE context_switches (' | ||
486 | 'id bigint NOT NULL,' | ||
487 | 'machine_id bigint,' | ||
488 | 'time bigint,' | ||
489 | 'cpu integer,' | ||
490 | 'thread_out_id bigint,' | ||
491 | 'comm_out_id bigint,' | ||
492 | 'thread_in_id bigint,' | ||
493 | 'comm_in_id bigint,' | ||
494 | 'flags integer)') | ||
495 | |||
485 | do_query(query, 'CREATE VIEW machines_view AS ' | 496 | do_query(query, 'CREATE VIEW machines_view AS ' |
486 | 'SELECT ' | 497 | 'SELECT ' |
487 | 'id,' | 498 | 'id,' |
@@ -695,6 +706,29 @@ do_query(query, 'CREATE VIEW power_events_view AS ' | |||
695 | ' INNER JOIN selected_events ON selected_events.id = samples.evsel_id' | 706 | ' INNER JOIN selected_events ON selected_events.id = samples.evsel_id' |
696 | ' ORDER BY samples.id') | 707 | ' ORDER BY samples.id') |
697 | 708 | ||
709 | do_query(query, 'CREATE VIEW context_switches_view AS ' | ||
710 | 'SELECT ' | ||
711 | 'context_switches.id,' | ||
712 | 'context_switches.machine_id,' | ||
713 | 'context_switches.time,' | ||
714 | 'context_switches.cpu,' | ||
715 | 'th_out.pid AS pid_out,' | ||
716 | 'th_out.tid AS tid_out,' | ||
717 | 'comm_out.comm AS comm_out,' | ||
718 | 'th_in.pid AS pid_in,' | ||
719 | 'th_in.tid AS tid_in,' | ||
720 | 'comm_in.comm AS comm_in,' | ||
721 | 'CASE WHEN context_switches.flags = 0 THEN \'in\'' | ||
722 | ' WHEN context_switches.flags = 1 THEN \'out\'' | ||
723 | ' WHEN context_switches.flags = 3 THEN \'out preempt\'' | ||
724 | ' ELSE CAST ( context_switches.flags AS VARCHAR(11) )' | ||
725 | 'END AS flags' | ||
726 | ' FROM context_switches' | ||
727 | ' INNER JOIN threads AS th_out ON th_out.id = context_switches.thread_out_id' | ||
728 | ' INNER JOIN threads AS th_in ON th_in.id = context_switches.thread_in_id' | ||
729 | ' INNER JOIN comms AS comm_out ON comm_out.id = context_switches.comm_out_id' | ||
730 | ' INNER JOIN comms AS comm_in ON comm_in.id = context_switches.comm_in_id') | ||
731 | |||
698 | file_header = struct.pack("!11sii", b"PGCOPY\n\377\r\n\0", 0, 0) | 732 | file_header = struct.pack("!11sii", b"PGCOPY\n\377\r\n\0", 0, 0) |
699 | file_trailer = b"\377\377" | 733 | file_trailer = b"\377\377" |
700 | 734 | ||
@@ -759,6 +793,7 @@ mwait_file = open_output_file("mwait_table.bin") | |||
759 | pwre_file = open_output_file("pwre_table.bin") | 793 | pwre_file = open_output_file("pwre_table.bin") |
760 | exstop_file = open_output_file("exstop_table.bin") | 794 | exstop_file = open_output_file("exstop_table.bin") |
761 | pwrx_file = open_output_file("pwrx_table.bin") | 795 | pwrx_file = open_output_file("pwrx_table.bin") |
796 | context_switches_file = open_output_file("context_switches_table.bin") | ||
762 | 797 | ||
763 | def trace_begin(): | 798 | def trace_begin(): |
764 | printdate("Writing to intermediate files...") | 799 | printdate("Writing to intermediate files...") |
@@ -807,6 +842,7 @@ def trace_end(): | |||
807 | copy_output_file(pwre_file, "pwre") | 842 | copy_output_file(pwre_file, "pwre") |
808 | copy_output_file(exstop_file, "exstop") | 843 | copy_output_file(exstop_file, "exstop") |
809 | copy_output_file(pwrx_file, "pwrx") | 844 | copy_output_file(pwrx_file, "pwrx") |
845 | copy_output_file(context_switches_file, "context_switches") | ||
810 | 846 | ||
811 | printdate("Removing intermediate files...") | 847 | printdate("Removing intermediate files...") |
812 | remove_output_file(evsel_file) | 848 | remove_output_file(evsel_file) |
@@ -828,6 +864,7 @@ def trace_end(): | |||
828 | remove_output_file(pwre_file) | 864 | remove_output_file(pwre_file) |
829 | remove_output_file(exstop_file) | 865 | remove_output_file(exstop_file) |
830 | remove_output_file(pwrx_file) | 866 | remove_output_file(pwrx_file) |
867 | remove_output_file(context_switches_file) | ||
831 | os.rmdir(output_dir_name) | 868 | os.rmdir(output_dir_name) |
832 | printdate("Adding primary keys") | 869 | printdate("Adding primary keys") |
833 | do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)') | 870 | do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)') |
@@ -849,6 +886,7 @@ def trace_end(): | |||
849 | do_query(query, 'ALTER TABLE pwre ADD PRIMARY KEY (id)') | 886 | do_query(query, 'ALTER TABLE pwre ADD PRIMARY KEY (id)') |
850 | do_query(query, 'ALTER TABLE exstop ADD PRIMARY KEY (id)') | 887 | do_query(query, 'ALTER TABLE exstop ADD PRIMARY KEY (id)') |
851 | do_query(query, 'ALTER TABLE pwrx ADD PRIMARY KEY (id)') | 888 | do_query(query, 'ALTER TABLE pwrx ADD PRIMARY KEY (id)') |
889 | do_query(query, 'ALTER TABLE context_switches ADD PRIMARY KEY (id)') | ||
852 | 890 | ||
853 | printdate("Adding foreign keys") | 891 | printdate("Adding foreign keys") |
854 | do_query(query, 'ALTER TABLE threads ' | 892 | do_query(query, 'ALTER TABLE threads ' |
@@ -900,6 +938,12 @@ def trace_end(): | |||
900 | 'ADD CONSTRAINT idfk FOREIGN KEY (id) REFERENCES samples (id)') | 938 | 'ADD CONSTRAINT idfk FOREIGN KEY (id) REFERENCES samples (id)') |
901 | do_query(query, 'ALTER TABLE pwrx ' | 939 | do_query(query, 'ALTER TABLE pwrx ' |
902 | 'ADD CONSTRAINT idfk FOREIGN KEY (id) REFERENCES samples (id)') | 940 | 'ADD CONSTRAINT idfk FOREIGN KEY (id) REFERENCES samples (id)') |
941 | do_query(query, 'ALTER TABLE context_switches ' | ||
942 | 'ADD CONSTRAINT machinefk FOREIGN KEY (machine_id) REFERENCES machines (id),' | ||
943 | 'ADD CONSTRAINT toutfk FOREIGN KEY (thread_out_id) REFERENCES threads (id),' | ||
944 | 'ADD CONSTRAINT tinfk FOREIGN KEY (thread_in_id) REFERENCES threads (id),' | ||
945 | 'ADD CONSTRAINT coutfk FOREIGN KEY (comm_out_id) REFERENCES comms (id),' | ||
946 | 'ADD CONSTRAINT cinfk FOREIGN KEY (comm_in_id) REFERENCES comms (id)') | ||
903 | 947 | ||
904 | printdate("Dropping unused tables") | 948 | printdate("Dropping unused tables") |
905 | if is_table_empty("ptwrite"): | 949 | if is_table_empty("ptwrite"): |
@@ -912,6 +956,8 @@ def trace_end(): | |||
912 | drop("pwrx") | 956 | drop("pwrx") |
913 | if is_table_empty("cbr"): | 957 | if is_table_empty("cbr"): |
914 | drop("cbr") | 958 | drop("cbr") |
959 | if is_table_empty("context_switches"): | ||
960 | drop("context_switches") | ||
915 | 961 | ||
916 | if (unhandled_count): | 962 | if (unhandled_count): |
917 | printdate("Warning: ", unhandled_count, " unhandled events") | 963 | printdate("Warning: ", unhandled_count, " unhandled events") |
@@ -1058,3 +1104,8 @@ def synth_data(id, config, raw_buf, *x): | |||
1058 | pwrx(id, raw_buf) | 1104 | pwrx(id, raw_buf) |
1059 | elif config == 5: | 1105 | elif config == 5: |
1060 | cbr(id, raw_buf) | 1106 | cbr(id, raw_buf) |
1107 | |||
1108 | def context_switch_table(id, machine_id, time, cpu, thread_out_id, comm_out_id, thread_in_id, comm_in_id, flags, *x): | ||
1109 | fmt = "!hiqiqiqiiiqiqiqiqii" | ||
1110 | value = struct.pack(fmt, 9, 8, id, 8, machine_id, 8, time, 4, cpu, 8, thread_out_id, 8, comm_out_id, 8, thread_in_id, 8, comm_in_id, 4, flags) | ||
1111 | context_switches_file.write(value) | ||