def set_input_path(self, path): """ Set the replay trace path :param path: the replay file path. If it is a directory, the OfflineReplayer will read all logs under this directory (logs in subdirectories are ignored) :type path: string """ dm_collector_c.reset() self._input_path = path
def run(self): """ Start monitoring the mobile network. This is usually the entrance of monitoring and analysis. """ # fd = open('./Diag.cfg','wb') # dm_collector_c.generate_diag_cfg(fd, self._type_names) # fd.close() self.log_info("Running Offline replayer") try: self.broadcast_info('STARTED',{}) log_list = [] if os.path.isfile(self._input_path): log_list = [self._input_path] elif os.path.isdir(self._input_path): for file in os.listdir(self._input_path): if file.endswith(".muxraw"): log_list.append(os.path.join(self._input_path, file)) else: self.log_debug("No files???") return log_list.sort() # Hidden assumption: logs follow the diag_log_TIMSTAMP_XXX format # mtk_log_parser.ws_dissector_proc_start(self.ws_dissector_path, self.libs_path) for file in log_list: self.log_info("Loading " + file) self._input_file = open(file, "rb") dm_collector_c.reset() while True: s = self._input_file.read() if not s: break decoded = mtk_log_parser.feed_binary(s) # self for debug # decoded = mtk_log_parser.receive_log_packet(self._skip_decoding, # True # include_timestamp # ) ###################################### if decoded != []: try: # # packet = DMLogPacket(decoded) # packet = DMLogPacket(decoded[0]) # d = packet.decode() # # print d["type_id"], d["timestamp"] # # xml = packet.decode_xml() # # print xml # # print "" # # Send event to analyzers # event = Event( timeit.default_timer(), # d["type_id"], # packet) # self.send(event) ############################################## for msg in decoded: typeid, rawid, msgstr = mtk_log_parser.decode(self, msg) #self for debug if typeid == "": continue packet = DMLogPacket([("log_msg_len", len(msg), ""),('type_id', typeid, ''),('timestamp', datetime.datetime.now(), ''),("Msg", msgstr, "msg")]) # ("Msg", msgstr, "raw_msg/" + rawid)]) # print "DMLogPacket decoded[0]:",str([typeid]) event = Event( timeit.default_timer(), typeid, packet) self.send(event) ############################################## except FormatError as e: print "FormatError: ", e # skip this packet self._input_file.close() except Exception as e: import traceback print str(traceback.format_exc())
def run(self): """ Start monitoring the mobile network. This is usually the entrance of monitoring and analysis. """ # fd = open('./Diag.cfg','wb') # dm_collector_c.generate_diag_cfg(fd, self._type_names) # fd.close() try: self.broadcast_info('STARTED', {}) log_list = [] if os.path.isfile(self._input_path): log_list = [self._input_path] elif os.path.isdir(self._input_path): for file in os.listdir(self._input_path): if file.endswith(".mi2log") or file.endswith(".qmdl"): # log_list.append(self._input_path+"/"+file) log_list.append(os.path.join(self._input_path, file)) else: return log_list.sort( ) # Hidden assumption: logs follow the diag_log_TIMSTAMP_XXX format for file in log_list: self.log_info("Loading " + file) self._input_file = open(file, "rb") dm_collector_c.reset() while True: s = self._input_file.read(64) if not s: # EOF encountered break dm_collector_c.feed_binary(s) # decoded = dm_collector_c.receive_log_packet() decoded = dm_collector_c.receive_log_packet( self._skip_decoding, True, # include_timestamp ) if decoded: try: # packet = DMLogPacket(decoded) packet = DMLogPacket(decoded[0]) # print "DMLogPacket decoded[0]:",str(decoded[0]) d = packet.decode() # print d["type_id"], d["timestamp"] # xml = packet.decode_xml() # print xml # print "" # Send event to analyzers if d["type_id"] in self._type_names: event = Event(timeit.default_timer(), d["type_id"], packet) self.send(event) except FormatError as e: # skip this packet print "FormatError: ", e self._input_file.close() except Exception as e: import traceback sys.exit(str(traceback.format_exc()))
def run(self): """ Start monitoring the mobile network. This is usually the entrance of monitoring and analysis. """ # fd = open('./Diag.cfg','wb') # dm_collector_c.generate_diag_cfg(fd, self._type_names) # fd.close() try: self.broadcast_info('STARTED', {}) self.log_info('STARTED: ' + str(time.time())) log_list = [] if os.path.isfile(self._input_path): log_list = [self._input_path] elif os.path.isdir(self._input_path): for file in os.listdir(self._input_path): if file.endswith(".mi2log") or file.endswith(".qmdl"): # log_list.append(self._input_path+"/"+file) log_list.append(os.path.join(self._input_path, file)) else: return log_list.sort( ) # Hidden assumption: logs follow the diag_log_TIMSTAMP_XXX format decoding_inter = 0 sending_inter = 0 for file in log_list: self.log_info("Loading " + file) self.log_info('Loading: ' + str(time.time())) self._input_file = open(file, "rb") dm_collector_c.reset() while True: s = self._input_file.read(64) if not s: # EOF encountered break dm_collector_c.feed_binary(s) decoded = dm_collector_c.receive_log_packet( self._skip_decoding, True, # include_timestamp ) if decoded: try: before_decode_time = time.time() # self.log_info('Before decoding: ' + str(time.time())) packet = DMLogPacket(decoded[0]) type_id = packet.get_type_id() after_decode_time = time.time() decoding_inter += after_decode_time - before_decode_time if type_id in self._type_names: event = Event(timeit.default_timer(), type_id, packet) self.send(event) after_sending_time = time.time() sending_inter += after_sending_time - after_decode_time # pself.log_info('After sending event: ' + str(time.time())) except FormatError as e: # skip this packet print "FormatError: ", e self.log_info('Decoding_inter: ' + str(decoding_inter)) self.log_info('sending_inter: ' + str(sending_inter)) self._input_file.close() except Exception as e: import traceback sys.exit(str(traceback.format_exc())) # sys.exit(e) event = Event(timeit.default_timer(), 'Monitor.STOP', None) self.send(event) self.log_info("Offline replay is completed.")