aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2014-10-30 10:09:44 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-11-03 16:07:34 -0500
commitc29414f5cfd641d956c5287848fdd8f25bb2afa3 (patch)
tree62ea8a2067fb13d3d76466eeb4a0317ac6403184 /tools
parentf2bff007679e7d293cb07bb26e18ccf11cc1c4b2 (diff)
perf tools: Add branch_type and in_tx to Python export
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> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1414678188-14946-4-git-send-email-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.py32
-rw-r--r--tools/perf/util/scripting-engines/trace-event-python.c30
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 d8f6df0093d6..bb79aecccf58 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 ('
123 'sym_end bigint,' 123 'sym_end bigint,'
124 'binding integer,' 124 'binding integer,'
125 'name varchar(2048))') 125 'name varchar(2048))')
126do_query(query, 'CREATE TABLE branch_types ('
127 'id integer NOT NULL,'
128 'name varchar(80))')
129
126if branches: 130if branches:
127 do_query(query, 'CREATE TABLE samples (' 131 do_query(query, 'CREATE TABLE samples ('
128 'id bigint NOT NULL,' 132 'id bigint NOT NULL,'
@@ -139,7 +143,9 @@ if branches:
139 'to_dso_id bigint,' 143 'to_dso_id bigint,'
140 'to_symbol_id bigint,' 144 'to_symbol_id bigint,'
141 'to_sym_offset bigint,' 145 'to_sym_offset bigint,'
142 'to_ip bigint)') 146 'to_ip bigint,'
147 'branch_type integer,'
148 'in_tx boolean)')
143else: 149else:
144 do_query(query, 'CREATE TABLE samples (' 150 do_query(query, 'CREATE TABLE samples ('
145 'id bigint NOT NULL,' 151 'id bigint NOT NULL,'
@@ -160,7 +166,9 @@ else:
160 'period bigint,' 166 'period bigint,'
161 'weight bigint,' 167 'weight bigint,'
162 'transaction bigint,' 168 'transaction bigint,'
163 'data_src bigint)') 169 'data_src bigint,'
170 'branch_type integer,'
171 'in_tx boolean)')
164 172
165do_query(query, 'CREATE VIEW samples_view AS ' 173do_query(query, 'CREATE VIEW samples_view AS '
166 'SELECT ' 174 'SELECT '
@@ -178,7 +186,9 @@ do_query(query, 'CREATE VIEW samples_view AS '
178 'to_hex(to_ip) AS to_ip_hex,' 186 'to_hex(to_ip) AS to_ip_hex,'
179 '(SELECT name FROM symbols WHERE id = to_symbol_id) AS to_symbol,' 187 '(SELECT name FROM symbols WHERE id = to_symbol_id) AS to_symbol,'
180 'to_sym_offset,' 188 'to_sym_offset,'
181 '(SELECT short_name FROM dsos WHERE id = to_dso_id) AS to_dso_short_name' 189 '(SELECT short_name FROM dsos WHERE id = to_dso_id) AS to_dso_short_name,'
190 '(SELECT name FROM branch_types WHERE id = branch_type) AS branch_type_name,'
191 'in_tx'
182 ' FROM samples') 192 ' FROM samples')
183 193
184 194
@@ -234,6 +244,7 @@ comm_file = open_output_file("comm_table.bin")
234comm_thread_file = open_output_file("comm_thread_table.bin") 244comm_thread_file = open_output_file("comm_thread_table.bin")
235dso_file = open_output_file("dso_table.bin") 245dso_file = open_output_file("dso_table.bin")
236symbol_file = open_output_file("symbol_table.bin") 246symbol_file = open_output_file("symbol_table.bin")
247branch_type_file = open_output_file("branch_type_table.bin")
237sample_file = open_output_file("sample_table.bin") 248sample_file = open_output_file("sample_table.bin")
238 249
239def trace_begin(): 250def trace_begin():
@@ -257,6 +268,7 @@ def trace_end():
257 copy_output_file(comm_thread_file, "comm_threads") 268 copy_output_file(comm_thread_file, "comm_threads")
258 copy_output_file(dso_file, "dsos") 269 copy_output_file(dso_file, "dsos")
259 copy_output_file(symbol_file, "symbols") 270 copy_output_file(symbol_file, "symbols")
271 copy_output_file(branch_type_file, "branch_types")
260 copy_output_file(sample_file, "samples") 272 copy_output_file(sample_file, "samples")
261 273
262 print datetime.datetime.today(), "Removing intermediate files..." 274 print datetime.datetime.today(), "Removing intermediate files..."
@@ -267,6 +279,7 @@ def trace_end():
267 remove_output_file(comm_thread_file) 279 remove_output_file(comm_thread_file)
268 remove_output_file(dso_file) 280 remove_output_file(dso_file)
269 remove_output_file(symbol_file) 281 remove_output_file(symbol_file)
282 remove_output_file(branch_type_file)
270 remove_output_file(sample_file) 283 remove_output_file(sample_file)
271 os.rmdir(output_dir_name) 284 os.rmdir(output_dir_name)
272 print datetime.datetime.today(), "Adding primary keys" 285 print datetime.datetime.today(), "Adding primary keys"
@@ -277,6 +290,7 @@ def trace_end():
277 do_query(query, 'ALTER TABLE comm_threads ADD PRIMARY KEY (id)') 290 do_query(query, 'ALTER TABLE comm_threads ADD PRIMARY KEY (id)')
278 do_query(query, 'ALTER TABLE dsos ADD PRIMARY KEY (id)') 291 do_query(query, 'ALTER TABLE dsos ADD PRIMARY KEY (id)')
279 do_query(query, 'ALTER TABLE symbols ADD PRIMARY KEY (id)') 292 do_query(query, 'ALTER TABLE symbols ADD PRIMARY KEY (id)')
293 do_query(query, 'ALTER TABLE branch_types ADD PRIMARY KEY (id)')
280 do_query(query, 'ALTER TABLE samples ADD PRIMARY KEY (id)') 294 do_query(query, 'ALTER TABLE samples ADD PRIMARY KEY (id)')
281 295
282 print datetime.datetime.today(), "Adding foreign keys" 296 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
352 value = struct.pack(fmt, 6, 8, symbol_id, 8, dso_id, 8, sym_start, 8, sym_end, 4, binding, n, symbol_name) 366 value = struct.pack(fmt, 6, 8, symbol_id, 8, dso_id, 8, sym_start, 8, sym_end, 4, binding, n, symbol_name)
353 symbol_file.write(value) 367 symbol_file.write(value)
354 368
355def 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): 369def branch_type_table(branch_type, name, *x):
370 n = len(name)
371 fmt = "!hiii" + str(n) + "s"
372 value = struct.pack(fmt, 2, 4, branch_type, n, name)
373 branch_type_file.write(value)
374
375def 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):
356 if branches: 376 if branches:
357 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) 377 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)
358 else: 378 else:
359 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) 379 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)
360 sample_file.write(value) 380 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 2fd7ee8f18c7..f3ca7798b3d0 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -66,6 +66,7 @@ struct tables {
66 PyObject *comm_thread_handler; 66 PyObject *comm_thread_handler;
67 PyObject *dso_handler; 67 PyObject *dso_handler;
68 PyObject *symbol_handler; 68 PyObject *symbol_handler;
69 PyObject *branch_type_handler;
69 PyObject *sample_handler; 70 PyObject *sample_handler;
70 bool db_export_mode; 71 bool db_export_mode;
71}; 72};
@@ -664,13 +665,31 @@ static int python_export_symbol(struct db_export *dbe, struct symbol *sym,
664 return 0; 665 return 0;
665} 666}
666 667
668static int python_export_branch_type(struct db_export *dbe, u32 branch_type,
669 const char *name)
670{
671 struct tables *tables = container_of(dbe, struct tables, dbe);
672 PyObject *t;
673
674 t = tuple_new(2);
675
676 tuple_set_s32(t, 0, branch_type);
677 tuple_set_string(t, 1, name);
678
679 call_object(tables->branch_type_handler, t, "branch_type_table");
680
681 Py_DECREF(t);
682
683 return 0;
684}
685
667static int python_export_sample(struct db_export *dbe, 686static int python_export_sample(struct db_export *dbe,
668 struct export_sample *es) 687 struct export_sample *es)
669{ 688{
670 struct tables *tables = container_of(dbe, struct tables, dbe); 689 struct tables *tables = container_of(dbe, struct tables, dbe);
671 PyObject *t; 690 PyObject *t;
672 691
673 t = tuple_new(19); 692 t = tuple_new(21);
674 693
675 tuple_set_u64(t, 0, es->db_id); 694 tuple_set_u64(t, 0, es->db_id);
676 tuple_set_u64(t, 1, es->evsel->db_id); 695 tuple_set_u64(t, 1, es->evsel->db_id);
@@ -691,6 +710,8 @@ static int python_export_sample(struct db_export *dbe,
691 tuple_set_u64(t, 16, es->sample->weight); 710 tuple_set_u64(t, 16, es->sample->weight);
692 tuple_set_u64(t, 17, es->sample->transaction); 711 tuple_set_u64(t, 17, es->sample->transaction);
693 tuple_set_u64(t, 18, es->sample->data_src); 712 tuple_set_u64(t, 18, es->sample->data_src);
713 tuple_set_s32(t, 19, es->sample->flags & PERF_BRANCH_MASK);
714 tuple_set_s32(t, 20, !!(es->sample->flags & PERF_IP_FLAG_IN_TX));
694 715
695 call_object(tables->sample_handler, t, "sample_table"); 716 call_object(tables->sample_handler, t, "sample_table");
696 717
@@ -861,6 +882,7 @@ static void set_table_handlers(struct tables *tables)
861 SET_TABLE_HANDLER(comm_thread); 882 SET_TABLE_HANDLER(comm_thread);
862 SET_TABLE_HANDLER(dso); 883 SET_TABLE_HANDLER(dso);
863 SET_TABLE_HANDLER(symbol); 884 SET_TABLE_HANDLER(symbol);
885 SET_TABLE_HANDLER(branch_type);
864 SET_TABLE_HANDLER(sample); 886 SET_TABLE_HANDLER(sample);
865} 887}
866 888
@@ -910,6 +932,12 @@ static int python_start_script(const char *script, int argc, const char **argv)
910 932
911 set_table_handlers(tables); 933 set_table_handlers(tables);
912 934
935 if (tables->db_export_mode) {
936 err = db_export__branch_types(&tables->dbe);
937 if (err)
938 goto error;
939 }
940
913 return err; 941 return err;
914error: 942error:
915 Py_Finalize(); 943 Py_Finalize();