Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MindSpore
mindinsight
提交
93060281
M
mindinsight
项目概览
MindSpore
/
mindinsight
通知
8
Star
3
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindinsight
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
93060281
编写于
6月 22, 2020
作者:
Z
zhangyunshu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimized the mechanism of adding framework info to timeline
上级
7f2d7f02
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
23 addition
and
51 deletion
+23
-51
mindinsight/profiler/analyser/timeline_analyser.py
mindinsight/profiler/analyser/timeline_analyser.py
+23
-51
未找到文件。
mindinsight/profiler/analyser/timeline_analyser.py
浏览文件 @
93060281
...
...
@@ -34,7 +34,6 @@ 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'
_timeline_filename
=
'timeline_detail_{}.json'
_display_filename
=
'timeline_display_{}.json'
_timeline_summary_filename
=
'timeline_summary_{}.json'
_timeline_meta
=
[]
...
...
@@ -64,15 +63,9 @@ class TimelineAnalyser(BaseAnalyser):
json, the content of timeline data.
"""
# Search timeline json file under profiling dir.
timeline_filename
=
self
.
_timeline_filename
.
format
(
self
.
_device_id
)
display_filename
=
self
.
_display_filename
.
format
(
self
.
_device_id
)
file_list
=
[
filename
for
filename
in
os
.
listdir
(
self
.
_profiling_dir
)
if
timeline_filename
in
filename
or
display_filename
in
filename
]
# Check if there is a timeline json file for display
file_path
=
os
.
path
.
join
(
self
.
_profiling_dir
,
display_filename
)
if
display_filename
not
in
file_list
:
file_path
=
os
.
path
.
join
(
self
.
_profiling_dir
,
timeline_filename
)
file_path
=
validate_and_normalize_path
(
file_path
,
raise_key
=
'Invalid timeline json path.'
)
...
...
@@ -121,39 +114,9 @@ class TimelineAnalyser(BaseAnalyser):
"""Load data according to the parsed profiling files."""
# Write timeline to file.
logger
.
info
(
'Writing timeline file...'
)
file_size
=
self
.
write_timeline_to_json
()
# If the file size is larger than 20MB, open a new file and
# write the first 20MB content into it.
if
file_size
>
SIZE_LIMIT
:
logger
.
debug
(
'File size is larger than 20MB, will be resized...'
)
# write to json file for display
self
.
write_timeline_to_json_by_limitation
()
self
.
write_timeline_to_json_by_limitation
()
logger
.
info
(
'Finished file writing!'
)
def
write_timeline_to_json
(
self
):
"""Write timeline to json."""
timeline_filename
=
self
.
_timeline_filename
.
format
(
self
.
_device_id
)
timeline_file_path
=
os
.
path
.
join
(
self
.
_profiling_dir
,
timeline_filename
)
timeline_file_path
=
validate_and_normalize_path
(
timeline_file_path
,
raise_key
=
'Invalid timeline json path.'
)
try
:
with
open
(
timeline_file_path
,
'w'
)
as
json_file
:
json
.
dump
(
self
.
_timeline_meta
,
json_file
)
file_size
=
os
.
path
.
getsize
(
timeline_file_path
)
except
(
IOError
,
OSError
)
as
err
:
logger
.
error
(
'Error occurred when write timeline full details: %s'
,
err
)
raise
ProfilerIOException
return
file_size
def
write_timeline_to_json_by_limitation
(
self
):
"""Write timeline to json by limitation."""
display_filename
=
self
.
_display_filename
.
format
(
self
.
_device_id
)
...
...
@@ -161,7 +124,6 @@ class TimelineAnalyser(BaseAnalyser):
self
.
_profiling_dir
,
display_filename
)
display_file_path
=
validate_and_normalize_path
(
display_file_path
,
raise_key
=
'Invalid timeline display json path.'
)
...
...
@@ -224,11 +186,11 @@ class TimelineAnalyser(BaseAnalyser):
return
timeline_list
def
_parse_timeline_data
(
self
,
line_list
):
def
_parse_timeline_data
(
self
,
timeline
):
"""Parse timeline data."""
# factor to convert the time unit from 1ms to 1us for timeline display
factor
=
1000
op_meta
=
TimelineContainer
(
line_list
)
op_meta
=
TimelineContainer
(
timeline
)
timeline_dict
=
{}
timeline_dict
[
'name'
]
=
op_meta
.
op_name
timeline_dict
[
'ph'
]
=
'X'
...
...
@@ -245,9 +207,9 @@ class TimelineAnalyser(BaseAnalyser):
self
.
_timeline_meta
.
append
(
timeline_dict
)
@
staticmethod
def
_update_num_of_streams
(
line_list
,
stream_count_dict
):
def
_update_num_of_streams
(
timeline
,
stream_count_dict
):
"""Update number of streams."""
stream_id
=
line_list
[
1
]
stream_id
=
timeline
[
1
]
if
stream_id
not
in
stream_count_dict
.
keys
():
stream_count_dict
[
stream_id
]
=
1
else
:
...
...
@@ -328,18 +290,28 @@ class TimelineAnalyser(BaseAnalyser):
framework_obj_list (list): The framework metadata.
"""
logger
.
debug
(
'Start adding framework info into timeline...'
)
# Get the framework info that will be written into timeline.
framework_info_dict
=
{}
for
framework_obj
in
framework_obj_list
:
op_name
=
framework_obj
[
0
]
op_type
=
framework_obj
[
1
]
op_full_name
=
framework_obj
[
4
]
op_info
=
framework_obj
[
5
]
for
timeline_obj
in
self
.
_timeline_meta
:
if
op_full_name
==
timeline_obj
.
get
(
'name'
):
timeline_obj
[
'name'
]
=
op_name
timeline_obj
[
'args'
]
=
{
'type'
:
op_type
,
'fullname'
:
op_full_name
}
timeline_obj
[
'args'
].
update
(
op_info
)
framework_info_dict
[
op_full_name
]
=
{
'name'
:
op_name
,
'args'
:
{
'type'
:
op_type
,
'fullname'
:
op_full_name
}
}
framework_info_dict
[
op_full_name
][
'args'
].
update
(
op_info
)
# Insert framework info into timeline.
for
timeline_item
in
self
.
_timeline_meta
:
op_full_name
=
timeline_item
.
get
(
'name'
)
framework_item
=
framework_info_dict
.
get
(
op_full_name
)
if
framework_item
:
timeline_item
[
'name'
]
=
framework_item
.
get
(
'name'
)
timeline_item
[
'args'
]
=
framework_item
.
get
(
'args'
)
logger
.
debug
(
'Finished adding framework info into timeline...'
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录