Browse Source

Modify profiler dir to fit the new RunPackage

tags/v1.1.0
gzhcv 5 years ago
parent
commit
5466b3e675
2 changed files with 17 additions and 3 deletions
  1. +1
    -1
      mindinsight/datavisual/data_transform/summary_watcher.py
  2. +16
    -2
      mindinsight/profiler/common/validator/validate_path.py

+ 1
- 1
mindinsight/datavisual/data_transform/summary_watcher.py View File

@@ -35,7 +35,7 @@ class SummaryWatcher:
SUMMARY_FILENAME_REGEX = r'summary\.(?P<timestamp>\d+)'
PB_FILENAME_REGEX = r'\.pb$'
PROFILER_DIRECTORY_REGEX = r'^profiler$'
PROFILER_DIRECTORY_REGEX = r'^profiler'
MAX_SUMMARY_DIR_COUNT = 999
# scan at most 20000 files/directories (approximately 1 seconds)


+ 16
- 2
mindinsight/profiler/common/validator/validate_path.py View File

@@ -14,13 +14,14 @@
# ============================================================================
"""Validate the input path."""
import os
import re
from typing import Union, List
from urllib.parse import unquote

from marshmallow import ValidationError

from mindinsight.profiler.common.exceptions.exceptions import \
ProfilerParamValueErrorException
ProfilerParamValueErrorException, ProfilerDirNotFoundException
from mindinsight.profiler.common.log import logger as log


@@ -136,13 +137,26 @@ def validate_and_normalize_profiler_path(summary_dir, summary_base_dir):
Returns:
str, normalized path of profiler directory.
"""
profiler_directory_pattern = r'^profiler.*'
if not summary_dir:
raise ProfilerParamValueErrorException('The file dir does not exist.')
try:
unquote_path = unquote(summary_dir, errors='strict')
except UnicodeDecodeError:
raise ProfilerParamValueErrorException('Unquote error with strict mode')
profiler_dir = os.path.join(summary_base_dir, unquote_path, 'profiler')
profiler_base_dir = os.path.join(summary_base_dir, unquote_path)
try:
profiler_name_list = []
for dir_name in os.listdir(profiler_base_dir):
search_res = re.search(profiler_directory_pattern, dir_name)
if search_res:
profiler_name_list.append(search_res[0])
profiler_name_list.sort()
profiler_name_newest = profiler_name_list[-1]
profiler_dir = os.path.join(summary_base_dir, unquote_path, profiler_name_newest)
except ValidationError:
log.error('no valid profiler dir under <%s>', profiler_base_dir)
raise ProfilerDirNotFoundException('Profiler dir not found.')
try:
profiler_dir = validate_and_normalize_path(profiler_dir, 'profiler')
except ValidationError:


Loading…
Cancel
Save