@@ -12,6 +12,7 @@ Sender<Value> Task::Process(Sender<Value> input) {
12
12
assert (v.is_array ());
13
13
// handle empty input
14
14
if (v.front ().empty ()) {
15
+ profiler::ScopedCounter counter (scope_);
15
16
return TransferJust (*sched_, Value (Value::Array (v.size (), Value::kArray )));
16
17
}
17
18
if (v.front ().is_array () && !is_batched_) {
@@ -24,6 +25,7 @@ Sender<Value> Task::Process(Sender<Value> input) {
24
25
return Value{std::move (input), std::move (output)};
25
26
})
26
27
| Bulk (batch_size, [&](size_t index , Value& in_out) {
28
+ profiler::ScopedCounter counter (scope_);
27
29
const auto & input = in_out[0 ];
28
30
auto & output = in_out[1 ];
29
31
output[index ] = module_->Process (input[index ]).value ();
@@ -33,8 +35,10 @@ Sender<Value> Task::Process(Sender<Value> input) {
33
35
});
34
36
// clang-format on
35
37
} else {
36
- return DynamicBatch (TransferJust (*sched_, std::move (v)), batch_context_,
37
- [&](const Value& u) { return module_->Process (u).value (); });
38
+ return DynamicBatch (TransferJust (*sched_, std::move (v)), batch_context_, [&](const Value& u) {
39
+ profiler::ScopedCounter counter (scope_);
40
+ return module_->Process (u).value ();
41
+ });
38
42
}
39
43
});
40
44
}
@@ -63,6 +67,17 @@ inline Result<unique_ptr<Module>> CreateModule(const Value& config) {
63
67
Result<unique_ptr<Node>> TaskBuilder::BuildImpl () {
64
68
try {
65
69
auto task = std::make_unique<Task>();
70
+ if (auto scope = Maybe{config_} / " context" / " scope" / identity<profiler::Scope*>{}) {
71
+ auto module_name = config_.value <std::string>(" module" , " " );
72
+ auto name = config_.value <std::string>(" name" , " " );
73
+ string scope_name = (name != " " ) ? name : module_name;
74
+ task->scope_ = (*scope)->CreateScope (scope_name);
75
+ config_[" context" ][" scope" ] = task->scope_ ;
76
+ if (module_name == " Transform" ) {
77
+ task->scope_ = nullptr ;
78
+ }
79
+ }
80
+
66
81
OUTCOME_TRY (task->module_ , CreateModule (config_));
67
82
68
83
if (auto name = Maybe{config_} / " scheduler" / identity<string>{}) {
0 commit comments