Skip to content

Commit

Permalink
DebugGUI: adding minor features to inputs/outputs display (AliceO2Gro…
Browse files Browse the repository at this point in the history
  • Loading branch information
ehellbar authored Oct 29, 2024
1 parent e4c085b commit b4d225b
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 9 deletions.
42 changes: 40 additions & 2 deletions Framework/GUISupport/src/FrameworkGUIDataRelayerUsage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
#include <functional>
#include "Framework/DeviceMetricsInfo.h"
#include "Framework/DeviceInfo.h"
#include "Framework/DeviceSpec.h"
#include "Framework/DataDescriptorMatcher.h"
#include "Framework/DataProcessingStates.h"
#include "InspectorHelpers.h"
#include "PaletteHelpers.h"
#include "Framework/Logger.h"
#include <iostream>
Expand All @@ -31,6 +33,7 @@ struct HeatMapHelper {
template <typename RECORD, typename ITEM>
static void draw(const char* name,
ImVec2 const& sizeHint,
std::function<size_t()> const& getNumInputs,
std::function<size_t()> const& getNumRecords,
std::function<RECORD(size_t)> const& getRecord,
std::function<size_t(RECORD const&)> const& getNumItems,
Expand All @@ -48,12 +51,13 @@ struct HeatMapHelper {
ImVec2 winPos = ImGui::GetCursorScreenPos() + ImVec2{0, 7};
auto records = getNumRecords();
auto boxSizeX = std::min(size.x / records, MAX_BOX_X_SIZE);
auto numInputs = getNumInputs();

ImGui::InvisibleButton("sensible area", ImVec2(size.x, size.y));
if (ImGui::IsItemHovered()) {
auto pos = ImGui::GetMousePos() - winPos;
auto slot = std::lround(std::trunc(pos.x / size.x * records));
auto row = std::lround(std::trunc(pos.y / size.y));
auto row = std::lround(std::trunc(pos.y / size.y * numInputs));
describeCell(row, slot);
}

Expand Down Expand Up @@ -96,9 +100,20 @@ struct HeatMapHelper {

void displayDataRelayer(DeviceMetricsInfo const& metrics,
DeviceInfo const& info,
DeviceSpec const& spec,
DataProcessingStates const& states,
ImVec2 const& size)
{
auto getNumInputs = [&states]() -> size_t {
auto& inputsView = states.statesViews[(int)ProcessingStateId::DATA_QUERIES];
std::string_view inputs(states.statesBuffer.data() + inputsView.first, inputsView.size);
if (inputs.size() == 0) {
return 0;
}
// count the number of semi-colon separators to get number of inputs
int numInputs = std::count(inputs.begin(), inputs.end(), ';');
return numInputs;
};
auto getNumRecords = [&states]() -> size_t {
auto& view = states.statesViews[(int)ProcessingStateId::DATA_RELAYER_BASE];
if (view.size == 0) {
Expand Down Expand Up @@ -154,8 +169,30 @@ void displayDataRelayer(DeviceMetricsInfo const& metrics,
}
return SLOT_ERROR;
};
auto describeCell = [&states](int input, int slot) -> void {
auto describeCell = [&states, &spec](int row, int slot) -> void {
ImGui::BeginTooltip();

// display the input (origin/descr/subspec)
auto& inputsView = states.statesViews[(int)ProcessingStateId::DATA_QUERIES];
std::string_view inputs(states.statesBuffer.data() + inputsView.first, inputsView.size);
auto beginInputs = inputs.begin();
auto endInputs = beginInputs + inputsView.size;
char const* input = beginInputs;
size_t i = 0;
while (input != endInputs) {
auto end = std::find(input, endInputs, ';');
if ((end - input) == 0) {
continue;
}
if (i == row) {
ImGui::Text("%d %.*s (%s)", row, int(end - input), input, InspectorHelpers::getLifeTimeStr(spec.inputs[i].matcher.lifetime).c_str());
break;
}
++i;
input = end + 1;
}

// display context variables
ImGui::Text("Input query matched values for slot: %d", slot);
auto& view = states.statesViews[(short)ProcessingStateId::CONTEXT_VARIABLES_BASE + (short)slot];
auto begin = view.first;
Expand Down Expand Up @@ -190,6 +227,7 @@ void displayDataRelayer(DeviceMetricsInfo const& metrics,
if (getNumRecords()) {
HeatMapHelper::draw<int, int8_t>("DataRelayer",
size,
getNumInputs,
getNumRecords,
getRecord,
getNumItems,
Expand Down
2 changes: 1 addition & 1 deletion Framework/GUISupport/src/FrameworkGUIDataRelayerUsage.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace gui
{

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

} // namespace gui
} // namespace o2::framework
19 changes: 14 additions & 5 deletions Framework/GUISupport/src/FrameworkGUIDeviceInspector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "Framework/DeviceController.h"
#include "Framework/DataProcessingStates.h"
#include "Framework/Signpost.h"
#include "InspectorHelpers.h"
#include <DebugGUI/icons_font_awesome.h>

#include "DebugGUI/imgui.h"
Expand Down Expand Up @@ -78,7 +79,7 @@ void deviceStateTable(DataProcessingStates const& states)
}
}

void deviceInfoTable(char const* label, ProcessingStateId id, DataProcessingStates const& states, DeviceMetricsInfo const& metrics)
void deviceInfoTable(char const* label, ProcessingStateId id, DataProcessingStates const& states, std::variant<std::vector<InputRoute>, std::vector<OutputRoute>> routes, DeviceMetricsInfo const& metrics)
{
// Find the state spec associated to data_queries
auto& view = states.statesViews[(int)id];
Expand All @@ -94,13 +95,21 @@ void deviceInfoTable(char const* label, ProcessingStateId id, DataProcessingStat
if ((end - input) == 0) {
continue;
}
ImGui::Text("%zu: %.*s", i, int(end - input), input);
auto getLifetime = [&routes, &i]() -> Lifetime {
if (std::get_if<std::vector<InputRoute>>(&routes)) {
return std::get<std::vector<InputRoute>>(routes)[i].matcher.lifetime;
} else {
return std::get<std::vector<OutputRoute>>(routes)[i].matcher.lifetime;
}
};
ImGui::Text("%zu: %.*s (%s)", i, int(end - input), input, InspectorHelpers::getLifeTimeStr(getLifetime()).c_str());
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::Text("%zu: %.*s", i, int(end - input), input);
ImGui::Text("%zu: %.*s (%s)", i, int(end - input), input, InspectorHelpers::getLifeTimeStr(getLifetime()).c_str());
ImGui::EndTooltip();
}
input = end + 1;
++i;
}
}
}
Expand Down Expand Up @@ -337,8 +346,8 @@ void displayDeviceInspector(DeviceSpec const& spec,
}

deviceStateTable(states);
deviceInfoTable("Inputs:", ProcessingStateId::DATA_QUERIES, states, metrics);
deviceInfoTable("Outputs:", ProcessingStateId::OUTPUT_MATCHERS, states, metrics);
deviceInfoTable("Inputs:", ProcessingStateId::DATA_QUERIES, states, std::variant<std::vector<InputRoute>, std::vector<OutputRoute>>(spec.inputs), metrics);
deviceInfoTable("Outputs:", ProcessingStateId::OUTPUT_MATCHERS, states, std::variant<std::vector<InputRoute>, std::vector<OutputRoute>>(spec.outputs), metrics);
configurationTable(info.currentConfig, info.currentProvenance);
optionsTable("Workflow Options", metadata.workflowOptions, control);
if (ImGui::CollapsingHeader("Labels", ImGuiTreeNodeFlags_DefaultOpen)) {
Expand Down
2 changes: 1 addition & 1 deletion Framework/GUISupport/src/FrameworkGUIDevicesGraph.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ void showTopologyNodeGraph(WorkspaceGUIState& state,
default:
break;
}
gui::displayDataRelayer(metricsInfos[node->ID], infos[node->ID], allStates[node->ID], ImVec2(140., 90.));
gui::displayDataRelayer(metricsInfos[node->ID], infos[node->ID], specs[node->ID], allStates[node->ID], ImVec2(140., 90.));
ImGui::EndGroup();

// Save the size of what we have emitted and whether any of the widgets are being used
Expand Down
51 changes: 51 additions & 0 deletions Framework/GUISupport/src/InspectorHelpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#ifndef O2_FRAMEWORK_INSPECTORHELPERS_H_
#define O2_FRAMEWORK_INSPECTORHELPERS_H_

#include <string>

#include "Framework/Lifetime.h"

namespace o2::framework
{

/// A helper class for inpsection of device information
struct InspectorHelpers {
static const std::string getLifeTimeStr(Lifetime lifetime)
{
switch (lifetime) {
case Lifetime::Timeframe:
return "Timeframe";
case Lifetime::Condition:
return "Condition";
case Lifetime::Sporadic:
return "Sporadic";
case Lifetime::Transient:
return "Transient";
case Lifetime::Timer:
return "Timer";
case Lifetime::Enumeration:
return "Enumeration";
case Lifetime::Signal:
return "Signal";
case Lifetime::Optional:
return "Optional";
case Lifetime::OutOfBand:
return "OutOfBand";
}
return "none";
};
};

} // namespace o2::framework

#endif // O2_FRAMEWORK_INSPECTORHELPERS_H_

0 comments on commit b4d225b

Please sign in to comment.