Ejemplo n.º 1
0
 def check_int(param_name, value, min_num, max_num):
     """Check if the value is positive integer."""
     if isinstance(value, int) and min_num <= value <= max_num:
         return
     log.error("Invalid param `%s`. The integer should be in [%d, %d].",
               param_name, min_num, max_num)
     raise DebuggerParamTypeError(f"Invalid param `{param_name}`.")
Ejemplo n.º 2
0
    def search_watchpoint_hits(self, group_condition):
        """
        Retrieve watchpoint hit.

        Args:
            group_condition (dict): Filter condition.

                - limit (int): The limit of each page.
                - offset (int): The offset of current page.
                - node_name (str): The retrieved node name.
                - graph_name (str): The retrieved graph name.

        Returns:
            dict, watch point list or relative graph.
        """
        if not isinstance(group_condition, dict):
            log.error(
                "Group condition for watchpoint-hits request should be a dict")
            raise DebuggerParamTypeError(
                "Group condition for watchpoint-hits request should be a dict")

        metadata_stream = self.cache_store.get_stream_handler(Streams.METADATA)
        if metadata_stream.state == ServerStatus.PENDING.value:
            log.info("The backend is in pending status.")
            return metadata_stream.get()

        reply = self.cache_store.get_stream_handler(
            Streams.WATCHPOINT_HIT).group_by(group_condition)
        reply['outdated'] = self.cache_store.get_stream_handler(
            Streams.WATCHPOINT).is_recheckable()
        return reply
Ejemplo n.º 3
0
    def _retrieve_all(self, filter_condition=None):
        """Retrieve metadata, root graph and watchpoint list."""
        if filter_condition:
            log.error("No filter condition required for retrieve all request.")
            raise DebuggerParamTypeError("filter_condition should be empty.")
        self.cache_store.clean_data()
        log.info("Clean data queue cache when retrieve all request.")
        result = {}
        for stream in [Streams.METADATA, Streams.GRAPH, Streams.DEVICE]:
            sub_res = self.cache_store.get_stream_handler(stream).get()
            result.update(sub_res)

        devices = result['devices']
        if not devices:
            graph = result['graph']
            metadata = result['metadata']
            device = {
                'rank_id': 0,
                'server_ip': metadata.get('ip', 'localhost'),
                'device_id': metadata.get('device_name', ''),
                'graph_names': graph.get('graph_names', [])
            }
            devices.append(device)
        sub_res = self._hide_parameters_for_ui()
        result.update(sub_res)

        return result
Ejemplo n.º 4
0
    def retrieve(self, mode, filter_condition=None):
        """
        Retrieve data according to mode and params.

        Args:
            mode (str): The type of info message.
            filter_condition (dict): The filter condition.

        Returns:
            dict, the retrieved data.
        """
        log.info(
            "receive retrieve request for mode:%s\n, filter_condition: %s",
            mode, filter_condition)
        # validate watchpoint_id

        mode_mapping = {
            'all': self._retrieve_all,
            'node': self._retrieve_node,
            'watchpoint': self._retrieve_watchpoint,
            'watchpoint_hit': self._retrieve_watchpoint_hit
        }
        # validate param <mode>
        if mode not in mode_mapping.keys():
            log.error(
                "Invalid param <mode>. <mode> should be in ['all', 'node', 'watchpoint', "
                "'watchpoint_hit', 'tensor'], but got %s.", mode_mapping)
            raise DebuggerParamTypeError("Invalid mode.")
        filter_condition = {} if filter_condition is None else filter_condition
        reply = mode_mapping[mode](filter_condition)

        return reply
Ejemplo n.º 5
0
 def validate_watchpoint_id(self, watch_point_id):
     """Validate watchpoint id."""
     if not isinstance(watch_point_id, int):
         log.error(
             "Invalid watchpoint id %s. The watch point id should be int.",
             watch_point_id)
         raise DebuggerParamTypeError("Watchpoint id should be int type.")
     if watch_point_id and watch_point_id not in self._watchpoints:
         log.error("Invalid watchpoint id: %d.", watch_point_id)
         raise DebuggerParamValueError(
             "Invalid watchpoint id: {}".format(watch_point_id))
Ejemplo n.º 6
0
def validate_watch_condition(watch_condition):
    """Validate watch condition."""
    if not isinstance(watch_condition, dict):
        log.error("<watch_condition> should be dict. %s received.",
                  watch_condition)
        raise DebuggerParamTypeError("<watch_condition> should be dict.")
    # validate condition
    condition = watch_condition.get('condition')
    if condition not in WATCHPOINT_CONDITION_MAPPING.keys():
        log.error("Invalid watch condition. Acceptable values are <%s>.",
                  str(WATCHPOINT_CONDITION_MAPPING.keys()))
        raise DebuggerParamValueError("Invalid watch condition value.")
    # validate param
    validate_watch_condition_params(watch_condition)
Ejemplo n.º 7
0
    def _retrieve_all(self, filter_condition=None):
        """Retrieve metadata, root graph and watchpoint list."""
        if filter_condition:
            log.error("No filter condition required for retrieve all request.")
            raise DebuggerParamTypeError("filter_condition should be empty.")
        result = {}
        self._watch_point_id = 0
        self.cache_store.clean_data()
        log.info("Clean data queue cache when retrieve all request.")
        for stream in [Streams.METADATA, Streams.GRAPH, Streams.WATCHPOINT]:
            sub_res = self.cache_store.get_stream_handler(stream).get()
            result.update(sub_res)

        return result
Ejemplo n.º 8
0
def validate_watch_condition(condition_mgr, watch_condition):
    """Validate watch condition."""
    if not isinstance(watch_condition, dict):
        log.error("<watch_condition> should be dict. %s received.",
                  watch_condition)
        raise DebuggerParamTypeError("<watch_condition> should be dict.")
    # validate condition_id
    condition_id = watch_condition.get('id')
    if condition_id not in condition_mgr.conditions.keys():
        log.error(
            "Invalid watch condition. Acceptable values are <%s>. %s received.",
            str(condition_mgr.conditions.keys()), condition_id)
        raise DebuggerParamValueError("Invalid watch condition value.")
    # validate param
    validate_watch_condition_params(condition_mgr, watch_condition)
Ejemplo n.º 9
0
def validate_stack_pattern(stack_pattern):
    """Check stack pattern."""
    if stack_pattern:
        if not isinstance(stack_pattern, str):
            log.error(
                "Invalid stack pattern. String type is required, but got %s.",
                type(stack_pattern))
            raise DebuggerParamTypeError("stack_pattern is not string type.")
        pattern_limit = 255
        if len(stack_pattern) > pattern_limit:
            log.error(
                "The length of stack_pattern is %s, which should no greater than %s.",
                len(stack_pattern), pattern_limit)
            raise DebuggerParamValueError(
                "stack_pattern is over length limit.")