fixing stats without hsa trace
Change-Id: Ic582175189be187acb30133b843f76fe69996191
This commit is contained in:
+20
-9
@@ -1,10 +1,11 @@
|
||||
import csv, sqlite3, re
|
||||
import csv, sqlite3, re, sys
|
||||
|
||||
# SQLite Database class
|
||||
class SQLiteDB:
|
||||
def __init__(self, file_name):
|
||||
self.connection = sqlite3.connect(file_name)
|
||||
self.tables = {}
|
||||
self.json_arg_list_enabled = 0
|
||||
|
||||
def __del__(self):
|
||||
self.connection.close()
|
||||
@@ -71,6 +72,9 @@ class SQLiteDB:
|
||||
def _get_raws(self, table_name):
|
||||
cursor = self.connection.execute('SELECT * FROM ' + table_name)
|
||||
return cursor.fetchall()
|
||||
def _get_raws_indexed(self, table_name):
|
||||
cursor = self.connection.execute('SELECT * FROM ' + table_name + ' order by "Index" asc;')
|
||||
return cursor.fetchall()
|
||||
def _get_raw_by_id(self, table_name, req_id):
|
||||
cursor = self.connection.execute('SELECT * FROM ' + table_name + ' WHERE "Index"=?', (req_id,))
|
||||
raws = cursor.fetchall()
|
||||
@@ -128,31 +132,38 @@ class SQLiteDB:
|
||||
name_ptrn = re.compile(r'(name|Name)')
|
||||
|
||||
table_fields = self._get_fields(table_name)
|
||||
table_raws = self._get_raws(table_name)
|
||||
table_raws = self._get_raws_indexed(table_name)
|
||||
data_fields = self._get_fields(data_name)
|
||||
data_raws = self._get_raws_indexed(data_name)
|
||||
|
||||
with open(file_name, mode='a') as fd:
|
||||
for raw_index in range(len(table_raws)):
|
||||
values = list(table_raws[raw_index])
|
||||
table_raws_len = len(table_raws)
|
||||
for raw_index in range(table_raws_len):
|
||||
if (raw_index == table_raws_len - 1) or (raw_index % 1000 == 0):
|
||||
sys.stdout.write( \
|
||||
"\rdump json " + str(raw_index) + ":" + str(len(table_raws)) + " "*100 \
|
||||
)
|
||||
|
||||
vals_list = []
|
||||
raw_id = 0;
|
||||
values = list(table_raws[raw_index])
|
||||
for value_index in range(len(values)):
|
||||
label = table_fields[value_index]
|
||||
value = values[value_index]
|
||||
if name_ptrn.search(label): value = sub_ptrn.sub(r'', value)
|
||||
if label == '"Index"': raw_id = value
|
||||
else: vals_list.append('%s:"%s"' % (label, value))
|
||||
if label != '"Index"': vals_list.append('%s:"%s"' % (label, value))
|
||||
|
||||
data = self._get_raw_by_id(data_name, raw_id)
|
||||
args_list = []
|
||||
data = list(data_raws[raw_index])
|
||||
for value_index in range(len(data)):
|
||||
label = data_fields[value_index]
|
||||
value = data[value_index]
|
||||
if name_ptrn.search(label): value = sub_ptrn.sub(r'', value)
|
||||
args_list.append('%s:"%s"' % (label, value))
|
||||
if label != '"Index"': args_list.append('%s:"%s"' % (label, value))
|
||||
|
||||
fd.write(',{"ph":"%s",%s,\n "args":{\n %s\n }\n}\n' % ('X', ','.join(vals_list), ',\n '.join(args_list)))
|
||||
|
||||
sys.stdout.write('\n')
|
||||
|
||||
# execute query on DB
|
||||
def execute(self, cmd):
|
||||
cursor = self.connection.cursor()
|
||||
|
||||
+21
-13
@@ -186,6 +186,8 @@ def fill_hsa_db(table_name, db, indir):
|
||||
ptrn_val = re.compile(r'(\d+):(\d+) (\d+):(\d+) ([^\(]+)(\(.*)$')
|
||||
ptrn_ac = re.compile(r'hsa_amd_memory_async_copy')
|
||||
|
||||
if not os.path.isfile(file_name): return 0
|
||||
|
||||
if not COPY_PID in dep_dict: dep_dict[COPY_PID] = {}
|
||||
dep_tid_list = []
|
||||
dep_from_us_list = []
|
||||
@@ -226,6 +228,8 @@ def fill_hsa_db(table_name, db, indir):
|
||||
|
||||
dep_dict[COPY_PID]['tid'] = dep_tid_list
|
||||
dep_dict[COPY_PID]['from'] = dep_from_us_list
|
||||
|
||||
return 1
|
||||
#############################################################
|
||||
|
||||
# fill COPY DB
|
||||
@@ -266,7 +270,6 @@ if (len(sys.argv) < 3): fatal("Usage: " + sys.argv[0] + " <output CSV file> <inp
|
||||
outfile = sys.argv[1]
|
||||
infiles = sys.argv[2:]
|
||||
indir = re.sub(r'\/[^\/]*$', r'', infiles[0])
|
||||
print "indir: '" + indir + "'"
|
||||
|
||||
dbfile = ''
|
||||
csvfile = ''
|
||||
@@ -291,15 +294,19 @@ else:
|
||||
|
||||
with open(dbfile, mode='w') as fd: fd.truncate()
|
||||
db = SQLiteDB(dbfile)
|
||||
db.open_json(jsonfile);
|
||||
|
||||
fill_hsa_db('HSA', db, indir)
|
||||
fill_copy_db('COPY', db, indir)
|
||||
hsa_trace_found = fill_hsa_db('HSA', db, indir)
|
||||
if hsa_trace_found:
|
||||
fill_copy_db('COPY', db, indir)
|
||||
fill_kernel_db('A', db)
|
||||
|
||||
db.open_json(jsonfile);
|
||||
db.label_json(HSA_PID, "CPU", jsonfile)
|
||||
db.label_json(COPY_PID, "COPY", jsonfile)
|
||||
for ind in range(0, int(max_gpu_id) + 1): db.label_json(int(ind) + int(GPU_BASE_PID), "GPU" + str(ind), jsonfile)
|
||||
if hsa_trace_found:
|
||||
db.label_json(HSA_PID, "CPU", jsonfile)
|
||||
db.label_json(COPY_PID, "COPY", jsonfile)
|
||||
|
||||
for ind in range(0, int(max_gpu_id) + 1):
|
||||
db.label_json(int(ind) + int(GPU_BASE_PID), "GPU" + str(ind), jsonfile)
|
||||
|
||||
if 'BeginNs' in var_list:
|
||||
dform.post_process_data(db, 'A', csvfile)
|
||||
@@ -308,13 +315,14 @@ else:
|
||||
else:
|
||||
db.dump_csv('A', csvfile)
|
||||
|
||||
statfile = re.sub(r'stats', r'hsa_stats', statfile)
|
||||
dform.post_process_data(db, 'HSA')
|
||||
dform.gen_table_bins(db, 'HSA', statfile, 'Name', 'DurationNs')
|
||||
dform.gen_api_json_trace(db, 'HSA', START_US, jsonfile)
|
||||
if hsa_trace_found:
|
||||
statfile = re.sub(r'stats', r'hsa_stats', statfile)
|
||||
dform.post_process_data(db, 'HSA')
|
||||
dform.gen_table_bins(db, 'HSA', statfile, 'Name', 'DurationNs')
|
||||
dform.gen_api_json_trace(db, 'HSA', START_US, jsonfile)
|
||||
|
||||
dform.post_process_data(db, 'COPY')
|
||||
dform.gen_api_json_trace(db, 'COPY', START_US, jsonfile)
|
||||
dform.post_process_data(db, 'COPY')
|
||||
dform.gen_api_json_trace(db, 'COPY', START_US, jsonfile)
|
||||
|
||||
dep_id = 0
|
||||
for (to_pid, dep_str) in dep_dict.items():
|
||||
|
||||
Reference in New Issue
Block a user