Browse Source

fix security and non-security issues

fixed security and non-security issues of Profiler Python code and
tags/v1.0.0
gzhcv 5 years ago
parent
commit
544463d970
6 changed files with 39 additions and 1 deletions
  1. +16
    -0
      mindinsight/profiler/analyser/analyser.py
  2. +3
    -0
      mindinsight/profiler/analyser/gpu_analyser.py
  3. +7
    -0
      mindinsight/profiler/analyser/integrator.py
  4. +5
    -1
      mindinsight/profiler/analyser/minddata_analyser.py
  5. +3
    -0
      mindinsight/profiler/analyser/minddata_pipeline_analyser.py
  6. +5
    -0
      mindinsight/profiler/analyser/step_trace_analyser.py

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

@@ -19,6 +19,7 @@ import os

from mindinsight.profiler.analyser.base_analyser import BaseAnalyser
from mindinsight.profiler.common.log import logger
from mindinsight.profiler.common.validator.validate_path import validate_and_normalize_path


class AicoreTypeAnalyser(BaseAnalyser):
@@ -42,6 +43,11 @@ class AicoreTypeAnalyser(BaseAnalyser):
self._profiling_dir,
self._file_name_aicore_type_time.format(self._device_id)
)

op_type_file_path = validate_and_normalize_path(
op_type_file_path, raise_key='Invalid aicore_type file path.'
)

if not os.path.isfile(op_type_file_path):
logger.warning('The file <%s> does not exist.', op_type_file_path)
return
@@ -161,6 +167,13 @@ class AicoreDetailAnalyser(BaseAnalyser):
self._profiling_dir,
self._file_name_framework_info.format(self._device_id)
)
op_detail_file_path = validate_and_normalize_path(
op_detail_file_path, raise_key='Invalid aicore_detail file path.'
)

framework_file_path = validate_and_normalize_path(
framework_file_path, raise_key='Invalid framework file path.'
)
if not os.path.isfile(op_detail_file_path):
logger.warning('The file <%s> does not exist.', op_detail_file_path)
return
@@ -283,6 +296,9 @@ class AicpuAnalyser(BaseAnalyser):
self._profiling_dir,
self._file_name_aicpu_time.format(self._device_id)
)
aicpu_file_path = validate_and_normalize_path(
aicpu_file_path, raise_key='Invalid aicpu file path.'
)
if not os.path.isfile(aicpu_file_path):
logger.warning('The file <%s> does not exist.', aicpu_file_path)
return


+ 3
- 0
mindinsight/profiler/analyser/gpu_analyser.py View File

@@ -18,6 +18,7 @@ import os
from mindinsight.profiler.analyser.base_analyser import BaseAnalyser
from mindinsight.profiler.common.log import logger
from mindinsight.profiler.common.validator.validate_path import validate_and_normalize_path
class GpuAnalyser(BaseAnalyser):
@@ -30,6 +31,8 @@ class GpuAnalyser(BaseAnalyser):
self._profiling_dir,
self._csv_file_to_analyse.format(self._device_id)
)
op_type_file_path = validate_and_normalize_path(
op_type_file_path, raise_key="Invalid op_type_file_path")
if not os.path.isfile(op_type_file_path):
logger.warning('The file <%s> does not exist.', op_type_file_path)
return


+ 7
- 0
mindinsight/profiler/analyser/integrator.py View File

@@ -16,6 +16,7 @@
import csv
import os
from decimal import Decimal
from mindinsight.profiler.common.validator.validate_path import validate_and_normalize_path


class Integrator:
@@ -54,6 +55,8 @@ class Integrator:
self._profiling_dir,
self._file_name_framework.format(self._device_id)
)
framework_file = validate_and_normalize_path(
framework_file, raise_key="Invaild framework file path.")
if not os.path.isfile(framework_file):
return

@@ -93,6 +96,8 @@ class Integrator:
self._profiling_dir,
self._file_name_aicore_detail_time.format(self._device_id)
)
aicore_detail_file = validate_and_normalize_path(
aicore_detail_file, raise_key="Invaild aicore_detail file path.")
if not os.path.isfile(aicore_detail_file):
return

@@ -132,6 +137,8 @@ class Integrator:
self._profiling_dir,
self._file_name_aicpu_time.format(self._device_id)
)
aicpu_file = validate_and_normalize_path(
aicpu_file, raise_key="Invaild aicpu file path.")
if not os.path.isfile(aicpu_file):
return



+ 5
- 1
mindinsight/profiler/analyser/minddata_analyser.py View File

@@ -16,7 +16,7 @@
import os
from mindinsight.profiler.analyser.base_analyser import BaseAnalyser
from mindinsight.profiler.common.validator.validate_path import validate_and_normalize_path
class MinddataAnalyser(BaseAnalyser):
"""The Minddata profiling analyser."""
@@ -49,6 +49,8 @@ class MinddataAnalyser(BaseAnalyser):
file_path = MinddataAnalyser.find_target_file(self._profiling_dir, file_name)
if file_path:
file_path = validate_and_normalize_path(
file_path, raise_key="Invaild minddata_aicpu file path.")
with open(file_path) as data_file:
for line in data_file.readlines():
node_info = line.split()
@@ -107,6 +109,8 @@ class MinddataAnalyser(BaseAnalyser):
file_path = self.get_device_queue_file_path()
if file_path:
file_path = validate_and_normalize_path(
file_path, raise_key="Invaild device_queue file path.")
with open(file_path) as data_file:
for line in data_file.readlines():
op_info = line.split()


+ 3
- 0
mindinsight/profiler/analyser/minddata_pipeline_analyser.py View File

@@ -22,6 +22,7 @@ from mindinsight.profiler.analyser.base_analyser import BaseAnalyser
from mindinsight.profiler.common.exceptions.exceptions import \
ProfilerPipelineOpNotExistException
from mindinsight.profiler.common.log import logger
from mindinsight.profiler.common.validator.validate_path import validate_and_normalize_path


class MinddataPipelineAnalyser(BaseAnalyser):
@@ -115,6 +116,8 @@ class MinddataPipelineAnalyser(BaseAnalyser):
self._profiling_dir,
self._file_name_pipeline.format(self._device_id)
)
pipeline_file_path = validate_and_normalize_path(
pipeline_file_path, raise_key="Invaild pipeline file path.")
if not os.path.isfile(pipeline_file_path):
logger.warning('The file <%s> does not exist.', pipeline_file_path)
return


+ 5
- 0
mindinsight/profiler/analyser/step_trace_analyser.py View File

@@ -24,6 +24,7 @@ from mindinsight.profiler.common.exceptions.exceptions import ProfilerParamValue
from mindinsight.profiler.common.log import logger as log
from mindinsight.profiler.common.util import query_latest_trace_time_file, get_field_value, \
get_summary_for_step_trace, to_millisecond
from mindinsight.profiler.common.validator.validate_path import validate_and_normalize_path


class StepTraceAnalyser(BaseAnalyser):
@@ -93,6 +94,8 @@ class StepTraceAnalyser(BaseAnalyser):
if not file_path:
log.error("Failed to find parsed trace time file.")
raise ProfilerFileNotFoundException('parsed step trace time file')
file_path = validate_and_normalize_path(
file_path, raise_key="Invaild latest_trace_trace_time file path.")
with open(file_path, 'r') as handle:
csv_reader = csv.reader(handle)
self.__column__ = next(csv_reader)
@@ -104,6 +107,8 @@ class StepTraceAnalyser(BaseAnalyser):
def _load_point_info(self):
"""Load point info."""
file_path = os.path.join(self._profiling_dir, 'step_trace_point_info.json')
file_path = validate_and_normalize_path(
file_path, raise_key="Invaild step_trace_point_info file path.")
if os.path.isfile(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
try:


Loading…
Cancel
Save