52 sys.path.append(os.environ[
'PERF_EXEC_PATH'] + \
53 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
59 perf_db_export_mode =
True 60 perf_db_export_calls =
False 61 perf_db_export_callchains =
False 64 print >> sys.stderr,
"Usage is: export-to-sqlite.py <database name> [<columns>] [<calls>] [<callchains>]" 65 print >> sys.stderr,
"where: columns 'all' or 'branches'" 66 print >> sys.stderr,
" calls 'calls' => create calls and call_paths table" 67 print >> sys.stderr,
" callchains 'callchains' => create call_paths table" 68 raise Exception(
"Too few arguments")
70 if (len(sys.argv) < 2):
75 if (len(sys.argv) >= 3):
80 if columns
not in (
"all",
"branches"):
83 branches = (columns ==
"branches")
85 for i
in range(3,len(sys.argv)):
86 if (sys.argv[i] ==
"calls"):
87 perf_db_export_calls =
True 88 elif (sys.argv[i] ==
"callchains"):
89 perf_db_export_callchains =
True 96 raise Exception(
"Query failed: " + q.lastError().text())
101 raise Exception(
"Query failed: " + q.lastError().text())
103 print datetime.datetime.today(),
"Creating database..." 114 raise Exception(dbname +
" already exists")
116 db = QSqlDatabase.addDatabase(
'QSQLITE')
117 db.setDatabaseName(dbname)
120 query = QSqlQuery(db)
122 do_query(query,
'PRAGMA journal_mode = OFF')
123 do_query(query,
'BEGIN TRANSACTION')
125 do_query(query,
'CREATE TABLE selected_events (' 126 'id integer NOT NULL PRIMARY KEY,' 128 do_query(query,
'CREATE TABLE machines (' 129 'id integer NOT NULL PRIMARY KEY,' 131 'root_dir varchar(4096))')
132 do_query(query,
'CREATE TABLE threads (' 133 'id integer NOT NULL PRIMARY KEY,' 138 do_query(query,
'CREATE TABLE comms (' 139 'id integer NOT NULL PRIMARY KEY,' 141 do_query(query,
'CREATE TABLE comm_threads (' 142 'id integer NOT NULL PRIMARY KEY,' 145 do_query(query,
'CREATE TABLE dsos (' 146 'id integer NOT NULL PRIMARY KEY,' 148 'short_name varchar(256),' 149 'long_name varchar(4096),' 150 'build_id varchar(64))')
151 do_query(query,
'CREATE TABLE symbols (' 152 'id integer NOT NULL PRIMARY KEY,' 157 'name varchar(2048))')
158 do_query(query,
'CREATE TABLE branch_types (' 159 'id integer NOT NULL PRIMARY KEY,' 163 do_query(query,
'CREATE TABLE samples (' 164 'id integer NOT NULL PRIMARY KEY,' 176 'to_symbol_id bigint,' 177 'to_sym_offset bigint,' 179 'branch_type integer,' 181 'call_path_id bigint)')
183 do_query(query,
'CREATE TABLE samples (' 184 'id integer NOT NULL PRIMARY KEY,' 196 'to_symbol_id bigint,' 197 'to_sym_offset bigint,' 201 'transaction_ bigint,' 203 'branch_type integer,' 205 'call_path_id bigint)')
207 if perf_db_export_calls
or perf_db_export_callchains:
208 do_query(query,
'CREATE TABLE call_paths (' 209 'id integer NOT NULL PRIMARY KEY,' 213 if perf_db_export_calls:
214 do_query(query,
'CREATE TABLE calls (' 215 'id integer NOT NULL PRIMARY KEY,' 218 'call_path_id bigint,' 220 'return_time bigint,' 221 'branch_count bigint,' 224 'parent_call_path_id bigint,' 228 sqlite_has_printf =
False 230 do_query(query,
'SELECT printf("") FROM machines')
231 sqlite_has_printf =
True 236 if sqlite_has_printf:
237 return 'printf("%x", ' + x +
')' 241 do_query(query,
'CREATE VIEW machines_view AS ' 246 'CASE WHEN id=0 THEN \'unknown\' WHEN pid=-1 THEN \'host\' ELSE \'guest\' END AS host_or_guest' 249 do_query(query,
'CREATE VIEW dsos_view AS ' 253 '(SELECT host_or_guest FROM machines_view WHERE id = machine_id) AS host_or_guest,' 259 do_query(query,
'CREATE VIEW symbols_view AS ' 263 '(SELECT short_name FROM dsos WHERE id=dso_id) AS dso,' 267 'CASE WHEN binding=0 THEN \'local\' WHEN binding=1 THEN \'global\' ELSE \'weak\' END AS binding' 270 do_query(query,
'CREATE VIEW threads_view AS ' 274 '(SELECT host_or_guest FROM machines_view WHERE id = machine_id) AS host_or_guest,' 280 do_query(query,
'CREATE VIEW comm_threads_view AS ' 283 '(SELECT comm FROM comms WHERE id = comm_id) AS command,' 285 '(SELECT pid FROM threads WHERE id = thread_id) AS pid,' 286 '(SELECT tid FROM threads WHERE id = thread_id) AS tid' 287 ' FROM comm_threads')
289 if perf_db_export_calls
or perf_db_export_callchains:
290 do_query(query,
'CREATE VIEW call_paths_view AS ' 295 '(SELECT name FROM symbols WHERE id = c.symbol_id) AS symbol,' 296 '(SELECT dso_id FROM symbols WHERE id = c.symbol_id) AS dso_id,' 297 '(SELECT dso FROM symbols_view WHERE id = c.symbol_id) AS dso_short_name,' 300 'p.symbol_id AS parent_symbol_id,' 301 '(SELECT name FROM symbols WHERE id = p.symbol_id) AS parent_symbol,' 302 '(SELECT dso_id FROM symbols WHERE id = p.symbol_id) AS parent_dso_id,' 303 '(SELECT dso FROM symbols_view WHERE id = p.symbol_id) AS parent_dso_short_name' 304 ' FROM call_paths c INNER JOIN call_paths p ON p.id = c.parent_id')
305 if perf_db_export_calls:
306 do_query(query,
'CREATE VIEW calls_view AS ' 310 '(SELECT pid FROM threads WHERE id = thread_id) AS pid,' 311 '(SELECT tid FROM threads WHERE id = thread_id) AS tid,' 312 '(SELECT comm FROM comms WHERE id = comm_id) AS command,' 316 '(SELECT name FROM symbols WHERE id = symbol_id) AS symbol,' 319 'return_time - call_time AS elapsed_time,' 323 'CASE WHEN flags=1 THEN \'no call\' WHEN flags=2 THEN \'no return\' WHEN flags=3 THEN \'no call/return\' ELSE \'\' END AS flags,' 324 'parent_call_path_id' 325 ' FROM calls INNER JOIN call_paths ON call_paths.id = call_path_id')
327 do_query(query,
'CREATE VIEW samples_view AS ' 332 '(SELECT pid FROM threads WHERE id = thread_id) AS pid,' 333 '(SELECT tid FROM threads WHERE id = thread_id) AS tid,' 334 '(SELECT comm FROM comms WHERE id = comm_id) AS command,' 335 '(SELECT name FROM selected_events WHERE id = evsel_id) AS event,' 337 '(SELECT name FROM symbols WHERE id = symbol_id) AS symbol,' 339 '(SELECT short_name FROM dsos WHERE id = dso_id) AS dso_short_name,' 341 '(SELECT name FROM symbols WHERE id = to_symbol_id) AS to_symbol,' 343 '(SELECT short_name FROM dsos WHERE id = to_dso_id) AS to_dso_short_name,' 344 '(SELECT name FROM branch_types WHERE id = branch_type) AS branch_type_name,' 350 evsel_query = QSqlQuery(db)
351 evsel_query.prepare(
"INSERT INTO selected_events VALUES (?, ?)")
352 machine_query = QSqlQuery(db)
353 machine_query.prepare(
"INSERT INTO machines VALUES (?, ?, ?)")
354 thread_query = QSqlQuery(db)
355 thread_query.prepare(
"INSERT INTO threads VALUES (?, ?, ?, ?, ?)")
356 comm_query = QSqlQuery(db)
357 comm_query.prepare(
"INSERT INTO comms VALUES (?, ?)")
358 comm_thread_query = QSqlQuery(db)
359 comm_thread_query.prepare(
"INSERT INTO comm_threads VALUES (?, ?, ?)")
360 dso_query = QSqlQuery(db)
361 dso_query.prepare(
"INSERT INTO dsos VALUES (?, ?, ?, ?, ?)")
362 symbol_query = QSqlQuery(db)
363 symbol_query.prepare(
"INSERT INTO symbols VALUES (?, ?, ?, ?, ?, ?)")
364 branch_type_query = QSqlQuery(db)
365 branch_type_query.prepare(
"INSERT INTO branch_types VALUES (?, ?)")
366 sample_query = QSqlQuery(db)
368 sample_query.prepare(
"INSERT INTO samples VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
370 sample_query.prepare(
"INSERT INTO samples VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
371 if perf_db_export_calls
or perf_db_export_callchains:
372 call_path_query = QSqlQuery(db)
373 call_path_query.prepare(
"INSERT INTO call_paths VALUES (?, ?, ?, ?)")
374 if perf_db_export_calls:
375 call_query = QSqlQuery(db)
376 call_query.prepare(
"INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
379 print datetime.datetime.today(),
"Writing records..." 380 do_query(query,
'BEGIN TRANSACTION')
386 dso_table(0, 0,
"unknown",
"unknown",
"")
388 sample_table(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
389 if perf_db_export_calls
or perf_db_export_callchains:
397 print datetime.datetime.today(),
"Adding indexes" 398 if perf_db_export_calls:
399 do_query(query,
'CREATE INDEX pcpid_idx ON calls (parent_call_path_id)')
401 if (unhandled_count):
402 print datetime.datetime.today(),
"Warning: ", unhandled_count,
" unhandled events" 403 print datetime.datetime.today(),
"Done" 406 global unhandled_count
414 q.addBindValue(
str(xx))
def trace_unhandled(event_name, context, event_fields_dict)
static int str(yyscan_t scanner, int token)
def sched__sched_switch(x)