-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Better timeline #9037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better timeline #9037
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -147,19 +147,48 @@ RecordEvent::RecordEvent(const std::string& name, const DeviceContext* dev_ctx) | |
| name_ = name; | ||
| PushEvent(name_, dev_ctx_); | ||
| // Maybe need the same push/pop behavior. | ||
| SetCurAnnotation(name_.c_str()); | ||
| SetCurAnnotation(name_); | ||
| } | ||
|
|
||
| RecordEvent::~RecordEvent() { | ||
| if (g_state == ProfilerState::kDisabled) return; | ||
| DeviceTracer* tracer = GetDeviceTracer(); | ||
| if (tracer) { | ||
| tracer->AddCPURecords(CurAnnotation(), start_ns_, PosixInNsec()); | ||
| tracer->AddCPURecords(CurAnnotation(), start_ns_, PosixInNsec(), | ||
| BlockDepth(), CurThread()); | ||
| } | ||
| ClearCurAnnotation(); | ||
| PopEvent(name_, dev_ctx_); | ||
| } | ||
|
|
||
| RecordBlock::RecordBlock(int block_id) : start_ns_(PosixInNsec()) { | ||
| if (g_state == ProfilerState::kDisabled) return; | ||
| SetCurBlock(block_id); | ||
| name_ = string::Sprintf("block_%d", block_id); | ||
| } | ||
|
|
||
| RecordBlock::~RecordBlock() { | ||
| if (g_state == ProfilerState::kDisabled) return; | ||
| DeviceTracer* tracer = GetDeviceTracer(); | ||
| if (tracer) { | ||
| // We try to put all blocks at the same nested depth in the | ||
| // same timeline lane. and distinguish the using thread_id. | ||
| tracer->AddCPURecords(name_, start_ns_, PosixInNsec(), BlockDepth(), | ||
| CurThread()); | ||
| } | ||
| ClearCurBlock(); | ||
| } | ||
|
|
||
| RecordThread::RecordThread(int thread_id) { | ||
| if (g_state == ProfilerState::kDisabled) return; | ||
| SetCurThread(thread_id); | ||
| } | ||
|
|
||
| RecordThread::~RecordThread() { | ||
| if (g_state == ProfilerState::kDisabled) return; | ||
| ClearCurThread(); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, currently, it doesn't auto support thread nesting. See comments here: Actually, user can add code to give nested thread different ids: int nested_thread_id = CurThread() * 10 + 1
std::thread([nested_thread_id]() {
RecordThread(nested_thread_id);
...
} |
||
|
|
||
| void EnableProfiler(ProfilerState state) { | ||
| PADDLE_ENFORCE(state != ProfilerState::kDisabled, | ||
| "Can't enbale profling, since the input state is ", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
kProgramIdto distinguish the differentprogramin a model?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. The global block has block id 0. However, before the block 0 starts, there are some other preprocessing and post-processing overhead. I wrap those codes into block id -1.