コード例 #1
0
def _find_leaks(referent, potential_leak, valid_refs, recursion_depth,
                output_ref_chain, possible_leak_chains):
    valid_refs.add(id(sys._getframe()))
    ret = False
    if recursion_depth > 1:
        output = '  ' * (recursion_depth - 1)
    else:
        output = ''
    type_name = type(potential_leak).__name__
    special_output = None
    if isinstance(potential_leak, types.FrameType):
        s = callable_repr(potential_leak)
        special_output = '{}: ID: {}, Frame: {}'.format(
            recursion_depth, id(potential_leak), s[:900])
    elif isinstance(potential_leak, types.FunctionType):
        s = callable_repr(potential_leak)
        special_output = '{}: ID: {}, Function: {}'.format(
            recursion_depth, id(potential_leak), s[:900])
    elif isinstance(potential_leak, dict):
        for (key_name, value) in potential_leak.items():
            if value is referent:
                special_output = '{}: ID: {}, dict[{}]'.format(
                    recursion_depth, id(potential_leak), key_name)
                break
    if special_output:
        output += special_output
    else:
        output += '{}: ID: {}, {}: {}'.format(recursion_depth,
                                              id(potential_leak), type_name,
                                              str(potential_leak)[:900])
    output_ref_chain.append(output)
    if _full_print:
        logger.error(output)
    if output.find('pydev') >= 0:
        return False
    if recursion_depth == _recursion_depth or id(
            potential_leak) in _termination_points:
        output_string = '\n'.join(output_ref_chain)
        possible_leak_chains.append(output_string)
        return True
    if recursion_depth == -1:
        raise StopIteration
    valid_refs.add(id(locals()))
    fl_refs = _get_refs(potential_leak, valid_refs)
    valid_refs.add(id(fl_refs))
    for ref in fl_refs:
        valid_refs.add(id(ref))
    for ref in fl_refs:
        recursion_depth += 1
        ret |= _find_leaks(potential_leak, ref, valid_refs, recursion_depth,
                           output_ref_chain, possible_leak_chains)
        if not _full_print and len(possible_leak_chains) > 9:
            if _termination_string not in possible_leak_chains:
                possible_leak_chains.append(_termination_string)
            return ret
        output_ref_chain.pop()
        recursion_depth -= 1
    return ret
コード例 #2
0
def _find_leaks(referent, potential_leak, valid_refs, recursion_depth, output_ref_chain, possible_leak_chains):
    valid_refs.add(id(sys._getframe()))
    ret = False
    if recursion_depth > 1:
        output = '  '*(recursion_depth - 1)
    else:
        output = ''
    type_name = type(potential_leak).__name__
    special_output = None
    if isinstance(potential_leak, types.FrameType):
        s = callable_repr(potential_leak)
        special_output = '{}: ID: {}, Frame: {}'.format(recursion_depth, id(potential_leak), s[:900])
    elif isinstance(potential_leak, types.FunctionType):
        s = callable_repr(potential_leak)
        special_output = '{}: ID: {}, Function: {}'.format(recursion_depth, id(potential_leak), s[:900])
    elif isinstance(potential_leak, dict):
        for (key_name, value) in potential_leak.items():
            while value is referent:
                special_output = '{}: ID: {}, dict[{}]'.format(recursion_depth, id(potential_leak), key_name)
                break
    if special_output:
        output += special_output
    else:
        output += '{}: ID: {}, {}: {}'.format(recursion_depth, id(potential_leak), type_name, str(potential_leak)[:900])
    output_ref_chain.append(output)
    if _full_print:
        logger.error(output)
    if output.find('pydev') >= 0:
        return False
    if recursion_depth == _recursion_depth or id(potential_leak) in _termination_points:
        output_string = '\n'.join(output_ref_chain)
        possible_leak_chains.append(output_string)
        return True
    if recursion_depth == -1:
        raise StopIteration
    valid_refs.add(id(locals()))
    fl_refs = _get_refs(potential_leak, valid_refs)
    valid_refs.add(id(fl_refs))
    for ref in fl_refs:
        valid_refs.add(id(ref))
    for ref in fl_refs:
        recursion_depth += 1
        ret |= _find_leaks(potential_leak, ref, valid_refs, recursion_depth, output_ref_chain, possible_leak_chains)
        if not _full_print and len(possible_leak_chains) > 9:
            if _termination_string not in possible_leak_chains:
                possible_leak_chains.append(_termination_string)
            return ret
        output_ref_chain.pop()
        recursion_depth -= 1
    return ret
コード例 #3
0
 def __repr__(self):
     conditions = []
     for condition in self.conditions:
         if callable(condition) and not isinstance(condition, TunableFactory.TunableFactoryWrapper):
             conditions.append(callable_repr(condition))
         else:
             conditions.append(condition)
     kwargs = {}
     if self.tests is not None:
         kwargs['tests'] = self.tests
     kwargs['restrictions'] = self.restrictions
     kwargs['interaction_action'] = self.interaction_action
     kwargs['progress_bar_action'] = self.progress_bar_action
     return standard_repr(self, conditions, **kwargs)
コード例 #4
0
def find_object_refs(obj,
                     valid_refs=set(),
                     termination_points=set(),
                     recursion_depth=15):
    global _recursion_depth, _termination_points
    gc.collect()
    logger.error('Searching for reference chains pointing to {}: {}', id(obj),
                 obj)
    try:
        _recursion_depth = recursion_depth
        _termination_points = {id(e) for e in termination_points}
        _termination_points.update(global_module_ids)
        valid_refs.add(id(locals()))
        valid_refs.add(id(obj))
        refs = _get_refs(obj, valid_refs)
        valid_refs.add(id(refs))
        try:
            i = 0
            while True:
                frame = sys._getframe(i)
                if _full_print:
                    logger.error('Ignoring frame: {}', callable_repr(frame))
                valid_refs.add(id(frame))
                i += 1
        except ValueError:
            pass
        if len(refs) > 0:
            valid_refs.update(id(ref) for ref in refs)
            ret = False
            possible_leak_chains = []
            for ref in refs:
                ret |= _find_leaks(obj, ref, valid_refs, 1, [],
                                   possible_leak_chains)
            if ret:
                output = 'Leaked Ref List:\nObject: {}, Type: {}\n'.format(
                    obj, type(obj))
                output += '\n'.join(possible_leak_chains)
                logger.error(output)
            else:
                logger.error(
                    'No leaks found. (Some allowed refs exist outside current call stack.)'
                )
        else:
            logger.error(
                'No leaks found. (No refs at all outside current call stack.)')
    except:
        logger.exception(
            'Exception thrown while ref tracking in find_object_refs.-Mike Duke'
        )
コード例 #5
0
 def __repr__(self):
     conditions = []
     for condition in self.conditions:
         if callable(condition) and not isinstance(
                 condition, TunableFactory.TunableFactoryWrapper):
             conditions.append(callable_repr(condition))
         else:
             conditions.append(condition)
     kwargs = {}
     if self.tests is not None:
         kwargs['tests'] = self.tests
     kwargs['restrictions'] = self.restrictions
     kwargs['interaction_action'] = self.interaction_action
     kwargs['progress_bar_action'] = self.progress_bar_action
     return standard_repr(self, conditions, **kwargs)
コード例 #6
0
def find_object_refs(obj, valid_refs=set(), termination_points=set(), recursion_depth=15):
    global _recursion_depth, _termination_points
    gc.collect()
    logger.error('Searching for reference chains pointing to {}: {}', id(obj), obj)
    try:
        _recursion_depth = recursion_depth
        _termination_points = {id(e) for e in termination_points}
        _termination_points.update(global_module_ids)
        valid_refs.add(id(locals()))
        valid_refs.add(id(obj))
        refs = _get_refs(obj, valid_refs)
        valid_refs.add(id(refs))
        try:
            i = 0
            while True:
                frame = sys._getframe(i)
                if _full_print:
                    logger.error('Ignoring frame: {}', callable_repr(frame))
                valid_refs.add(id(frame))
                i += 1
        except ValueError:
            pass
        if len(refs) > 0:
            valid_refs.update(id(ref) for ref in refs)
            ret = False
            possible_leak_chains = []
            for ref in refs:
                ret |= _find_leaks(obj, ref, valid_refs, 1, [], possible_leak_chains)
            if ret:
                output = 'Leaked Ref List:\nObject: {}, Type: {}\n'.format(obj, type(obj))
                output += '\n'.join(possible_leak_chains)
                logger.error(output)
            else:
                logger.error('No leaks found. (Some allowed refs exist outside current call stack.)')
        else:
            logger.error('No leaks found. (No refs at all outside current call stack.)')
    except:
        logger.exception('Exception thrown while ref tracking in find_object_refs.-Mike Duke')
コード例 #7
0
def generate_interaction_tuning_data(*args, zone_id: int = None, **kwargs):
    interaction_tuning_data = []
    for affordance in services.get_instance_manager(
            sims4.resources.Types.INTERACTION).types.values():
        if not affordance.is_super:
            pass
        data = {}
        data['name'] = affordance.__name__
        canonical_animation = affordance.canonical_animation
        if canonical_animation is not None:
            data['canonical_animation'] = str(canonical_animation).replace(
                'TunableAnimationReferenceWrapper.', '')
        else:
            data['canonical_animation'] = None
        constraint_list = []
        all_postures = set()
        all_slots = set()
        for participant_type in _PARTICIPANT_TYPES_THAT_GET_CONSTRAINTS:
            try:
                for constraints in affordance.constraint_gen(
                        GLOBAL_STUB_ACTOR, GLOBAL_STUB_TARGET,
                        participant_type):
                    for constraint in constraints:
                        constraint_data = {}
                        constraint_data[
                            'participant_type'] = participant_type.name
                        constraint_data['constraint_type'] = type(
                            constraint).__name__
                        if constraint.posture_state_spec:
                            postures = set(p.name for p in itertools.chain(*[
                                e.posture_types for e in
                                constraint.posture_state_spec.posture_manifest
                            ]))
                            all_postures.update(postures)
                            postures = ', '.join(sorted(postures))
                            if postures:
                                data['has_posture_constraints'] = True
                                constraint_data[
                                    'constraint_postures'] = postures
                            slots = set(
                                str(e) for e in
                                constraint.posture_state_spec.slot_manifest)
                            all_slots.update(slots)
                            slots = ', '.join(sorted(slots))
                            if slots:
                                data['has_slot_constraints'] = True
                                constraint_data['constraint_slots'] = slots
                        constraint_data['constraint_info'] = str(constraint)
                        constraint_list.append(constraint_data)
            except Exception as exc:
                constraint_data = {}
                constraint_data['participant_type'] = participant_type.name
                constraint_data['constraint_type'] = 'ERROR'
                constraint_data['constraint_info'] = str(exc)
                constraint_list.append(constraint_data)
        data['constraints'] = constraint_list
        data['postures'] = ', '.join(sorted(all_postures))
        data['slots'] = ', '.join(sorted(all_slots))
        callback_list = []
        if affordance._simoleon_delta_callbacks:
            for callback in affordance._simoleon_delta_callbacks:
                callback_data = {}
                callback_data['callback_type'] = 'Simoleon'
                callback_data['callback_value'] = callable_repr(callback)
                callback_list.append(callback_data)
        if affordance._sim_can_violate_privacy_callbacks:
            for callback in affordance._sim_can_violate_privacy_callbacks:
                callback_data = {}
                callback_data['callback_type'] = 'Privacy'
                callback_data['callback_value'] = callable_repr(callback)
                callback_list.append(callback_data)
        if affordance._additional_conditional_actions:
            for callback in affordance._additional_conditional_actions:
                callback_data = {}
                callback_data['callback_type'] = 'Exit Condition'
                callback_data['callback_value'] = str(callback)
                callback_list.append(callback_data)
        if affordance._additional_tests:
            for callback in affordance._additional_tests:
                callback_data = {}
                callback_data['callback_type'] = 'Test'
                callback_data['callback_value'] = str(callback)
                callback_list.append(callback_data)
        data['callbacks'] = callback_list
        data['has_callbacks'] = ', '.join(
            sorted(set(e['callback_type'] for e in callback_list))) or ''
        interaction_tuning_data.append(data)
    return interaction_tuning_data
コード例 #8
0
def generate_interaction_tuning_data(*args, zone_id:int=None, **kwargs):
    interaction_tuning_data = []
    for affordance in services.get_instance_manager(sims4.resources.Types.INTERACTION).types.values():
        if not affordance.is_super:
            pass
        data = {}
        data['name'] = affordance.__name__
        canonical_animation = affordance.canonical_animation
        if canonical_animation is not None:
            data['canonical_animation'] = str(canonical_animation).replace('TunableAnimationReferenceWrapper.', '')
        else:
            data['canonical_animation'] = None
        constraint_list = []
        all_postures = set()
        all_slots = set()
        for participant_type in _PARTICIPANT_TYPES_THAT_GET_CONSTRAINTS:
            try:
                for constraints in affordance.constraint_gen(GLOBAL_STUB_ACTOR, GLOBAL_STUB_TARGET, participant_type):
                    for constraint in constraints:
                        constraint_data = {}
                        constraint_data['participant_type'] = participant_type.name
                        constraint_data['constraint_type'] = type(constraint).__name__
                        if constraint.posture_state_spec:
                            postures = set(p.name for p in itertools.chain(*[e.posture_types for e in constraint.posture_state_spec.posture_manifest]))
                            all_postures.update(postures)
                            postures = ', '.join(sorted(postures))
                            if postures:
                                data['has_posture_constraints'] = True
                                constraint_data['constraint_postures'] = postures
                            slots = set(str(e) for e in constraint.posture_state_spec.slot_manifest)
                            all_slots.update(slots)
                            slots = ', '.join(sorted(slots))
                            if slots:
                                data['has_slot_constraints'] = True
                                constraint_data['constraint_slots'] = slots
                        constraint_data['constraint_info'] = str(constraint)
                        constraint_list.append(constraint_data)
            except Exception as exc:
                constraint_data = {}
                constraint_data['participant_type'] = participant_type.name
                constraint_data['constraint_type'] = 'ERROR'
                constraint_data['constraint_info'] = str(exc)
                constraint_list.append(constraint_data)
        data['constraints'] = constraint_list
        data['postures'] = ', '.join(sorted(all_postures))
        data['slots'] = ', '.join(sorted(all_slots))
        callback_list = []
        if affordance._simoleon_delta_callbacks:
            for callback in affordance._simoleon_delta_callbacks:
                callback_data = {}
                callback_data['callback_type'] = 'Simoleon'
                callback_data['callback_value'] = callable_repr(callback)
                callback_list.append(callback_data)
        if affordance._sim_can_violate_privacy_callbacks:
            for callback in affordance._sim_can_violate_privacy_callbacks:
                callback_data = {}
                callback_data['callback_type'] = 'Privacy'
                callback_data['callback_value'] = callable_repr(callback)
                callback_list.append(callback_data)
        if affordance._additional_conditional_actions:
            for callback in affordance._additional_conditional_actions:
                callback_data = {}
                callback_data['callback_type'] = 'Exit Condition'
                callback_data['callback_value'] = str(callback)
                callback_list.append(callback_data)
        if affordance._additional_tests:
            for callback in affordance._additional_tests:
                callback_data = {}
                callback_data['callback_type'] = 'Test'
                callback_data['callback_value'] = str(callback)
                callback_list.append(callback_data)
        data['callbacks'] = callback_list
        data['has_callbacks'] = ', '.join(sorted(set(e['callback_type'] for e in callback_list))) or ''
        interaction_tuning_data.append(data)
    return interaction_tuning_data