Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import json
  2.  
  3.  
  4. class TimeLiner:
  5. _timeline_dict = None
  6.  
  7. def update_timeline(self, chrome_trace):
  8. # convert crome trace to python dict
  9. chrome_trace_dict = json.loads(chrome_trace)
  10. # for first run store full trace
  11. if self._timeline_dict is None:
  12. self._timeline_dict = chrome_trace_dict
  13. # for other - update only time consumption, not definitions
  14. else:
  15. for event in chrome_trace_dict['traceEvents']:
  16. # events time consumption started with 'ts' prefix
  17. if 'ts' in event:
  18. self._timeline_dict['traceEvents'].append(event)
  19.  
  20. def save(self, f_name):
  21. with open(f_name, 'w') as f:
  22. json.dump(self._timeline_dict, f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement