Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

90 рядки
2.2 KiB

  1. import pandas as pd
  2. import plotly.graph_objs as go
  3. call_depths = [0]
  4. datas = []
  5. def ensure_big_enough(list, idx, el):
  6. l = len(list)
  7. if (idx >= l):
  8. list.extend([el]*(idx-l+1))
  9. def incr_call_depth(thread):
  10. ensure_big_enough(call_depths, thread, 0)
  11. call_depths[thread] += 1
  12. def append_to_datas(thread, data):
  13. ensure_big_enough(datas, thread, [])
  14. datas[thread].append(data)
  15. with open("../bin/profiler.report", "r") as file:
  16. for line in file:
  17. infos = line.split()
  18. thread = int(infos[0])
  19. if infos[1] == "->":
  20. incr_call_depth(thread)
  21. append_to_datas(thread, {
  22. "task": f"[T{thread}] - {'{:03d}'.format(call_depths[thread])}",
  23. "start": int(infos[5]),
  24. "end": None
  25. })
  26. elif infos[1] == "<-":
  27. call_depths[thread] -= 1
  28. for set in datas[thread][::-1]:
  29. if set["end"] == None:
  30. set["end"] = int(infos[2])
  31. break
  32. else:
  33. print("couldn't find task that finished")
  34. break
  35. else:
  36. print("neither -> nor <-")
  37. fig = go.Figure(
  38. layout = {
  39. 'barmode': 'stack',
  40. "dragmode" : "pan",
  41. }
  42. )
  43. flat_datas= [item for sublist in datas for item in sublist]
  44. # i = 1
  45. # df = flat_datas[:20]
  46. # for call in df:
  47. # name = call["task"]
  48. # start = call["start"]
  49. # end = call["end"]
  50. # duration = end,start
  51. # fig.add_bar(x=(i,duration),
  52. # y=(i,name),
  53. # base=(i,start),
  54. # orientation='h',
  55. # showlegend=False,
  56. # name=name,
  57. # hovertext=f"yes",
  58. # text=""
  59. # )
  60. # i += 1
  61. df = pd.DataFrame(flat_datas[:20])
  62. df['duration'] = df['end'] - df['start']
  63. for stackdepth, stackdepth_df in df.groupby('task'):
  64. params = {"x": stackdepth_df.duration,
  65. "y": stackdepth_df.task,
  66. "name": stackdepth,
  67. "base": stackdepth_df.start
  68. }
  69. print(params)
  70. fig.add_bar(**params,
  71. orientation='h',
  72. showlegend=False,
  73. hovertext=f"yes",
  74. text=""
  75. )
  76. fig.show(config={'scrollZoom': True})