Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

89 Zeilen
2.3 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("../src/profiler_reports/04.10.2019-13.29.21-140737348403048-profiler.report", "r") as file:
  16. for line in file:
  17. infos = line.split()
  18. if infos[1] == "->":
  19. incr_call_depth(thread)
  20. append_to_datas(thread, {
  21. "task": f"[T{thread}] - {'{:03d}'.format(call_depths[thread])}",
  22. "start": int(infos[5]),
  23. "end": None
  24. })
  25. elif infos[1] == "<-":
  26. call_depths[thread] -= 1
  27. for set in datas[thread][::-1]:
  28. if set["end"] == None:
  29. set["end"] = int(infos[2])
  30. break
  31. else:
  32. print("couldn't find task that finished")
  33. break
  34. else:
  35. print("neither -> nor <-")
  36. fig = go.Figure(
  37. layout = {
  38. 'barmode': 'stack',
  39. "dragmode" : "pan",
  40. }
  41. )
  42. flat_datas= [item for sublist in datas for item in sublist]
  43. # i = 1
  44. # df = flat_datas[:20]
  45. # for call in df:
  46. # name = call["task"]
  47. # start = call["start"]
  48. # end = call["end"]
  49. # duration = end,start
  50. # fig.add_bar(x=(i,duration),
  51. # y=(i,name),
  52. # base=(i,start),
  53. # orientation='h',
  54. # showlegend=False,
  55. # name=name,
  56. # hovertext=f"yes",
  57. # text=""
  58. # )
  59. # i += 1
  60. df = pd.DataFrame(flat_datas[:20])
  61. df['duration'] = df['end'] - df['start']
  62. for stackdepth, stackdepth_df in df.groupby('task'):
  63. params = {"x": stackdepth_df.duration,
  64. "y": stackdepth_df.task,
  65. "name": stackdepth,
  66. "base": stackdepth_df.start
  67. }
  68. print(params)
  69. fig.add_bar(**params,
  70. orientation='h',
  71. showlegend=False,
  72. hovertext=f"yes",
  73. text=""
  74. )
  75. fig.show(config={'scrollZoom': True})