def load_log_sample(self, logname, idx): """Load sample idx into the subscribed components""" if self.logname != logname: if not self._load_log(logname): return #Load new page if out of bounds if idx < self.log_start_idx or idx > self.log_end_idx: search_idx = (self.log_file_idx + 1) % len(self.log_info) while True: if self.log_info[search_idx][ 'start_idx'] <= idx and self.log_info[search_idx][ 'end_idx'] >= idx: self.log_file_idx = search_idx self.log_start_idx = self.log_info[search_idx]['start_idx'] self.log_end_idx = self.log_info[search_idx]['end_idx'] break search_idx = (search_idx + 1) % len(self.log_info) if search_idx == self.log_file_idx: raise m3t.M3Exception( 'M3RtProxy invalid log sample idx: ' + str(idx)) filename = self.log_info[self.log_file_idx]['filename'] self.log_page = mbs.M3StatusLogPage() s = self.proxy.get_log_file(filename).data self.log_page.ParseFromString(s) entry_idx = idx - self.log_info[self.log_file_idx]['start_idx'] status_all = self.log_page.entry[entry_idx] for i in range(len(status_all.name)): for name in self.log_names: if name == status_all.name[i]: self.log_comps[name].status.ParseFromString( status_all.datum[i])
def get_log_component_names(self, logname): """Get the available components contained in a completed log session""" if self.logname != logname: if not self._load_log(logname): return [] filename = self.log_info[0]['filename'] self.log_page = mbs.M3StatusLogPage() s = self.proxy.get_log_file(filename).data self.log_page.ParseFromString(s) status_all = self.log_page.entry[0] return [str(x) for x in status_all.name]
def _load_log(self, logname): self.logname = logname self.log_info = self.proxy.get_log_info(logname) if len(self.log_info) == 0: return False self.log_start_idx = self.log_info[0]['start_idx'] self.log_end_idx = self.log_info[0]['end_idx'] self.log_file_idx = 0 filename = self.log_info[0]['filename'] self.log_page = mbs.M3StatusLogPage() s = self.proxy.get_log_file(filename).data self.log_page.ParseFromString(s) return True
def dump_log_dir_to_loglist(logname, comp_name, status): print 'Loading log: ', logname info = get_log_info(logname) ret = [] for ip in info: #loop over all logfile pages log_page = mbs.M3StatusLogPage() f = open(ip['filename'], "rb") s = f.read() f.close() log_page.ParseFromString(s) #load page into protobuf class for status_all in log_page.entry: #loop over all entries in a page for i in range(len( status_all.name)): #loop over all components in an entry if status_all.name[i] == comp_name: status.ParseFromString(status_all.datum[i]) d = GetDictFromMsg(status) ret.append(d) return ret