1# -*- coding: utf-8 -*- 2import json 3from trace_parser import TraceSubsystem, Trace 4 5class Aquarium(object): 6 7 def __init__(self, json_defs): 8 self._trace = None 9 with open(json_defs) as f: 10 json_data = json.load(f) 11 self._event_types = dict() 12 for typekey, evtype in json_data.items(): 13 t = TraceSubsystem(typekey, evtype) 14 self._event_types[t._id] = t 15 16 def load_trace(self, tracefile): 17 if self._trace is None: 18 t = Trace(self._event_types) 19 with open(tracefile) as f: 20 for line in f: 21 if '\0\0' in line: 22 lines = line.split('\0\0') 23 t.parse_line(lines[1]) 24 else: 25 t.parse_line(line) 26 self._trace = t 27 28 return self._trace 29 30 def get_event_types(self): 31 return self._event_types 32