def _parse_performance(self): self.__event_values['run_time'] = None self.__event_values['reads'] = None self.__event_values['writes'] = None self.__event_values['fetches'] = None self.__event_values['marks'] = None self.__event_values['access'] = None if not self.__current_block: return if 'records fetched' in self.__current_block[0]: line = self.__current_block.popleft() self.__event_values['records'] = int(line.split()[0]) values = self.__current_block.popleft().split(',') while values: value, val_type = values.pop().split() if 'ms' in val_type: self.__event_values['run_time'] = int(value) elif 'read' in val_type: self.__event_values['reads'] = int(value) elif 'write' in val_type: self.__event_values['writes'] = int(value) elif 'fetch' in val_type: self.__event_values['fetches'] = int(value) elif 'mark' in val_type: self.__event_values['marks'] = int(value) else: raise fdb.ParseError("Unhandled performance parameter %s" % val_type) if self.__current_block: self.__event_values['access'] = [] if self.__current_block.popleft( ) != "Table Natural Index Update Insert Delete Backout Purge Expunge": raise fdb.ParseError("Performance table header expected") if self.__current_block.popleft() != "*" * 111: raise fdb.ParseError( "Performance table header separator expected") while self.__current_block: entry = self.__current_block.popleft() self.__event_values['access'].append( AccessTuple._make( (intern(entry[:32].strip()), utils.safe_int(entry[32:41].strip()), utils.safe_int(entry[41:51].strip()), utils.safe_int(entry[51:61].strip()), utils.safe_int(entry[61:71].strip()), utils.safe_int(entry[71:81].strip()), utils.safe_int(entry[81:91].strip()), utils.safe_int(entry[91:101].strip()), utils.safe_int(entry[101:111].strip()))))
def _parse_service(self): line = self.__current_block.popleft() if 'service_mgr' not in line: raise fdb.ParseError("Service connection description expected.") pad, sep, s = line.partition(' (') svc_id, user, protocol_address, remote_process_id = s.strip('()').split(',') pad, svc_id = svc_id.split(' ') svc_id = int(svc_id if svc_id.startswith('0x') else '0x%s' % svc_id, 0) if svc_id not in self.seen_services: svc_values = {} svc_values['service_id'] = svc_id svc_values['user'] = user.strip() protocol_address = protocol_address.strip() if protocol_address == '<internal>': protocol = address = protocol_address else: protocol, address = protocol_address.split(':') svc_values['protocol'] = protocol svc_values['address'] = address remote_process_id = remote_process_id.strip() remote_process, remote_pid = remote_process_id.rsplit(':', 1) svc_values['remote_process'] = remote_process svc_values['remote_pid'] = int(remote_pid) self.__buffer.append(ServiceInfo(**svc_values)) self.seen_services.add(svc_id) self.__event_values['service_id'] = svc_id
def _parse_statement_id(self): self.__event_values['plan'] = None self.__event_values['sql'] = None pad, s = self.__current_block.popleft().split() self.__event_values['statement_id'] = int(s[:-1]) if self.__current_block.popleft() != '-'*79: raise fdb.ParseError("Separator '-'*79 line expected")
def _parse_header(self, line): """Parses trace entry header into 3-item tuple. :param string line: Line of text to be parsed. :returns: Tuple with items: (timestamp, status, trace_entry_type_id) :raises `~fdb.ParseError`: When event is not recognized """ items = line.split() timestamp = datetime.datetime.strptime(items[0], '%Y-%m-%dT%H:%M:%S.%f') if (len(items) == 3) or (items[2] in ['ERROR', 'WARNING']): return (timestamp, STATUS_OK, EVENTS.index(items[2]) if items[2] in EVENTS else EVENT_UNKNOWN) else: if items[2] == 'UNAUTHORIZED': return (timestamp, STATUS_UNAUTHORIZED, EVENTS.index(items[3])) elif items[2] == 'FAILED': return (timestamp, STATUS_FAILED, EVENTS.index(items[3])) elif items[2] == 'Unknown': return (timestamp, STATUS_UNKNOWN, EVENT_UNKNOWN ) # ' '.join(items[3:])) else: raise fdb.ParseError('Unrecognized event header: "%s"' % line)
def _parse_sweep_tr_counters(self): line = self.__current_block.popleft() if not line: line = self.__current_block.popleft() if 'Transaction counters:' not in line: raise fdb.ParseError("Transaction counters expected") while len(self.__current_block) > 0: line = self.__current_block.popleft() if 'Oldest interesting' in line: self.__event_values['oit'] = int(line.rsplit(' ', 1)[1]) elif 'Oldest active' in line: self.__event_values['oat'] = int(line.rsplit(' ', 1)[1]) elif 'Oldest snapshot' in line: self.__event_values['ost'] = int(line.rsplit(' ', 1)[1]) elif 'Next transaction' in line: self.__event_values['next'] = int(line.rsplit(' ', 1)[1]) elif 'ms' in line and len(self.__current_block) == 0: # Put back performance counters self.__current_block.appendleft(line) break
def _parse_transaction_performance(self): self.__event_values['run_time'] = None self.__event_values['reads'] = None self.__event_values['writes'] = None self.__event_values['fetches'] = None self.__event_values['marks'] = None if self.__current_block: values = self.__current_block.popleft().split(',') while values: value, val_type = values.pop().split() if 'ms' in val_type: self.__event_values['run_time'] = int(value) elif 'read' in val_type: self.__event_values['reads'] = int(value) elif 'write' in val_type: self.__event_values['writes'] = int(value) elif 'fetch' in val_type: self.__event_values['fetches'] = int(value) elif 'mark' in val_type: self.__event_values['marks'] = int(value) else: raise fdb.ParseError("Unhandled performance parameter %s" % val_type)
def _parse_plan(self): if not self.__current_block: return line = self.__current_block.popleft() if self._is_perf_start(line): self.__current_block.appendleft(line) return if self._is_param_start(line): self.__current_block.appendleft(line) return if not self._is_plan_separator(line): raise fdb.ParseError("Separator '^'*79 line expected") line = self.__current_block.popleft() plan = [] while line and not (self._is_perf_start(line) or self._is_param_start(line)): plan.append(line) if self.__current_block: line = self.__current_block.popleft() else: line = None if line: self.__current_block.appendleft(line) self.__event_values['plan'] = '\n'.join(plan)