export-to-postgresql.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. # export-to-postgresql.py: export perf data to a postgresql database
  2. # Copyright (c) 2014, Intel Corporation.
  3. #
  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.
  7. #
  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
  11. # more details.
  12. import os
  13. import sys
  14. import struct
  15. import datetime
  16. # To use this script you will need to have installed package python-pyside which
  17. # provides LGPL-licensed Python bindings for Qt. You will also need the package
  18. # libqt4-sql-psql for Qt postgresql support.
  19. #
  20. # The script assumes postgresql is running on the local machine and that the
  21. # user has postgresql permissions to create databases. Examples of installing
  22. # postgresql and adding such a user are:
  23. #
  24. # fedora:
  25. #
  26. # $ sudo yum install postgresql postgresql-server python-pyside qt-postgresql
  27. # $ sudo su - postgres -c initdb
  28. # $ sudo service postgresql start
  29. # $ sudo su - postgres
  30. # $ createuser <your user id here>
  31. # Shall the new role be a superuser? (y/n) y
  32. #
  33. # ubuntu:
  34. #
  35. # $ sudo apt-get install postgresql
  36. # $ sudo su - postgres
  37. # $ createuser <your user id here>
  38. # Shall the new role be a superuser? (y/n) y
  39. #
  40. # An example of using this script with Intel PT:
  41. #
  42. # $ perf record -e intel_pt//u ls
  43. # $ perf script -s ~/libexec/perf-core/scripts/python/export-to-postgresql.py pt_example branches calls
  44. # 2015-05-29 12:49:23.464364 Creating database...
  45. # 2015-05-29 12:49:26.281717 Writing to intermediate files...
  46. # 2015-05-29 12:49:27.190383 Copying to database...
  47. # 2015-05-29 12:49:28.140451 Removing intermediate files...
  48. # 2015-05-29 12:49:28.147451 Adding primary keys
  49. # 2015-05-29 12:49:28.655683 Adding foreign keys
  50. # 2015-05-29 12:49:29.365350 Done
  51. #
  52. # To browse the database, psql can be used e.g.
  53. #
  54. # $ psql pt_example
  55. # pt_example=# select * from samples_view where id < 100;
  56. # pt_example=# \d+
  57. # pt_example=# \d+ samples_view
  58. # pt_example=# \q
  59. #
  60. # An example of using the database is provided by the script
  61. # call-graph-from-postgresql.py. Refer to that script for details.
  62. from PySide.QtSql import *
  63. # Need to access PostgreSQL C library directly to use COPY FROM STDIN
  64. from ctypes import *
  65. libpq = CDLL("libpq.so.5")
  66. PQconnectdb = libpq.PQconnectdb
  67. PQconnectdb.restype = c_void_p
  68. PQfinish = libpq.PQfinish
  69. PQstatus = libpq.PQstatus
  70. PQexec = libpq.PQexec
  71. PQexec.restype = c_void_p
  72. PQresultStatus = libpq.PQresultStatus
  73. PQputCopyData = libpq.PQputCopyData
  74. PQputCopyData.argtypes = [ c_void_p, c_void_p, c_int ]
  75. PQputCopyEnd = libpq.PQputCopyEnd
  76. PQputCopyEnd.argtypes = [ c_void_p, c_void_p ]
  77. sys.path.append(os.environ['PERF_EXEC_PATH'] + \
  78. '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
  79. # These perf imports are not used at present
  80. #from perf_trace_context import *
  81. #from Core import *
  82. perf_db_export_mode = True
  83. perf_db_export_calls = False
  84. def usage():
  85. print >> sys.stderr, "Usage is: export-to-postgresql.py <database name> [<columns>] [<calls>]"
  86. print >> sys.stderr, "where: columns 'all' or 'branches'"
  87. print >> sys.stderr, " calls 'calls' => create calls table"
  88. raise Exception("Too few arguments")
  89. if (len(sys.argv) < 2):
  90. usage()
  91. dbname = sys.argv[1]
  92. if (len(sys.argv) >= 3):
  93. columns = sys.argv[2]
  94. else:
  95. columns = "all"
  96. if columns not in ("all", "branches"):
  97. usage()
  98. branches = (columns == "branches")
  99. if (len(sys.argv) >= 4):
  100. if (sys.argv[3] == "calls"):
  101. perf_db_export_calls = True
  102. else:
  103. usage()
  104. output_dir_name = os.getcwd() + "/" + dbname + "-perf-data"
  105. os.mkdir(output_dir_name)
  106. def do_query(q, s):
  107. if (q.exec_(s)):
  108. return
  109. raise Exception("Query failed: " + q.lastError().text())
  110. print datetime.datetime.today(), "Creating database..."
  111. db = QSqlDatabase.addDatabase('QPSQL')
  112. query = QSqlQuery(db)
  113. db.setDatabaseName('postgres')
  114. db.open()
  115. try:
  116. do_query(query, 'CREATE DATABASE ' + dbname)
  117. except:
  118. os.rmdir(output_dir_name)
  119. raise
  120. query.finish()
  121. query.clear()
  122. db.close()
  123. db.setDatabaseName(dbname)
  124. db.open()
  125. query = QSqlQuery(db)
  126. do_query(query, 'SET client_min_messages TO WARNING')
  127. do_query(query, 'CREATE TABLE selected_events ('
  128. 'id bigint NOT NULL,'
  129. 'name varchar(80))')
  130. do_query(query, 'CREATE TABLE machines ('
  131. 'id bigint NOT NULL,'
  132. 'pid integer,'
  133. 'root_dir varchar(4096))')
  134. do_query(query, 'CREATE TABLE threads ('
  135. 'id bigint NOT NULL,'
  136. 'machine_id bigint,'
  137. 'process_id bigint,'
  138. 'pid integer,'
  139. 'tid integer)')
  140. do_query(query, 'CREATE TABLE comms ('
  141. 'id bigint NOT NULL,'
  142. 'comm varchar(16))')
  143. do_query(query, 'CREATE TABLE comm_threads ('
  144. 'id bigint NOT NULL,'
  145. 'comm_id bigint,'
  146. 'thread_id bigint)')
  147. do_query(query, 'CREATE TABLE dsos ('
  148. 'id bigint NOT NULL,'
  149. 'machine_id bigint,'
  150. 'short_name varchar(256),'
  151. 'long_name varchar(4096),'
  152. 'build_id varchar(64))')
  153. do_query(query, 'CREATE TABLE symbols ('
  154. 'id bigint NOT NULL,'
  155. 'dso_id bigint,'
  156. 'sym_start bigint,'
  157. 'sym_end bigint,'
  158. 'binding integer,'
  159. 'name varchar(2048))')
  160. do_query(query, 'CREATE TABLE branch_types ('
  161. 'id integer NOT NULL,'
  162. 'name varchar(80))')
  163. if branches:
  164. do_query(query, 'CREATE TABLE samples ('
  165. 'id bigint NOT NULL,'
  166. 'evsel_id bigint,'
  167. 'machine_id bigint,'
  168. 'thread_id bigint,'
  169. 'comm_id bigint,'
  170. 'dso_id bigint,'
  171. 'symbol_id bigint,'
  172. 'sym_offset bigint,'
  173. 'ip bigint,'
  174. 'time bigint,'
  175. 'cpu integer,'
  176. 'to_dso_id bigint,'
  177. 'to_symbol_id bigint,'
  178. 'to_sym_offset bigint,'
  179. 'to_ip bigint,'
  180. 'branch_type integer,'
  181. 'in_tx boolean)')
  182. else:
  183. do_query(query, 'CREATE TABLE samples ('
  184. 'id bigint NOT NULL,'
  185. 'evsel_id bigint,'
  186. 'machine_id bigint,'
  187. 'thread_id bigint,'
  188. 'comm_id bigint,'
  189. 'dso_id bigint,'
  190. 'symbol_id bigint,'
  191. 'sym_offset bigint,'
  192. 'ip bigint,'
  193. 'time bigint,'
  194. 'cpu integer,'
  195. 'to_dso_id bigint,'
  196. 'to_symbol_id bigint,'
  197. 'to_sym_offset bigint,'
  198. 'to_ip bigint,'
  199. 'period bigint,'
  200. 'weight bigint,'
  201. 'transaction bigint,'
  202. 'data_src bigint,'
  203. 'branch_type integer,'
  204. 'in_tx boolean)')
  205. if perf_db_export_calls:
  206. do_query(query, 'CREATE TABLE call_paths ('
  207. 'id bigint NOT NULL,'
  208. 'parent_id bigint,'
  209. 'symbol_id bigint,'
  210. 'ip bigint)')
  211. do_query(query, 'CREATE TABLE calls ('
  212. 'id bigint NOT NULL,'
  213. 'thread_id bigint,'
  214. 'comm_id bigint,'
  215. 'call_path_id bigint,'
  216. 'call_time bigint,'
  217. 'return_time bigint,'
  218. 'branch_count bigint,'
  219. 'call_id bigint,'
  220. 'return_id bigint,'
  221. 'parent_call_path_id bigint,'
  222. 'flags integer)')
  223. do_query(query, 'CREATE VIEW samples_view AS '
  224. 'SELECT '
  225. 'id,'
  226. 'time,'
  227. 'cpu,'
  228. '(SELECT pid FROM threads WHERE id = thread_id) AS pid,'
  229. '(SELECT tid FROM threads WHERE id = thread_id) AS tid,'
  230. '(SELECT comm FROM comms WHERE id = comm_id) AS command,'
  231. '(SELECT name FROM selected_events WHERE id = evsel_id) AS event,'
  232. 'to_hex(ip) AS ip_hex,'
  233. '(SELECT name FROM symbols WHERE id = symbol_id) AS symbol,'
  234. 'sym_offset,'
  235. '(SELECT short_name FROM dsos WHERE id = dso_id) AS dso_short_name,'
  236. 'to_hex(to_ip) AS to_ip_hex,'
  237. '(SELECT name FROM symbols WHERE id = to_symbol_id) AS to_symbol,'
  238. 'to_sym_offset,'
  239. '(SELECT short_name FROM dsos WHERE id = to_dso_id) AS to_dso_short_name,'
  240. '(SELECT name FROM branch_types WHERE id = branch_type) AS branch_type_name,'
  241. 'in_tx'
  242. ' FROM samples')
  243. file_header = struct.pack("!11sii", "PGCOPY\n\377\r\n\0", 0, 0)
  244. file_trailer = "\377\377"
  245. def open_output_file(file_name):
  246. path_name = output_dir_name + "/" + file_name
  247. file = open(path_name, "w+")
  248. file.write(file_header)
  249. return file
  250. def close_output_file(file):
  251. file.write(file_trailer)
  252. file.close()
  253. def copy_output_file_direct(file, table_name):
  254. close_output_file(file)
  255. sql = "COPY " + table_name + " FROM '" + file.name + "' (FORMAT 'binary')"
  256. do_query(query, sql)
  257. # Use COPY FROM STDIN because security may prevent postgres from accessing the files directly
  258. def copy_output_file(file, table_name):
  259. conn = PQconnectdb("dbname = " + dbname)
  260. if (PQstatus(conn)):
  261. raise Exception("COPY FROM STDIN PQconnectdb failed")
  262. file.write(file_trailer)
  263. file.seek(0)
  264. sql = "COPY " + table_name + " FROM STDIN (FORMAT 'binary')"
  265. res = PQexec(conn, sql)
  266. if (PQresultStatus(res) != 4):
  267. raise Exception("COPY FROM STDIN PQexec failed")
  268. data = file.read(65536)
  269. while (len(data)):
  270. ret = PQputCopyData(conn, data, len(data))
  271. if (ret != 1):
  272. raise Exception("COPY FROM STDIN PQputCopyData failed, error " + str(ret))
  273. data = file.read(65536)
  274. ret = PQputCopyEnd(conn, None)
  275. if (ret != 1):
  276. raise Exception("COPY FROM STDIN PQputCopyEnd failed, error " + str(ret))
  277. PQfinish(conn)
  278. def remove_output_file(file):
  279. name = file.name
  280. file.close()
  281. os.unlink(name)
  282. evsel_file = open_output_file("evsel_table.bin")
  283. machine_file = open_output_file("machine_table.bin")
  284. thread_file = open_output_file("thread_table.bin")
  285. comm_file = open_output_file("comm_table.bin")
  286. comm_thread_file = open_output_file("comm_thread_table.bin")
  287. dso_file = open_output_file("dso_table.bin")
  288. symbol_file = open_output_file("symbol_table.bin")
  289. branch_type_file = open_output_file("branch_type_table.bin")
  290. sample_file = open_output_file("sample_table.bin")
  291. if perf_db_export_calls:
  292. call_path_file = open_output_file("call_path_table.bin")
  293. call_file = open_output_file("call_table.bin")
  294. def trace_begin():
  295. print datetime.datetime.today(), "Writing to intermediate files..."
  296. # id == 0 means unknown. It is easier to create records for them than replace the zeroes with NULLs
  297. evsel_table(0, "unknown")
  298. machine_table(0, 0, "unknown")
  299. thread_table(0, 0, 0, -1, -1)
  300. comm_table(0, "unknown")
  301. dso_table(0, 0, "unknown", "unknown", "")
  302. symbol_table(0, 0, 0, 0, 0, "unknown")
  303. sample_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
  304. if perf_db_export_calls:
  305. call_path_table(0, 0, 0, 0)
  306. unhandled_count = 0
  307. def trace_end():
  308. print datetime.datetime.today(), "Copying to database..."
  309. copy_output_file(evsel_file, "selected_events")
  310. copy_output_file(machine_file, "machines")
  311. copy_output_file(thread_file, "threads")
  312. copy_output_file(comm_file, "comms")
  313. copy_output_file(comm_thread_file, "comm_threads")
  314. copy_output_file(dso_file, "dsos")
  315. copy_output_file(symbol_file, "symbols")
  316. copy_output_file(branch_type_file, "branch_types")
  317. copy_output_file(sample_file, "samples")
  318. if perf_db_export_calls:
  319. copy_output_file(call_path_file, "call_paths")
  320. copy_output_file(call_file, "calls")
  321. print datetime.datetime.today(), "Removing intermediate files..."
  322. remove_output_file(evsel_file)
  323. remove_output_file(machine_file)
  324. remove_output_file(thread_file)
  325. remove_output_file(comm_file)
  326. remove_output_file(comm_thread_file)
  327. remove_output_file(dso_file)
  328. remove_output_file(symbol_file)
  329. remove_output_file(branch_type_file)
  330. remove_output_file(sample_file)
  331. if perf_db_export_calls:
  332. remove_output_file(call_path_file)
  333. remove_output_file(call_file)
  334. os.rmdir(output_dir_name)
  335. print datetime.datetime.today(), "Adding primary keys"
  336. do_query(query, 'ALTER TABLE selected_events ADD PRIMARY KEY (id)')
  337. do_query(query, 'ALTER TABLE machines ADD PRIMARY KEY (id)')
  338. do_query(query, 'ALTER TABLE threads ADD PRIMARY KEY (id)')
  339. do_query(query, 'ALTER TABLE comms ADD PRIMARY KEY (id)')
  340. do_query(query, 'ALTER TABLE comm_threads ADD PRIMARY KEY (id)')
  341. do_query(query, 'ALTER TABLE dsos ADD PRIMARY KEY (id)')
  342. do_query(query, 'ALTER TABLE symbols ADD PRIMARY KEY (id)')
  343. do_query(query, 'ALTER TABLE branch_types ADD PRIMARY KEY (id)')
  344. do_query(query, 'ALTER TABLE samples ADD PRIMARY KEY (id)')
  345. if perf_db_export_calls:
  346. do_query(query, 'ALTER TABLE call_paths ADD PRIMARY KEY (id)')
  347. do_query(query, 'ALTER TABLE calls ADD PRIMARY KEY (id)')
  348. print datetime.datetime.today(), "Adding foreign keys"
  349. do_query(query, 'ALTER TABLE threads '
  350. 'ADD CONSTRAINT machinefk FOREIGN KEY (machine_id) REFERENCES machines (id),'
  351. 'ADD CONSTRAINT processfk FOREIGN KEY (process_id) REFERENCES threads (id)')
  352. do_query(query, 'ALTER TABLE comm_threads '
  353. 'ADD CONSTRAINT commfk FOREIGN KEY (comm_id) REFERENCES comms (id),'
  354. 'ADD CONSTRAINT threadfk FOREIGN KEY (thread_id) REFERENCES threads (id)')
  355. do_query(query, 'ALTER TABLE dsos '
  356. 'ADD CONSTRAINT machinefk FOREIGN KEY (machine_id) REFERENCES machines (id)')
  357. do_query(query, 'ALTER TABLE symbols '
  358. 'ADD CONSTRAINT dsofk FOREIGN KEY (dso_id) REFERENCES dsos (id)')
  359. do_query(query, 'ALTER TABLE samples '
  360. 'ADD CONSTRAINT evselfk FOREIGN KEY (evsel_id) REFERENCES selected_events (id),'
  361. 'ADD CONSTRAINT machinefk FOREIGN KEY (machine_id) REFERENCES machines (id),'
  362. 'ADD CONSTRAINT threadfk FOREIGN KEY (thread_id) REFERENCES threads (id),'
  363. 'ADD CONSTRAINT commfk FOREIGN KEY (comm_id) REFERENCES comms (id),'
  364. 'ADD CONSTRAINT dsofk FOREIGN KEY (dso_id) REFERENCES dsos (id),'
  365. 'ADD CONSTRAINT symbolfk FOREIGN KEY (symbol_id) REFERENCES symbols (id),'
  366. 'ADD CONSTRAINT todsofk FOREIGN KEY (to_dso_id) REFERENCES dsos (id),'
  367. 'ADD CONSTRAINT tosymbolfk FOREIGN KEY (to_symbol_id) REFERENCES symbols (id)')
  368. if perf_db_export_calls:
  369. do_query(query, 'ALTER TABLE call_paths '
  370. 'ADD CONSTRAINT parentfk FOREIGN KEY (parent_id) REFERENCES call_paths (id),'
  371. 'ADD CONSTRAINT symbolfk FOREIGN KEY (symbol_id) REFERENCES symbols (id)')
  372. do_query(query, 'ALTER TABLE calls '
  373. 'ADD CONSTRAINT threadfk FOREIGN KEY (thread_id) REFERENCES threads (id),'
  374. 'ADD CONSTRAINT commfk FOREIGN KEY (comm_id) REFERENCES comms (id),'
  375. 'ADD CONSTRAINT call_pathfk FOREIGN KEY (call_path_id) REFERENCES call_paths (id),'
  376. 'ADD CONSTRAINT callfk FOREIGN KEY (call_id) REFERENCES samples (id),'
  377. 'ADD CONSTRAINT returnfk FOREIGN KEY (return_id) REFERENCES samples (id),'
  378. 'ADD CONSTRAINT parent_call_pathfk FOREIGN KEY (parent_call_path_id) REFERENCES call_paths (id)')
  379. do_query(query, 'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)')
  380. if (unhandled_count):
  381. print datetime.datetime.today(), "Warning: ", unhandled_count, " unhandled events"
  382. print datetime.datetime.today(), "Done"
  383. def trace_unhandled(event_name, context, event_fields_dict):
  384. global unhandled_count
  385. unhandled_count += 1
  386. def sched__sched_switch(*x):
  387. pass
  388. def evsel_table(evsel_id, evsel_name, *x):
  389. n = len(evsel_name)
  390. fmt = "!hiqi" + str(n) + "s"
  391. value = struct.pack(fmt, 2, 8, evsel_id, n, evsel_name)
  392. evsel_file.write(value)
  393. def machine_table(machine_id, pid, root_dir, *x):
  394. n = len(root_dir)
  395. fmt = "!hiqiii" + str(n) + "s"
  396. value = struct.pack(fmt, 3, 8, machine_id, 4, pid, n, root_dir)
  397. machine_file.write(value)
  398. def thread_table(thread_id, machine_id, process_id, pid, tid, *x):
  399. value = struct.pack("!hiqiqiqiiii", 5, 8, thread_id, 8, machine_id, 8, process_id, 4, pid, 4, tid)
  400. thread_file.write(value)
  401. def comm_table(comm_id, comm_str, *x):
  402. n = len(comm_str)
  403. fmt = "!hiqi" + str(n) + "s"
  404. value = struct.pack(fmt, 2, 8, comm_id, n, comm_str)
  405. comm_file.write(value)
  406. def comm_thread_table(comm_thread_id, comm_id, thread_id, *x):
  407. fmt = "!hiqiqiq"
  408. value = struct.pack(fmt, 3, 8, comm_thread_id, 8, comm_id, 8, thread_id)
  409. comm_thread_file.write(value)
  410. def dso_table(dso_id, machine_id, short_name, long_name, build_id, *x):
  411. n1 = len(short_name)
  412. n2 = len(long_name)
  413. n3 = len(build_id)
  414. fmt = "!hiqiqi" + str(n1) + "si" + str(n2) + "si" + str(n3) + "s"
  415. value = struct.pack(fmt, 5, 8, dso_id, 8, machine_id, n1, short_name, n2, long_name, n3, build_id)
  416. dso_file.write(value)
  417. def symbol_table(symbol_id, dso_id, sym_start, sym_end, binding, symbol_name, *x):
  418. n = len(symbol_name)
  419. fmt = "!hiqiqiqiqiii" + str(n) + "s"
  420. value = struct.pack(fmt, 6, 8, symbol_id, 8, dso_id, 8, sym_start, 8, sym_end, 4, binding, n, symbol_name)
  421. symbol_file.write(value)
  422. def branch_type_table(branch_type, name, *x):
  423. n = len(name)
  424. fmt = "!hiii" + str(n) + "s"
  425. value = struct.pack(fmt, 2, 4, branch_type, n, name)
  426. branch_type_file.write(value)
  427. 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, *x):
  428. if branches:
  429. 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)
  430. else:
  431. 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)
  432. sample_file.write(value)
  433. def call_path_table(cp_id, parent_id, symbol_id, ip, *x):
  434. fmt = "!hiqiqiqiq"
  435. value = struct.pack(fmt, 4, 8, cp_id, 8, parent_id, 8, symbol_id, 8, ip)
  436. call_path_file.write(value)
  437. 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):
  438. fmt = "!hiqiqiqiqiqiqiqiqiqiqii"
  439. 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)
  440. call_file.write(value)