linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
	linux-kernel@vger.kernel.org, David Ahern <dsahern@gmail.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@gmail.com>,
	Paul Mackerras <paulus@samba.org>,
	Stephane Eranian <eranian@google.com>
Subject: [PATCH 23/31] perf tools: Add branch_type and in_tx to Python export
Date: Thu, 31 Jul 2014 09:01:06 +0300	[thread overview]
Message-ID: <1406786474-9306-24-git-send-email-adrian.hunter@intel.com> (raw)
In-Reply-To: <1406786474-9306-1-git-send-email-adrian.hunter@intel.com>

Add branch_type and in_tx to Python db export and
the export-to-postgresql.py script.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/perf/scripts/python/export-to-postgresql.py  | 32 ++++++++++++++++++----
 .../util/scripting-engines/trace-event-python.c    | 30 +++++++++++++++++++-
 2 files changed, 55 insertions(+), 7 deletions(-)

diff --git a/tools/perf/scripts/python/export-to-postgresql.py b/tools/perf/scripts/python/export-to-postgresql.py
index d8f6df0..bb79aec 100644
--- a/tools/perf/scripts/python/export-to-postgresql.py
+++ b/tools/perf/scripts/python/export-to-postgresql.py
@@ -123,6 +123,10 @@ do_query(query, 'CREATE TABLE symbols ('
 		'sym_end	bigint,'
 		'binding	integer,'
 		'name		varchar(2048))')
+do_query(query, 'CREATE TABLE branch_types ('
+		'id		integer		NOT NULL,'
+		'name		varchar(80))')
+
 if branches:
 	do_query(query, 'CREATE TABLE samples ('
 		'id		bigint		NOT NULL,'
@@ -139,7 +143,9 @@ if branches:
 		'to_dso_id	bigint,'
 		'to_symbol_id	bigint,'
 		'to_sym_offset	bigint,'
-		'to_ip		bigint)')
+		'to_ip		bigint,'
+		'branch_type	integer,'
+		'in_tx		boolean)')
 else:
 	do_query(query, 'CREATE TABLE samples ('
 		'id		bigint		NOT NULL,'
@@ -160,7 +166,9 @@ else:
 		'period		bigint,'
 		'weight		bigint,'
 		'transaction	bigint,'
-		'data_src	bigint)')
+		'data_src	bigint,'
+		'branch_type	integer,'
+		'in_tx		boolean)')
 
 do_query(query, 'CREATE VIEW samples_view AS '
 	'SELECT '
@@ -178,7 +186,9 @@ do_query(query, 'CREATE VIEW samples_view AS '
 		'to_hex(to_ip) AS to_ip_hex,'
 		'(SELECT name FROM symbols WHERE id = to_symbol_id) AS to_symbol,'
 		'to_sym_offset,'
-		'(SELECT short_name FROM dsos WHERE id = to_dso_id) AS to_dso_short_name'
+		'(SELECT short_name FROM dsos WHERE id = to_dso_id) AS to_dso_short_name,'
+		'(SELECT name FROM branch_types WHERE id = branch_type) AS branch_type_name,'
+		'in_tx'
 	' FROM samples')
 
 
@@ -234,6 +244,7 @@ comm_file		= open_output_file("comm_table.bin")
 comm_thread_file	= open_output_file("comm_thread_table.bin")
 dso_file		= open_output_file("dso_table.bin")
 symbol_file		= open_output_file("symbol_table.bin")
+branch_type_file	= open_output_file("branch_type_table.bin")
 sample_file		= open_output_file("sample_table.bin")
 
 def trace_begin():
@@ -257,6 +268,7 @@ def trace_end():
 	copy_output_file(comm_thread_file,	"comm_threads")
 	copy_output_file(dso_file,		"dsos")
 	copy_output_file(symbol_file,		"symbols")
+	copy_output_file(branch_type_file,	"branch_types")
 	copy_output_file(sample_file,		"samples")
 
 	print datetime.datetime.today(), "Removing intermediate files..."
@@ -267,6 +279,7 @@ def trace_end():
 	remove_output_file(comm_thread_file)
 	remove_output_file(dso_file)
 	remove_output_file(symbol_file)
+	remove_output_file(branch_type_file)
 	remove_output_file(sample_file)
 	os.rmdir(output_dir_name)
 	print datetime.datetime.today(), "Adding primary keys"
@@ -277,6 +290,7 @@ def trace_end():
 	do_query(query, 'ALTER TABLE comm_threads    ADD PRIMARY KEY (id)')
 	do_query(query, 'ALTER TABLE dsos            ADD PRIMARY KEY (id)')
 	do_query(query, 'ALTER TABLE symbols         ADD PRIMARY KEY (id)')
+	do_query(query, 'ALTER TABLE branch_types    ADD PRIMARY KEY (id)')
 	do_query(query, 'ALTER TABLE samples         ADD PRIMARY KEY (id)')
 
 	print datetime.datetime.today(), "Adding foreign keys"
@@ -352,9 +366,15 @@ def symbol_table(symbol_id, dso_id, sym_start, sym_end, binding, symbol_name, *x
 	value = struct.pack(fmt, 6, 8, symbol_id, 8, dso_id, 8, sym_start, 8, sym_end, 4, binding, n, symbol_name)
 	symbol_file.write(value)
 
-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, *x):
+def branch_type_table(branch_type, name, *x):
+	n = len(name)
+	fmt = "!hiii" + str(n) + "s"
+	value = struct.pack(fmt, 2, 4, branch_type, n, name)
+	branch_type_file.write(value)
+
+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):
 	if branches:
-		value = struct.pack("!hiqiqiqiqiqiqiqiqiqiqiiiqiqiqiq", 15, 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)
+		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)
 	else:
-		value = struct.pack("!hiqiqiqiqiqiqiqiqiqiqiiiqiqiqiqiqiqiqiq", 19, 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)
+		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)
 	sample_file.write(value)
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index 3062eb8..45483a4 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -65,6 +65,7 @@ struct tables {
 	PyObject		*comm_thread_handler;
 	PyObject		*dso_handler;
 	PyObject		*symbol_handler;
+	PyObject		*branch_type_handler;
 	PyObject		*sample_handler;
 	bool			db_export_mode;
 };
@@ -662,13 +663,31 @@ static int python_export_symbol(struct db_export *dbe, struct symbol *sym,
 	return 0;
 }
 
+static int python_export_branch_type(struct db_export *dbe, u32 branch_type,
+				     const char *name)
+{
+	struct tables *tables = container_of(dbe, struct tables, dbe);
+	PyObject *t;
+
+	t = tuple_new(2);
+
+	tuple_set_s32(t, 0, branch_type);
+	tuple_set_string(t, 1, name);
+
+	call_object(tables->branch_type_handler, t, "branch_type_table");
+
+	Py_DECREF(t);
+
+	return 0;
+}
+
 static int python_export_sample(struct db_export *dbe,
 				struct export_sample *es)
 {
 	struct tables *tables = container_of(dbe, struct tables, dbe);
 	PyObject *t;
 
-	t = tuple_new(19);
+	t = tuple_new(21);
 
 	tuple_set_u64(t, 0, es->db_id);
 	tuple_set_u64(t, 1, es->evsel->db_id);
@@ -689,6 +708,8 @@ static int python_export_sample(struct db_export *dbe,
 	tuple_set_u64(t, 16, es->sample->weight);
 	tuple_set_u64(t, 17, es->sample->transaction);
 	tuple_set_u64(t, 18, es->sample->data_src);
+	tuple_set_s32(t, 19, es->sample->flags & PERF_BRANCH_MASK);
+	tuple_set_s32(t, 20, !!(es->sample->flags & PERF_FLAG_IN_TX));
 
 	call_object(tables->sample_handler, t, "sample_table");
 
@@ -855,6 +876,7 @@ static void set_table_handlers(struct tables *tables)
 	SET_TABLE_HANDLER(comm_thread);
 	SET_TABLE_HANDLER(dso);
 	SET_TABLE_HANDLER(symbol);
+	SET_TABLE_HANDLER(branch_type);
 	SET_TABLE_HANDLER(sample);
 }
 
@@ -904,6 +926,12 @@ static int python_start_script(const char *script, int argc, const char **argv)
 
 	set_table_handlers(tables);
 
+	if (tables->db_export_mode) {
+		err = db_export__branch_types(&tables->dbe);
+		if (err)
+			goto error;
+	}
+
 	return err;
 error:
 	Py_Finalize();
-- 
1.8.3.2


  parent reply	other threads:[~2014-07-31  6:03 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-31  6:00 [PATCH 00/31] perf tools: Yet more preparation for call graph from Intel BTS Adrian Hunter
2014-07-31  6:00 ` [PATCH 01/31] perf tools: Identify which comms are from exec Adrian Hunter
2014-08-14  8:51   ` [tip:perf/core] " tip-bot for Adrian Hunter
2014-07-31  6:00 ` [PATCH 02/31] perf tools: Add machine__thread_exec_comm() Adrian Hunter
2014-08-14  8:51   ` [tip:perf/core] perf machine: " tip-bot for Adrian Hunter
2014-07-31  6:00 ` [PATCH 03/31] perf tools: Fix missing label symbols Adrian Hunter
2014-08-14  8:50   ` [tip:perf/core] perf symbols: " tip-bot for Adrian Hunter
2014-07-31  6:00 ` [PATCH 04/31] perf tools: Add machine__kernel_ip() Adrian Hunter
2014-07-31  6:00 ` [PATCH 05/31] perf tools: Let a user specify a PMU event without any config terms Adrian Hunter
2014-07-31  6:00 ` [PATCH 06/31] perf tools: Let default config be defined for a PMU Adrian Hunter
2014-09-19  5:20   ` [tip:perf/core] " tip-bot for Adrian Hunter
2014-07-31  6:00 ` [PATCH 07/31] perf tools: Add perf_pmu__scan_file() Adrian Hunter
2014-09-19  5:21   ` [tip:perf/core] " tip-bot for Adrian Hunter
2014-07-31  6:00 ` [PATCH 08/31] perf evlist: Add 'system_wide' option Adrian Hunter
2014-08-14  8:50   ` [tip:perf/core] " tip-bot for Adrian Hunter
2014-07-31  6:00 ` [PATCH 09/31] perf evlist: Add perf_evlist__set_tracking_event() Adrian Hunter
2014-08-14  8:50   ` [tip:perf/core] perf evlist: Add perf_evlist__set_tracking_event( ) tip-bot for Adrian Hunter
2014-07-31  6:00 ` [PATCH 10/31] perf tools: Add id index Adrian Hunter
2014-07-31  6:00 ` [PATCH 11/31] perf pmu: Let pmu's with no events show up on perf list Adrian Hunter
2014-07-31  6:00 ` [PATCH 12/31] perf session: Add perf_session__deliver_synth_event() Adrian Hunter
2014-07-31  6:00 ` [PATCH 13/31] perf evlist: Add perf_evlist__enable_event_idx() Adrian Hunter
2014-08-14  8:52   ` [tip:perf/core] " tip-bot for Adrian Hunter
2014-07-31  6:00 ` [PATCH 14/31] perf session: Add perf_session__peek_event() Adrian Hunter
2014-08-14  8:50   ` [tip:perf/core] " tip-bot for Adrian Hunter
2014-07-31  6:00 ` [PATCH 15/31] perf tools: Add a thread stack for synthesizing call chains Adrian Hunter
2014-07-31  6:00 ` [PATCH 16/31] perf script: Allow callchains if any event samples them Adrian Hunter
2014-08-14  8:51   ` [tip:perf/core] " tip-bot for Adrian Hunter
2014-07-31  6:01 ` [PATCH 17/31] perf tools: Add facility to export data in database-friendly way Adrian Hunter
2014-07-31  6:01 ` [PATCH 18/31] perf tools: Add helpers for calling Python objects Adrian Hunter
2014-08-14  8:51   ` [tip:perf/core] perf script python: " tip-bot for Adrian Hunter
2014-07-31  6:01 ` [PATCH 19/31] perf tools: Extend Python script interface to export data in a database-friendly way Adrian Hunter
2014-07-31  6:01 ` [PATCH 20/31] perf tools: Add Python script to export to postgresql Adrian Hunter
2014-07-31  6:01 ` [PATCH 21/31] perf tools: Add flags and insn_len to struct sample Adrian Hunter
2014-08-14  8:51   ` [tip:perf/core] " tip-bot for Adrian Hunter
2014-07-31  6:01 ` [PATCH 22/31] perf tools: Add branch type to db export Adrian Hunter
2014-07-31  6:01 ` Adrian Hunter [this message]
2014-07-31  6:01 ` [PATCH 24/31] perf tools: Enhance the thread stack to output call/return data Adrian Hunter
2014-07-31  6:01 ` [PATCH 25/31] perf tools: Add call information to the database export API Adrian Hunter
2014-07-31  6:01 ` [PATCH 26/31] perf tools: Add call information to Python export Adrian Hunter
2014-07-31  6:01 ` [PATCH 27/31] perf tools: Add 'flush' callback to scripting API Adrian Hunter
2014-07-31  6:01 ` [PATCH 28/31] perf tools: Defer export of comms that were not 'set' Adrian Hunter
2014-07-31  6:01 ` [PATCH 29/31] perf tools: Add perf-with-kcore script Adrian Hunter
2014-09-19  5:20   ` [tip:perf/core] " tip-bot for Adrian Hunter
2014-07-31  6:01 ` [PATCH 30/31] perf tools: Build programs to copy 32-bit compatibility VDSOs Adrian Hunter
2014-07-31  6:01 ` [PATCH 31/31] perf tools: Add support for " Adrian Hunter
2014-08-04 21:58 ` [PATCH 00/31] perf tools: Yet more preparation for call graph from Intel BTS Arnaldo Carvalho de Melo
2014-08-05 17:13   ` Adrian Hunter

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=1406786474-9306-24-git-send-email-adrian.hunter@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=namhyung@gmail.com \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    /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).