History

perf tools: Add call information to Python export

Add the ability to export detailed information about paired calls and returns to Python db export and the export-to-postgresql.py script.

Adrian Hunter committed 12 years ago

Commit 6a703071 parent 88f50d63 files · +158 −7Browse files

Showing the changes to tools/perf/scripts/python (2 of 3 files). Show all

Unified · Split

2 files
  1. tools/perf/scripts/python/bin/export-to-postgresql-report +10 −5
  2. tools/perf/scripts/python/export-to-postgresql.py +65 −1
tools/perf/scripts/python/bin/export-to-postgresql-report+10−5
@@ -1,6 +1,6 @@
11 #!/bin/bash
22 # description: export perf data to a postgresql database
3−# args: [database name] [columns]
3+# args: [database name] [columns] [calls]
44 n_args=0
55 for i in "$@"
66 do
@@ -9,11 +9,16 @@ do · 2 unmodified lines
99 fi
1010 n_args=$(( $n_args + 1 ))
1111 done
12−if [ "$n_args" -gt 2 ] ; then
13− echo "usage: export-to-postgresql-report [database name] [columns]"
12+if [ "$n_args" -gt 3 ] ; then
13+ echo "usage: export-to-postgresql-report [database name] [columns] [calls]"
1414 exit
1515 fi
16−if [ "$n_args" -gt 1 ] ; then
16+if [ "$n_args" -gt 2 ] ; then
17+ dbname=$1
18+ columns=$2
19+ calls=$3
20+ shift 3
21+elif [ "$n_args" -gt 1 ] ; then
1722 dbname=$1
1823 columns=$2
1924 shift 2
@@ -21,4 +26,4 @@ elif [ "$n_args" -gt 0 ] ; then · 1 unmodified line
2126 dbname=$1
2227 shift
2328 fi
24−perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/export-to-postgresql.py $dbname $columns
29+perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/export-to-postgresql.py $dbname $columns $calls
tools/perf/scripts/python/export-to-postgresql.py+65−1
@@ -40,10 +40,12 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \ · 39 unmodified lines
4040 #from Core import *
4141
4242 perf_db_export_mode = True
43+perf_db_export_calls = False
4344
4445 def usage():
45− print >> sys.stderr, "Usage is: export-to-postgresql.py <database name> [<columns>]"
46+ print >> sys.stderr, "Usage is: export-to-postgresql.py <database name> [<columns>] [<calls>]"
4647 print >> sys.stderr, "where: columns 'all' or 'branches'"
48+ print >> sys.stderr, " calls 'calls' => create calls table"
4749 raise Exception("Too few arguments")
4850
4951 if (len(sys.argv) < 2):
@@ -61,6 +63,12 @@ if columns not in ("all", "branches"): · 11 unmodified lines
6163
6264 branches = (columns == "branches")
6365
66+if (len(sys.argv) >= 4):
67+ if (sys.argv[3] == "calls"):
68+ perf_db_export_calls = True
69+ else:
70+ usage()
71+
6472 output_dir_name = os.getcwd() + "/" + dbname + "-perf-data"
6573 os.mkdir(output_dir_name)
6674
@@ -170,6 +178,25 @@ else: · 103 unmodified lines
170178 'branch_type integer,'
171179 'in_tx boolean)')
172180
181+if perf_db_export_calls:
182+ do_query(query, 'CREATE TABLE call_paths ('
183+ 'id bigint NOT NULL,'
184+ 'parent_id bigint,'
185+ 'symbol_id bigint,'
186+ 'ip bigint)')
187+ do_query(query, 'CREATE TABLE calls ('
188+ 'id bigint NOT NULL,'
189+ 'thread_id bigint,'
190+ 'comm_id bigint,'
191+ 'call_path_id bigint,'
192+ 'call_time bigint,'
193+ 'return_time bigint,'
194+ 'branch_count bigint,'
195+ 'call_id bigint,'
196+ 'return_id bigint,'
197+ 'parent_call_path_id bigint,'
198+ 'flags integer)')
199+
173200 do_query(query, 'CREATE VIEW samples_view AS '
174201 'SELECT '
175202 'id,'
@@ -246,6 +273,9 @@ dso_file = open_output_file("dso_table.bin") · 70 unmodified lines
246273 symbol_file = open_output_file("symbol_table.bin")
247274 branch_type_file = open_output_file("branch_type_table.bin")
248275 sample_file = open_output_file("sample_table.bin")
276+if perf_db_export_calls:
277+ call_path_file = open_output_file("call_path_table.bin")
278+ call_file = open_output_file("call_table.bin")
249279
250280 def trace_begin():
251281 print datetime.datetime.today(), "Writing to intermediate files..."
@@ -256,6 +286,9 @@ def trace_begin(): · 4 unmodified lines
256286 comm_table(0, "unknown")
257287 dso_table(0, 0, "unknown", "unknown", "")
258288 symbol_table(0, 0, 0, 0, 0, "unknown")
289+ sample_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
290+ if perf_db_export_calls:
291+ call_path_table(0, 0, 0, 0)
259292
260293 unhandled_count = 0
261294
@@ -270,6 +303,9 @@ def trace_end(): · 8 unmodified lines
270303 copy_output_file(symbol_file, "symbols")
271304 copy_output_file(branch_type_file, "branch_types")
272305 copy_output_file(sample_file, "samples")
306+ if perf_db_export_calls:
307+ copy_output_file(call_path_file, "call_paths")
308+ copy_output_file(call_file, "calls")
273309
274310 print datetime.datetime.today(), "Removing intermediate files..."
275311 remove_output_file(evsel_file)
@@ -281,6 +317,9 @@ def trace_end(): · 5 unmodified lines
281317 remove_output_file(symbol_file)
282318 remove_output_file(branch_type_file)
283319 remove_output_file(sample_file)
320+ if perf_db_export_calls:
321+ remove_output_file(call_path_file)
322+ remove_output_file(call_file)
284323 os.rmdir(output_dir_name)
285324 print datetime.datetime.today(), "Adding primary keys"
286325 do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)')
@@ -292,6 +331,9 @@ def trace_end(): · 5 unmodified lines
292331 do_query(query, 'ALTER TABLE symbols ADD PRIMARY KEY (id)')
293332 do_query(query, 'ALTER TABLE branch_types ADD PRIMARY KEY (id)')
294333 do_query(query, 'ALTER TABLE samples ADD PRIMARY KEY (id)')
334+ if perf_db_export_calls:
335+ do_query(query, 'ALTER TABLE call_paths ADD PRIMARY KEY (id)')
336+ do_query(query, 'ALTER TABLE calls ADD PRIMARY KEY (id)')
295337
296338 print datetime.datetime.today(), "Adding foreign keys"
297339 do_query(query, 'ALTER TABLE threads '
@@ -313,6 +355,18 @@ def trace_end(): · 15 unmodified lines
313355 'ADD CONSTRAINT symbolfk FOREIGN KEY (symbol_id) REFERENCES symbols (id),'
314356 'ADD CONSTRAINT todsofk FOREIGN KEY (to_dso_id) REFERENCES dsos (id),'
315357 'ADD CONSTRAINT tosymbolfk FOREIGN KEY (to_symbol_id) REFERENCES symbols (id)')
358+ if perf_db_export_calls:
359+ do_query(query, 'ALTER TABLE call_paths '
360+ 'ADD CONSTRAINT parentfk FOREIGN KEY (parent_id) REFERENCES call_paths (id),'
361+ 'ADD CONSTRAINT symbolfk FOREIGN KEY (symbol_id) REFERENCES symbols (id)')
362+ do_query(query, 'ALTER TABLE calls '
363+ 'ADD CONSTRAINT threadfk FOREIGN KEY (thread_id) REFERENCES threads (id),'
364+ 'ADD CONSTRAINT commfk FOREIGN KEY (comm_id) REFERENCES comms (id),'
365+ 'ADD CONSTRAINT call_pathfk FOREIGN KEY (call_path_id) REFERENCES call_paths (id),'
366+ 'ADD CONSTRAINT callfk FOREIGN KEY (call_id) REFERENCES samples (id),'
367+ 'ADD CONSTRAINT returnfk FOREIGN KEY (return_id) REFERENCES samples (id),'
368+ 'ADD CONSTRAINT parent_call_pathfk FOREIGN KEY (parent_call_path_id) REFERENCES call_paths (id)')
369+ do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)')
316370
317371 if (unhandled_count):
318372 print datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events"
@@ -378,3 +432,13 @@ def sample_table(sample_id, evsel_id, machine_id, thread_id, comm_id, dso_id, sy · 59 unmodified lines
378432 else:
379433 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)
380434 sample_file.write(value)
435+
436+def call_path_table(cp_id, parent_id, symbol_id, ip, *x):
437+ fmt = "!hiqiqiqiq"
438+ value = struct.pack(fmt, 4, 8, cp_id, 8, parent_id, 8, symbol_id, 8, ip)
439+ call_path_file.write(value)
440+
441+def call_return_table(cr_id, thread_id, comm_id, call_path_id, call_time, return_time, branch_count, call_id, return_id, parent_call_path_id, flags, *x):
442+ fmt = "!hiqiqiqiqiqiqiqiqiqiqii"
443+ value = struct.pack(fmt, 11, 8, cr_id, 8, thread_id, 8, comm_id, 8, call_path_id, 8, call_time, 8, return_time, 8, branch_count, 8, call_id, 8, return_id, 8, parent_call_path_id, 4, flags)
444+ call_file.write(value)