Skip to content

Commit b4d225b

Browse files
authored
DebugGUI: adding minor features to inputs/outputs display (AliceO2Group#13628)
1 parent e4c085b commit b4d225b

File tree

5 files changed

+107
-9
lines changed

5 files changed

+107
-9
lines changed

Framework/GUISupport/src/FrameworkGUIDataRelayerUsage.cxx

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
#include <functional>
1313
#include "Framework/DeviceMetricsInfo.h"
1414
#include "Framework/DeviceInfo.h"
15+
#include "Framework/DeviceSpec.h"
1516
#include "Framework/DataDescriptorMatcher.h"
1617
#include "Framework/DataProcessingStates.h"
18+
#include "InspectorHelpers.h"
1719
#include "PaletteHelpers.h"
1820
#include "Framework/Logger.h"
1921
#include <iostream>
@@ -31,6 +33,7 @@ struct HeatMapHelper {
3133
template <typename RECORD, typename ITEM>
3234
static void draw(const char* name,
3335
ImVec2 const& sizeHint,
36+
std::function<size_t()> const& getNumInputs,
3437
std::function<size_t()> const& getNumRecords,
3538
std::function<RECORD(size_t)> const& getRecord,
3639
std::function<size_t(RECORD const&)> const& getNumItems,
@@ -48,12 +51,13 @@ struct HeatMapHelper {
4851
ImVec2 winPos = ImGui::GetCursorScreenPos() + ImVec2{0, 7};
4952
auto records = getNumRecords();
5053
auto boxSizeX = std::min(size.x / records, MAX_BOX_X_SIZE);
54+
auto numInputs = getNumInputs();
5155

5256
ImGui::InvisibleButton("sensible area", ImVec2(size.x, size.y));
5357
if (ImGui::IsItemHovered()) {
5458
auto pos = ImGui::GetMousePos() - winPos;
5559
auto slot = std::lround(std::trunc(pos.x / size.x * records));
56-
auto row = std::lround(std::trunc(pos.y / size.y));
60+
auto row = std::lround(std::trunc(pos.y / size.y * numInputs));
5761
describeCell(row, slot);
5862
}
5963

@@ -96,9 +100,20 @@ struct HeatMapHelper {
96100

97101
void displayDataRelayer(DeviceMetricsInfo const& metrics,
98102
DeviceInfo const& info,
103+
DeviceSpec const& spec,
99104
DataProcessingStates const& states,
100105
ImVec2 const& size)
101106
{
107+
auto getNumInputs = [&states]() -> size_t {
108+
auto& inputsView = states.statesViews[(int)ProcessingStateId::DATA_QUERIES];
109+
std::string_view inputs(states.statesBuffer.data() + inputsView.first, inputsView.size);
110+
if (inputs.size() == 0) {
111+
return 0;
112+
}
113+
// count the number of semi-colon separators to get number of inputs
114+
int numInputs = std::count(inputs.begin(), inputs.end(), ';');
115+
return numInputs;
116+
};
102117
auto getNumRecords = [&states]() -> size_t {
103118
auto& view = states.statesViews[(int)ProcessingStateId::DATA_RELAYER_BASE];
104119
if (view.size == 0) {
@@ -154,8 +169,30 @@ void displayDataRelayer(DeviceMetricsInfo const& metrics,
154169
}
155170
return SLOT_ERROR;
156171
};
157-
auto describeCell = [&states](int input, int slot) -> void {
172+
auto describeCell = [&states, &spec](int row, int slot) -> void {
158173
ImGui::BeginTooltip();
174+
175+
// display the input (origin/descr/subspec)
176+
auto& inputsView = states.statesViews[(int)ProcessingStateId::DATA_QUERIES];
177+
std::string_view inputs(states.statesBuffer.data() + inputsView.first, inputsView.size);
178+
auto beginInputs = inputs.begin();
179+
auto endInputs = beginInputs + inputsView.size;
180+
char const* input = beginInputs;
181+
size_t i = 0;
182+
while (input != endInputs) {
183+
auto end = std::find(input, endInputs, ';');
184+
if ((end - input) == 0) {
185+
continue;
186+
}
187+
if (i == row) {
188+
ImGui::Text("%d %.*s (%s)", row, int(end - input), input, InspectorHelpers::getLifeTimeStr(spec.inputs[i].matcher.lifetime).c_str());
189+
break;
190+
}
191+
++i;
192+
input = end + 1;
193+
}
194+
195+
// display context variables
159196
ImGui::Text("Input query matched values for slot: %d", slot);
160197
auto& view = states.statesViews[(short)ProcessingStateId::CONTEXT_VARIABLES_BASE + (short)slot];
161198
auto begin = view.first;
@@ -190,6 +227,7 @@ void displayDataRelayer(DeviceMetricsInfo const& metrics,
190227
if (getNumRecords()) {
191228
HeatMapHelper::draw<int, int8_t>("DataRelayer",
192229
size,
230+
getNumInputs,
193231
getNumRecords,
194232
getRecord,
195233
getNumItems,

Framework/GUISupport/src/FrameworkGUIDataRelayerUsage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace gui
2121
{
2222

2323
/// View of the DataRelayer metrics for a given DeviceInfo
24-
void displayDataRelayer(DeviceMetricsInfo const& metrics, DeviceInfo const& info, DataProcessingStates const&, ImVec2 const& size);
24+
void displayDataRelayer(DeviceMetricsInfo const& metrics, DeviceInfo const& info, DeviceSpec const& spec, DataProcessingStates const&, ImVec2 const& size);
2525

2626
} // namespace gui
2727
} // namespace o2::framework

Framework/GUISupport/src/FrameworkGUIDeviceInspector.cxx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "Framework/DeviceController.h"
2222
#include "Framework/DataProcessingStates.h"
2323
#include "Framework/Signpost.h"
24+
#include "InspectorHelpers.h"
2425
#include <DebugGUI/icons_font_awesome.h>
2526

2627
#include "DebugGUI/imgui.h"
@@ -78,7 +79,7 @@ void deviceStateTable(DataProcessingStates const& states)
7879
}
7980
}
8081

81-
void deviceInfoTable(char const* label, ProcessingStateId id, DataProcessingStates const& states, DeviceMetricsInfo const& metrics)
82+
void deviceInfoTable(char const* label, ProcessingStateId id, DataProcessingStates const& states, std::variant<std::vector<InputRoute>, std::vector<OutputRoute>> routes, DeviceMetricsInfo const& metrics)
8283
{
8384
// Find the state spec associated to data_queries
8485
auto& view = states.statesViews[(int)id];
@@ -94,13 +95,21 @@ void deviceInfoTable(char const* label, ProcessingStateId id, DataProcessingStat
9495
if ((end - input) == 0) {
9596
continue;
9697
}
97-
ImGui::Text("%zu: %.*s", i, int(end - input), input);
98+
auto getLifetime = [&routes, &i]() -> Lifetime {
99+
if (std::get_if<std::vector<InputRoute>>(&routes)) {
100+
return std::get<std::vector<InputRoute>>(routes)[i].matcher.lifetime;
101+
} else {
102+
return std::get<std::vector<OutputRoute>>(routes)[i].matcher.lifetime;
103+
}
104+
};
105+
ImGui::Text("%zu: %.*s (%s)", i, int(end - input), input, InspectorHelpers::getLifeTimeStr(getLifetime()).c_str());
98106
if (ImGui::IsItemHovered()) {
99107
ImGui::BeginTooltip();
100-
ImGui::Text("%zu: %.*s", i, int(end - input), input);
108+
ImGui::Text("%zu: %.*s (%s)", i, int(end - input), input, InspectorHelpers::getLifeTimeStr(getLifetime()).c_str());
101109
ImGui::EndTooltip();
102110
}
103111
input = end + 1;
112+
++i;
104113
}
105114
}
106115
}
@@ -337,8 +346,8 @@ void displayDeviceInspector(DeviceSpec const& spec,
337346
}
338347

339348
deviceStateTable(states);
340-
deviceInfoTable("Inputs:", ProcessingStateId::DATA_QUERIES, states, metrics);
341-
deviceInfoTable("Outputs:", ProcessingStateId::OUTPUT_MATCHERS, states, metrics);
349+
deviceInfoTable("Inputs:", ProcessingStateId::DATA_QUERIES, states, std::variant<std::vector<InputRoute>, std::vector<OutputRoute>>(spec.inputs), metrics);
350+
deviceInfoTable("Outputs:", ProcessingStateId::OUTPUT_MATCHERS, states, std::variant<std::vector<InputRoute>, std::vector<OutputRoute>>(spec.outputs), metrics);
342351
configurationTable(info.currentConfig, info.currentProvenance);
343352
optionsTable("Workflow Options", metadata.workflowOptions, control);
344353
if (ImGui::CollapsingHeader("Labels", ImGuiTreeNodeFlags_DefaultOpen)) {

Framework/GUISupport/src/FrameworkGUIDevicesGraph.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ void showTopologyNodeGraph(WorkspaceGUIState& state,
705705
default:
706706
break;
707707
}
708-
gui::displayDataRelayer(metricsInfos[node->ID], infos[node->ID], allStates[node->ID], ImVec2(140., 90.));
708+
gui::displayDataRelayer(metricsInfos[node->ID], infos[node->ID], specs[node->ID], allStates[node->ID], ImVec2(140., 90.));
709709
ImGui::EndGroup();
710710

711711
// Save the size of what we have emitted and whether any of the widgets are being used
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
#ifndef O2_FRAMEWORK_INSPECTORHELPERS_H_
12+
#define O2_FRAMEWORK_INSPECTORHELPERS_H_
13+
14+
#include <string>
15+
16+
#include "Framework/Lifetime.h"
17+
18+
namespace o2::framework
19+
{
20+
21+
/// A helper class for inpsection of device information
22+
struct InspectorHelpers {
23+
static const std::string getLifeTimeStr(Lifetime lifetime)
24+
{
25+
switch (lifetime) {
26+
case Lifetime::Timeframe:
27+
return "Timeframe";
28+
case Lifetime::Condition:
29+
return "Condition";
30+
case Lifetime::Sporadic:
31+
return "Sporadic";
32+
case Lifetime::Transient:
33+
return "Transient";
34+
case Lifetime::Timer:
35+
return "Timer";
36+
case Lifetime::Enumeration:
37+
return "Enumeration";
38+
case Lifetime::Signal:
39+
return "Signal";
40+
case Lifetime::Optional:
41+
return "Optional";
42+
case Lifetime::OutOfBand:
43+
return "OutOfBand";
44+
}
45+
return "none";
46+
};
47+
};
48+
49+
} // namespace o2::framework
50+
51+
#endif // O2_FRAMEWORK_INSPECTORHELPERS_H_

0 commit comments

Comments
 (0)