49 virtual void set_up(
unsigned num_workers) {};
90 task_view {tv}, beg {b} {
98 task_view {tv}, beg {b}, end {e} {
131 inline size_t num_tasks()
const;
135 inline void set_up(
unsigned num_workers)
override final;
136 inline void on_entry(
unsigned worker_id,
TaskView task_view)
override final;
137 inline void on_exit(
unsigned worker_id,
TaskView task_view)
override final;
143 inline void ExecutorObserver::set_up(
unsigned num_workers) {
145 _timeline.executions.resize(num_workers);
147 for(
unsigned w=0; w<num_workers; ++w) {
148 _timeline.executions[w].reserve(1024);
155 inline void ExecutorObserver::on_entry(
unsigned w,
TaskView tv) {
160 inline void ExecutorObserver::on_exit(
unsigned w,
TaskView tv) {
161 assert(_timeline.executions[w].size() > 0);
167 for(
size_t w=0; w<_timeline.executions.size(); ++w) {
168 _timeline.executions[w].clear();
177 for(
size_t w=0; w<_timeline.executions.size(); w++) {
179 if(w != 0 && _timeline.executions[w].size() > 0 &&
180 _timeline.executions[w-1].size() > 0) {
184 for(
size_t i=0; i<_timeline.executions[w].size(); i++) {
187 <<
"\"cat\":\"ExecutorObserver\"," 188 <<
"\"name\":\"" << _timeline.executions[w][i].task_view.name() <<
"\"," 191 <<
"\"tid\":" << w <<
',' 193 _timeline.executions[w][i].beg - _timeline.origin
196 _timeline.executions[w][i].end - _timeline.executions[w][i].beg
199 if(i != _timeline.executions[w].size() - 1) {
219 return std::accumulate(
220 _timeline.executions.begin(), _timeline.executions.end(),
size_t{0},
221 [](
size_t sum,
const auto& exe){
222 return sum + exe.size();
Default executor observer to dump the execution timelines.
Definition: observer.hpp:74
virtual ~ExecutorObserverInterface()=default
virtual destructor
size_t num_tasks() const
get the number of total tasks in the observer
Definition: observer.hpp:218
T duration_cast(T... args)
Definition: taskflow.hpp:5
virtual void set_up(unsigned num_workers)
constructor-like method to call when the executor observer is fully created
Definition: observer.hpp:49
A constant wrapper class to a task node, mainly used in the tf::ExecutorObserver interface.
Definition: task.hpp:300
virtual void on_exit(unsigned worker_id, TaskView task_view)
method to call after a worker thread executed a closure
Definition: observer.hpp:63
virtual void on_entry(unsigned worker_id, TaskView task_view)
method to call before a worker thread executes a closure
Definition: observer.hpp:56
void clear()
clear the timeline data
Definition: observer.hpp:166
std::string dump() const
dump the timelines in JSON to a std::string
Definition: observer.hpp:211
The executor class to run a taskflow graph.
Definition: executor.hpp:73
The interface class for creating an executor observer.
Definition: observer.hpp:36