Browse Source

!608 add gpu timeline restful

Merge pull request !608 from gzhcv/bugfix
tags/v1.0.0
mindspore-ci-bot Gitee 5 years ago
parent
commit
06a404bdf3
2 changed files with 32 additions and 9 deletions
  1. +11
    -2
      mindinsight/backend/profiler/profile_api.py
  2. +21
    -7
      mindinsight/profiler/analyser/timeline_analyser.py

+ 11
- 2
mindinsight/backend/profiler/profile_api.py View File

@@ -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)


+ 21
- 7
mindinsight/profiler/analyser/timeline_analyser.py View File

@@ -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.'


Loading…
Cancel
Save