def parse_cnode(xml_node: XMLNode): cnode = CNode(_id=int(xml_node.get('id')), callee_region_id=int(xml_node.get('calleeId'))) for cnode_xml_child in xml_node.findall('cnode'): cnode_child = parse_cnode(cnode_xml_child) cnode.add_child(cnode_child) return cnode
def print_calltree(self, indent=0, cnode: CNode = None): if cnode is None: cnode = self._anchor_result.cnodes[0] print('\t' * indent, self.get_region(cnode).name) for child in cnode.get_children(): self.print_calltree(indent + 1, cnode=child)
def _convert_values(self, cnode: CNode, values: List[Any], to_inclusive: bool = True): # Go over all cnode children and add the metric values # Does change the values array! for child_cnode in cnode.get_children(): child_values = self.cnode_values(child_cnode, convert_to_inclusive=True, convert_to_exclusive=False) if to_inclusive: self._iadd(values, child_values) else: self._isub(values, child_values) return values
def get_calltree(self, indent=0, cnode: CNode = None): if cnode is None: cnode = self._anchor_result.cnodes[0] call_tree_string = "" child_string = "" child_string += "-" * indent + self.get_region(cnode).name call_tree_string += child_string call_tree_string += "\n" for child in cnode.get_children(): tmp = self.get_calltree(indent + 1, cnode=child) if tmp is not None: call_tree_string += tmp return call_tree_string
def _convert_values(self, cnode: CNode, values: List[Any], to_inclusive: bool = True): # Go over all cnode children and add the metric values # Does NOT change the values array! for child_cnode in cnode.get_all_children(with_self=False): if child_cnode.id not in self.cnode_indices: continue values = [ x + y if to_inclusive else x - y for x, y in zip(values, self.cnode_values( child_cnode, convert_to_inclusive=False, convert_to_exclusive=False) ) ] return values
def cnode_values(self, cnode: CNode, convert_to_exclusive: bool = False, convert_to_inclusive: bool = False): if isinstance(cnode, int): warnings.warn('Calling with Cnode ID is deprecated use Cnode directly.', DeprecationWarning) if convert_to_inclusive or convert_to_exclusive: raise InvalidConversionInstructionError('Conversion is not supported when passing a Cnode ID.') cnode = CNode(_id=cnode, callee_region_id=-1) else: if convert_to_inclusive and convert_to_exclusive: raise InvalidConversionInstructionError() assert not (convert_to_inclusive and convert_to_exclusive) cid = self.metric.tree_enumeration[cnode.id] if cid not in self.cnode_indices: values = [0] * self.num_locations() else: start_index = int(self.cnode_indices[cid] * self.num_locations()) end_index = start_index + self.num_locations() values = self.values[start_index: end_index] # creates copy must_convert = ((convert_to_exclusive and self.metric.metric_type == MetricType.INCLUSIVE) or (convert_to_inclusive and self.metric.metric_type == MetricType.EXCLUSIVE)) if must_convert: values = self._convert_values(cnode, values, to_inclusive=convert_to_inclusive) return values