Skip to content

Commit d566fd1

Browse files
committed
Ability to turn on / off the logger from the GUI.
1 parent 4df6e4a commit d566fd1

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

Framework/Core/include/Framework/DeviceControl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ struct DeviceControl {
4848
DeviceController* controller = nullptr;
4949
/// What kind of events should run with the TRACE level
5050
int tracingFlags = 0;
51+
/// What kind of log streams should be enabled
52+
int logStreams = 0;
5153
/// An incremental number to identify the device state
5254
int requestedState = 0;
5355
};

Framework/Core/include/Framework/DeviceState.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ struct DeviceState {
5757
DATA_CONNECTED = 1 << 19, // Data channel connected
5858
};
5959

60+
enum LogStreams : int {
61+
NO_LOG = 0,
62+
DEVICE_LOG = 1 << 0, // Log for Data Processing Device activities.
63+
COMPLETION_LOG = 1 << 1, // Log for the completion policy of the device.
64+
MONITORING_SERVICE_LOG = 1 << 2, // Log for the monitoring service flushing.
65+
};
66+
6067
std::vector<InputChannelInfo> inputChannelInfos;
6168
StreamingState streaming = StreamingState::Streaming;
6269
bool quitRequested = false;
@@ -93,6 +100,8 @@ struct DeviceState {
93100
int loopReason = 0;
94101
/// Bitmask of LoopReason to trace
95102
int tracingFlags = 0;
103+
/// Bitmask of log streams which are available
104+
int logStreams = 0;
96105
/// Stack of the severity, so that we can display only
97106
/// the bits we are interested in.
98107
std::vector<int> severityStack;

Framework/Core/src/WSDriverClient.cxx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@
1616
#include "Framework/DeviceSpec.h"
1717
#include "DriverClientContext.h"
1818
#include "DPLWebSocket.h"
19+
#include "Framework/Signpost.h"
1920
#include <uv.h>
2021
#include <string_view>
2122
#include <charconv>
2223

24+
O2_DECLARE_DYNAMIC_LOG(device);
25+
O2_DECLARE_DYNAMIC_LOG(completion);
26+
O2_DECLARE_DYNAMIC_LOG(monitoring_service);
27+
2328
namespace o2::framework
2429
{
2530

@@ -152,6 +157,41 @@ void on_connect(uv_connect_t* connection, int status)
152157
state.tracingFlags = tracingFlags;
153158
});
154159

160+
client->observe("/log-streams", [ref = context->ref](std::string_view cmd) {
161+
auto& state = ref.get<DeviceState>();
162+
static constexpr int prefixSize = std::string_view{"/log-streams "}.size();
163+
if (prefixSize > cmd.size()) {
164+
LOG(error) << "Malformed log-streams request";
165+
return;
166+
}
167+
cmd.remove_prefix(prefixSize);
168+
int logStreams = 0;
169+
170+
auto error = std::from_chars(cmd.data(), cmd.data() + cmd.size(), logStreams);
171+
if (error.ec != std::errc()) {
172+
LOG(error) << "Malformed log-streams mask";
173+
return;
174+
}
175+
LOGP(info, "Logstreams flags set to {}", logStreams);
176+
state.logStreams = logStreams;
177+
if ((state.logStreams & DeviceState::LogStreams::DEVICE_LOG) != 0) {
178+
O2_LOG_ENABLE(device);
179+
} else {
180+
O2_LOG_DISABLE(device);
181+
}
182+
if ((state.logStreams & DeviceState::LogStreams::COMPLETION_LOG) != 0) {
183+
O2_LOG_ENABLE(completion);
184+
} else {
185+
O2_LOG_DISABLE(completion);
186+
}
187+
188+
if ((state.logStreams & DeviceState::LogStreams::MONITORING_SERVICE_LOG) != 0) {
189+
O2_LOG_ENABLE(monitoring_service);
190+
} else {
191+
O2_LOG_DISABLE(monitoring_service);
192+
}
193+
});
194+
155195
// Client will be filled in the line after. I can probably have a single
156196
// client per device.
157197
auto dplClient = std::make_unique<WSDPLClient>();

Framework/GUISupport/src/FrameworkGUIDeviceInspector.cxx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,17 @@ void displayDeviceInspector(DeviceSpec const& spec,
400400
}
401401
}
402402

403+
bool logsChanged = false;
404+
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+
if (logsChanged && control.controller) {
409+
std::string cmd = fmt::format("/log-streams {}", control.logStreams);
410+
control.controller->write(cmd.c_str(), cmd.size());
411+
}
412+
}
413+
403414
bool flagsChanged = false;
404415
if (ImGui::CollapsingHeader("Event loop tracing", ImGuiTreeNodeFlags_DefaultOpen)) {
405416
flagsChanged |= ImGui::CheckboxFlags("METRICS_MUST_FLUSH", &control.tracingFlags, DeviceState::LoopReason::METRICS_MUST_FLUSH);

Framework/TestWorkflows/test/test_DetectMissingTimeframe.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& specs)
4343
if (i++ % 2 == 0) {
4444
outputs.make<int>(OutputRef{"a2"}, 1);
4545
}
46+
sleep(1);
4647
})},
4748
};
4849
DataProcessorSpec d{

0 commit comments

Comments
 (0)