1 # export-to-sqlite.py: export perf data to a sqlite3 database
2 # Copyright (c) 2017, Intel Corporation.
4 # This program is free software; you can redistribute it and/or modify it
5 # under the terms and conditions of the GNU General Public License,
6 # version 2, as published by the Free Software Foundation.
8 # This program is distributed in the hope it will be useful, but WITHOUT
9 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 from __future__
import print_function
20 # To use this script you will need to have installed package python-pyside which
21 # provides LGPL-licensed Python bindings for Qt. You will also need the package
22 # libqt4-sql-sqlite for Qt sqlite3 support.
24 # Examples of installing pyside:
28 # $ sudo apt-get install python-pyside.qtsql libqt4-sql-psql
30 # Alternately, to use Python3 and/or pyside 2, one of the following:
32 # $ sudo apt-get install python3-pyside.qtsql libqt4-sql-psql
33 # $ sudo apt-get install python-pyside2.qtsql libqt5sql5-psql
34 # $ sudo apt-get install python3-pyside2.qtsql libqt5sql5-psql
37 # $ sudo yum install python-pyside
39 # Alternately, to use Python3 and/or pyside 2, one of the following:
40 # $ sudo yum install python3-pyside
41 # $ pip install --user PySide2
42 # $ pip3 install --user PySide2
44 # An example of using this script with Intel PT:
46 # $ perf record -e intel_pt//u ls
47 # $ perf script -s ~/libexec/perf-core/scripts/python/export-to-sqlite.py pt_example branches calls
48 # 2017-07-31 14:26:07.326913 Creating database...
49 # 2017-07-31 14:26:07.538097 Writing records...
50 # 2017-07-31 14:26:09.889292 Adding indexes
51 # 2017-07-31 14:26:09.958746 Done
53 # To browse the database, sqlite3 can be used e.g.
55 # $ sqlite3 pt_example
57 # sqlite> select * from samples_view where id < 10;
58 # sqlite> .mode column
59 # sqlite> select * from samples_view where id < 10;
61 # sqlite> .schema samples_view
64 # An example of using the database is provided by the script
65 # exported-sql-viewer.py. Refer to that script for details.
67 # The database structure is practically the same as created by the script
68 # export-to-postgresql.py. Refer to that script for details. A notable
69 # difference is the 'transaction' column of the 'samples' table which is
70 # renamed 'transaction_' in sqlite because 'transaction' is a reserved word.
72 pyside_version_1
= True
73 if not "pyside-version-1" in sys
.argv
:
75 from PySide2
.QtSql
import *
76 pyside_version_1
= False
81 from PySide
.QtSql
import *
83 sys
.path
.append(os
.environ
['PERF_EXEC_PATH'] + \
84 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
86 # These perf imports are not used at present
87 #from perf_trace_context import *
90 perf_db_export_mode
= True
91 perf_db_export_calls
= False
92 perf_db_export_callchains
= False
94 def printerr(*args
, **keyword_args
):
95 print(*args
, file=sys
.stderr
, **keyword_args
)
97 def printdate(*args
, **kw_args
):
98 print(datetime
.datetime
.today(), *args
, sep
=' ', **kw_args
)
101 printerr("Usage is: export-to-sqlite.py <database name> [<columns>] [<calls>] [<callchains>] [<pyside-version-1>]");
102 printerr("where: columns 'all' or 'branches'");
103 printerr(" calls 'calls' => create calls and call_paths table");
104 printerr(" callchains 'callchains' => create call_paths table");
105 printerr(" pyside-version-1 'pyside-version-1' => use pyside version 1");
106 raise Exception("Too few or bad arguments")
108 if (len(sys
.argv
) < 2):
113 if (len(sys
.argv
) >= 3):
114 columns
= sys
.argv
[2]
118 if columns
not in ("all", "branches"):
121 branches
= (columns
== "branches")
123 for i
in range(3,len(sys
.argv
)):
124 if (sys
.argv
[i
] == "calls"):
125 perf_db_export_calls
= True
126 elif (sys
.argv
[i
] == "callchains"):
127 perf_db_export_callchains
= True
128 elif (sys
.argv
[i
] == "pyside-version-1"):
136 raise Exception("Query failed: " + q
.lastError().text())
141 raise Exception("Query failed: " + q
.lastError().text())
143 printdate("Creating database ...")
154 raise Exception(dbname
+ " already exists")
156 db
= QSqlDatabase
.addDatabase('QSQLITE')
157 db
.setDatabaseName(dbname
)
160 query
= QSqlQuery(db
)
162 do_query(query
, 'PRAGMA journal_mode = OFF')
163 do_query(query
, 'BEGIN TRANSACTION')
165 do_query(query
, 'CREATE TABLE selected_events ('
166 'id integer NOT NULL PRIMARY KEY,'
168 do_query(query
, 'CREATE TABLE machines ('
169 'id integer NOT NULL PRIMARY KEY,'
171 'root_dir varchar(4096))')
172 do_query(query
, 'CREATE TABLE threads ('
173 'id integer NOT NULL PRIMARY KEY,'
178 do_query(query
, 'CREATE TABLE comms ('
179 'id integer NOT NULL PRIMARY KEY,'
181 'c_thread_id bigint,'
183 'exec_flag boolean)')
184 do_query(query
, 'CREATE TABLE comm_threads ('
185 'id integer NOT NULL PRIMARY KEY,'
188 do_query(query
, 'CREATE TABLE dsos ('
189 'id integer NOT NULL PRIMARY KEY,'
191 'short_name varchar(256),'
192 'long_name varchar(4096),'
193 'build_id varchar(64))')
194 do_query(query
, 'CREATE TABLE symbols ('
195 'id integer NOT NULL PRIMARY KEY,'
200 'name varchar(2048))')
201 do_query(query
, 'CREATE TABLE branch_types ('
202 'id integer NOT NULL PRIMARY KEY,'
206 do_query(query
, 'CREATE TABLE samples ('
207 'id integer NOT NULL PRIMARY KEY,'
219 'to_symbol_id bigint,'
220 'to_sym_offset bigint,'
222 'branch_type integer,'
224 'call_path_id bigint,'
228 do_query(query
, 'CREATE TABLE samples ('
229 'id integer NOT NULL PRIMARY KEY,'
241 'to_symbol_id bigint,'
242 'to_sym_offset bigint,'
246 'transaction_ bigint,'
248 'branch_type integer,'
250 'call_path_id bigint,'
254 if perf_db_export_calls
or perf_db_export_callchains
:
255 do_query(query
, 'CREATE TABLE call_paths ('
256 'id integer NOT NULL PRIMARY KEY,'
260 if perf_db_export_calls
:
261 do_query(query
, 'CREATE TABLE calls ('
262 'id integer NOT NULL PRIMARY KEY,'
265 'call_path_id bigint,'
267 'return_time bigint,'
268 'branch_count bigint,'
271 'parent_call_path_id bigint,'
277 do_query(query
, 'CREATE TABLE ptwrite ('
278 'id integer NOT NULL PRIMARY KEY,'
282 do_query(query
, 'CREATE TABLE cbr ('
283 'id integer NOT NULL PRIMARY KEY,'
288 do_query(query
, 'CREATE TABLE mwait ('
289 'id integer NOT NULL PRIMARY KEY,'
291 'extensions integer)')
293 do_query(query
, 'CREATE TABLE pwre ('
294 'id integer NOT NULL PRIMARY KEY,'
299 do_query(query
, 'CREATE TABLE exstop ('
300 'id integer NOT NULL PRIMARY KEY,'
303 do_query(query
, 'CREATE TABLE pwrx ('
304 'id integer NOT NULL PRIMARY KEY,'
305 'deepest_cstate integer,'
306 'last_cstate integer,'
307 'wake_reason integer)')
309 do_query(query
, 'CREATE TABLE context_switches ('
310 'id integer NOT NULL PRIMARY KEY,'
314 'thread_out_id bigint,'
315 'comm_out_id bigint,'
316 'thread_in_id bigint,'
320 # printf was added to sqlite in version 3.8.3
321 sqlite_has_printf
= False
323 do_query(query
, 'SELECT printf("") FROM machines')
324 sqlite_has_printf
= True
329 if sqlite_has_printf
:
330 return 'printf("%x", ' + x
+ ')'
334 do_query(query
, 'CREATE VIEW machines_view AS '
339 'CASE WHEN id=0 THEN \'unknown\' WHEN pid=-1 THEN \'host\' ELSE \'guest\' END AS host_or_guest'
342 do_query(query
, 'CREATE VIEW dsos_view AS '
346 '(SELECT host_or_guest FROM machines_view WHERE id = machine_id) AS host_or_guest,'
352 do_query(query
, 'CREATE VIEW symbols_view AS '
356 '(SELECT short_name FROM dsos WHERE id=dso_id) AS dso,'
360 'CASE WHEN binding=0 THEN \'local\' WHEN binding=1 THEN \'global\' ELSE \'weak\' END AS binding'
363 do_query(query
, 'CREATE VIEW threads_view AS '
367 '(SELECT host_or_guest FROM machines_view WHERE id = machine_id) AS host_or_guest,'
373 do_query(query
, 'CREATE VIEW comm_threads_view AS '
376 '(SELECT comm FROM comms WHERE id = comm_id) AS command,'
378 '(SELECT pid FROM threads WHERE id = thread_id) AS pid,'
379 '(SELECT tid FROM threads WHERE id = thread_id) AS tid'
380 ' FROM comm_threads')
382 if perf_db_export_calls
or perf_db_export_callchains
:
383 do_query(query
, 'CREATE VIEW call_paths_view AS '
386 + emit_to_hex('c.ip') + ' AS ip,'
388 '(SELECT name FROM symbols WHERE id = c.symbol_id) AS symbol,'
389 '(SELECT dso_id FROM symbols WHERE id = c.symbol_id) AS dso_id,'
390 '(SELECT dso FROM symbols_view WHERE id = c.symbol_id) AS dso_short_name,'
392 + emit_to_hex('p.ip') + ' AS parent_ip,'
393 'p.symbol_id AS parent_symbol_id,'
394 '(SELECT name FROM symbols WHERE id = p.symbol_id) AS parent_symbol,'
395 '(SELECT dso_id FROM symbols WHERE id = p.symbol_id) AS parent_dso_id,'
396 '(SELECT dso FROM symbols_view WHERE id = p.symbol_id) AS parent_dso_short_name'
397 ' FROM call_paths c INNER JOIN call_paths p ON p.id = c.parent_id')
398 if perf_db_export_calls
:
399 do_query(query
, 'CREATE VIEW calls_view AS '
403 '(SELECT pid FROM threads WHERE id = thread_id) AS pid,'
404 '(SELECT tid FROM threads WHERE id = thread_id) AS tid,'
405 '(SELECT comm FROM comms WHERE id = comm_id) AS command,'
407 + emit_to_hex('ip') + ' AS ip,'
409 '(SELECT name FROM symbols WHERE id = symbol_id) AS symbol,'
412 'return_time - call_time AS elapsed_time,'
416 'CASE WHEN cyc_count=0 THEN CAST(0 AS FLOAT) ELSE ROUND(CAST(insn_count AS FLOAT) / cyc_count, 2) END AS IPC,'
419 '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,'
420 'parent_call_path_id,'
422 ' FROM calls INNER JOIN call_paths ON call_paths.id = call_path_id')
424 do_query(query
, 'CREATE VIEW samples_view AS '
429 '(SELECT pid FROM threads WHERE id = thread_id) AS pid,'
430 '(SELECT tid FROM threads WHERE id = thread_id) AS tid,'
431 '(SELECT comm FROM comms WHERE id = comm_id) AS command,'
432 '(SELECT name FROM selected_events WHERE id = evsel_id) AS event,'
433 + emit_to_hex('ip') + ' AS ip_hex,'
434 '(SELECT name FROM symbols WHERE id = symbol_id) AS symbol,'
436 '(SELECT short_name FROM dsos WHERE id = dso_id) AS dso_short_name,'
437 + emit_to_hex('to_ip') + ' AS to_ip_hex,'
438 '(SELECT name FROM symbols WHERE id = to_symbol_id) AS to_symbol,'
440 '(SELECT short_name FROM dsos WHERE id = to_dso_id) AS to_dso_short_name,'
441 '(SELECT name FROM branch_types WHERE id = branch_type) AS branch_type_name,'
445 'CASE WHEN cyc_count=0 THEN CAST(0 AS FLOAT) ELSE ROUND(CAST(insn_count AS FLOAT) / cyc_count, 2) END AS IPC'
448 do_query(query
, 'CREATE VIEW ptwrite_view AS '
453 + emit_to_hex('payload') + ' AS payload_hex,'
454 'CASE WHEN exact_ip=0 THEN \'False\' ELSE \'True\' END AS exact_ip'
456 ' INNER JOIN samples ON samples.id = ptwrite.id')
458 do_query(query
, 'CREATE VIEW cbr_view AS '
467 ' INNER JOIN samples ON samples.id = cbr.id')
469 do_query(query
, 'CREATE VIEW mwait_view AS '
474 + emit_to_hex('hints') + ' AS hints_hex,'
475 + emit_to_hex('extensions') + ' AS extensions_hex'
477 ' INNER JOIN samples ON samples.id = mwait.id')
479 do_query(query
, 'CREATE VIEW pwre_view AS '
486 'CASE WHEN hw=0 THEN \'False\' ELSE \'True\' END AS hw'
488 ' INNER JOIN samples ON samples.id = pwre.id')
490 do_query(query
, 'CREATE VIEW exstop_view AS '
495 'CASE WHEN exact_ip=0 THEN \'False\' ELSE \'True\' END AS exact_ip'
497 ' INNER JOIN samples ON samples.id = exstop.id')
499 do_query(query
, 'CREATE VIEW pwrx_view AS '
506 'CASE WHEN wake_reason=1 THEN \'Interrupt\''
507 ' WHEN wake_reason=2 THEN \'Timer Deadline\''
508 ' WHEN wake_reason=4 THEN \'Monitored Address\''
509 ' WHEN wake_reason=8 THEN \'HW\''
513 ' INNER JOIN samples ON samples.id = pwrx.id')
515 do_query(query
, 'CREATE VIEW power_events_view AS '
520 'selected_events.name AS event,'
521 'CASE WHEN selected_events.name=\'cbr\' THEN (SELECT cbr FROM cbr WHERE cbr.id = samples.id) ELSE "" END AS cbr,'
522 'CASE WHEN selected_events.name=\'cbr\' THEN (SELECT mhz FROM cbr WHERE cbr.id = samples.id) ELSE "" END AS mhz,'
523 'CASE WHEN selected_events.name=\'cbr\' THEN (SELECT percent FROM cbr WHERE cbr.id = samples.id) ELSE "" END AS percent,'
524 'CASE WHEN selected_events.name=\'mwait\' THEN (SELECT ' + emit_to_hex('hints') + ' FROM mwait WHERE mwait.id = samples.id) ELSE "" END AS hints_hex,'
525 'CASE WHEN selected_events.name=\'mwait\' THEN (SELECT ' + emit_to_hex('extensions') + ' FROM mwait WHERE mwait.id = samples.id) ELSE "" END AS extensions_hex,'
526 'CASE WHEN selected_events.name=\'pwre\' THEN (SELECT cstate FROM pwre WHERE pwre.id = samples.id) ELSE "" END AS cstate,'
527 'CASE WHEN selected_events.name=\'pwre\' THEN (SELECT subcstate FROM pwre WHERE pwre.id = samples.id) ELSE "" END AS subcstate,'
528 'CASE WHEN selected_events.name=\'pwre\' THEN (SELECT hw FROM pwre WHERE pwre.id = samples.id) ELSE "" END AS hw,'
529 'CASE WHEN selected_events.name=\'exstop\' THEN (SELECT exact_ip FROM exstop WHERE exstop.id = samples.id) ELSE "" END AS exact_ip,'
530 'CASE WHEN selected_events.name=\'pwrx\' THEN (SELECT deepest_cstate FROM pwrx WHERE pwrx.id = samples.id) ELSE "" END AS deepest_cstate,'
531 'CASE WHEN selected_events.name=\'pwrx\' THEN (SELECT last_cstate FROM pwrx WHERE pwrx.id = samples.id) ELSE "" END AS last_cstate,'
532 'CASE WHEN selected_events.name=\'pwrx\' THEN (SELECT '
533 'CASE WHEN wake_reason=1 THEN \'Interrupt\''
534 ' WHEN wake_reason=2 THEN \'Timer Deadline\''
535 ' WHEN wake_reason=4 THEN \'Monitored Address\''
536 ' WHEN wake_reason=8 THEN \'HW\''
539 ' FROM pwrx WHERE pwrx.id = samples.id) ELSE "" END AS wake_reason'
541 ' INNER JOIN selected_events ON selected_events.id = evsel_id'
542 ' WHERE selected_events.name IN (\'cbr\',\'mwait\',\'exstop\',\'pwre\',\'pwrx\')')
544 do_query(query
, 'CREATE VIEW context_switches_view AS '
546 'context_switches.id,'
547 'context_switches.machine_id,'
548 'context_switches.time,'
549 'context_switches.cpu,'
550 'th_out.pid AS pid_out,'
551 'th_out.tid AS tid_out,'
552 'comm_out.comm AS comm_out,'
553 'th_in.pid AS pid_in,'
554 'th_in.tid AS tid_in,'
555 'comm_in.comm AS comm_in,'
556 'CASE WHEN context_switches.flags = 0 THEN \'in\''
557 ' WHEN context_switches.flags = 1 THEN \'out\''
558 ' WHEN context_switches.flags = 3 THEN \'out preempt\''
559 ' ELSE context_switches.flags '
561 ' FROM context_switches'
562 ' INNER JOIN threads AS th_out ON th_out.id = context_switches.thread_out_id'
563 ' INNER JOIN threads AS th_in ON th_in.id = context_switches.thread_in_id'
564 ' INNER JOIN comms AS comm_out ON comm_out.id = context_switches.comm_out_id'
565 ' INNER JOIN comms AS comm_in ON comm_in.id = context_switches.comm_in_id')
567 do_query(query
, 'END TRANSACTION')
569 evsel_query
= QSqlQuery(db
)
570 evsel_query
.prepare("INSERT INTO selected_events VALUES (?, ?)")
571 machine_query
= QSqlQuery(db
)
572 machine_query
.prepare("INSERT INTO machines VALUES (?, ?, ?)")
573 thread_query
= QSqlQuery(db
)
574 thread_query
.prepare("INSERT INTO threads VALUES (?, ?, ?, ?, ?)")
575 comm_query
= QSqlQuery(db
)
576 comm_query
.prepare("INSERT INTO comms VALUES (?, ?, ?, ?, ?)")
577 comm_thread_query
= QSqlQuery(db
)
578 comm_thread_query
.prepare("INSERT INTO comm_threads VALUES (?, ?, ?)")
579 dso_query
= QSqlQuery(db
)
580 dso_query
.prepare("INSERT INTO dsos VALUES (?, ?, ?, ?, ?)")
581 symbol_query
= QSqlQuery(db
)
582 symbol_query
.prepare("INSERT INTO symbols VALUES (?, ?, ?, ?, ?, ?)")
583 branch_type_query
= QSqlQuery(db
)
584 branch_type_query
.prepare("INSERT INTO branch_types VALUES (?, ?)")
585 sample_query
= QSqlQuery(db
)
587 sample_query
.prepare("INSERT INTO samples VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
589 sample_query
.prepare("INSERT INTO samples VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
590 if perf_db_export_calls
or perf_db_export_callchains
:
591 call_path_query
= QSqlQuery(db
)
592 call_path_query
.prepare("INSERT INTO call_paths VALUES (?, ?, ?, ?)")
593 if perf_db_export_calls
:
594 call_query
= QSqlQuery(db
)
595 call_query
.prepare("INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
596 ptwrite_query
= QSqlQuery(db
)
597 ptwrite_query
.prepare("INSERT INTO ptwrite VALUES (?, ?, ?)")
598 cbr_query
= QSqlQuery(db
)
599 cbr_query
.prepare("INSERT INTO cbr VALUES (?, ?, ?, ?)")
600 mwait_query
= QSqlQuery(db
)
601 mwait_query
.prepare("INSERT INTO mwait VALUES (?, ?, ?)")
602 pwre_query
= QSqlQuery(db
)
603 pwre_query
.prepare("INSERT INTO pwre VALUES (?, ?, ?, ?)")
604 exstop_query
= QSqlQuery(db
)
605 exstop_query
.prepare("INSERT INTO exstop VALUES (?, ?)")
606 pwrx_query
= QSqlQuery(db
)
607 pwrx_query
.prepare("INSERT INTO pwrx VALUES (?, ?, ?, ?)")
608 context_switch_query
= QSqlQuery(db
)
609 context_switch_query
.prepare("INSERT INTO context_switches VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)")
612 printdate("Writing records...")
613 do_query(query
, 'BEGIN TRANSACTION')
614 # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs
615 evsel_table(0, "unknown")
616 machine_table(0, 0, "unknown")
617 thread_table(0, 0, 0, -1, -1)
618 comm_table(0, "unknown", 0, 0, 0)
619 dso_table(0, 0, "unknown", "unknown", "")
620 symbol_table(0, 0, 0, 0, 0, "unknown")
621 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)
622 if perf_db_export_calls
or perf_db_export_callchains
:
623 call_path_table(0, 0, 0, 0)
624 call_return_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
628 def is_table_empty(table_name
):
629 do_query(query
, 'SELECT * FROM ' + table_name
+ ' LIMIT 1');
634 def drop(table_name
):
635 do_query(query
, 'DROP VIEW ' + table_name
+ '_view');
636 do_query(query
, 'DROP TABLE ' + table_name
);
639 do_query(query
, 'END TRANSACTION')
641 printdate("Adding indexes")
642 if perf_db_export_calls
:
643 do_query(query
, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)')
644 do_query(query
, 'CREATE INDEX pid_idx ON calls (parent_id)')
645 do_query(query
, 'ALTER TABLE comms ADD has_calls boolean')
646 do_query(query
, 'UPDATE comms SET has_calls = 1 WHERE comms.id IN (SELECT DISTINCT comm_id FROM calls)')
648 printdate("Dropping unused tables")
649 if is_table_empty("ptwrite"):
651 if is_table_empty("mwait") and is_table_empty("pwre") and is_table_empty("exstop") and is_table_empty("pwrx"):
652 do_query(query
, 'DROP VIEW power_events_view');
657 if is_table_empty("cbr"):
659 if is_table_empty("context_switches"):
660 drop("context_switches")
662 if (unhandled_count
):
663 printdate("Warning: ", unhandled_count
, " unhandled events")
666 def trace_unhandled(event_name
, context
, event_fields_dict
):
667 global unhandled_count
670 def sched__sched_switch(*x
):
673 def bind_exec(q
, n
, x
):
675 q
.addBindValue(str(xx
))
679 bind_exec(evsel_query
, 2, x
)
681 def machine_table(*x
):
682 bind_exec(machine_query
, 3, x
)
684 def thread_table(*x
):
685 bind_exec(thread_query
, 5, x
)
688 bind_exec(comm_query
, 5, x
)
690 def comm_thread_table(*x
):
691 bind_exec(comm_thread_query
, 3, x
)
694 bind_exec(dso_query
, 5, x
)
696 def symbol_table(*x
):
697 bind_exec(symbol_query
, 6, x
)
699 def branch_type_table(*x
):
700 bind_exec(branch_type_query
, 2, x
)
702 def sample_table(*x
):
705 sample_query
.addBindValue(str(xx
))
707 sample_query
.addBindValue(str(xx
))
708 do_query_(sample_query
)
710 bind_exec(sample_query
, 24, x
)
712 def call_path_table(*x
):
713 bind_exec(call_path_query
, 4, x
)
715 def call_return_table(*x
):
716 bind_exec(call_query
, 14, x
)
718 def ptwrite(id, raw_buf
):
719 data
= struct
.unpack_from("<IQ", raw_buf
)
723 ptwrite_query
.addBindValue(str(id))
724 ptwrite_query
.addBindValue(str(payload
))
725 ptwrite_query
.addBindValue(str(exact_ip
))
726 do_query_(ptwrite_query
)
728 def cbr(id, raw_buf
):
729 data
= struct
.unpack_from("<BBBBII", raw_buf
)
731 MHz
= (data
[4] + 500) / 1000
732 percent
= ((cbr
* 1000 / data
[2]) + 5) / 10
733 cbr_query
.addBindValue(str(id))
734 cbr_query
.addBindValue(str(cbr
))
735 cbr_query
.addBindValue(str(MHz
))
736 cbr_query
.addBindValue(str(percent
))
739 def mwait(id, raw_buf
):
740 data
= struct
.unpack_from("<IQ", raw_buf
)
742 hints
= payload
& 0xff
743 extensions
= (payload
>> 32) & 0x3
744 mwait_query
.addBindValue(str(id))
745 mwait_query
.addBindValue(str(hints
))
746 mwait_query
.addBindValue(str(extensions
))
747 do_query_(mwait_query
)
749 def pwre(id, raw_buf
):
750 data
= struct
.unpack_from("<IQ", raw_buf
)
752 hw
= (payload
>> 7) & 1
753 cstate
= (payload
>> 12) & 0xf
754 subcstate
= (payload
>> 8) & 0xf
755 pwre_query
.addBindValue(str(id))
756 pwre_query
.addBindValue(str(cstate
))
757 pwre_query
.addBindValue(str(subcstate
))
758 pwre_query
.addBindValue(str(hw
))
759 do_query_(pwre_query
)
761 def exstop(id, raw_buf
):
762 data
= struct
.unpack_from("<I", raw_buf
)
765 exstop_query
.addBindValue(str(id))
766 exstop_query
.addBindValue(str(exact_ip
))
767 do_query_(exstop_query
)
769 def pwrx(id, raw_buf
):
770 data
= struct
.unpack_from("<IQ", raw_buf
)
772 deepest_cstate
= payload
& 0xf
773 last_cstate
= (payload
>> 4) & 0xf
774 wake_reason
= (payload
>> 8) & 0xf
775 pwrx_query
.addBindValue(str(id))
776 pwrx_query
.addBindValue(str(deepest_cstate
))
777 pwrx_query
.addBindValue(str(last_cstate
))
778 pwrx_query
.addBindValue(str(wake_reason
))
779 do_query_(pwrx_query
)
781 def synth_data(id, config
, raw_buf
, *x
):
795 def context_switch_table(*x
):
796 bind_exec(context_switch_query
, 9, x
)