未验证 提交 406f1b96 编写于 作者: L liutiexing 提交者: GitHub

Update host tracer (#39975)

* add align for WorkQueue

* add spinlock

* merge develop

* merge

* Add EventsWaiter

* Revert "Add EventsWaiter"

This reverts commit e206173aa9be7401b83a53581627bfaf557c8fb2.

* update HostTracer

* fix

* update

* update
Co-authored-by: Nliutiexing <liutiexing@google.com>
上级 18ee051e
......@@ -231,6 +231,8 @@ void FastThreadedSSAGraphExecutor::RunOpAsync(
OpHandleBase *op,
const std::shared_ptr<BlockingQueue<size_t>> &complete_q) {
++remaining_;
platform::RecordEvent("WorkQueue::AddTask",
platform::TracerEventType::UserDefined, 10 /*level*/);
this->pool_->enqueue([=] {
std::deque<OpHandleBase *> op_queue;
op_queue.push_front(op);
......
......@@ -95,8 +95,6 @@ std::unordered_map<uint64_t, ThreadId> GetAllThreadIds() {
return res;
}
static constexpr const char* kDefaultThreadName = "unset";
std::string GetCurrentThreadName() {
const auto& thread_name =
internal::ThreadDataRegistry<std::string>::GetInstance()
......@@ -112,7 +110,7 @@ std::unordered_map<uint64_t, std::string> GetAllThreadNames() {
bool SetCurrentThreadName(const std::string& name) {
auto& instance = internal::ThreadDataRegistry<std::string>::GetInstance();
const auto& cur_name = instance.GetCurrentThreadData();
if (!cur_name.empty() || cur_name == kDefaultThreadName) {
if (!cur_name.empty() || name.empty() || name == kDefaultThreadName) {
return false;
}
instance.SetCurrentThreadData(name);
......
......@@ -57,7 +57,8 @@ ThreadId GetCurrentThreadId();
// create/destory when using it.
std::unordered_map<uint64_t, ThreadId> GetAllThreadIds();
// Returns 'unset' if SetCurrentThreadName is never called.
static constexpr const char* kDefaultThreadName = "unset";
// Returns kDefaultThreadName if SetCurrentThreadName is never called.
std::string GetCurrentThreadName();
// Return the map from StdTid to ThreadName
......
......@@ -26,6 +26,9 @@ void ProcessHostEvents(const HostEventSection& host_events,
TraceEventCollector* collector) {
for (const auto& thr_sec : host_events.thr_sections) {
uint64_t tid = thr_sec.thread_id;
if (thr_sec.thread_name != kDefaultThreadName) {
collector->AddThreadName(tid, thr_sec.thread_name);
}
for (const auto& evt : thr_sec.events) {
HostTraceEvent event;
event.name = evt.name;
......@@ -41,12 +44,18 @@ void ProcessHostEvents(const HostEventSection& host_events,
} // namespace
void HostTracer::PrepareTracing() {
// warm up
HostTraceLevel::GetInstance().SetLevel(options_.trace_level);
state_ = TracerState::READY;
}
void HostTracer::StartTracing() {
PADDLE_ENFORCE_EQ(
state_ == TracerState::READY || state_ == TracerState::STOPED, true,
platform::errors::PreconditionNotMet("TracerState must be READY"));
HostEventRecorder::GetInstance().GatherEvents();
HostTraceLevel::GetInstance().SetLevel(trace_level_);
HostTraceLevel::GetInstance().SetLevel(options_.trace_level);
state_ = TracerState::STARTED;
}
......
......@@ -45,9 +45,9 @@ struct HostTracerOptions {
class HostTracer : public TracerBase {
public:
explicit HostTracer(const HostTracerOptions& options) {
trace_level_ = options.trace_level;
}
explicit HostTracer(const HostTracerOptions& options) : options_(options) {}
void PrepareTracing() override;
void StartTracing() override;
......@@ -56,7 +56,7 @@ class HostTracer : public TracerBase {
void CollectTraceData(TraceEventCollector* collector) override;
private:
uint32_t trace_level_;
HostTracerOptions options_;
};
} // namespace platform
......
......@@ -15,6 +15,8 @@ limitations under the License. */
#pragma once
#include <list>
#include <string>
#include <unordered_map>
#include "paddle/fluid/platform/profiler/trace_event.h"
namespace paddle {
......@@ -32,6 +34,10 @@ class TraceEventCollector {
device_events_.push_back(event);
}
void AddThreadName(uint64_t tid, const std::string& name) {
thread_names_[tid] = name;
}
const std::list<HostTraceEvent>& HostEvents() const { return host_events_; }
const std::list<RuntimeTraceEvent>& RuntimeEvents() const {
......@@ -42,7 +48,12 @@ class TraceEventCollector {
return device_events_;
}
const std::unordered_map<uint64_t, std::string>& ThreadNames() const {
return thread_names_;
}
private:
std::unordered_map<uint64_t, std::string> thread_names_;
std::list<HostTraceEvent> host_events_;
std::list<RuntimeTraceEvent> runtime_events_;
std::list<DeviceTraceEvent> device_events_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册