Skip to content

Commit dd9cf40

Browse files
MrCirdoBenBEExplorer09
committed
Add backtrace screen
Co-authored-by: Benny Baumann <[email protected]> Co-authored-by: Kang-Che Sung <[email protected]>
1 parent 0837e92 commit dd9cf40

File tree

6 files changed

+841
-0
lines changed

6 files changed

+841
-0
lines changed

Action.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ in the source distribution for its full text.
2727
#include "ListItem.h"
2828
#include "Macros.h"
2929
#include "MainPanel.h"
30+
#include "Object.h"
3031
#include "OpenFilesScreen.h"
32+
#include "Panel.h"
3133
#include "Process.h"
3234
#include "ProcessLocksScreen.h"
3335
#include "ProvideCurses.h"
@@ -47,6 +49,10 @@ in the source distribution for its full text.
4749
#include "AffinityPanel.h"
4850
#endif
4951

52+
#if defined(HAVE_BACKTRACE_SCREEN)
53+
#include "BacktraceScreen.h"
54+
#endif
55+
5056

5157
Object* Action_pickFromVector(State* st, Panel* list, int x, bool follow) {
5258
MainPanel* mainPanel = st->mainPanel;
@@ -604,6 +610,35 @@ static Htop_Reaction actionShowLocks(State* st) {
604610
return HTOP_REFRESH | HTOP_REDRAW_BAR;
605611
}
606612

613+
#if defined(HAVE_BACKTRACE_SCREEN)
614+
static Htop_Reaction actionBacktrace(State *st) {
615+
Process* selectedProcess = (Process *) Panel_getSelected((Panel *)st->mainPanel);
616+
const Vector* allProcesses = st->mainPanel->super.items;
617+
618+
Vector* processes = Vector_new(Class(Process), false, VECTOR_DEFAULT_SIZE);
619+
if (!Process_isUserlandThread(selectedProcess)) {
620+
for (int i = 0; i < Vector_size(allProcesses); i++) {
621+
Process* process = (Process *)Vector_get(allProcesses, i);
622+
if (Process_getThreadGroup(process) == Process_getThreadGroup(selectedProcess)) {
623+
Vector_add(processes, process);
624+
}
625+
}
626+
} else {
627+
Vector_add(processes, selectedProcess);
628+
}
629+
630+
BacktracePanel* panel = BacktracePanel_new(processes, st->host->settings);
631+
ScreenManager* screenManager = ScreenManager_new(NULL, st->host, st, false);
632+
ScreenManager_add(screenManager, (Panel *)panel, 0);
633+
634+
ScreenManager_run(screenManager, NULL, NULL, NULL);
635+
BacktracePanel_delete((Object *)panel);
636+
ScreenManager_delete(screenManager);
637+
638+
return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
639+
}
640+
#endif
641+
607642
static Htop_Reaction actionStrace(State* st) {
608643
if (!Action_writeableProcess(st))
609644
return HTOP_OK;
@@ -687,6 +722,9 @@ static const struct {
687722
{ .key = " F8 [: ", .roInactive = true, .info = "lower priority (+ nice)" },
688723
#if (defined(HAVE_LIBHWLOC) || defined(HAVE_AFFINITY))
689724
{ .key = " a: ", .roInactive = true, .info = "set CPU affinity" },
725+
#endif
726+
#if defined(HAVE_BACKTRACE_SCREEN)
727+
{ .key = " b: ", .roInactive = false, .info = "show process backtrace" },
690728
#endif
691729
{ .key = " e: ", .roInactive = false, .info = "show process environment" },
692730
{ .key = " i: ", .roInactive = true, .info = "set IO priority" },
@@ -931,6 +969,9 @@ void Action_setBindings(Htop_Action* keys) {
931969
keys['\\'] = actionIncFilter;
932970
keys[']'] = actionHigherPriority;
933971
keys['a'] = actionSetAffinity;
972+
#if defined(HAVE_BACKTRACE_SCREEN)
973+
keys['b'] = actionBacktrace;
974+
#endif
934975
keys['c'] = actionTagAllChildren;
935976
keys['e'] = actionShowEnvScreen;
936977
keys['h'] = actionHelp;

0 commit comments

Comments
 (0)