Skip to content

Commit 750c06c

Browse files
committed
DPL GUI: refactor 2D Metrics index
This makes the old DataRelayerViewIndex a generic component for metrics which should really grouped in a 2D display. To be used by the soon to be introduced DataDescriptorMatcher debug view.
1 parent 79fd4f4 commit 750c06c

File tree

6 files changed

+121
-57
lines changed

6 files changed

+121
-57
lines changed

Framework/Core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ set(SRCS
5656
src/LifetimeHelpers.cxx
5757
src/LocalRootFileService.cxx
5858
src/LogParsingHelpers.cxx
59+
src/Metric2DViewIndex.cxx
5960
src/ExternalFairMQDeviceProxy.cxx
6061
src/SimpleResourceManager.cxx
6162
src/TextControlService.cxx
@@ -149,6 +150,7 @@ set(HEADERS
149150
include/Framework/DPLBoostSerializer.h
150151
include/Framework/TableBuilder.h
151152
include/Framework/FairMQResizableBuffer.h
153+
include/Framework/Metric2DViewIndex.h
152154
src/ComputingResource.h
153155
src/DDSConfigHelpers.h
154156
src/DeviceSpecHelpers.h

Framework/Core/include/Framework/DeviceInfo.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define FRAMEWORK_DEVICEINFO_H
1212

1313
#include "Framework/LogParsingHelpers.h"
14+
#include "Framework/Metric2DViewIndex.h"
1415
#include "Framework/Variant.h"
1516

1617
#include <cstddef>
@@ -25,16 +26,6 @@ namespace o2
2526
namespace framework
2627
{
2728

28-
/// Index of what metrics have to be picked up
29-
/// for the DataRelayer view of a given device.
30-
struct DataRelayerViewIndex {
31-
int w = 0;
32-
int h = 0;
33-
std::vector<size_t> indexes = {};
34-
/// Whether or not the view is ready to be used.
35-
bool isComplete() const { return (w * h) != 0; }
36-
};
37-
3829
struct DeviceInfo {
3930
/// The pid of the device associated to this device
4031
pid_t pid;
@@ -57,8 +48,8 @@ struct DeviceInfo {
5748
bool active;
5849
/// Whether the device is ready to quit.
5950
bool readyToQuit;
60-
/// Index for a particular release.
61-
DataRelayerViewIndex dataRelayerViewIndex;
51+
/// Index for a particular relayer.
52+
Metric2DViewIndex dataRelayerViewIndex;
6253
};
6354

6455
} // namespace framework
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
#ifndef o2_framework_Metric2DViewInfo_H_INCLUDED
11+
#define o2_framework_Metric2DViewInfo_H_INCLUDED
12+
13+
#include <functional>
14+
#include <cstddef>
15+
#include <string>
16+
#include <vector>
17+
18+
namespace o2
19+
{
20+
namespace framework
21+
{
22+
23+
struct MetricInfo;
24+
25+
/// This allows keeping track of the metrics which should be grouped together
26+
/// in some sort of 2D representation.
27+
struct Metric2DViewIndex {
28+
using Updater = std::function<void(std::string const&, MetricInfo const&, int)>;
29+
/// The prefix in the metrics store to be used for the view
30+
std::string prefix;
31+
/// The size in X of the metrics
32+
int w = 0;
33+
/// The size in Y of the metrics
34+
int h = 0;
35+
/// The row major list of indices for the metrics which compose the 2D view
36+
std::vector<std::size_t> indexes = {};
37+
/// Whether or not the view is ready to be used.
38+
bool isComplete() const { return (w * h) != 0; }
39+
40+
static Updater getUpdater(Metric2DViewIndex& view);
41+
};
42+
43+
} // namespace framework
44+
} // namespace o2
45+
46+
#endif // o2_framework_Metric2DViewInfo_H_INCLUDED
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#include "Framework/Metric2DViewIndex.h"
12+
13+
#include "Framework/DeviceMetricsInfo.h"
14+
15+
#include <fairmq/FairMQLogger.h>
16+
17+
#include <algorithm>
18+
#include <functional>
19+
20+
namespace o2
21+
{
22+
namespace framework
23+
{
24+
25+
Metric2DViewIndex::Updater Metric2DViewIndex::getUpdater(Metric2DViewIndex& view)
26+
{
27+
return [&view](std::string const& name, MetricInfo const& metric, int value) -> void {
28+
if (view.prefix.size() > name.size()) {
29+
return;
30+
}
31+
if (std::mismatch(view.prefix.begin(), view.prefix.end(), name.begin()).first != view.prefix.end()) {
32+
return;
33+
}
34+
35+
auto extra = name;
36+
37+
// +1 is to remove the /
38+
extra.erase(0, view.prefix.size() + 1);
39+
if (extra == "w") {
40+
view.w = value;
41+
view.indexes.resize(view.w * view.h);
42+
return;
43+
} else if (extra == "h") {
44+
view.h = value;
45+
view.indexes.resize(view.w * view.h);
46+
return;
47+
}
48+
int idx = -1;
49+
try {
50+
idx = std::stoi(extra, nullptr, 10);
51+
} catch (...) {
52+
LOG(ERROR) << "Badly formatted metric";
53+
}
54+
if (idx < 0) {
55+
LOG(ERROR) << "Negative metric";
56+
return;
57+
}
58+
if (view.indexes.size() <= idx) {
59+
view.indexes.resize(std::max(idx + 1, view.w * view.h));
60+
}
61+
view.indexes[idx] = metric.storeIdx;
62+
};
63+
}
64+
65+
} // namespace framework
66+
} // namespace o2

Framework/Core/src/runDataProcessing.cxx

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,6 @@ static void handle_sigint(int) { graceful_exit = true; }
288288

289289
static void handle_sigchld(int) { sigchld_requested = true; }
290290

291-
bool startsWith(std::string mainStr, std::string toMatch)
292-
{
293-
if (mainStr.find(toMatch) == 0) {
294-
return true;
295-
} else {
296-
return false;
297-
}
298-
}
299291

300292
/// This will start a new device by forking and executing a
301293
/// new child
@@ -354,7 +346,7 @@ void spawnDevice(DeviceSpec const& spec, std::map<int, size_t>& socket2DeviceInf
354346
info.historySize = 1000;
355347
info.historyPos = 0;
356348
info.maxLogLevel = LogParsingHelpers::LogLevel::Debug;
357-
info.dataRelayerViewIndex = DataRelayerViewIndex{ 0, 0, {} };
349+
info.dataRelayerViewIndex = Metric2DViewIndex{ "data_relayer", 0, 0, {} };
358350

359351
socket2DeviceInfo.insert(std::make_pair(childstdout[0], deviceInfos.size()));
360352
socket2DeviceInfo.insert(std::make_pair(childstderr[0], deviceInfos.size()));
@@ -371,8 +363,6 @@ void spawnDevice(DeviceSpec const& spec, std::map<int, size_t>& socket2DeviceInf
371363
void processChildrenOutput(DriverInfo& driverInfo, DeviceInfos& infos, DeviceSpecs const& specs,
372364
DeviceControls& controls, std::vector<DeviceMetricsInfo>& metricsInfos)
373365
{
374-
static const char* DATA_RELAYER_METRIC_PREFIX = "data_relayer";
375-
static const size_t DATA_RELAYER_METRIC_PREFIX_SIZE = std::strlen(DATA_RELAYER_METRIC_PREFIX);
376366
// Wait for children to say something. When they do
377367
// print it.
378368
fd_set fdset;
@@ -426,39 +416,7 @@ void processChildrenOutput(DriverInfo& driverInfo, DeviceInfos& infos, DeviceSpe
426416
info.history.resize(info.historySize);
427417
info.historyLevel.resize(info.historySize);
428418

429-
auto& view = info.dataRelayerViewIndex;
430-
auto updateDataRelayerViewIndex = [&view](std::string const& name, MetricInfo const& metric, int value) {
431-
if (startsWith(name, DATA_RELAYER_METRIC_PREFIX) == false) {
432-
return;
433-
}
434-
auto extra = name;
435-
436-
// +1 is to remove the /
437-
extra.erase(0, DATA_RELAYER_METRIC_PREFIX_SIZE + 1);
438-
if (extra == "w") {
439-
view.w = value;
440-
view.indexes.resize(view.w * view.h);
441-
return;
442-
} else if (extra == "h") {
443-
view.h = value;
444-
view.indexes.resize(view.w * view.h);
445-
return;
446-
}
447-
int idx = -1;
448-
try {
449-
idx = std::stoi(extra, nullptr, 10);
450-
} catch (...) {
451-
LOG(ERROR) << "Badly formatted metric" << std::endl;
452-
}
453-
if (idx < 0) {
454-
LOG(ERROR) << "Negative metric" << std::endl;
455-
return;
456-
}
457-
if (view.indexes.size() <= idx) {
458-
view.indexes.resize(std::max(idx + 1, view.w * view.h));
459-
}
460-
view.indexes[idx] = metric.storeIdx;
461-
};
419+
auto updateDataRelayerViewIndex = Metric2DViewIndex::getUpdater(info.dataRelayerViewIndex);
462420

463421
while ((pos = s.find(delimiter)) != std::string::npos) {
464422
token = s.substr(0, pos);

Framework/Core/test/test_GUITests.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ BOOST_AUTO_TEST_CASE(HeatmapTest)
6666
DeviceInfo deviceInfo;
6767
DeviceInfo deviceInfo2;
6868
deviceInfo2.dataRelayerViewIndex = {
69+
"data_relayer",
6970
1,
7071
1,
7172
{ 0 }
@@ -174,7 +175,7 @@ BOOST_AUTO_TEST_CASE(DevicesGraph)
174175
{},
175176
true,
176177
false,
177-
0 });
178+
Metric2DViewIndex{}});
178179

179180
std::vector<DeviceControl> controls;
180181
controls.push_back(

0 commit comments

Comments
 (0)