linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Adrian Hunter <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: mingo@kernel.org, adrian.hunter@intel.com, acme@redhat.com,
	linux-kernel@vger.kernel.org, jolsa@redhat.com, hpa@zytor.com,
	tglx@linutronix.de
Subject: [tip:perf/urgent] perf scripts python: export-to-postgresql.py: Export switch events
Date: Wed, 17 Jul 2019 16:05:31 -0700	[thread overview]
Message-ID: <tip-56789f3dc127d4f8c07ce2bb48629ba75e8ef16c@git.kernel.org> (raw)
In-Reply-To: <20190710085810.1650-22-adrian.hunter@intel.com>

Commit-ID:  56789f3dc127d4f8c07ce2bb48629ba75e8ef16c
Gitweb:     https://git.kernel.org/tip/56789f3dc127d4f8c07ce2bb48629ba75e8ef16c
Author:     Adrian Hunter <adrian.hunter@intel.com>
AuthorDate: Wed, 10 Jul 2019 11:58:10 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 10 Jul 2019 13:05:12 -0300

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>
---
 tools/perf/scripts/python/export-to-postgresql.py | 51 +++++++++++++++++++++++
 1 file changed, 51 insertions(+)

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 ('
 	'last_cstate	integer,'
 	'wake_reason	integer)')
 
+do_query(query, 'CREATE TABLE context_switches ('
+		'id		bigint		NOT NULL,'
+		'machine_id	bigint,'
+		'time		bigint,'
+		'cpu		integer,'
+		'thread_out_id	bigint,'
+		'comm_out_id	bigint,'
+		'thread_in_id	bigint,'
+		'comm_in_id	bigint,'
+		'flags		integer)')
+
 do_query(query, 'CREATE VIEW machines_view AS '
 	'SELECT '
 		'id,'
@@ -695,6 +706,29 @@ do_query(query, 'CREATE VIEW power_events_view AS '
 	' INNER JOIN selected_events ON selected_events.id = samples.evsel_id'
 	' ORDER BY samples.id')
 
+do_query(query, 'CREATE VIEW context_switches_view AS '
+	'SELECT '
+		'context_switches.id,'
+		'context_switches.machine_id,'
+		'context_switches.time,'
+		'context_switches.cpu,'
+		'th_out.pid AS pid_out,'
+		'th_out.tid AS tid_out,'
+		'comm_out.comm AS comm_out,'
+		'th_in.pid AS pid_in,'
+		'th_in.tid AS tid_in,'
+		'comm_in.comm AS comm_in,'
+		'CASE	  WHEN context_switches.flags = 0 THEN \'in\''
+			' WHEN context_switches.flags = 1 THEN \'out\''
+			' WHEN context_switches.flags = 3 THEN \'out preempt\''
+			' ELSE CAST ( context_switches.flags AS VARCHAR(11) )'
+		'END AS flags'
+	' FROM context_switches'
+	' INNER JOIN threads AS th_out ON th_out.id   = context_switches.thread_out_id'
+	' INNER JOIN threads AS th_in  ON th_in.id    = context_switches.thread_in_id'
+	' INNER JOIN comms AS comm_out ON comm_out.id = context_switches.comm_out_id'
+	' INNER JOIN comms AS comm_in  ON comm_in.id  = context_switches.comm_in_id')
+
 file_header = struct.pack("!11sii", b"PGCOPY\n\377\r\n\0", 0, 0)
 file_trailer = b"\377\377"
 
@@ -759,6 +793,7 @@ mwait_file		= open_output_file("mwait_table.bin")
 pwre_file		= open_output_file("pwre_table.bin")
 exstop_file		= open_output_file("exstop_table.bin")
 pwrx_file		= open_output_file("pwrx_table.bin")
+context_switches_file	= open_output_file("context_switches_table.bin")
 
 def trace_begin():
 	printdate("Writing to intermediate files...")
@@ -807,6 +842,7 @@ def trace_end():
 	copy_output_file(pwre_file,		"pwre")
 	copy_output_file(exstop_file,		"exstop")
 	copy_output_file(pwrx_file,		"pwrx")
+	copy_output_file(context_switches_file,	"context_switches")
 
 	printdate("Removing intermediate files...")
 	remove_output_file(evsel_file)
@@ -828,6 +864,7 @@ def trace_end():
 	remove_output_file(pwre_file)
 	remove_output_file(exstop_file)
 	remove_output_file(pwrx_file)
+	remove_output_file(context_switches_file)
 	os.rmdir(output_dir_name)
 	printdate("Adding primary keys")
 	do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)')
@@ -849,6 +886,7 @@ def trace_end():
 	do_query(query, 'ALTER TABLE pwre            ADD PRIMARY KEY (id)')
 	do_query(query, 'ALTER TABLE exstop          ADD PRIMARY KEY (id)')
 	do_query(query, 'ALTER TABLE pwrx            ADD PRIMARY KEY (id)')
+	do_query(query, 'ALTER TABLE context_switches ADD PRIMARY KEY (id)')
 
 	printdate("Adding foreign keys")
 	do_query(query, 'ALTER TABLE threads '
@@ -900,6 +938,12 @@ def trace_end():
 					'ADD CONSTRAINT idfk        FOREIGN KEY (id)           REFERENCES samples   (id)')
 	do_query(query, 'ALTER TABLE  pwrx '
 					'ADD CONSTRAINT idfk        FOREIGN KEY (id)           REFERENCES samples   (id)')
+	do_query(query, 'ALTER TABLE  context_switches '
+					'ADD CONSTRAINT machinefk   FOREIGN KEY (machine_id)    REFERENCES machines (id),'
+					'ADD CONSTRAINT toutfk      FOREIGN KEY (thread_out_id) REFERENCES threads  (id),'
+					'ADD CONSTRAINT tinfk       FOREIGN KEY (thread_in_id)  REFERENCES threads  (id),'
+					'ADD CONSTRAINT coutfk      FOREIGN KEY (comm_out_id)   REFERENCES comms    (id),'
+					'ADD CONSTRAINT cinfk       FOREIGN KEY (comm_in_id)    REFERENCES comms    (id)')
 
 	printdate("Dropping unused tables")
 	if is_table_empty("ptwrite"):
@@ -912,6 +956,8 @@ def trace_end():
 		drop("pwrx")
 		if is_table_empty("cbr"):
 			drop("cbr")
+	if is_table_empty("context_switches"):
+		drop("context_switches")
 
 	if (unhandled_count):
 		printdate("Warning: ", unhandled_count, " unhandled events")
@@ -1058,3 +1104,8 @@ def synth_data(id, config, raw_buf, *x):
 		pwrx(id, raw_buf)
 	elif config == 5:
 		cbr(id, raw_buf)
+
+def context_switch_table(id, machine_id, time, cpu, thread_out_id, comm_out_id, thread_in_id, comm_in_id, flags, *x):
+	fmt = "!hiqiqiqiiiqiqiqiqii"
+	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)
+	context_switches_file.write(value)

      reply	other threads:[~2019-07-17 23:05 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-10  8:57 [PATCH 00/21] perf db-export: Comm tidy-up and export switch events Adrian Hunter
2019-07-10  8:57 ` [PATCH 01/21] perf db-export: Get rid of db_export__deferred() Adrian Hunter
2019-07-17 22:51   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2019-07-10  8:57 ` [PATCH 02/21] perf db-export: Rename db_export__comm() to db_export__exec_comm() Adrian Hunter
2019-07-17 22:52   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2019-07-10  8:57 ` [PATCH 03/21] perf db-export: Pass main_thread to db_export__thread() Adrian Hunter
2019-07-17 22:52   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2019-07-10  8:57 ` [PATCH 04/21] perf db-export: Export main_thread in db_export__sample() Adrian Hunter
2019-07-17 22:53   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2019-07-10  8:57 ` [PATCH 05/21] perf db-export: Export comm before exporting thread Adrian Hunter
2019-07-17 22:54   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2019-07-10  8:57 ` [PATCH 06/21] perf db-export: Move export__comm_thread into db_export__sample() Adrian Hunter
2019-07-17 22:54   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2019-07-10  8:57 ` [PATCH 07/21] perf db-export: Fix a white space issue in db_export__sample() Adrian Hunter
2019-07-17 22:55   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2019-07-10  8:57 ` [PATCH 08/21] perf db-export: Export comm details Adrian Hunter
2019-07-17 22:56   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2019-07-10  8:57 ` [PATCH 09/21] perf scripts python: export-to-sqlite.py: " Adrian Hunter
2019-07-17 22:56   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2019-07-10  8:57 ` [PATCH 10/21] perf scripts python: export-to-postgresql.py: " Adrian Hunter
2019-07-17 22:57   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2019-07-10  8:58 ` [PATCH 11/21] perf db-export: Factor out db_export__comm() Adrian Hunter
2019-07-17 22:58   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2019-07-10  8:58 ` [PATCH 12/21] perf db-export: Also export thread's current comm Adrian Hunter
2019-07-17 22:59   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2019-07-10  8:58 ` [PATCH 13/21] perf scripts python: export-to-sqlite.py: Add has_calls column to comms table Adrian Hunter
2019-07-17 22:59   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2019-07-10  8:58 ` [PATCH 14/21] perf scripts python: export-to-postgresql.py: " Adrian Hunter
2019-07-17 23:00   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2019-07-10  8:58 ` [PATCH 15/21] perf scripts python: exported-sql-viewer.py: Remove redundant semi-colons Adrian Hunter
2019-07-17 23:01   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2019-07-10  8:58 ` [PATCH 16/21] perf scripts python: exported-sql-viewer.py: Use new 'has_calls' column Adrian Hunter
2019-07-17 23:01   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2019-07-10  8:58 ` [PATCH 17/21] perf script: Add scripting operation process_switch() Adrian Hunter
2019-07-17 23:02   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2019-07-10  8:58 ` [PATCH 18/21] perf db-export: Factor out db_export__threads() Adrian Hunter
2019-07-17 23:03   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2019-07-10  8:58 ` [PATCH 19/21] perf db-export: Export switch events Adrian Hunter
2019-07-17 23:04   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2019-07-10  8:58 ` [PATCH 20/21] perf scripts python: export-to-sqlite.py: " Adrian Hunter
2019-07-17 23:04   ` [tip:perf/urgent] " tip-bot for Adrian Hunter
2019-07-10  8:58 ` [PATCH 21/21] perf scripts python: export-to-postgresql.py: " Adrian Hunter
2019-07-17 23:05   ` tip-bot for Adrian Hunter [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-56789f3dc127d4f8c07ce2bb48629ba75e8ef16c@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=hpa@zytor.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).