diff --git a/mindinsight/backend/profiler/profile_api.py b/mindinsight/backend/profiler/profile_api.py index 7bfec3d1..6c6dc2d6 100644 --- a/mindinsight/backend/profiler/profile_api.py +++ b/mindinsight/backend/profiler/profile_api.py @@ -39,6 +39,7 @@ from mindinsight.profiler.common.validator.validate_path import \ validate_and_normalize_path from mindinsight.profiler.common.validator.validate_path import validate_and_normalize_profiler_path from mindinsight.profiler.proposer.compose_proposer import ComposeProposal +from mindinsight.profiler.common.log import logger from mindinsight.utils.exceptions import ParamValueError from mindinsight.backend.application import CustomResponse @@ -433,10 +434,14 @@ def get_timeline_summary(): raise ProfilerDirNotFoundException(msg=summary_dir) device_id = request.args.get("device_id", default='0') _ = to_int(device_id, 'device_id') + device_type = request.args.get("device_type", default='ascend') + if device_type not in ['gpu', 'ascend']: + logger.info("Invalid device_type, device_type should be gpu or ascend.") + raise ParamValueError("Invalid device_type.") analyser = AnalyserFactory.instance().get_analyser( 'timeline', profiler_dir, device_id) - summary = analyser.get_timeline_summary() + summary = analyser.get_timeline_summary(device_type) return summary @@ -458,10 +463,14 @@ def get_timeline_detail(): raise ProfilerDirNotFoundException(msg=summary_dir) device_id = request.args.get("device_id", default='0') _ = to_int(device_id, 'device_id') + device_type = request.args.get("device_type", default='ascend') + if device_type not in ['gpu', 'ascend']: + logger.info("Invalid device_type, device_type should be gpu or ascend.") + raise ParamValueError("Invalid device_type.") analyser = AnalyserFactory.instance().get_analyser( 'timeline', profiler_dir, device_id) - timeline = analyser.get_display_timeline() + timeline = analyser.get_display_timeline(device_type) return jsonify(timeline) diff --git a/mindinsight/profiler/analyser/timeline_analyser.py b/mindinsight/profiler/analyser/timeline_analyser.py index 6124b092..5af13797 100644 --- a/mindinsight/profiler/analyser/timeline_analyser.py +++ b/mindinsight/profiler/analyser/timeline_analyser.py @@ -21,7 +21,7 @@ from mindinsight.profiler.common.exceptions.exceptions import ProfilerFileNotFou ProfilerIOException from mindinsight.profiler.common.log import logger from mindinsight.profiler.common.validator.validate_path import validate_and_normalize_path - +from mindinsight.utils.exceptions import ParamValueError SIZE_LIMIT = 20 * 1024 * 1024 # 20MB @@ -75,8 +75,10 @@ class TimelineAnalyser(BaseAnalyser): __col_names__ = ['op_name', 'stream_id', 'start_time', 'duration'] _output_timeline_data_file_path = 'output_timeline_data_{}.txt' _min_cycle_counter_file_path = 'min_cycle_counter_{}.txt' - _display_filename = 'timeline_display_{}.json' - _timeline_summary_filename = 'timeline_summary_{}.json' + _ascend_display_filename = 'ascend_timeline_display_{}.json' + _gpu_display_filename = 'gpu_timeline_display_{}.json' + _ascend_timeline_summary_filename = 'ascend_timeline_summary_{}.json' + _gpu_timeline_summary_filename = 'gpu_timeline_summary_{}.json' _timeline_meta = [] _timeline_summary = { 'total_time': 0, @@ -96,14 +98,20 @@ class TimelineAnalyser(BaseAnalyser): filter_condition (dict): The filter condition. """ - def get_display_timeline(self): + def get_display_timeline(self, device_type): """ Get timeline data for UI display. Returns: json, the content of timeline data. """ - display_filename = self._display_filename.format(self._device_id) + if device_type == "ascend": + display_filename = self._ascend_display_filename.format(self._device_id) + elif device_type == "gpu": + display_filename = self._gpu_display_filename.format(self._device_id) + else: + logger.info('device type should be ascend or gpu. Please check the device type.') + raise ParamValueError("Invalid device_type.") file_path = os.path.join(self._profiling_dir, display_filename) file_path = validate_and_normalize_path( file_path, raise_key='Invalid timeline json path.' @@ -122,14 +130,20 @@ class TimelineAnalyser(BaseAnalyser): return timeline - def get_timeline_summary(self): + def get_timeline_summary(self, device_type): """ Get timeline summary information for UI display. Returns: json, the content of timeline summary information. """ - summary_filename = self._timeline_summary_filename.format(self._device_id) + if device_type == "ascend": + summary_filename = self._ascend_timeline_summary_filename.format(self._device_id) + elif device_type == "gpu": + summary_filename = self._gpu_timeline_summary_filename.format(self._device_id) + else: + logger.info('device type should be ascend or gpu. Please check the device type.') + raise ParamValueError("Invalid device_type.") file_path = os.path.join(self._profiling_dir, summary_filename) file_path = validate_and_normalize_path( file_path, raise_key='Invalid timeline summary path.'