Skip to content

Commit dca327a

Browse files
committed
DPL GUI: add buttons to debug / profile the driver
1 parent b82cdda commit dca327a

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

Framework/Core/src/FrameworkGUIDebugger.cxx

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88
// granted to it by virtue of its status as an Intergovernmental Organization
99
// or submit itself to any jurisdiction.
1010
#include "Framework/FrameworkGUIDebugger.h"
11-
#include <algorithm>
12-
#include <iostream>
13-
#include <set>
14-
#include <string>
15-
#include <cinttypes>
1611
#include "Framework/ConfigContext.h"
1712
#include "Framework/ConfigParamRegistry.h"
1813
#include "DebugGUI/imgui.h"
@@ -26,6 +21,14 @@
2621
#include "Framework/PaletteHelpers.h"
2722
#include "Framework/FrameworkGUIState.h"
2823

24+
#include <fmt/format.h>
25+
26+
#include <algorithm>
27+
#include <iostream>
28+
#include <set>
29+
#include <string>
30+
#include <cinttypes>
31+
2932
// Simplify debugging
3033
template class std::vector<o2::framework::DeviceMetricsInfo>;
3134

@@ -734,6 +737,42 @@ void displayDriverInfo(DriverInfo const& driverInfo, DriverControl& driverContro
734737
if (ImGui::Button("SIGCONT all children")) {
735738
kill(0, SIGCONT);
736739
}
740+
ImGui::SameLine();
741+
if (ImGui::Button("Debug driver")) {
742+
std::string pidStr = std::to_string(pid);
743+
setenv("O2DEBUGGEDPID", pidStr.c_str(), 1);
744+
#ifdef __APPLE__
745+
std::string defaultAppleDebugCommand =
746+
"osascript -e 'tell application \"Terminal\" to activate'"
747+
" -e 'tell application \"Terminal\" to do script \"lldb -p \" & (system attribute \"O2DEBUGGEDPID\")'";
748+
setenv("O2DPLDEBUG", defaultAppleDebugCommand.c_str(), 0);
749+
#else
750+
setenv("O2DPLDEBUG", "xterm -hold -e gdb attach $O2DEBUGGEDPID &", 0);
751+
#endif
752+
int retVal = system(getenv("O2DPLDEBUG"));
753+
(void)retVal;
754+
}
755+
756+
ImGui::SameLine();
757+
if (ImGui::Button("Profile")) {
758+
std::string pidStr = std::to_string(pid);
759+
setenv("O2PROFILEDPID", pidStr.c_str(), 1);
760+
#ifdef __APPLE__
761+
auto defaultAppleProfileCommand = fmt::format(
762+
"osascript -e 'tell application \"Terminal\" to activate'"
763+
" -e 'tell application \"Terminal\" to do script \"xcrun xctrace record --output dpl-profile-{}.trace"
764+
" --time-limit 30s --template Time\\\\ Profiler --attach {} "
765+
" && open dpl-profile-{}.trace && exit\"'"
766+
" && open dpl-driver-profile-{}.trace",
767+
pid, pid, pid, pid);
768+
std::cout << defaultAppleProfileCommand << std::endl;
769+
setenv("O2DPLPROFILE", defaultAppleProfileCommand.c_str(), 0);
770+
#else
771+
setenv("O2DPLPROFILE", "xterm -hold -e perf record -a -g -p $O2PROFILEDPID > perf-$O2PROFILEDPID.data &", 0);
772+
#endif
773+
int retVal = system(getenv("O2DPLPROFILE"));
774+
(void)retVal;
775+
}
737776

738777
for (size_t i = 0; i < driverInfo.states.size(); ++i) {
739778
ImGui::Text("#%lu: %s", i, DriverHelper::stateToString(driverInfo.states[i]));

0 commit comments

Comments
 (0)