Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
c0ed75a8
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
c0ed75a8
编写于
6月 07, 2022
作者:
L
liutiexing
提交者:
GitHub
6月 07, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update profiler (#42998)
* Update Profiler * make HostEventRecorder templated
上级
b4a3dab7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
34 addition
and
27 deletion
+34
-27
paddle/fluid/platform/profiler.cc
paddle/fluid/platform/profiler.cc
+17
-13
paddle/fluid/platform/profiler/host_event_recorder.h
paddle/fluid/platform/profiler/host_event_recorder.h
+13
-10
paddle/fluid/platform/profiler/host_tracer.cc
paddle/fluid/platform/profiler/host_tracer.cc
+4
-4
未找到文件。
paddle/fluid/platform/profiler.cc
浏览文件 @
c0ed75a8
...
...
@@ -192,15 +192,15 @@ void RecordEvent::End() {
if
(
LIKELY
(
FLAGS_enable_host_event_recorder_hook
&&
is_enabled_
))
{
uint64_t
end_ns
=
PosixInNsec
();
if
(
LIKELY
(
shallow_copy_name_
!=
nullptr
))
{
HostEventRecorder
::
GetInstance
().
RecordEvent
(
HostEventRecorder
<
CommonEvent
>
::
GetInstance
().
RecordEvent
(
shallow_copy_name_
,
start_ns_
,
end_ns
,
role_
,
type_
);
}
else
if
(
name_
!=
nullptr
)
{
if
(
attr_
==
nullptr
)
{
HostEventRecorder
::
GetInstance
().
RecordEvent
(
*
name_
,
start_ns_
,
end_ns
,
role_
,
type_
);
HostEventRecorder
<
CommonEvent
>::
GetInstance
().
RecordEvent
(
*
name_
,
start_ns_
,
end_ns
,
role_
,
type_
);
}
else
{
HostEventRecorder
::
GetInstance
().
RecordEvent
(
*
name_
,
start_ns_
,
end_ns
,
role_
,
type_
,
*
attr_
);
HostEventRecorder
<
CommonEvent
>::
GetInstance
().
RecordEvent
(
*
name_
,
start_ns_
,
end_ns
,
role_
,
type_
,
*
attr_
);
delete
attr_
;
}
delete
name_
;
...
...
@@ -232,8 +232,8 @@ RecordInstantEvent::RecordInstantEvent(const char *name, TracerEventType type,
return
;
}
auto
start_end_ns
=
PosixInNsec
();
HostEventRecorder
::
GetInstance
().
RecordEvent
(
name
,
start_end_ns
,
start_end_ns
,
EventRole
::
kOrdinary
,
type
);
HostEventRecorder
<
CommonEvent
>::
GetInstance
().
RecordEvent
(
name
,
start_end_ns
,
start_end_ns
,
EventRole
::
kOrdinary
,
type
);
}
void
MemEvenRecorder
::
PushMemRecord
(
const
void
*
ptr
,
const
Place
&
place
,
...
...
@@ -327,7 +327,7 @@ void PopMemEvent(uint64_t start_ns, uint64_t end_ns, size_t bytes,
void
Mark
(
const
std
::
string
&
name
)
{
if
(
FLAGS_enable_host_event_recorder_hook
)
{
HostEventRecorder
::
GetInstance
().
RecordEvent
(
HostEventRecorder
<
CommonEvent
>
::
GetInstance
().
RecordEvent
(
name
,
0
,
0
,
EventRole
::
kOrdinary
,
TracerEventType
::
UserDefined
);
return
;
}
...
...
@@ -522,7 +522,8 @@ void DisableHostEventRecorder() {
std
::
string
PrintHostEvents
()
{
std
::
ostringstream
oss
;
auto
host_evt_sec
=
HostEventRecorder
::
GetInstance
().
GatherEvents
();
auto
host_evt_sec
=
HostEventRecorder
<
CommonEvent
>::
GetInstance
().
GatherEvents
();
for
(
const
auto
&
thr_evt_sec
:
host_evt_sec
.
thr_sections
)
{
oss
<<
thr_evt_sec
.
thread_id
<<
std
::
endl
;
for
(
const
auto
&
evt
:
thr_evt_sec
.
events
)
{
...
...
@@ -534,8 +535,9 @@ std::string PrintHostEvents() {
return
oss
.
str
();
}
static
void
EmulateEventPushAndPop
(
const
HostEventSection
&
host_sec
,
std
::
map
<
uint64_t
,
ThreadEvents
>
*
out
)
{
static
void
EmulateEventPushAndPop
(
const
HostEventSection
<
CommonEvent
>
&
host_sec
,
std
::
map
<
uint64_t
,
ThreadEvents
>
*
out
)
{
for
(
const
auto
&
thr_sec
:
host_sec
.
thr_sections
)
{
uint64_t
tid
=
thr_sec
.
thread_id
;
auto
cur_thr_list
=
std
::
make_shared
<
EventList
<
Event
>>
();
...
...
@@ -582,7 +584,8 @@ static void EmulateEventPushAndPop(const HostEventSection &host_sec,
}
}
static
void
EmulateCPURecordsAdd
(
const
HostEventSection
&
host_sec
)
{
static
void
EmulateCPURecordsAdd
(
const
HostEventSection
<
CommonEvent
>
&
host_sec
)
{
DeviceTracer
*
tracer
=
GetDeviceTracer
();
if
(
tracer
==
nullptr
)
{
return
;
...
...
@@ -610,7 +613,8 @@ static std::map<uint64_t, ThreadEvents> DockHostEventRecorderHostPart() {
if
(
FLAGS_enable_host_event_recorder_hook
==
false
)
{
return
thr_events
;
}
auto
host_evt_sec
=
HostEventRecorder
::
GetInstance
().
GatherEvents
();
auto
host_evt_sec
=
HostEventRecorder
<
CommonEvent
>::
GetInstance
().
GatherEvents
();
EmulateEventPushAndPop
(
host_evt_sec
,
&
thr_events
);
EmulateCPURecordsAdd
(
host_evt_sec
);
return
thr_events
;
...
...
paddle/fluid/platform/profiler/host_event_recorder.h
浏览文件 @
c0ed75a8
...
...
@@ -21,7 +21,6 @@
#include "paddle/fluid/framework/new_executor/workqueue/thread_data_registry.h"
#include "paddle/fluid/platform/macros.h"
#include "paddle/fluid/platform/os_info.h"
#include "paddle/fluid/platform/profiler/common_event.h"
namespace
paddle
{
namespace
platform
{
...
...
@@ -182,12 +181,14 @@ char *EventContainer<EventType>::GetStringStorage(size_t sz) {
return
storage
;
}
template
<
typename
EventType
>
struct
ThreadEventSection
{
std
::
string
thread_name
;
uint64_t
thread_id
;
std
::
vector
<
CommonEvent
>
events
;
std
::
vector
<
EventType
>
events
;
};
template
<
typename
EventType
>
class
ThreadEventRecorder
{
public:
ThreadEventRecorder
()
{
...
...
@@ -204,8 +205,8 @@ class ThreadEventRecorder {
base_evt_cntr_
.
Record
(
std
::
forward
<
Args
>
(
args
)...);
}
ThreadEventSection
GatherEvents
()
{
ThreadEventSection
thr_sec
;
ThreadEventSection
<
EventType
>
GatherEvents
()
{
ThreadEventSection
<
EventType
>
thr_sec
;
thr_sec
.
thread_name
=
thread_name_
;
thr_sec
.
thread_id
=
thread_id_
;
thr_sec
.
events
=
std
::
move
(
base_evt_cntr_
.
Reduce
());
...
...
@@ -215,15 +216,17 @@ class ThreadEventRecorder {
private:
uint64_t
thread_id_
;
std
::
string
thread_name_
;
EventContainer
<
CommonEvent
>
base_evt_cntr_
;
EventContainer
<
EventType
>
base_evt_cntr_
;
};
template
<
typename
EventType
>
struct
HostEventSection
{
std
::
string
process_name
;
uint64_t
process_id
;
std
::
vector
<
ThreadEventSection
>
thr_sections
;
std
::
vector
<
ThreadEventSection
<
EventType
>
>
thr_sections
;
};
template
<
typename
EventType
>
class
HostEventRecorder
{
public:
// singleton
...
...
@@ -244,10 +247,10 @@ class HostEventRecorder {
// thread-unsafe, make sure make sure there is no running tracing.
// Poor performance, call it at the ending
HostEventSection
GatherEvents
()
{
HostEventSection
<
EventType
>
GatherEvents
()
{
auto
thr_recorders
=
ThreadEventRecorderRegistry
::
GetInstance
().
GetAllThreadDataByRef
();
HostEventSection
host_sec
;
HostEventSection
<
EventType
>
host_sec
;
host_sec
.
process_id
=
GetProcessId
();
host_sec
.
thr_sections
.
reserve
(
thr_recorders
.
size
());
for
(
auto
&
kv
:
thr_recorders
)
{
...
...
@@ -260,12 +263,12 @@ class HostEventRecorder {
private:
using
ThreadEventRecorderRegistry
=
framework
::
ThreadDataRegistry
<
ThreadEventRecorder
>
;
framework
::
ThreadDataRegistry
<
ThreadEventRecorder
<
EventType
>
>
;
HostEventRecorder
()
=
default
;
DISABLE_COPY_AND_ASSIGN
(
HostEventRecorder
);
ThreadEventRecorder
*
GetThreadLocalRecorder
()
{
ThreadEventRecorder
<
EventType
>
*
GetThreadLocalRecorder
()
{
return
ThreadEventRecorderRegistry
::
GetInstance
()
.
GetMutableCurrentThreadData
();
}
...
...
paddle/fluid/platform/profiler/host_tracer.cc
浏览文件 @
c0ed75a8
...
...
@@ -30,7 +30,7 @@ namespace platform {
namespace
{
void
ProcessHostEvents
(
const
HostEventSection
&
host_events
,
void
ProcessHostEvents
(
const
HostEventSection
<
CommonEvent
>
&
host_events
,
TraceEventCollector
*
collector
)
{
for
(
const
auto
&
thr_sec
:
host_events
.
thr_sections
)
{
uint64_t
tid
=
thr_sec
.
thread_id
;
...
...
@@ -62,7 +62,7 @@ void HostTracer::StartTracing() {
PADDLE_ENFORCE_EQ
(
state_
==
TracerState
::
READY
||
state_
==
TracerState
::
STOPED
,
true
,
platform
::
errors
::
PreconditionNotMet
(
"TracerState must be READY"
));
HostEventRecorder
::
GetInstance
().
GatherEvents
();
HostEventRecorder
<
CommonEvent
>
::
GetInstance
().
GatherEvents
();
HostTraceLevel
::
GetInstance
().
SetLevel
(
options_
.
trace_level
);
state_
=
TracerState
::
STARTED
;
}
...
...
@@ -79,8 +79,8 @@ void HostTracer::CollectTraceData(TraceEventCollector* collector) {
PADDLE_ENFORCE_EQ
(
state_
,
TracerState
::
STOPED
,
platform
::
errors
::
PreconditionNotMet
(
"TracerState must be STOPED"
));
HostEventSection
host_events
=
HostEventRecorder
::
GetInstance
().
GatherEvents
();
HostEventSection
<
CommonEvent
>
host_events
=
HostEventRecorder
<
CommonEvent
>
::
GetInstance
().
GatherEvents
();
ProcessHostEvents
(
host_events
,
collector
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录