-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathFrameworkGUIDebugger.cxx
More file actions
790 lines (726 loc) · 28.6 KB
/
FrameworkGUIDebugger.cxx
File metadata and controls
790 lines (726 loc) · 28.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// 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.
#include "Framework/FrameworkGUIDebugger.h"
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <cinttypes>
#include "Framework/ConfigContext.h"
#include "Framework/ConfigParamRegistry.h"
#include "DebugGUI/imgui.h"
#include "DebugGUI/imgui_extras.h"
#include "DriverControl.cxx"
#include "DriverInfo.cxx"
#include "FrameworkGUIDeviceInspector.h"
#include "Framework/FrameworkGUIDevicesGraph.h"
#include "Framework/FrameworkGUIDataRelayerUsage.h"
#include "Framework/PaletteHelpers.h"
#include "Framework/FrameworkGUIState.h"
// Simplify debugging
template class std::vector<o2::framework::DeviceMetricsInfo>;
static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x + rhs.x, lhs.y + rhs.y); }
static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x - rhs.x, lhs.y - rhs.y); }
namespace o2
{
namespace framework
{
namespace gui
{
// Type erased information for the plotting
struct MultiplotData {
int mod;
size_t first;
size_t size;
const void* Y;
const void* X;
MetricType type;
};
} // namespace gui
} // namespace framework
} // namespace o2
template class std::vector<o2::framework::gui::MultiplotData>;
namespace o2
{
namespace framework
{
namespace gui
{
ImVec4 colorForLogLevel(LogParsingHelpers::LogLevel logLevel)
{
switch (logLevel) {
case LogParsingHelpers::LogLevel::Info:
return PaletteHelpers::GREEN;
case LogParsingHelpers::LogLevel::Debug:
return ImVec4(153. / 255, 61. / 255, 61. / 255, 255. / 255);
case LogParsingHelpers::LogLevel::Warning:
return PaletteHelpers::DARK_YELLOW;
case LogParsingHelpers::LogLevel::Error:
return PaletteHelpers::RED;
case LogParsingHelpers::LogLevel::Unknown:
return ImVec4(153. / 255, 61. / 255, 61. / 255, 255. / 255);
default:
return PaletteHelpers::WHITE;
};
}
void displayHistory(const DeviceInfo& info, DeviceControl& control)
{
if (info.history.empty()) {
return;
}
int startPos = info.historyPos;
const int historySize = info.history.size();
int triggerStartPos = startPos + 1 % historySize;
int triggerStopPos = startPos % historySize;
int j = startPos;
// We look for a stop trigger, so that we know where to stop the search for
// out start search. If no stop trigger is found, we search until the end
if (control.logStopTrigger[0]) {
while ((j % historySize) != ((startPos + 1) % historySize)) {
assert(j >= 0);
assert(j < historySize);
auto& line = info.history[j];
if (strstr(line.c_str(), control.logStopTrigger)) {
triggerStopPos = (j + 1) % historySize;
break;
}
// Wrap in case we end up below 0
j = (j == 0) ? historySize - 1 : j - 1;
}
}
// Look for the last instance of the start trigger before the
// last stop trigger.
j = startPos + 1;
if (control.logStartTrigger[0]) {
while ((j % historySize) != triggerStopPos) {
assert(historySize > j);
assert(historySize == 1000);
auto& line = info.history[j];
if (strstr(line.c_str(), control.logStartTrigger)) {
triggerStartPos = j;
}
j = (j + 1) % historySize;
}
}
// We start from the last trigger found. Eventually this is the first
// line in the ring buffer, if no trigger is specified.
size_t ji = triggerStartPos % historySize;
size_t je = triggerStopPos % historySize;
size_t iterations = 0;
while (historySize && ((ji % historySize) != je)) {
assert(iterations < historySize);
iterations++;
assert(historySize == 1000);
assert(ji < historySize);
auto& line = info.history[ji];
auto logLevel = info.historyLevel[ji];
// Skip empty lines
if (line.empty()) {
ji = (ji + 1) % historySize;
continue;
}
// Print matching lines
if (strstr(line.c_str(), control.logFilter) != nullptr) {
auto color = colorForLogLevel(logLevel);
// We filter twice, once on input, to reduce the
// stream, a second time at display time, to avoid
// showing unrelevant messages from past.
if (logLevel >= control.logLevel) {
if (line.find('%', 0) != std::string::npos) {
ImGui::TextUnformatted(line.c_str(), line.c_str() + line.size());
} else {
ImGui::TextColored(color, line.c_str(), line.c_str() + line.size());
}
}
}
ji = (ji + 1) % historySize;
}
}
template <typename T>
struct HistoData {
int mod;
size_t first;
size_t size;
const T* points;
};
enum struct MetricsDisplayStyle : int {
Lines = 0,
Histos = 1,
Sparks = 2,
Table = 3
};
void displayDeviceMetrics(const char* label, ImVec2 canvasSize, std::string const& selectedMetricName,
size_t rangeBegin, size_t rangeEnd, size_t bins, MetricsDisplayStyle displayType,
std::vector<DeviceSpec> const& specs, std::vector<DeviceMetricsInfo> const& metricsInfos)
{
static std::vector<ImColor> palette = {
ImColor{218, 124, 48},
ImColor{62, 150, 81},
ImColor{204, 37, 41},
ImColor{83, 81, 84},
ImColor{107, 76, 154},
ImColor{146, 36, 40},
ImColor{148, 139, 61}};
std::vector<void const*> metricsToDisplay;
std::vector<const char*> deviceNames;
std::vector<MultiplotData> userData;
std::vector<ImColor> colors;
MetricType metricType;
size_t metricSize = 0;
assert(specs.size() == metricsInfos.size());
float maxValue = std::numeric_limits<float>::lowest();
float minValue = 0;
size_t maxDomain = std::numeric_limits<size_t>::lowest();
size_t minDomain = std::numeric_limits<size_t>::max();
for (int mi = 0; mi < metricsInfos.size(); ++mi) {
auto vi = DeviceMetricsHelper::metricIdxByName(selectedMetricName, metricsInfos[mi]);
if (vi == metricsInfos[mi].metricLabelsIdx.size()) {
continue;
}
auto& metric = metricsInfos[mi].metrics[vi];
deviceNames.push_back(specs[mi].name.c_str());
colors.push_back(palette[mi % palette.size()]);
metricType = metric.type;
MultiplotData data;
data.mod = metricsInfos[mi].timestamps[vi].size();
data.first = metric.pos - data.mod;
data.X = metricsInfos[mi].timestamps[vi].data();
minValue = std::min(minValue, metricsInfos[mi].min[vi]);
maxValue = std::max(maxValue, metricsInfos[mi].max[vi]);
minDomain = std::min(minDomain, metricsInfos[mi].minDomain[vi]);
maxDomain = std::max(maxDomain, metricsInfos[mi].maxDomain[vi]);
switch (metric.type) {
case MetricType::Int: {
data.size = metricsInfos[mi].intMetrics[metric.storeIdx].size();
data.Y = metricsInfos[mi].intMetrics[metric.storeIdx].data();
data.type = MetricType::Int;
metricType = MetricType::Int;
metricSize = metricsInfos[mi].intMetrics[metric.storeIdx].size();
} break;
case MetricType::Uint64: {
data.size = metricsInfos[mi].uint64Metrics[metric.storeIdx].size();
data.Y = metricsInfos[mi].uint64Metrics[metric.storeIdx].data();
data.type = MetricType::Uint64;
metricType = MetricType::Uint64;
metricSize = metricsInfos[mi].uint64Metrics[metric.storeIdx].size();
} break;
case MetricType::Float: {
data.size = metricsInfos[mi].floatMetrics[metric.storeIdx].size();
data.Y = metricsInfos[mi].floatMetrics[metric.storeIdx].data();
data.type = MetricType::Float;
metricType = MetricType::Float;
metricSize = metricsInfos[mi].floatMetrics[metric.storeIdx].size();
} break;
case MetricType::Unknown:
case MetricType::String: {
data.size = metricsInfos[mi].stringMetrics[metric.storeIdx].size();
data.Y = nullptr;
data.type = MetricType::String;
metricType = MetricType::String;
metricSize = metricsInfos[mi].stringMetrics[metric.storeIdx].size();
} break;
}
userData.emplace_back(data);
}
maxDomain = std::max(minDomain + 1024, maxDomain);
for (size_t ui = 0; ui < userData.size(); ++ui) {
metricsToDisplay.push_back(&(userData[ui]));
}
auto getterY = [](const void* hData, int idx) -> float {
auto histoData = reinterpret_cast<const MultiplotData*>(hData);
size_t pos = (histoData->first + static_cast<size_t>(idx)) % histoData->mod;
// size_t pos = (static_cast<size_t>(idx)) % histoData->mod;
assert(pos >= 0 && pos < 1024);
if (histoData->type == MetricType::Int) {
return static_cast<const int*>(histoData->Y)[pos];
} else if (histoData->type == MetricType::Uint64) {
return static_cast<const uint64_t*>(histoData->Y)[pos];
} else if (histoData->type == MetricType::Float) {
return static_cast<const float*>(histoData->Y)[pos];
} else {
return 0;
}
};
auto getterX = [](const void* hData, int idx) -> size_t {
auto histoData = reinterpret_cast<const MultiplotData*>(hData);
size_t pos = (histoData->first + static_cast<size_t>(idx)) % histoData->mod;
//size_t pos = (static_cast<size_t>(idx)) % histoData->mod;
assert(pos >= 0 && pos < 1024);
return static_cast<const size_t*>(histoData->X)[pos];
};
switch (displayType) {
case MetricsDisplayStyle::Histos:
ImGui::PlotMultiHistograms(
label,
userData.size(),
deviceNames.data(),
colors.data(),
getterY,
getterX,
metricsToDisplay.data(),
metricSize,
minValue,
maxValue * 1.2f,
minDomain,
maxDomain,
canvasSize);
break;
case MetricsDisplayStyle::Lines:
ImGui::PlotMultiLines(
label,
userData.size(),
deviceNames.data(),
colors.data(),
getterY,
getterX,
metricsToDisplay.data(),
metricSize,
minValue,
maxValue * 1.2f,
minDomain,
maxDomain,
canvasSize);
break;
default:
break;
}
}
struct ColumnInfo {
MetricType type;
int index;
};
void metricsTableRow(std::vector<ColumnInfo> columnInfos,
std::vector<DeviceMetricsInfo> const& metricsInfos,
int row)
{
ImGui::Text("%d", row);
ImGui::NextColumn();
for (size_t j = 0; j < columnInfos.size(); j++) {
auto& info = columnInfos[j];
auto& metricsInfo = metricsInfos[j];
if (info.index == -1) {
ImGui::TextUnformatted("-");
ImGui::NextColumn();
continue;
}
switch (info.type) {
case MetricType::Int: {
ImGui::Text("%i (%i)", metricsInfo.intMetrics[info.index][row], info.index);
ImGui::NextColumn();
} break;
case MetricType::Uint64: {
ImGui::Text("%" PRIu64 " (%i)", metricsInfo.uint64Metrics[info.index][row], info.index);
ImGui::NextColumn();
} break;
case MetricType::Float: {
ImGui::Text("%f (%i)", metricsInfo.floatMetrics[info.index][row], info.index);
ImGui::NextColumn();
} break;
case MetricType::String: {
ImGui::Text("%s (%i)", metricsInfo.stringMetrics[info.index][row].data, info.index);
ImGui::NextColumn();
} break;
default:
ImGui::NextColumn();
break;
}
}
}
void historyBar(gui::WorkspaceGUIState& globalGUIState,
size_t rangeBegin, size_t rangeEnd,
gui::DeviceGUIState& state,
DriverInfo const& driverInfo,
DeviceSpec const& spec,
DeviceMetricsInfo const& metricsInfo)
{
bool open = ImGui::TreeNode(state.label.c_str());
if (open) {
ImGui::Text("# channels: %lu", spec.outputChannels.size() + spec.inputChannels.size());
ImGui::TreePop();
}
ImGui::NextColumn();
if (globalGUIState.selectedMetric == -1) {
ImGui::NextColumn();
return;
}
auto currentMetricName = driverInfo.availableMetrics[globalGUIState.selectedMetric];
size_t i = DeviceMetricsHelper::metricIdxByName(currentMetricName, metricsInfo);
// We did not find any plot, skipping this.
if (i == metricsInfo.metricLabelsIdx.size()) {
ImGui::NextColumn();
return;
}
auto& metric = metricsInfo.metrics[i];
switch (metric.type) {
case MetricType::Int: {
HistoData<int> data;
data.mod = metricsInfo.timestamps[i].size();
data.first = metric.pos - data.mod;
data.size = metricsInfo.intMetrics[metric.storeIdx].size();
data.points = metricsInfo.intMetrics[metric.storeIdx].data();
auto getter = [](void* hData, int idx) -> float {
auto histoData = reinterpret_cast<HistoData<int>*>(hData);
size_t pos = (histoData->first + static_cast<size_t>(idx)) % histoData->mod;
assert(pos >= 0 && pos < 1024);
return histoData->points[pos];
};
ImGui::PlotLines(("##" + currentMetricName).c_str(), getter, &data, data.size);
ImGui::NextColumn();
} break;
case MetricType::Uint64: {
HistoData<uint64_t> data;
data.mod = metricsInfo.timestamps[i].size();
data.first = metric.pos - data.mod;
data.size = metricsInfo.uint64Metrics[metric.storeIdx].size();
data.points = metricsInfo.uint64Metrics[metric.storeIdx].data();
auto getter = [](void* hData, int idx) -> float {
auto histoData = reinterpret_cast<HistoData<uint64_t>*>(hData);
size_t pos = (histoData->first + static_cast<size_t>(idx)) % histoData->mod;
assert(pos >= 0 && pos < 1024);
return histoData->points[pos];
};
ImGui::PlotLines(("##" + currentMetricName).c_str(), getter, &data, data.size);
ImGui::NextColumn();
} break;
case MetricType::Float: {
HistoData<float> data;
data.mod = metricsInfo.timestamps[i].size();
data.first = metric.pos - data.mod;
data.size = metricsInfo.floatMetrics[metric.storeIdx].size();
data.points = metricsInfo.floatMetrics[metric.storeIdx].data();
auto getter = [](void* hData, int idx) -> float {
auto histoData = reinterpret_cast<HistoData<float>*>(hData);
size_t pos = (histoData->first + static_cast<size_t>(idx)) % histoData->mod;
assert(pos >= 0 && pos < 1024);
return histoData->points[pos];
};
ImGui::PlotLines(("##" + currentMetricName).c_str(), getter, &data, data.size);
ImGui::NextColumn();
} break;
default:
ImGui::NextColumn();
return;
break;
}
}
/// Calculate where to find the coliumns for a give metric
std::vector<ColumnInfo> calculateTableIndex(gui::WorkspaceGUIState& globalGUIState,
int selectedMetric,
DriverInfo const& driverInfo,
std::vector<DeviceMetricsInfo> const& metricsInfos)
{
std::vector<ColumnInfo> columns;
for (size_t j = 0; j < globalGUIState.devices.size(); ++j) {
const DeviceMetricsInfo& metricsInfo = metricsInfos[j];
/// Nothing to draw, if no metric selected.
if (selectedMetric == -1) {
columns.push_back({MetricType::Int, -1});
continue;
}
auto currentMetricName = driverInfo.availableMetrics[selectedMetric];
size_t idx = DeviceMetricsHelper::metricIdxByName(currentMetricName, metricsInfo);
// We did not find any plot, skipping this.
if (idx == metricsInfo.metricLabelsIdx.size()) {
columns.push_back({MetricType::Int, -1});
continue;
}
auto metric = metricsInfos[j].metrics[idx];
columns.push_back({metric.type, static_cast<int>(metric.storeIdx)});
}
return columns;
};
void displayDeviceHistograms(gui::WorkspaceGUIState& state,
DriverInfo const& driverInfo,
std::vector<DeviceInfo> const& infos,
std::vector<DeviceSpec> const& devices,
std::vector<DataProcessorInfo> const& metadata,
std::vector<DeviceControl>& controls,
std::vector<DeviceMetricsInfo> const& metricsInfos)
{
showTopologyNodeGraph(state, infos, devices, metadata, controls, metricsInfos);
if (state.bottomPaneVisible == false) {
return;
}
ImGui::SetNextWindowPos(ImVec2(0, ImGui::GetIO().DisplaySize.y - state.bottomPaneSize), 0);
ImGui::SetNextWindowSize(ImVec2(ImGui::GetIO().DisplaySize.x, state.bottomPaneSize), 0);
ImGui::Begin("Devices", nullptr, ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);
ImGui::BeginGroup();
char const* currentMetric = nullptr;
if (state.selectedMetric != -1) {
currentMetric = driverInfo.availableMetrics[state.selectedMetric].c_str();
} else {
currentMetric = "Click to select metric";
}
if (ImGui::BeginCombo("###Select metric", currentMetric, 0)) {
for (size_t mi = 0; mi < driverInfo.availableMetrics.size(); ++mi) {
auto metric = driverInfo.availableMetrics[mi];
bool isSelected = mi == state.selectedMetric;
if (ImGui::Selectable(driverInfo.availableMetrics[mi].c_str(), isSelected)) {
state.selectedMetric = mi;
}
if (isSelected) {
ImGui::SetItemDefaultFocus();
}
}
ImGui::EndCombo();
};
static char const* plotStyles[] = {
"lines",
"histograms",
"sparks",
"table"};
ImGui::SameLine();
static enum MetricsDisplayStyle currentStyle = MetricsDisplayStyle::Lines;
ImGui::Combo("##Select style", reinterpret_cast<int*>(¤tStyle), plotStyles, IM_ARRAYSIZE(plotStyles));
// Calculate the full timestamp range for the selected metric
size_t minTime = -1;
size_t maxTime = 0;
std::string currentMetricName;
if (state.selectedMetric >= 0) {
currentMetricName = driverInfo.availableMetrics[state.selectedMetric];
for (auto& metricInfo : metricsInfos) {
size_t mi = DeviceMetricsHelper::metricIdxByName(currentMetricName, metricInfo);
if (mi == metricInfo.metricLabelsIdx.size()) {
continue;
}
auto& metric = metricInfo.metrics[mi];
auto& timestamps = metricInfo.timestamps[mi];
for (size_t ti = 0; ti != metricInfo.timestamps.size(); ++ti) {
size_t minRangePos = (metric.pos + ti) % metricInfo.timestamps.size();
size_t curMinTime = timestamps[minRangePos];
if (curMinTime == 0) {
continue;
}
minTime = minTime < curMinTime ? minTime : curMinTime;
if (minTime != 0 && minTime != -1) {
break;
}
}
size_t maxRangePos = (size_t)(metric.pos) - 1 % metricInfo.timestamps.size();
size_t curMaxTime = timestamps[maxRangePos];
maxTime = maxTime > curMaxTime ? maxTime : curMaxTime;
}
}
if (minTime != -1) {
ImGui::Text("min timestamp: %zu, max timestamp: %zu", minTime, maxTime);
}
ImGui::EndGroup();
if (!currentMetricName.empty()) {
switch (currentStyle) {
case MetricsDisplayStyle::Histos:
case MetricsDisplayStyle::Lines: {
displayDeviceMetrics("Metrics",
ImVec2(ImGui::GetIO().DisplaySize.x - 10, state.bottomPaneSize - ImGui::GetItemRectSize().y - 20), currentMetricName, minTime, maxTime, 1024,
currentStyle, devices, metricsInfos);
} break;
case MetricsDisplayStyle::Sparks: {
ImGui::BeginChild("##ScrollingRegion", ImVec2(ImGui::GetIO().DisplaySize.x + state.leftPaneSize + state.rightPaneSize - 10, -ImGui::GetItemsLineHeightWithSpacing()), false,
ImGuiWindowFlags_HorizontalScrollbar);
ImGui::Columns(2);
ImGui::SetColumnOffset(1, 300);
for (size_t i = 0; i < state.devices.size(); ++i) {
gui::DeviceGUIState& deviceGUIState = state.devices[i];
const DeviceSpec& spec = devices[i];
const DeviceMetricsInfo& metricsInfo = metricsInfos[i];
historyBar(state, minTime, maxTime, deviceGUIState, driverInfo, spec, metricsInfo);
}
ImGui::Columns(1);
ImGui::EndChild();
} break;
case MetricsDisplayStyle::Table: {
ImGui::BeginChild("##ScrollingRegion", ImVec2(ImGui::GetIO().DisplaySize.x + state.leftPaneSize + state.rightPaneSize - 10, -ImGui::GetItemsLineHeightWithSpacing()), false,
ImGuiWindowFlags_HorizontalScrollbar);
// The +1 is for the timestamp column
ImGui::Columns(state.devices.size() + 1);
ImGui::TextUnformatted("entry");
ImGui::NextColumn();
ImVec2 textsize = ImGui::CalcTextSize("extry", nullptr, true);
float offset = 0.f;
offset += std::max(100.f, textsize.x);
for (size_t j = 0; j < state.devices.size(); ++j) {
gui::DeviceGUIState& deviceGUIState = state.devices[j];
const DeviceSpec& spec = devices[j];
ImGui::SetColumnOffset(-1, offset);
textsize = ImGui::CalcTextSize(spec.name.c_str(), nullptr, true);
offset += std::max(100.f, textsize.x);
ImGui::TextUnformatted(spec.name.c_str());
ImGui::NextColumn();
}
ImGui::Separator();
auto columns = calculateTableIndex(state, state.selectedMetric, driverInfo, metricsInfos);
// Calculate which columns we want to see.
// FIXME: only one column for now.
for (size_t i = 0; i < 10; ++i) {
metricsTableRow(columns, metricsInfos, i);
}
ImGui::Columns(1);
ImGui::EndChild();
} break;
}
}
ImGui::End();
}
void pushWindowColorDueToStatus(const DeviceInfo& info)
{
using LogLevel = LogParsingHelpers::LogLevel;
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 4.);
if (info.active == false) {
ImGui::PushStyleColor(ImGuiCol_TitleBg, PaletteHelpers::DARK_RED);
ImGui::PushStyleColor(ImGuiCol_TitleBgActive, PaletteHelpers::RED);
ImGui::PushStyleColor(ImGuiCol_TitleBgCollapsed, PaletteHelpers::RED);
return;
}
switch (info.maxLogLevel) {
case LogLevel::Error:
ImGui::PushStyleColor(ImGuiCol_TitleBg, PaletteHelpers::SHADED_RED);
ImGui::PushStyleColor(ImGuiCol_TitleBgActive, PaletteHelpers::RED);
ImGui::PushStyleColor(ImGuiCol_TitleBgCollapsed, PaletteHelpers::SHADED_RED);
break;
case LogLevel::Warning:
ImGui::PushStyleColor(ImGuiCol_TitleBg, PaletteHelpers::SHADED_YELLOW);
ImGui::PushStyleColor(ImGuiCol_TitleBgActive, PaletteHelpers::YELLOW);
ImGui::PushStyleColor(ImGuiCol_TitleBgCollapsed, PaletteHelpers::SHADED_YELLOW);
break;
case LogLevel::Info:
ImGui::PushStyleColor(ImGuiCol_TitleBg, PaletteHelpers::SHADED_GREEN);
ImGui::PushStyleColor(ImGuiCol_TitleBgActive, PaletteHelpers::GREEN);
ImGui::PushStyleColor(ImGuiCol_TitleBgCollapsed, PaletteHelpers::SHADED_GREEN);
break;
default:
ImGui::PushStyleColor(ImGuiCol_TitleBg, PaletteHelpers::SHADED_BLUE);
ImGui::PushStyleColor(ImGuiCol_TitleBgActive, PaletteHelpers::BLUE);
ImGui::PushStyleColor(ImGuiCol_TitleBgCollapsed, PaletteHelpers::SHADED_BLUE);
break;
}
}
void popWindowColorDueToStatus()
{
ImGui::PopStyleColor(3);
ImGui::PopStyleVar(1);
}
struct DriverHelper {
static char const* stateToString(enum DriverState state)
{
static const char* names[static_cast<int>(DriverState::LAST)] = {
"INIT", //
"SCHEDULE", //
"RUNNING", //
"GUI", //
"REDEPLOY_GUI", //
"QUIT_REQUESTED", //
"HANDLE_CHILDREN", //
"EXIT", //
"UNKNOWN" //
"PERFORM_CALLBACKS" //
};
return names[static_cast<int>(state)];
}
};
/// Display information window about the driver
/// and its state.
void displayDriverInfo(DriverInfo const& driverInfo, DriverControl& driverControl)
{
ImGui::Begin("Driver information");
if (driverControl.state == DriverControlState::STEP) {
driverControl.state = DriverControlState::PAUSE;
}
auto state = reinterpret_cast<int*>(&driverControl.state);
ImGui::RadioButton("Play", state, static_cast<int>(DriverControlState::PLAY));
ImGui::SameLine();
ImGui::RadioButton("Pause", state, static_cast<int>(DriverControlState::PAUSE));
ImGui::SameLine();
ImGui::RadioButton("Step", state, static_cast<int>(DriverControlState::STEP));
auto& registry = driverInfo.configContext->options();
ImGui::Columns();
ImGui::Text("Frame cost (latency): %.1f(%.1f)ms", driverInfo.frameCost, driverInfo.frameLatency);
ImGui::Text("Input parsing cost (latency): %.1f(%.1f)ms", driverInfo.inputProcessingCost, driverInfo.inputProcessingLatency);
ImGui::Text("State stack (depth %lu)", driverInfo.states.size());
if (ImGui::Button("SIGCONT all children")) {
kill(0, SIGCONT);
}
for (size_t i = 0; i < driverInfo.states.size(); ++i) {
ImGui::Text("#%lu: %s", i, DriverHelper::stateToString(driverInfo.states[i]));
}
ImGui::End();
}
// FIXME: return empty function in case we were not built
// with GLFW support.
///
std::function<void(void)> getGUIDebugger(std::vector<DeviceInfo> const& infos,
std::vector<DeviceSpec> const& devices,
std::vector<DataProcessorInfo> const& metadata,
std::vector<DeviceMetricsInfo> const& metricsInfos,
DriverInfo const& driverInfo,
std::vector<DeviceControl>& controls,
DriverControl& driverControl)
{
static gui::WorkspaceGUIState globalGUIState;
gui::WorkspaceGUIState& guiState = globalGUIState;
guiState.selectedMetric = -1;
guiState.metricMaxRange = 0UL;
guiState.metricMinRange = -1;
// FIXME: this should probaly have a better mapping between our window state and
guiState.devices.resize(infos.size());
for (size_t i = 0; i < guiState.devices.size(); ++i) {
gui::DeviceGUIState& state = guiState.devices[i];
state.label = devices[i].id + "(" + std::to_string(infos[i].pid) + ")";
}
guiState.bottomPaneSize = 300;
guiState.leftPaneSize = 200;
guiState.rightPaneSize = 300;
// Show all the panes by default.
guiState.bottomPaneVisible = true;
guiState.leftPaneVisible = true;
guiState.rightPaneVisible = true;
return [&guiState, &infos, &devices, &metadata, &controls, &metricsInfos, &driverInfo, &driverControl]() {
ImGuiStyle& style = ImGui::GetStyle();
style.FrameRounding = 0.;
style.WindowRounding = 0.;
style.Colors[ImGuiCol_WindowBg] = ImVec4(0x1b / 255.f, 0x1b / 255.f, 0x1b / 255.f, 1.00f);
style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0x1b / 255.f, 0x1b / 255.f, 0x1b / 255.f, 1.00f);
displayDeviceHistograms(guiState, driverInfo, infos, devices, metadata, controls, metricsInfos);
displayDriverInfo(driverInfo, driverControl);
int windowPosStepping = (ImGui::GetIO().DisplaySize.y - 500) / guiState.devices.size();
for (size_t i = 0; i < guiState.devices.size(); ++i) {
gui::DeviceGUIState& state = guiState.devices[i];
assert(i < infos.size());
assert(i < devices.size());
const DeviceInfo& info = infos[i];
const DeviceSpec& spec = devices[i];
const DeviceMetricsInfo& metrics = metricsInfos[i];
assert(controls.size() == devices.size());
DeviceControl& control = controls[i];
pushWindowColorDueToStatus(info);
if (control.logVisible) {
ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x / 3 * 2, i * windowPosStepping), ImGuiCond_Once);
ImGui::SetNextWindowSize(ImVec2(ImGui::GetIO().DisplaySize.x / 3, ImGui::GetIO().DisplaySize.y - 300),
ImGuiCond_Once);
ImGui::Begin(state.label.c_str(), &control.logVisible);
ImGui::InputText("Log filter", control.logFilter, sizeof(control.logFilter));
ImGui::InputText("Log start trigger", control.logStartTrigger, sizeof(control.logStartTrigger));
ImGui::InputText("Log stop trigger", control.logStopTrigger, sizeof(control.logStopTrigger));
ImGui::Checkbox("Stop logging", &control.quiet);
ImGui::SameLine();
ImGui::Combo("Log level", reinterpret_cast<int*>(&control.logLevel), LogParsingHelpers::LOG_LEVELS,
(int)LogParsingHelpers::LogLevel::Size, 5);
ImGui::Separator();
ImGui::BeginChild("ScrollingRegion", ImVec2(0, -ImGui::GetItemsLineHeightWithSpacing()), false,
ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_NoMove);
displayHistory(info, control);
ImGui::EndChild();
ImGui::End();
}
popWindowColorDueToStatus();
}
};
}
} // namespace gui
} // namespace framework
} // namespace o2