Browse Source

profiler: fixed json decode error in timeline

tags/v0.6.0-beta
zhangyunshu 5 years ago
parent
commit
c49d233f0c
1 changed files with 6 additions and 3 deletions
  1. +6
    -3
      mindinsight/profiler/analyser/timeline_analyser.py

+ 6
- 3
mindinsight/profiler/analyser/timeline_analyser.py View File

@@ -75,7 +75,7 @@ class TimelineAnalyser(BaseAnalyser):
try: try:
with open(file_path, 'r') as f_obj: with open(file_path, 'r') as f_obj:
timeline = json.load(f_obj) timeline = json.load(f_obj)
except (IOError, OSError) as err:
except (IOError, OSError, json.JSONDecodeError) as err:
logger.error('Error occurred when read timeline display file: %s', err) logger.error('Error occurred when read timeline display file: %s', err)
raise ProfilerIOException raise ProfilerIOException
else: else:
@@ -104,7 +104,7 @@ class TimelineAnalyser(BaseAnalyser):
try: try:
with open(file_path, 'r') as f_obj: with open(file_path, 'r') as f_obj:
timeline_summary = json.load(f_obj) timeline_summary = json.load(f_obj)
except (IOError, OSError) as err:
except (IOError, OSError, json.JSONDecodeError) as err:
logger.error('Error occurred when read timeline summary file: %s', err) logger.error('Error occurred when read timeline summary file: %s', err)
raise ProfilerIOException raise ProfilerIOException


@@ -128,14 +128,17 @@ class TimelineAnalyser(BaseAnalyser):
display_file_path, raise_key='Invalid timeline display json path.' display_file_path, raise_key='Invalid timeline display json path.'
) )


length = len(self._timeline_meta)
try: try:
with open(display_file_path, 'w') as json_file: with open(display_file_path, 'w') as json_file:
json_file.write('[') json_file.write('[')
for item in self._timeline_meta:
for index, item in enumerate(self._timeline_meta):
json.dump(item, json_file) json.dump(item, json_file)
file_size = os.path.getsize(display_file_path) file_size = os.path.getsize(display_file_path)
if file_size > SIZE_LIMIT: if file_size > SIZE_LIMIT:
break break
if index == length - 1:
break
json_file.write(',') json_file.write(',')
json_file.write(']') json_file.write(']')
except (IOError, OSError) as err: except (IOError, OSError) as err:


Loading…
Cancel
Save