History

perf scripts python: export-to-sqlite.py: Export IPC information

Export cycle and instruction counts on samples and calls tables. Committer testing: First runs some workload collecting intel_pt with the 'cyc' ter just for userspace: [root@quaco adrian.hunter]# perf record -o simple-retpoline.perf.data -e intel_pt/cyc/u ./simple-retpoline [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.035 MB simple-retpoline.perf.data ] [root@quaco adrian.hunter]# Then use the export-to-sqlite.py script to see if the changes in this cset don't make it to break and if the changes in the db schema are the ones expected: [root@quaco adrian.hunter]# perf script -i simple-retpoline.perf.data --itrace=be -s ~acme/libexec/perf-core/scripts/python/export-to-sqlite.py simple-retpoline.db branches calls 2019-05-31 11:50:46.942710 Creating database ... 2019-05-31 11:50:46.949663 Writing records... 2019-05-31 11:50:47.224033 Adding indexes 2019-05-31 11:50:47.231599 Done [root@quaco adrian.hunter]# Now lets use the db: [root@quaco adrian.hunter]# sqlite3 simple-retpoline.db SQLite version 3.26.0 2018-12-01 12:34:55 Enter ".help" for usage hints. sqlite> .schema samples CREATE TABLE samples (id integer NOT NULL PRIMARY KEY,evsel_id bigint,machine_id bigint,thread_id bigint,comm_id bigint,dso_id bigint,symbol_id bigint,sym_offset bigint,ip bigint,time bigint,cpuinteger,to_dso_id bigint,to_symbol_id bigint,to_sym_offset bigint,to_ip bigint,branch_type integer,in_tx boolean,call_path_id bigint,insn_count bigint,cyc_count bigint); sqlite> Cool, the 'insn_count' and 'cyc_count' are there, now lets see if we can use them in a query: sqlite> select insn_count,cyc_count from samples where cyc_count > 1500 and insn_count < 10; 6|1507 sqlite> select insn_count,cyc_count from samples where cyc_count > 1500; 118|2210 140|1516 3783|1861 132|1521 6|1507 sqlite> Seems to work :-)

Adrian Hunter committed 7 years ago

Commit 64adadb1 parent 52a2ab61 file · +24 −12Browse files

Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all

Unified · Split

tools/perf/scripts/python/export-to-sqlite.py+24−12
@@ -218,7 +218,9 @@ if branches: · 217 unmodified lines
218218 'to_ip bigint,'
219219 'branch_type integer,'
220220 'in_tx boolean,'
221− 'call_path_id bigint)')
221+ 'call_path_id bigint,'
222+ 'insn_count bigint,'
223+ 'cyc_count bigint)')
222224 else:
223225 do_query(query, 'CREATE TABLE samples ('
224226 'id integer NOT NULL PRIMARY KEY,'
@@ -242,7 +244,9 @@ else: · 17 unmodified lines
242244 'data_src bigint,'
243245 'branch_type integer,'
244246 'in_tx boolean,'
245− 'call_path_id bigint)')
247+ 'call_path_id bigint,'
248+ 'insn_count bigint,'
249+ 'cyc_count bigint)')
246250
247251 if perf_db_export_calls or perf_db_export_callchains:
248252 do_query(query, 'CREATE TABLE call_paths ('
@@ -263,7 +267,9 @@ if perf_db_export_calls: · 14 unmodified lines
263267 'return_id bigint,'
264268 'parent_call_path_id bigint,'
265269 'flags integer,'
266− 'parent_id bigint)')
270+ 'parent_id bigint,'
271+ 'insn_count bigint,'
272+ 'cyc_count bigint)')
267273
268274 # printf was added to sqlite in version 3.8.3
269275 sqlite_has_printf = False
@@ -359,6 +365,9 @@ if perf_db_export_calls: · 89 unmodified lines
359365 'return_time,'
360366 'return_time - call_time AS elapsed_time,'
361367 'branch_count,'
368+ 'insn_count,'
369+ 'cyc_count,'
370+ 'CASE WHEN cyc_count=0 THEN CAST(0 AS FLOAT) ELSE ROUND(CAST(insn_count AS FLOAT) / cyc_count, 2) END AS IPC,'
362371 'call_id,'
363372 'return_id,'
364373 'CASE WHEN flags=0 THEN \'\' WHEN flags=1 THEN \'no call\' WHEN flags=2 THEN \'no return\' WHEN flags=3 THEN \'no call/return\' WHEN flags=6 THEN \'jump\' ELSE flags END AS flags,'
@@ -384,7 +393,10 @@ do_query(query, 'CREATE VIEW samples_view AS ' · 19 unmodified lines
384393 'to_sym_offset,'
385394 '(SELECT short_name FROM dsos WHERE id = to_dso_id) AS to_dso_short_name,'
386395 '(SELECT name FROM branch_types WHERE id = branch_type) AS branch_type_name,'
387− 'in_tx'
396+ 'in_tx,'
397+ 'insn_count,'
398+ 'cyc_count,'
399+ 'CASE WHEN cyc_count=0 THEN CAST(0 AS FLOAT) ELSE ROUND(CAST(insn_count AS FLOAT) / cyc_count, 2) END AS IPC'
388400 ' FROM samples')
389401
390402 do_query(query, 'END TRANSACTION')
@@ -407,15 +419,15 @@ branch_type_query = QSqlQuery(db) · 16 unmodified lines
407419 branch_type_query.prepare("INSERT INTO branch_types VALUES (?, ?)")
408420 sample_query = QSqlQuery(db)
409421 if branches:
410− sample_query.prepare("INSERT INTO samples VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
422+ sample_query.prepare("INSERT INTO samples VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
411423 else:
412− sample_query.prepare("INSERT INTO samples VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
424+ sample_query.prepare("INSERT INTO samples VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
413425 if perf_db_export_calls or perf_db_export_callchains:
414426 call_path_query = QSqlQuery(db)
415427 call_path_query.prepare("INSERT INTO call_paths VALUES (?, ?, ?, ?)")
416428 if perf_db_export_calls:
417429 call_query = QSqlQuery(db)
418− call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
430+ call_query.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
419431
420432 def trace_begin():
421433 printdate("Writing records...")
@@ -427,10 +439,10 @@ def trace_begin(): · 5 unmodified lines
427439 comm_table(0, "unknown")
428440 dso_table(0, 0, "unknown", "unknown", "")
429441 symbol_table(0, 0, 0, 0, 0, "unknown")
430− sample_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
442+ sample_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
431443 if perf_db_export_calls or perf_db_export_callchains:
432444 call_path_table(0, 0, 0, 0)
433− call_return_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
445+ call_return_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
434446
435447 unhandled_count = 0
436448
@@ -486,14 +498,14 @@ def sample_table(*x): · 49 unmodified lines
486498 if branches:
487499 for xx in x[0:15]:
488500 sample_query.addBindValue(str(xx))
489− for xx in x[19:22]:
501+ for xx in x[19:24]:
490502 sample_query.addBindValue(str(xx))
491503 do_query_(sample_query)
492504 else:
493− bind_exec(sample_query, 22, x)
505+ bind_exec(sample_query, 24, x)
494506
495507 def call_path_table(*x):
496508 bind_exec(call_path_query, 4, x)
497509
498510 def call_return_table(*x):
499− bind_exec(call_query, 12, x)
511+ bind_exec(call_query, 14, x)