Example #1
0
 def test_validate_condition_normal(self):
     """Test the validate condition of normal input."""
     op_type_list = [
         'aicpu_type', 'aicpu_detail', 'aicore_type', 'aicore_detail',
         'gpu_op_type', 'gpu_op_info', 'gpu_cuda_activity'
     ]
     sort_name_list = [
         'op_type', 'serial_number', 'op_type', 'op_name', 'op_type',
         'op_side', 'name'
     ]
     for idx, op_type in enumerate(op_type_list):
         condition = {
             'device_id': '0',
             'op_type': op_type,
             'filter_condition': {
                 'op_id': 0
             },
             'group_condition': {
                 'limit': 1,
                 'offset': 1
             },
             'sort_condition': {
                 'name': sort_name_list[idx],
                 'type': 'ascending'
             }
         }
         validate_condition(condition)
Example #2
0
 def test_validate_condition_param_type_error_exception(self):
     """Test the exception of parameter type error."""
     condition = "not a dict"
     exception_message = 'Param type error. Invalid search_condition type, it should be dict.'
     with pytest.raises(ProfilerParamTypeErrorException) as exc_info:
         validate_condition(condition)
     assert exc_info.value.error_code == '50546082'
     assert exc_info.value.message == exception_message
Example #3
0
 def test_validate_condition_op_type_exception(self):
     """Test the exception of profiler operation type."""
     condition_list = [{'op_type': "xxx"}, {}]
     exception_message = "The op_type in search_condition error, The op_type must in " \
                         "['aicpu_type','aicpu_detail', 'aicore_type', 'aicore_detail', "\
                         "'gpu_op_type', 'gpu_op_info', 'gpu_cuda_activity', 'cpu_op_type', 'cpu_op_info']"
     for condition in condition_list:
         with pytest.raises(ProfilerOpTypeException) as exc_info:
             validate_condition(condition)
         assert exc_info.value.error_code == '50546183'
         assert exc_info.value.message == exception_message
Example #4
0
 def test_validate_group_condition_exception(self):
     """test the group condition exception."""
     condition_list = [
         {
             'op_type': 'aicpu_type',
             'group_condition': 0
         },
         {
             'op_type': 'aicpu_type',
             'group_condition': {
                 'limit': True
             }
         },
         {
             'op_type': 'aicpu_type',
             'group_condition': {
                 'limit': 0
             }
         },
         {
             'op_type': 'aicpu_type',
             'group_condition': {
                 'offset': True
             }
         },
         {
             'op_type': 'aicpu_type',
             'group_condition': {
                 'offset': -1
             }
         },
         {
             'op_type': 'aicpu_type',
             'group_condition': {
                 'offset': 10000000
             }
         },
     ]
     exception_message_list = [
         "The group condition must be dict.", "The limit must be int.",
         "The limit must in [1, 100].", "The offset must be int.",
         "The offset must ge 0.", "The offset must le 1000000."
     ]
     exception_message_list = [
         'The group_condition in search_condition error, ' + message
         for message in exception_message_list
     ]
     for idx, condition in enumerate(condition_list):
         with pytest.raises(ProfilerGroupConditionException) as exc_info:
             validate_condition(condition)
         assert exc_info.value.error_code == '50546184'
         assert exc_info.value.message == exception_message_list[idx]
Example #5
0
def get_profile_op_info():
    """
    Get operation profiling info.

    Returns:
        str, the operation profiling information.

    Raises:
        ParamValueError: If the search condition contains some errors.

    Examples:
        >>> POST http://xxxx/v1/mindinsight/profile/ops/search
    """
    profiler_dir = get_profiler_dir(request)
    train_id = get_train_id(request)
    if not profiler_dir or not train_id:
        raise ParamValueError("No profiler_dir or train_id.")

    search_condition = request.stream.read()
    try:
        search_condition = json.loads(
            search_condition if search_condition else "{}")
    except (json.JSONDecodeError, ValueError):
        raise ParamValueError("Json data parse failed.")
    validate_condition(search_condition)

    device_id = search_condition.get("device_id", "0")
    to_int(device_id, 'device_id')
    profiler_dir_abs = os.path.join(settings.SUMMARY_BASE_DIR, train_id,
                                    profiler_dir)
    try:
        profiler_dir_abs = validate_and_normalize_path(profiler_dir_abs,
                                                       "profiler")
    except ValidationError:
        raise ParamValueError("Invalid profiler dir")

    check_train_job_and_profiler_dir(profiler_dir_abs)

    op_type = search_condition.get("op_type")

    analyser = AnalyserFactory.instance().get_analyser(op_type,
                                                       profiler_dir_abs,
                                                       device_id)

    op_info = analyser.query(search_condition)
    return jsonify(op_info)
Example #6
0
    def test_validate_op_type_exception(self):
        """Test the operate type exception."""
        condition = "not a dict"
        exception_message = 'Param type error. Invalid search_condition type, it should be dict.'
        with pytest.raises(ProfilerParamTypeErrorException) as exc_info:
            validate_condition(condition)
        assert exc_info.value.error_code == '50546082'
        assert exc_info.value.message == exception_message

        condition_list = [{'op_type': "xxx"}, {}]
        exception_message = "The op_type in search_condition error, The op_type must in " \
                            "['aicpu_type','aicpu_detail', 'aicore_type', 'aicore_detail', "\
                            "'gpu_op_type', 'gpu_op_info', 'gpu_cuda_activity']"
        for condition in condition_list:
            with pytest.raises(ProfilerOpTypeException) as exc_info:
                validate_condition(condition)
            assert exc_info.value.error_code == '50546183'
            assert exc_info.value.message == exception_message