Skip to content

Commit db1bd8a

Browse files
committed
DPL: allow generic control of signposts from the driver
1 parent 4f060ca commit db1bd8a

File tree

2 files changed

+47
-46
lines changed

2 files changed

+47
-46
lines changed

Framework/Core/src/WSDriverClient.cxx

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -188,48 +188,40 @@ void on_connect(uv_connect_t* connection, int status)
188188
state.tracingFlags = tracingFlags;
189189
});
190190

191-
client->observe("/log-streams", [ref = context->ref](std::string_view cmd) {
192-
auto& state = ref.get<DeviceState>();
193-
static constexpr int prefixSize = std::string_view{"/log-streams "}.size();
194-
if (prefixSize > cmd.size()) {
195-
LOG(error) << "Malformed log-streams request";
191+
client->observe("/signpost:enable", [](std::string_view cmd) {
192+
static constexpr int prefixSize = std::string_view{"/signpost:enable "}.size();
193+
if (cmd.size() <= prefixSize) {
194+
LOG(error) << "Malformed /signpost:enable request";
196195
return;
197196
}
198-
cmd.remove_prefix(prefixSize);
199-
int logStreams = 0;
197+
std::string name(cmd.substr(prefixSize));
198+
o2_walk_logs([](char const* logName, void* l, void* context) -> bool {
199+
auto* log = static_cast<_o2_log_t*>(l);
200+
auto* target = static_cast<std::string*>(context);
201+
if (*target == logName) {
202+
_o2_log_set_stacktrace(log, log->defaultStacktrace);
203+
return false;
204+
}
205+
return true;
206+
}, &name);
207+
});
200208

201-
auto error = std::from_chars(cmd.data(), cmd.data() + cmd.size(), logStreams);
202-
if (error.ec != std::errc()) {
203-
LOG(error) << "Malformed log-streams mask";
209+
client->observe("/signpost:disable", [](std::string_view cmd) {
210+
static constexpr int prefixSize = std::string_view{"/signpost:disable "}.size();
211+
if (cmd.size() <= prefixSize) {
212+
LOG(error) << "Malformed /signpost:disable request";
204213
return;
205214
}
206-
LOGP(info, "Logstreams flags set to {}", logStreams);
207-
state.logStreams = logStreams;
208-
if ((state.logStreams & DeviceState::LogStreams::DEVICE_LOG) != 0) {
209-
O2_LOG_ENABLE(device);
210-
} else {
211-
O2_LOG_DISABLE(device);
212-
}
213-
if ((state.logStreams & DeviceState::LogStreams::COMPLETION_LOG) != 0) {
214-
O2_LOG_ENABLE(completion);
215-
} else {
216-
O2_LOG_DISABLE(completion);
217-
}
218-
if ((state.logStreams & DeviceState::LogStreams::MONITORING_SERVICE_LOG) != 0) {
219-
O2_LOG_ENABLE(monitoring_service);
220-
} else {
221-
O2_LOG_DISABLE(monitoring_service);
222-
}
223-
if ((state.logStreams & DeviceState::LogStreams::DATA_PROCESSOR_CONTEXT_LOG) != 0) {
224-
O2_LOG_ENABLE(data_processor_context);
225-
} else {
226-
O2_LOG_DISABLE(data_processor_context);
227-
}
228-
if ((state.logStreams & DeviceState::LogStreams::STREAM_CONTEXT_LOG) != 0) {
229-
O2_LOG_ENABLE(stream_context);
230-
} else {
231-
O2_LOG_DISABLE(stream_context);
232-
}
215+
std::string name(cmd.substr(prefixSize));
216+
o2_walk_logs([](char const* logName, void* l, void* context) -> bool {
217+
auto* log = static_cast<_o2_log_t*>(l);
218+
auto* target = static_cast<std::string*>(context);
219+
if (*target == logName) {
220+
_o2_log_set_stacktrace(log, 0);
221+
return false;
222+
}
223+
return true;
224+
}, &name);
233225
});
234226

235227
// Client will be filled in the line after. I can probably have a single

Framework/GUISupport/src/FrameworkGUIDeviceInspector.cxx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,25 @@ void displayDeviceInspector(DeviceSpec const& spec,
400400
}
401401
}
402402

403-
bool logsChanged = false;
404403
if (ImGui::CollapsingHeader("Signposts", ImGuiTreeNodeFlags_DefaultOpen)) {
405-
logsChanged = ImGui::CheckboxFlags("Device", &control.logStreams, DeviceState::LogStreams::DEVICE_LOG);
406-
logsChanged = ImGui::CheckboxFlags("Completion", &control.logStreams, DeviceState::LogStreams::COMPLETION_LOG);
407-
logsChanged = ImGui::CheckboxFlags("Monitoring", &control.logStreams, DeviceState::LogStreams::MONITORING_SERVICE_LOG);
408-
logsChanged = ImGui::CheckboxFlags("DataProcessorContext", &control.logStreams, DeviceState::LogStreams::DATA_PROCESSOR_CONTEXT_LOG);
409-
logsChanged = ImGui::CheckboxFlags("StreamContext", &control.logStreams, DeviceState::LogStreams::STREAM_CONTEXT_LOG);
410-
if (logsChanged && control.controller) {
411-
std::string cmd = fmt::format("/log-streams {}", control.logStreams);
412-
control.controller->write(cmd.c_str(), cmd.size());
404+
static const struct {
405+
const char* label;
406+
int bit;
407+
const char* fullName;
408+
} kStreams[] = {
409+
{"Device", DeviceState::LogStreams::DEVICE_LOG, "ch.cern.aliceo2.device"},
410+
{"Completion", DeviceState::LogStreams::COMPLETION_LOG, "ch.cern.aliceo2.completion"},
411+
{"Monitoring", DeviceState::LogStreams::MONITORING_SERVICE_LOG, "ch.cern.aliceo2.monitoring_service"},
412+
{"DataProcessorContext", DeviceState::LogStreams::DATA_PROCESSOR_CONTEXT_LOG, "ch.cern.aliceo2.data_processor_context"},
413+
{"StreamContext", DeviceState::LogStreams::STREAM_CONTEXT_LOG, "ch.cern.aliceo2.stream_context"},
414+
};
415+
for (auto const& s : kStreams) {
416+
if (ImGui::CheckboxFlags(s.label, &control.logStreams, s.bit) && control.controller) {
417+
bool enabled = (control.logStreams & s.bit) != 0;
418+
std::string cmd = enabled ? fmt::format("/signpost:enable {}", s.fullName)
419+
: fmt::format("/signpost:disable {}", s.fullName);
420+
control.controller->write(cmd.c_str(), cmd.size());
421+
}
413422
}
414423
}
415424

0 commit comments

Comments
 (0)