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.
Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all
Unified · Split
| @@ -482,6 +482,17 @@ do_query(query, 'CREATE TABLE pwrx (' · 481 unmodified lines | |||
| 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 ' · 207 unmodified lines | |||
| 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") · 58 unmodified lines | |||
| 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(): · 42 unmodified lines | |||
| 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(): · 15 unmodified lines | |||
| 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(): · 15 unmodified lines | |||
| 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(): · 45 unmodified lines | |||
| 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(): · 6 unmodified lines | |||
| 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): · 140 unmodified lines | |||
| 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) | ||