89 lines
2.3 KiB
Python
89 lines
2.3 KiB
Python
import pandas as pd
|
|
import plotly.graph_objs as go
|
|
|
|
call_depths = [0]
|
|
datas = []
|
|
|
|
def ensure_big_enough(list, idx, el):
|
|
l = len(list)
|
|
if (idx >= l):
|
|
list.extend([el]*(idx-l+1))
|
|
|
|
def incr_call_depth(thread):
|
|
ensure_big_enough(call_depths, thread, 0)
|
|
call_depths[thread] += 1
|
|
|
|
def append_to_datas(thread, data):
|
|
ensure_big_enough(datas, thread, [])
|
|
datas[thread].append(data)
|
|
|
|
with open("../src/profiler_reports/04.10.2019-13.29.21-140737348403048-profiler.report", "r") as file:
|
|
for line in file:
|
|
infos = line.split()
|
|
if infos[1] == "->":
|
|
incr_call_depth(thread)
|
|
append_to_datas(thread, {
|
|
"task": f"[T{thread}] - {'{:03d}'.format(call_depths[thread])}",
|
|
"start": int(infos[5]),
|
|
"end": None
|
|
})
|
|
elif infos[1] == "<-":
|
|
call_depths[thread] -= 1
|
|
for set in datas[thread][::-1]:
|
|
if set["end"] == None:
|
|
set["end"] = int(infos[2])
|
|
break
|
|
else:
|
|
print("couldn't find task that finished")
|
|
break
|
|
|
|
else:
|
|
print("neither -> nor <-")
|
|
|
|
|
|
fig = go.Figure(
|
|
layout = {
|
|
'barmode': 'stack',
|
|
"dragmode" : "pan",
|
|
}
|
|
)
|
|
|
|
flat_datas= [item for sublist in datas for item in sublist]
|
|
# i = 1
|
|
# df = flat_datas[:20]
|
|
# for call in df:
|
|
# name = call["task"]
|
|
# start = call["start"]
|
|
# end = call["end"]
|
|
# duration = end,start
|
|
# fig.add_bar(x=(i,duration),
|
|
# y=(i,name),
|
|
# base=(i,start),
|
|
# orientation='h',
|
|
# showlegend=False,
|
|
# name=name,
|
|
# hovertext=f"yes",
|
|
# text=""
|
|
# )
|
|
# i += 1
|
|
|
|
df = pd.DataFrame(flat_datas[:20])
|
|
df['duration'] = df['end'] - df['start']
|
|
|
|
for stackdepth, stackdepth_df in df.groupby('task'):
|
|
params = {"x": stackdepth_df.duration,
|
|
"y": stackdepth_df.task,
|
|
"name": stackdepth,
|
|
"base": stackdepth_df.start
|
|
}
|
|
print(params)
|
|
fig.add_bar(**params,
|
|
orientation='h',
|
|
showlegend=False,
|
|
hovertext=f"yes",
|
|
text=""
|
|
)
|
|
|
|
|
|
fig.show(config={'scrollZoom': True})
|