1 # export-to-postgresql.py: export perf data to a postgresql database
2 # Copyright (c) 2014, 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-psql for Qt postgresql support.
24 # The script assumes postgresql is running on the local machine and that the
25 # user has postgresql permissions to create databases. Examples of installing
26 # postgresql and adding such a user are:
30 # $ sudo yum install postgresql postgresql-server python-pyside qt-postgresql
31 # $ sudo su - postgres -c initdb
32 # $ sudo service postgresql start
33 # $ sudo su - postgres
34 # $ createuser <your user id here>
35 # Shall the new role be a superuser? (y/n) y
39 # $ sudo apt-get install postgresql python-pyside.qtsql libqt4-sql-psql
40 # $ sudo su - postgres
41 # $ createuser -s <your user id here>
43 # An example of using this script with Intel PT:
45 # $ perf record -e intel_pt//u ls
46 # $ perf script -s ~/libexec/perf-core/scripts/python/export-to-postgresql.py pt_example branches calls
47 # 2015-05-29 12:49:23.464364 Creating database...
48 # 2015-05-29 12:49:26.281717 Writing to intermediate files...
49 # 2015-05-29 12:49:27.190383 Copying to database...
50 # 2015-05-29 12:49:28.140451 Removing intermediate files...
51 # 2015-05-29 12:49:28.147451 Adding primary keys
52 # 2015-05-29 12:49:28.655683 Adding foreign keys
53 # 2015-05-29 12:49:29.365350 Done
55 # To browse the database, psql can be used e.g.
58 # pt_example=# select * from samples_view where id < 100;
60 # pt_example=# \d+ samples_view
63 # An example of using the database is provided by the script
64 # exported-sql-viewer.py. Refer to that script for details.
68 # The tables largely correspond to perf tools' data structures. They are largely self-explanatory.
72 # 'samples' is the main table. It represents what instruction was executing at a point in time
73 # when something (a selected event) happened. The memory address is the instruction pointer or 'ip'.
77 # 'calls' represents function calls and is related to 'samples' by 'call_id' and 'return_id'.
78 # 'calls' is only created when the 'calls' option to this script is specified.
82 # 'call_paths' represents all the call stacks. Each 'call' has an associated record in 'call_paths'.
83 # 'calls_paths' is only created when the 'calls' option to this script is specified.
87 # 'branch_types' provides descriptions for each type of branch.
91 # 'comm_threads' shows how 'comms' relates to 'threads'.
95 # 'comms' contains a record for each 'comm' - the name given to the executable that is running.
99 # 'dsos' contains a record for each executable file or library.
103 # 'machines' can be used to distinguish virtual machines if virtualization is supported.
107 # 'selected_events' contains a record for each kind of event that has been sampled.
111 # 'symbols' contains a record for each symbol. Only symbols that have samples are present.
115 # 'threads' contains a record for each thread.
119 # Most of the tables have views for more friendly display. The views are:
130 # More examples of browsing the database with psql:
131 # Note that some of the examples are not the most optimal SQL query.
132 # Note that call information is only available if the script's 'calls' option has been used.
134 # Top 10 function calls (not aggregated by symbol):
136 # SELECT * FROM calls_view ORDER BY elapsed_time DESC LIMIT 10;
138 # Top 10 function calls (aggregated by symbol):
140 # SELECT symbol_id,(SELECT name FROM symbols WHERE id = symbol_id) AS symbol,
141 # SUM(elapsed_time) AS tot_elapsed_time,SUM(branch_count) AS tot_branch_count
142 # FROM calls_view GROUP BY symbol_id ORDER BY tot_elapsed_time DESC LIMIT 10;
144 # Note that the branch count gives a rough estimation of cpu usage, so functions
145 # that took a long time but have a relatively low branch count must have spent time
148 # Find symbols by pattern matching on part of the name (e.g. names containing 'alloc'):
150 # SELECT * FROM symbols_view WHERE name LIKE '%alloc%';
152 # Top 10 function calls for a specific symbol (e.g. whose symbol_id is 187):
154 # SELECT * FROM calls_view WHERE symbol_id = 187 ORDER BY elapsed_time DESC LIMIT 10;
156 # Show function calls made by function in the same context (i.e. same call path) (e.g. one with call_path_id 254):
158 # SELECT * FROM calls_view WHERE parent_call_path_id = 254;
160 # Show branches made during a function call (e.g. where call_id is 29357 and return_id is 29370 and tid is 29670)
162 # SELECT * FROM samples_view WHERE id >= 29357 AND id <= 29370 AND tid = 29670 AND event LIKE 'branches%';
166 # SELECT * FROM samples_view WHERE event = 'transactions';
168 # Note transaction start has 'in_tx' true whereas, transaction end has 'in_tx' false.
169 # Transaction aborts have branch_type_name 'transaction abort'
171 # Show transaction aborts:
173 # SELECT * FROM samples_view WHERE event = 'transactions' AND branch_type_name = 'transaction abort';
175 # To print a call stack requires walking the call_paths table. For example this python script:
179 # from PySide.QtSql import *
181 # if __name__ == '__main__':
182 # if (len(sys.argv) < 3):
183 # print >> sys.stderr, "Usage is: printcallstack.py <database name> <call_path_id>"
184 # raise Exception("Too few arguments")
185 # dbname = sys.argv[1]
186 # call_path_id = sys.argv[2]
187 # db = QSqlDatabase.addDatabase('QPSQL')
188 # db.setDatabaseName(dbname)
190 # raise Exception("Failed to open database " + dbname + " error: " + db.lastError().text())
191 # query = QSqlQuery(db)
192 # print " id ip symbol_id symbol dso_id dso_short_name"
193 # while call_path_id != 0 and call_path_id != 1:
194 # ret = query.exec_('SELECT * FROM call_paths_view WHERE id = ' + str(call_path_id))
196 # raise Exception("Query failed: " + query.lastError().text())
197 # if not query.next():
198 # raise Exception("Query failed")
199 # print "{0:>6} {1:>10} {2:>9} {3:<30} {4:>6} {5:<30}".format(query.value(0), query.value(1), query.value(2), query.value(3), query.value(4), query.value(5))
200 # call_path_id = query.value(6)
202 from PySide.QtSql import *
204 if sys.version_info < (3, 0):
205 def toserverstr(str):
207 def toclientstr(str):
210 # Assume UTF-8 server_encoding and client_encoding
211 def toserverstr(str):
212 return bytes(str, "UTF_8")
213 def toclientstr(str):
214 return bytes(str, "UTF_8")
216 # Need to access PostgreSQL C library directly to use COPY FROM STDIN
218 libpq = CDLL("libpq.so.5")
219 PQconnectdb = libpq.PQconnectdb
220 PQconnectdb.restype = c_void_p
221 PQconnectdb.argtypes = [ c_char_p ]
222 PQfinish = libpq.PQfinish
223 PQfinish.argtypes = [ c_void_p ]
224 PQstatus = libpq.PQstatus
225 PQstatus.restype = c_int
226 PQstatus.argtypes = [ c_void_p ]
227 PQexec = libpq.PQexec
228 PQexec.restype = c_void_p
229 PQexec.argtypes = [ c_void_p, c_char_p ]
230 PQresultStatus = libpq.PQresultStatus
231 PQresultStatus.restype = c_int
232 PQresultStatus.argtypes = [ c_void_p ]
233 PQputCopyData = libpq.PQputCopyData
234 PQputCopyData.restype = c_int
235 PQputCopyData.argtypes = [ c_void_p, c_void_p, c_int ]
236 PQputCopyEnd = libpq.PQputCopyEnd
237 PQputCopyEnd.restype = c_int
238 PQputCopyEnd.argtypes = [ c_void_p, c_void_p ]
240 sys.path.append(os.environ['PERF_EXEC_PATH'] + \
241 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
243 # These perf imports are not used at present
244 #from perf_trace_context import *
247 perf_db_export_mode = True
248 perf_db_export_calls = False
249 perf_db_export_callchains = False
251 def printerr(*args, **kw_args):
252 print(*args, file=sys.stderr, **kw_args)
254 def printdate(*args, **kw_args):
255 print(datetime.datetime.today(), *args, sep=' ', **kw_args)
258 printerr("Usage is: export-to-postgresql.py <database name> [<columns>] [<calls>] [<callchains>]")
259 printerr("where: columns 'all' or 'branches'")
260 printerr(" calls 'calls' => create calls and call_paths table")
261 printerr(" callchains 'callchains' => create call_paths table")
262 raise Exception("Too few arguments")
264 if (len(sys.argv) < 2):
269 if (len(sys.argv) >= 3):
270 columns = sys.argv[2]
274 if columns not in ("all", "branches"):
277 branches = (columns == "branches")
279 for i in range(3,len(sys.argv)):
280 if (sys.argv[i] == "calls"):
281 perf_db_export_calls = True
282 elif (sys.argv[i] == "callchains"):
283 perf_db_export_callchains = True
287 output_dir_name = os.getcwd() + "/" + dbname + "-perf-data"
288 os.mkdir(output_dir_name)
293 raise Exception("Query failed: " + q.lastError().text())
295 printdate("Creating database...")
297 db = QSqlDatabase.addDatabase('QPSQL')
298 query = QSqlQuery(db)
299 db.setDatabaseName('postgres')
302 do_query(query, 'CREATE DATABASE ' + dbname)
304 os.rmdir(output_dir_name)
310 db.setDatabaseName(dbname)
313 query = QSqlQuery(db)
314 do_query(query, 'SET client_min_messages TO WARNING')
316 do_query(query, 'CREATE TABLE selected_events ('
317 'id bigint NOT NULL,'
319 do_query(query, 'CREATE TABLE machines ('
320 'id bigint NOT NULL,'
322 'root_dir varchar(4096))')
323 do_query(query, 'CREATE TABLE threads ('
324 'id bigint NOT NULL,'
329 do_query(query, 'CREATE TABLE comms ('
330 'id bigint NOT NULL,'
332 do_query(query, 'CREATE TABLE comm_threads ('
333 'id bigint NOT NULL,'
336 do_query(query, 'CREATE TABLE dsos ('
337 'id bigint NOT NULL,'
339 'short_name varchar(256),'
340 'long_name varchar(4096),'
341 'build_id varchar(64))')
342 do_query(query, 'CREATE TABLE symbols ('
343 'id bigint NOT NULL,'
348 'name varchar(2048))')
349 do_query(query, 'CREATE TABLE branch_types ('
350 'id integer NOT NULL,'
354 do_query(query, 'CREATE TABLE samples ('
355 'id bigint NOT NULL,'
367 'to_symbol_id bigint,'
368 'to_sym_offset bigint,'
370 'branch_type integer,'
372 'call_path_id bigint)')
374 do_query(query, 'CREATE TABLE samples ('
375 'id bigint NOT NULL,'
387 'to_symbol_id bigint,'
388 'to_sym_offset bigint,'
392 'transaction bigint,'
394 'branch_type integer,'
396 'call_path_id bigint)')
398 if perf_db_export_calls or perf_db_export_callchains:
399 do_query(query, 'CREATE TABLE call_paths ('
400 'id bigint NOT NULL,'
404 if perf_db_export_calls:
405 do_query(query, 'CREATE TABLE calls ('
406 'id bigint NOT NULL,'
409 'call_path_id bigint,'
411 'return_time bigint,'
412 'branch_count bigint,'
415 'parent_call_path_id bigint,'
419 do_query(query, 'CREATE VIEW machines_view AS '
424 'CASE WHEN id=0 THEN \'unknown\' WHEN pid=-1 THEN \'host\' ELSE \'guest\' END AS host_or_guest'
427 do_query(query, 'CREATE VIEW dsos_view AS '
431 '(SELECT host_or_guest FROM machines_view WHERE id = machine_id) AS host_or_guest,'
437 do_query(query, 'CREATE VIEW symbols_view AS '
441 '(SELECT short_name FROM dsos WHERE id=dso_id) AS dso,'
445 'CASE WHEN binding=0 THEN \'local\' WHEN binding=1 THEN \'global\' ELSE \'weak\' END AS binding'
448 do_query(query, 'CREATE VIEW threads_view AS '
452 '(SELECT host_or_guest FROM machines_view WHERE id = machine_id) AS host_or_guest,'
458 do_query(query, 'CREATE VIEW comm_threads_view AS '
461 '(SELECT comm FROM comms WHERE id = comm_id) AS command,'
463 '(SELECT pid FROM threads WHERE id = thread_id) AS pid,'
464 '(SELECT tid FROM threads WHERE id = thread_id) AS tid'
465 ' FROM comm_threads')
467 if perf_db_export_calls or perf_db_export_callchains:
468 do_query(query, 'CREATE VIEW call_paths_view AS '
471 'to_hex(c.ip) AS ip,'
473 '(SELECT name FROM symbols WHERE id = c.symbol_id) AS symbol,'
474 '(SELECT dso_id FROM symbols WHERE id = c.symbol_id) AS dso_id,'
475 '(SELECT dso FROM symbols_view WHERE id = c.symbol_id) AS dso_short_name,'
477 'to_hex(p.ip) AS parent_ip,'
478 'p.symbol_id AS parent_symbol_id,'
479 '(SELECT name FROM symbols WHERE id = p.symbol_id) AS parent_symbol,'
480 '(SELECT dso_id FROM symbols WHERE id = p.symbol_id) AS parent_dso_id,'
481 '(SELECT dso FROM symbols_view WHERE id = p.symbol_id) AS parent_dso_short_name'
482 ' FROM call_paths c INNER JOIN call_paths p ON p.id = c.parent_id')
483 if perf_db_export_calls:
484 do_query(query, 'CREATE VIEW calls_view AS '
488 '(SELECT pid FROM threads WHERE id = thread_id) AS pid,'
489 '(SELECT tid FROM threads WHERE id = thread_id) AS tid,'
490 '(SELECT comm FROM comms WHERE id = comm_id) AS command,'
494 '(SELECT name FROM symbols WHERE id = symbol_id) AS symbol,'
497 'return_time - call_time AS elapsed_time,'
501 '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 CAST ( flags AS VARCHAR(6) ) END AS flags,'
502 'parent_call_path_id,'
504 ' FROM calls INNER JOIN call_paths ON call_paths.id = call_path_id')
506 do_query(query, 'CREATE VIEW samples_view AS '
511 '(SELECT pid FROM threads WHERE id = thread_id) AS pid,'
512 '(SELECT tid FROM threads WHERE id = thread_id) AS tid,'
513 '(SELECT comm FROM comms WHERE id = comm_id) AS command,'
514 '(SELECT name FROM selected_events WHERE id = evsel_id) AS event,'
515 'to_hex(ip) AS ip_hex,'
516 '(SELECT name FROM symbols WHERE id = symbol_id) AS symbol,'
518 '(SELECT short_name FROM dsos WHERE id = dso_id) AS dso_short_name,'
519 'to_hex(to_ip) AS to_ip_hex,'
520 '(SELECT name FROM symbols WHERE id = to_symbol_id) AS to_symbol,'
522 '(SELECT short_name FROM dsos WHERE id = to_dso_id) AS to_dso_short_name,'
523 '(SELECT name FROM branch_types WHERE id = branch_type) AS branch_type_name,'
528 file_header = struct.pack("!11sii", b"PGCOPY\n\377\r\n\0", 0, 0)
529 file_trailer = b"\377\377"
531 def open_output_file(file_name):
532 path_name = output_dir_name + "/" + file_name
533 file = open(path_name, "wb+")
534 file.write(file_header)
537 def close_output_file(file):
538 file.write(file_trailer)
541 def copy_output_file_direct(file, table_name):
542 close_output_file(file)
543 sql = "COPY " + table_name + " FROM '" + file.name + "' (FORMAT 'binary')"
546 # Use COPY FROM STDIN because security may prevent postgres from accessing the files directly
547 def copy_output_file(file, table_name):
548 conn = PQconnectdb(toclientstr("dbname = " + dbname))
550 raise Exception("COPY FROM STDIN PQconnectdb failed")
551 file.write(file_trailer)
553 sql = "COPY " + table_name + " FROM STDIN (FORMAT 'binary')"
554 res = PQexec(conn, toclientstr(sql))
555 if (PQresultStatus(res) != 4):
556 raise Exception("COPY FROM STDIN PQexec failed")
557 data = file.read(65536)
559 ret = PQputCopyData(conn, data, len(data))
561 raise Exception("COPY FROM STDIN PQputCopyData failed, error " + str(ret))
562 data = file.read(65536)
563 ret = PQputCopyEnd(conn, None)
565 raise Exception("COPY FROM STDIN PQputCopyEnd failed, error " + str(ret))
568 def remove_output_file(file):
573 evsel_file = open_output_file("evsel_table.bin")
574 machine_file = open_output_file("machine_table.bin")
575 thread_file = open_output_file("thread_table.bin")
576 comm_file = open_output_file("comm_table.bin")
577 comm_thread_file = open_output_file("comm_thread_table.bin")
578 dso_file = open_output_file("dso_table.bin")
579 symbol_file = open_output_file("symbol_table.bin")
580 branch_type_file = open_output_file("branch_type_table.bin")
581 sample_file = open_output_file("sample_table.bin")
582 if perf_db_export_calls or perf_db_export_callchains:
583 call_path_file = open_output_file("call_path_table.bin")
584 if perf_db_export_calls:
585 call_file = open_output_file("call_table.bin")
588 printdate("Writing to intermediate files...")
589 # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs
590 evsel_table(0, "unknown")
591 machine_table(0, 0, "unknown")
592 thread_table(0, 0, 0, -1, -1)
593 comm_table(0, "unknown")
594 dso_table(0, 0, "unknown", "unknown", "")
595 symbol_table(0, 0, 0, 0, 0, "unknown")
596 sample_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
597 if perf_db_export_calls or perf_db_export_callchains:
598 call_path_table(0, 0, 0, 0)
599 call_return_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
604 printdate("Copying to database...")
605 copy_output_file(evsel_file, "selected_events")
606 copy_output_file(machine_file, "machines")
607 copy_output_file(thread_file, "threads")
608 copy_output_file(comm_file, "comms")
609 copy_output_file(comm_thread_file, "comm_threads")
610 copy_output_file(dso_file, "dsos")
611 copy_output_file(symbol_file, "symbols")
612 copy_output_file(branch_type_file, "branch_types")
613 copy_output_file(sample_file, "samples")
614 if perf_db_export_calls or perf_db_export_callchains:
615 copy_output_file(call_path_file, "call_paths")
616 if perf_db_export_calls:
617 copy_output_file(call_file, "calls")
619 printdate("Removing intermediate files...")
620 remove_output_file(evsel_file)
621 remove_output_file(machine_file)
622 remove_output_file(thread_file)
623 remove_output_file(comm_file)
624 remove_output_file(comm_thread_file)
625 remove_output_file(dso_file)
626 remove_output_file(symbol_file)
627 remove_output_file(branch_type_file)
628 remove_output_file(sample_file)
629 if perf_db_export_calls or perf_db_export_callchains:
630 remove_output_file(call_path_file)
631 if perf_db_export_calls:
632 remove_output_file(call_file)
633 os.rmdir(output_dir_name)
634 printdate("Adding primary keys")
635 do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)')
636 do_query(query, 'ALTER TABLE machines ADD PRIMARY KEY (id)')
637 do_query(query, 'ALTER TABLE threads ADD PRIMARY KEY (id)')
638 do_query(query, 'ALTER TABLE comms ADD PRIMARY KEY (id)')
639 do_query(query, 'ALTER TABLE comm_threads ADD PRIMARY KEY (id)')
640 do_query(query, 'ALTER TABLE dsos ADD PRIMARY KEY (id)')
641 do_query(query, 'ALTER TABLE symbols ADD PRIMARY KEY (id)')
642 do_query(query, 'ALTER TABLE branch_types ADD PRIMARY KEY (id)')
643 do_query(query, 'ALTER TABLE samples ADD PRIMARY KEY (id)')
644 if perf_db_export_calls or perf_db_export_callchains:
645 do_query(query, 'ALTER TABLE call_paths ADD PRIMARY KEY (id)')
646 if perf_db_export_calls:
647 do_query(query, 'ALTER TABLE calls ADD PRIMARY KEY (id)')
649 printdate("Adding foreign keys")
650 do_query(query, 'ALTER TABLE threads '
651 'ADD CONSTRAINT machinefk FOREIGN KEY (machine_id) REFERENCES machines (id),'
652 'ADD CONSTRAINT processfk FOREIGN KEY (process_id) REFERENCES threads (id)')
653 do_query(query, 'ALTER TABLE comm_threads '
654 'ADD CONSTRAINT commfk FOREIGN KEY (comm_id) REFERENCES comms (id),'
655 'ADD CONSTRAINT threadfk FOREIGN KEY (thread_id) REFERENCES threads (id)')
656 do_query(query, 'ALTER TABLE dsos '
657 'ADD CONSTRAINT machinefk FOREIGN KEY (machine_id) REFERENCES machines (id)')
658 do_query(query, 'ALTER TABLE symbols '
659 'ADD CONSTRAINT dsofk FOREIGN KEY (dso_id) REFERENCES dsos (id)')
660 do_query(query, 'ALTER TABLE samples '
661 'ADD CONSTRAINT evselfk FOREIGN KEY (evsel_id) REFERENCES selected_events (id),'
662 'ADD CONSTRAINT machinefk FOREIGN KEY (machine_id) REFERENCES machines (id),'
663 'ADD CONSTRAINT threadfk FOREIGN KEY (thread_id) REFERENCES threads (id),'
664 'ADD CONSTRAINT commfk FOREIGN KEY (comm_id) REFERENCES comms (id),'
665 'ADD CONSTRAINT dsofk FOREIGN KEY (dso_id) REFERENCES dsos (id),'
666 'ADD CONSTRAINT symbolfk FOREIGN KEY (symbol_id) REFERENCES symbols (id),'
667 'ADD CONSTRAINT todsofk FOREIGN KEY (to_dso_id) REFERENCES dsos (id),'
668 'ADD CONSTRAINT tosymbolfk FOREIGN KEY (to_symbol_id) REFERENCES symbols (id)')
669 if perf_db_export_calls or perf_db_export_callchains:
670 do_query(query, 'ALTER TABLE call_paths '
671 'ADD CONSTRAINT parentfk FOREIGN KEY (parent_id) REFERENCES call_paths (id),'
672 'ADD CONSTRAINT symbolfk FOREIGN KEY (symbol_id) REFERENCES symbols (id)')
673 if perf_db_export_calls:
674 do_query(query, 'ALTER TABLE calls '
675 'ADD CONSTRAINT threadfk FOREIGN KEY (thread_id) REFERENCES threads (id),'
676 'ADD CONSTRAINT commfk FOREIGN KEY (comm_id) REFERENCES comms (id),'
677 'ADD CONSTRAINT call_pathfk FOREIGN KEY (call_path_id) REFERENCES call_paths (id),'
678 'ADD CONSTRAINT callfk FOREIGN KEY (call_id) REFERENCES samples (id),'
679 'ADD CONSTRAINT returnfk FOREIGN KEY (return_id) REFERENCES samples (id),'
680 'ADD CONSTRAINT parent_call_pathfk FOREIGN KEY (parent_call_path_id) REFERENCES call_paths (id)')
681 do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)')
682 do_query(query, 'CREATE INDEX pid_idx ON calls (parent_id)')
684 if (unhandled_count):
685 printdate("Warning: ", unhandled_count, " unhandled events")
688 def trace_unhandled(event_name, context, event_fields_dict):
689 global unhandled_count
692 def sched__sched_switch(*x):
695 def evsel_table(evsel_id, evsel_name, *x):
696 evsel_name = toserverstr(evsel_name)
698 fmt = "!hiqi" + str(n) + "s"
699 value = struct.pack(fmt, 2, 8, evsel_id, n, evsel_name)
700 evsel_file.write(value)
702 def machine_table(machine_id, pid, root_dir, *x):
703 root_dir = toserverstr(root_dir)
705 fmt = "!hiqiii" + str(n) + "s"
706 value = struct.pack(fmt, 3, 8, machine_id, 4, pid, n, root_dir)
707 machine_file.write(value)
709 def thread_table(thread_id, machine_id, process_id, pid, tid, *x):
710 value = struct.pack("!hiqiqiqiiii", 5, 8, thread_id, 8, machine_id, 8, process_id, 4, pid, 4, tid)
711 thread_file.write(value)
713 def comm_table(comm_id, comm_str, *x):
714 comm_str = toserverstr(comm_str)
716 fmt = "!hiqi" + str(n) + "s"
717 value = struct.pack(fmt, 2, 8, comm_id, n, comm_str)
718 comm_file.write(value)
720 def comm_thread_table(comm_thread_id, comm_id, thread_id, *x):
722 value = struct.pack(fmt, 3, 8, comm_thread_id, 8, comm_id, 8, thread_id)
723 comm_thread_file.write(value)
725 def dso_table(dso_id, machine_id, short_name, long_name, build_id, *x):
726 short_name = toserverstr(short_name)
727 long_name = toserverstr(long_name)
728 build_id = toserverstr(build_id)
732 fmt = "!hiqiqi" + str(n1) + "si" + str(n2) + "si" + str(n3) + "s"
733 value = struct.pack(fmt, 5, 8, dso_id, 8, machine_id, n1, short_name, n2, long_name, n3, build_id)
734 dso_file.write(value)
736 def symbol_table(symbol_id, dso_id, sym_start, sym_end, binding, symbol_name, *x):
737 symbol_name = toserverstr(symbol_name)
739 fmt = "!hiqiqiqiqiii" + str(n) + "s"
740 value = struct.pack(fmt, 6, 8, symbol_id, 8, dso_id, 8, sym_start, 8, sym_end, 4, binding, n, symbol_name)
741 symbol_file.write(value)
743 def branch_type_table(branch_type, name, *x):
744 name = toserverstr(name)
746 fmt = "!hiii" + str(n) + "s"
747 value = struct.pack(fmt, 2, 4, branch_type, n, name)
748 branch_type_file.write(value)
750 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, call_path_id, *x):
752 value = struct.pack("!hiqiqiqiqiqiqiqiqiqiqiiiqiqiqiqiiiBiq", 18, 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, 8, call_path_id)
754 value = struct.pack("!hiqiqiqiqiqiqiqiqiqiqiiiqiqiqiqiqiqiqiqiiiBiq", 22, 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, 8, call_path_id)
755 sample_file.write(value)
757 def call_path_table(cp_id, parent_id, symbol_id, ip, *x):
759 value = struct.pack(fmt, 4, 8, cp_id, 8, parent_id, 8, symbol_id, 8, ip)
760 call_path_file.write(value)
762 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, parent_id, *x):
763 fmt = "!hiqiqiqiqiqiqiqiqiqiqiiiq"
764 value = struct.pack(fmt, 12, 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, 8, parent_id)
765 call_file.write(value)