Browse Source

add function of check whether the op name exists in framework

tags/v0.5.0-beta
chenchao99 5 years ago
parent
commit
6e9fedba5d
5 changed files with 42 additions and 2 deletions
  1. +1
    -0
      mindinsight/profiler/analyser/analyser.py
  2. +4
    -1
      mindinsight/profiler/analyser/base_analyser.py
  3. +2
    -0
      mindinsight/profiler/common/exceptions/error_code.py
  4. +11
    -0
      mindinsight/profiler/common/exceptions/exceptions.py
  5. +24
    -1
      mindinsight/profiler/parser/framework_parser.py

+ 1
- 0
mindinsight/profiler/analyser/analyser.py View File

@@ -93,6 +93,7 @@ class AicoreDetailAnalyser(BaseAnalyser):
self._none_filter_condition_key = [
'is_display_detail', 'is_display_full_op_name'
]
self._none_sort_col_names = ['op_info']

def query_and_sort_by_op_type(self, filter_condition, op_type_order: list):
"""


+ 4
- 1
mindinsight/profiler/analyser/base_analyser.py View File

@@ -20,7 +20,7 @@ from marshmallow import ValidationError

from mindinsight.profiler.common.exceptions.exceptions import \
ProfilerColumnNotExistException, ProfilerPathErrorException, \
ProfilerIOException
ProfilerIOException, ProfilerColumnNotSupportSortException
from mindinsight.profiler.common.log import logger
from mindinsight.profiler.common.validator.validate_path import \
validate_and_normalize_path
@@ -50,6 +50,7 @@ class BaseAnalyser(ABC):
self._display_col_names = None
self._size = 0
self._none_filter_condition_key = []
self._none_sort_col_names = []

try:
self._load()
@@ -150,6 +151,8 @@ class BaseAnalyser(ABC):
index = self.__col_names__.index(sort_name)
except ValueError:
raise ProfilerColumnNotExistException(sort_name)
if self._none_sort_col_names and sort_name in self._none_sort_col_names:
raise ProfilerColumnNotSupportSortException(sort_name)
self._result.sort(key=functools.cmp_to_key(_cmp), reverse=reverse)

def _group(self, group_condition: dict):


+ 2
- 0
mindinsight/profiler/common/exceptions/error_code.py View File

@@ -46,6 +46,7 @@ class ProfilerErrors(ProfilerMgrErrors):
GROUP_CONDITION_ERROR = 4 | _ANALYSER_MASK
SORT_CONDITION_ERROR = 5 | _ANALYSER_MASK
FILTER_CONDITION_ERROR = 6 | _ANALYSER_MASK
COLUMN_NOT_SUPPORT_SORT_ERROR = 7 | _ANALYSER_MASK


@unique
@@ -71,3 +72,4 @@ class ProfilerErrorMsg(Enum):
OP_TYPE_ERROR = 'The op_type in search_condition error, {}'
GROUP_CONDITION_ERROR = 'The group_condition in search_condition error, {}'
SORT_CONDITION_ERROR = 'The sort_condition in search_condition error, {}'
COLUMN_NOT_SUPPORT_SORT_ERROR = 'The column {} does not support to sort.'

+ 11
- 0
mindinsight/profiler/common/exceptions/exceptions.py View File

@@ -181,3 +181,14 @@ class ProfilerGroupConditionException(MindInsightException):
message=ProfilerErrorMsg.GROUP_CONDITION_ERROR.value.format(msg),
http_code=400
)


class ProfilerColumnNotSupportSortException(MindInsightException):
"""The column does not support to sort error in profiler module."""

def __init__(self, msg):
super(ProfilerColumnNotSupportSortException, self).__init__(
error=ProfilerErrors.COLUMN_NOT_SUPPORT_SORT_ERROR,
message=ProfilerErrorMsg.COLUMN_NOT_SUPPORT_SORT_ERROR.value.format(msg),
http_code=400
)

+ 24
- 1
mindinsight/profiler/parser/framework_parser.py View File

@@ -24,7 +24,7 @@ from marshmallow import ValidationError
from mindinsight.profiler.common.exceptions.exceptions import \
ProfilerPathErrorException, ProfilerDirNotFoundException, \
ProfilerFileNotFoundException, ProfilerDeviceIdMismatchException, \
ProfilerRawFileException
ProfilerRawFileException, ProfilerParamValueErrorException
from mindinsight.profiler.common.validator.validate_path import \
validate_and_normalize_path

@@ -223,6 +223,29 @@ class FrameworkParser:
self._parse_graph_files_and_save(self._task_cache)
del self._task_cache

def check_op_name(self, op_name, is_prefix=True):
"""
Check whether the operator name exists.

Args:
op_name (str): The operator name or operator name prefix.
is_prefix (bool): `True` if the op_name is prefix, else `False`.
Default: True.

Returns:
bool, `True` if the operator name does exist in framework file, else
`False`.
"""
if not op_name:
raise ProfilerParamValueErrorException('The op_name should exist.')
for full_op_name in self._task_id_full_op_name_dict.values():
if full_op_name:
if is_prefix and full_op_name.startswith(op_name):
return True
if not is_prefix and op_name == full_op_name:
return True
return False

def _get_raw_profiling_path(self, profiling_id):
"""
Get raw profiling path.


Loading…
Cancel
Save