summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Action.c515
-rw-r--r--Action.h17
-rw-r--r--Affinity.c71
-rw-r--r--Affinity.h22
-rw-r--r--AffinityPanel.c6
-rw-r--r--AffinityPanel.h2
-rw-r--r--AvailableColumnsPanel.c22
-rw-r--r--AvailableColumnsPanel.h7
-rw-r--r--AvailableMetersPanel.c36
-rw-r--r--AvailableMetersPanel.h6
-rw-r--r--BatteryMeter.c4
-rw-r--r--CPUMeter.c42
-rw-r--r--CRT.c826
-rw-r--r--CRT.h51
-rw-r--r--CategoriesPanel.c39
-rw-r--r--CategoriesPanel.h7
-rw-r--r--ColorsPanel.c12
-rw-r--r--ColorsPanel.h2
-rw-r--r--ColumnsPanel.c60
-rw-r--r--ColumnsPanel.h5
-rw-r--r--DisplayOptionsPanel.c32
-rw-r--r--Header.c154
-rw-r--r--Header.h38
-rw-r--r--ListItem.c11
-rw-r--r--ListItem.h1
-rw-r--r--LoadAverageMeter.c2
-rw-r--r--Makefile.am16
-rw-r--r--MemoryMeter.c19
-rw-r--r--Meter.c102
-rw-r--r--Meter.h14
-rw-r--r--MetersPanel.c72
-rw-r--r--MetersPanel.h9
-rw-r--r--Panel.c180
-rw-r--r--Panel.h11
-rw-r--r--Process.c342
-rw-r--r--Process.h46
-rw-r--r--ProcessList.c193
-rw-r--r--ProcessList.h98
-rw-r--r--ScreenManager.c135
-rw-r--r--ScreenManager.h6
-rw-r--r--Settings.c333
-rw-r--r--Settings.h45
-rw-r--r--SwapMeter.c9
-rw-r--r--TasksMeter.c33
-rw-r--r--Vector.c4
-rw-r--r--configure.ac17
-rw-r--r--htop.1.in6
-rw-r--r--htop.c721
-rw-r--r--htop.h3
-rw-r--r--linux/Battery.c292
-rw-r--r--linux/Battery.h23
-rw-r--r--linux/LinuxProcess.c42
-rw-r--r--linux/LinuxProcess.h10
-rw-r--r--linux/LinuxProcessList.c139
-rw-r--r--linux/LinuxProcessList.h56
-rw-r--r--linux/Platform.c84
-rw-r--r--linux/Platform.h10
-rwxr-xr-xscripts/MakeHeader.py2
-rw-r--r--unsupported/Platform.c6
-rw-r--r--unsupported/Platform.h4
60 files changed, 2752 insertions, 2320 deletions
diff --git a/Action.c b/Action.c
index 499422e0..f968fc4a 100644
--- a/Action.c
+++ b/Action.c
@@ -5,16 +5,37 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
-#include "Process.h"
-#include "Panel.h"
+#include "config.h"
+
#include "Action.h"
+#include "Affinity.h"
+#include "AffinityPanel.h"
+#include "CategoriesPanel.h"
+#include "CRT.h"
+#include "MainPanel.h"
+#include "OpenFilesScreen.h"
+#include "Process.h"
#include "ScreenManager.h"
+#include "SignalsPanel.h"
+#include "String.h"
+#include "TraceScreen.h"
+
+#include <ctype.h>
+#include <math.h>
+#include <pwd.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <sys/param.h>
+#include <sys/time.h>
/*{
#include "IncSet.h"
#include "Settings.h"
+#include "Header.h"
#include "UsersTable.h"
+#include "ProcessList.h"
+#include "Panel.h"
typedef enum {
HTOP_OK = 0x00,
@@ -33,51 +54,29 @@ typedef struct State_ {
IncSet* inc;
Settings* settings;
UsersTable* ut;
+ ProcessList* pl;
+ Panel* panel;
+ Header* header;
} State;
-typedef bool(*Action_ForeachProcessFn)(Process*, size_t);
-
}*/
-int Action_selectedPid(Panel* panel) {
- Process* p = (Process*) Panel_getSelected(panel);
- if (p) {
- return p->pid;
- }
- return -1;
-}
-
-bool Action_foreachProcess(Panel* panel, Action_ForeachProcessFn fn, int arg, bool* wasAnyTagged) {
- bool ok = true;
- bool anyTagged = false;
- for (int i = 0; i < Panel_size(panel); i++) {
- Process* p = (Process*) Panel_get(panel, i);
- if (p->tag) {
- ok = fn(p, arg) && ok;
- anyTagged = true;
- }
- }
- if (!anyTagged) {
- Process* p = (Process*) Panel_getSelected(panel);
- if (p) ok = fn(p, arg) && ok;
- }
- if (wasAnyTagged)
- *wasAnyTagged = anyTagged;
- return ok;
-}
-
-Object* Action_pickFromVector(Panel* panel, Panel* list, int x, const char** keyLabels, Header* header) {
+Object* Action_pickFromVector(State* st, Panel* list, int x, const char** keyLabels) {
+ Panel* panel = st->panel;
+ Header* header = st->header;
+ Settings* settings = st->settings;
+
int y = panel->y;
const char* fuKeys[] = {"Enter", "Esc", NULL};
int fuEvents[] = {13, 27};
- ScreenManager* scr = ScreenManager_new(0, y, 0, -1, HORIZONTAL, header, false);
+ ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, false);
scr->allowFocusChange = false;
ScreenManager_add(scr, list, FunctionBar_new(keyLabels, fuKeys, fuEvents), x - 1);
ScreenManager_add(scr, panel, NULL, -1);
Panel* panelFocus;
int ch;
bool unfollow = false;
- int pid = Action_selectedPid(panel);
+ int pid = MainPanel_selectedPid((MainPanel*)panel);
if (header->pl->following == -1) {
header->pl->following = pid;
unfollow = true;
@@ -98,3 +97,451 @@ Object* Action_pickFromVector(Panel* panel, Panel* list, int x, const char** key
}
return NULL;
}
+
+// ----------------------------------------
+
+static const char* CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
+
+static void Setup_run(Settings* settings, const Header* header, ProcessList* pl) {
+ ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, true);
+ CategoriesPanel* panelCategories = CategoriesPanel_new(scr, settings, (Header*) header, pl);
+ ScreenManager_add(scr, (Panel*) panelCategories, FunctionBar_new(CategoriesFunctions, NULL, NULL), 16);
+ CategoriesPanel_makeMetersPage(panelCategories);
+ Panel* panelFocus;
+ int ch;
+ ScreenManager_run(scr, &panelFocus, &ch);
+ ScreenManager_delete(scr);
+}
+
+static bool changePriority(MainPanel* panel, int delta) {
+ bool anyTagged;
+ bool ok = MainPanel_foreachProcess(panel, (MainPanel_ForeachProcessFn) Process_changePriorityBy, delta, &anyTagged);
+ if (!ok)
+ beep();
+ return anyTagged;
+}
+
+static void addUserToVector(int key, void* userCast, void* panelCast) {
+ char* user = (char*) userCast;
+ Panel* panel = (Panel*) panelCast;
+ Panel_add(panel, (Object*) ListItem_new(user, key));
+}
+
+bool Action_setUserOnly(const char* userName, uid_t* userId) {
+ struct passwd* user = getpwnam(userName);
+ if (user) {
+ *userId = user->pw_uid;
+ return true;
+ }
+ *userId = -1;
+ return false;
+}
+
+static void tagAllChildren(Panel* panel, Process* parent) {
+ parent->tag = true;
+ pid_t ppid = parent->pid;
+ for (int i = 0; i < Panel_size(panel); i++) {
+ Process* p = (Process*) Panel_get(panel, i);
+ if (!p->tag && p->ppid == ppid) {
+ tagAllChildren(panel, p);
+ }
+ }
+}
+
+static bool expandCollapse(Panel* panel) {
+ Process* p = (Process*) Panel_getSelected(panel);
+ if (!p) return false;
+ p->showChildren = !p->showChildren;
+ return true;
+}
+
+static inline Htop_Reaction setSortKey(Settings* settings, ProcessField sortKey) {
+ settings->sortKey = sortKey;
+ settings->direction = 1;
+ settings->treeView = false;
+ return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_UPDATE_PANELHDR;
+}
+
+static Htop_Reaction sortBy(State* st) {
+ Htop_Reaction reaction = HTOP_OK;
+ Panel* sortPanel = Panel_new(0, 0, 0, 0, true, Class(ListItem));
+ Panel_setHeader(sortPanel, "Sort by");
+ const char* fuFunctions[] = {"Sort ", "Cancel ", NULL};
+ ProcessField* fields = st->settings->fields;
+ for (int i = 0; fields[i]; i++) {
+ char* name = String_trim(Process_fields[fields[i]].name);
+ Panel_add(sortPanel, (Object*) ListItem_new(name, fields[i]));
+ if (fields[i] == st->settings->sortKey)
+ Panel_setSelected(sortPanel, i);
+ free(name);
+ }
+ ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15, fuFunctions);
+ if (field) {
+ reaction |= setSortKey(st->settings, field->key);
+ }
+ Object_delete(sortPanel);
+ return reaction | HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
+}
+
+// ----------------------------------------
+
+static Htop_Reaction actionResize(State* st) {
+ Panel_resize(st->panel, COLS, LINES-(st->panel->y)-1);
+ return HTOP_REDRAW_BAR;
+}
+
+static Htop_Reaction actionSortByMemory(State* st) {
+ return setSortKey(st->settings, PERCENT_MEM);
+}
+
+static Htop_Reaction actionSortByCPU(State* st) {
+ return setSortKey(st->settings, PERCENT_CPU);
+}
+
+static Htop_Reaction actionSortByTime(State* st) {
+ return setSortKey(st->settings, TIME);
+}
+
+static Htop_Reaction actionToggleKernelThreads(State* st) {
+ st->settings->hideKernelThreads = !st->settings->hideKernelThreads;
+ return HTOP_RECALCULATE | HTOP_SAVE_SETTINGS;
+}
+
+static Htop_Reaction actionToggleUserlandThreads(State* st) {
+ st->settings->hideUserlandThreads = !st->settings->hideUserlandThreads;
+ st->settings->hideThreads = st->settings->hideUserlandThreads;
+ return HTOP_RECALCULATE | HTOP_SAVE_SETTINGS;
+}
+
+static Htop_Reaction actionToggleTreeView(State* st) {
+ st->settings->treeView = !st->settings->treeView;
+ if (st->settings->treeView) st->settings->direction = 1;
+ ProcessList_expandTree(st->pl);
+ return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_KEEP_FOLLOWING | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
+}
+
+static Htop_Reaction actionIncFilter(State* st) {
+ IncSet_activate(st->inc, INC_FILTER);
+ return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
+}
+
+static Htop_Reaction actionIncSearch(State* st) {
+ IncSet_activate(st->inc, INC_SEARCH);
+ return HTOP_REFRESH | HTOP_KEEP_FOLLOWING;
+}
+
+static Htop_Reaction actionHigherPriority(State* st) {
+ bool changed = changePriority((MainPanel*)st->panel, -1);
+ return changed ? HTOP_REFRESH : HTOP_OK;
+}
+
+static Htop_Reaction actionLowerPriority(State* st) {
+ bool changed = changePriority((MainPanel*)st->panel, 1);
+ return changed ? HTOP_REFRESH : HTOP_OK;
+}
+
+static Htop_Reaction actionInvertSortOrder(State* st) {
+ Settings_invertSortOrder(st->settings);
+ return HTOP_REFRESH | HTOP_SAVE_SETTINGS;
+}
+
+static Htop_Reaction actionSetSortColumn(State* st) {
+ return sortBy(st);
+}
+
+static Htop_Reaction actionExpandOrCollapse(State* st) {
+ bool changed = expandCollapse(st->panel);
+ return changed ? HTOP_RECALCULATE : HTOP_OK;
+}
+
+static Htop_Reaction actionExpandCollapseOrSortColumn(State* st) {
+ return st->settings->treeView ? actionExpandOrCollapse(st) : actionSetSortColumn(st);
+}
+
+static Htop_Reaction actionQuit() {
+ return HTOP_QUIT;
+}
+
+static Htop_Reaction actionSetAffinity(State* st) {
+ if (st->pl->cpuCount == 1)
+ return HTOP_OK;
+#if (HAVE_LIBHWLOC || HAVE_NATIVE_AFFINITY)
+ Panel* panel = st->panel;
+
+ Process* p = (Process*) Panel_getSelected(panel);
+ if (!p) return HTOP_OK;
+ Affinity* affinity = Affinity_get(p, st->pl);
+ if (!affinity) return HTOP_OK;
+ Panel* affinityPanel = AffinityPanel_new(st->pl, affinity);
+ Affinity_delete(affinity);
+
+ const char* fuFunctions[] = {"Set ", "Cancel ", NULL};
+ void* set = Action_pickFromVector(st, affinityPanel, 15, fuFunctions);
+ if (set) {
+ Affinity* affinity = AffinityPanel_getAffinity(affinityPanel, st->pl);
+ bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) Affinity_set, (size_t) affinity, NULL);
+ if (!ok) beep();
+ Affinity_delete(affinity);
+ }
+ Panel_delete((Object*)affinityPanel);
+#endif
+ return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
+}
+
+static Htop_Reaction actionKill(State* st) {
+ Panel* signalsPanel = (Panel*) SignalsPanel_new();
+ const char* fuFunctions[] = {"Send ", "Cancel ", NULL};
+ ListItem* sgn = (ListItem*) Action_pickFromVector(st, signalsPanel, 15, fuFunctions);
+ if (sgn) {
+ if (sgn->key != 0) {
+ Panel_setHeader(st->panel, "Sending...");
+ Panel_draw(st->panel, true);
+ refresh();
+ MainPanel_foreachProcess((MainPanel*)st->panel, (MainPanel_ForeachProcessFn) Process_sendSignal, (size_t) sgn->key, NULL);
+ napms(500);
+ }
+ }
+ Panel_delete((Object*)signalsPanel);
+ return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
+}
+
+static Htop_Reaction actionFilterByUser(State* st) {
+ Panel* usersPanel = Panel_new(0, 0, 0, 0, true, Class(ListItem));
+ Panel_setHeader(usersPanel, "Show processes of:");
+ UsersTable_foreach(st->ut, addUserToVector, usersPanel);
+ Vector_insertionSort(usersPanel->items);
+ ListItem* allUsers = ListItem_new("All users", -1);
+ Panel_insert(usersPanel, 0, (Object*) allUsers);
+ const char* fuFunctions[] = {"Show ", "Cancel ", NULL};
+ ListItem* picked = (ListItem*) Action_pickFromVector(st, usersPanel, 20, fuFunctions);
+ if (picked) {
+ if (picked == allUsers) {
+ st->pl->userId = -1;
+ } else {
+ Action_setUserOnly(ListItem_getRef(picked), &(st->pl->userId));
+ }
+ }
+ Panel_delete((Object*)usersPanel);
+ return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
+}
+
+static Htop_Reaction actionFollow(State* st) {
+ st->pl->following = MainPanel_selectedPid((MainPanel*)st->panel);
+ return HTOP_KEEP_FOLLOWING;
+}
+
+static Htop_Reaction actionSetup(State* st) {
+ Setup_run(st->settings, st->header, st->pl);
+ // TODO: shouldn't need this, colors should be dynamic
+ int headerHeight = Header_calculateHeight(st->header);
+ Panel_move(st->panel, 0, headerHeight);
+ Panel_resize(st->panel, COLS, LINES-headerHeight-1);
+ return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
+}
+
+static Htop_Reaction actionLsof(State* st) {
+ Process* p = (Process*) Panel_getSelected(st->panel);
+ if (!p) return HTOP_OK;
+ OpenFilesScreen* ts = OpenFilesScreen_new(p);
+ OpenFilesScreen_run(ts);
+ OpenFilesScreen_delete(ts);
+ clear();
+ CRT_enableDelay();
+ return HTOP_REFRESH | HTOP_REDRAW_BAR;
+}
+
+static Htop_Reaction actionStrace(State* st) {
+ Process* p = (Process*) Panel_getSelected(st->panel);
+ if (!p) return HTOP_OK;
+ TraceScreen* ts = TraceScreen_new(p);
+ TraceScreen_run(ts);
+ TraceScreen_delete(ts);
+ clear();
+ CRT_enableDelay();
+ return HTOP_REFRESH | HTOP_REDRAW_BAR;
+}
+
+static Htop_Reaction actionTag(State* st) {
+ Process* p = (Process*) Panel_getSelected(st->panel);
+ if (!p) return HTOP_OK;
+ Process_toggleTag(p);
+ Panel_onKey(st->panel, KEY_DOWN);
+ return HTOP_OK;
+}
+
+static Htop_Reaction actionRedraw() {
+ clear();
+ return HTOP_REFRESH | HTOP_REDRAW_BAR;
+}
+
+static struct { const char* key; const char* info; } helpLeft[] = {
+ { .key = " Arrows: ", .info = "scroll process list" },
+ { .key = " Digits: ", .info = "incremental PID search" },
+ { .key = " F3 /: ", .info = "incremental name search" },
+ { .key = " F4 \\: ",.info = "incremental name filtering" },
+ { .key = " F5 t: ", .info = "tree view" },
+ { .key = " u: ", .info = "show processes of a single user" },
+ { .key = " H: ", .info = "hide/show user threads" },
+ { .key = " K: ", .info = "hide/show kernel threads" },
+ { .key = " F: ", .info = "cursor follows process" },
+ { .key = " F6 + -: ", .info = "expand/collapse tree" },
+ { .key = " P M T: ", .info = "sort by CPU%, MEM% or TIME" },
+ { .key = " I: ", .info = "invert sort order" },
+ { .key = " F6 >: ", .info = "select sort column" },
+ { .key = NULL, .info = NULL }
+};
+
+static struct { const char* key; const char* info; } helpRight[] = {
+ { .key = " Space: ", .info = "tag process" },
+ { .key = " c: ", .info = "tag process and its children" },
+ { .key = " U: ", .info = "untag all processes" },
+ { .key = " F9 k: ", .info = "kill process/tagged processes" },
+ { .key = " F7 ]: ", .info = "higher priority (root only)" },
+ { .key = " F8 [: ", .info = "lower priority (+ nice)" },
+#if (HAVE_LIBHWLOC || HAVE_NATIVE_AFFINITY)
+ { .key = " a: ", .info = "set CPU affinity" },
+#endif
+ { .key = " i: ", .info = "set IO prority" },
+ { .key = " l: ", .info = "list open files with lsof" },
+ { .key = " s: ", .info = "trace syscalls with strace" },
+ { .key = " ", .info = "" },
+ { .key = " F2 S: ", .info = "setup" },
+ { .key = " F1 h: ", .info = "show this help screen" },
+ { .key = " F10 q: ", .info = "quit" },
+ { .key = NULL, .info = NULL }
+};
+
+static Htop_Reaction actionHelp(State* st) {
+ Settings* settings = st->settings;
+
+ clear();
+ attrset(CRT_colors[HELP_BOLD]);
+
+ for (int i = 0; i < LINES-1; i++)
+ mvhline(i, 0, ' ', COLS);
+
+ mvaddstr(0, 0, "htop " VERSION " - " COPYRIGHT);
+ mvaddstr(1, 0, "Released under the GNU GPL. See 'man' page for more info.");
+
+ attrset(CRT_colors[DEFAULT_COLOR]);
+ mvaddstr(3, 0, "CPU usage bar: ");
+ #define addattrstr(a,s) attrset(a);addstr(s)
+ addattrstr(CRT_colors[BAR_BORDER], "[");
+ if (settings->detailedCPUTime) {
+ addattrstr(CRT_colors[CPU_NICE_TEXT], "low"); addstr("/");
+ addattrstr(CRT_colors[CPU_NORMAL], "normal"); addstr("/");
+ addattrstr(CRT_colors[CPU_KERNEL], "kernel"); addstr("/");
+ addattrstr(CRT_colors[CPU_IRQ], "irq"); addstr("/");
+ addattrstr(CRT_colors[CPU_SOFTIRQ], "soft-irq"); addstr("/");
+ addattrstr(CRT_colors[CPU_STEAL], "steal"); addstr("/");
+ addattrstr(CRT_colors[CPU_GUEST], "guest"); addstr("/");
+ addattrstr(CRT_colors[CPU_IOWAIT], "io-wait");
+ addattrstr(CRT_colors[BAR_SHADOW], " used%");
+ } else {
+ addattrstr(CRT_colors[CPU_NICE_TEXT], "low-priority"); addstr("/");
+ addattrstr(CRT_colors[CPU_NORMAL], "normal"); addstr("/");
+ addattrstr(CRT_colors[CPU_KERNEL], "kernel"); addstr("/");
+ addattrstr(CRT_colors[CPU_STEAL], "virtualiz");
+ addattrstr(CRT_colors[BAR_SHADOW], " used%");
+ }
+ addattrstr(CRT_colors[BAR_BORDER], "]");
+ attrset(CRT_colors[DEFAULT_COLOR]);
+ mvaddstr(4, 0, "Memory bar: ");
+ addattrstr(CRT_colors[BAR_BORDER], "[");
+ addattrstr(CRT_colors[MEMORY_USED], "used"); addstr("/");
+ addattrstr(CRT_colors[MEMORY_BUFFERS_TEXT], "buffers"); addstr("/");
+ addattrstr(CRT_colors[MEMORY_CACHE], "cache");
+ addattrstr(CRT_colors[BAR_SHADOW], " used/total");
+ addattrstr(CRT_colors[BAR_BORDER], "]");
+ attrset(CRT_colors[DEFAULT_COLOR]);
+ mvaddstr(5, 0, "Swap bar: ");
+ addattrstr(CRT_colors[BAR_BORDER], "[");
+ addattrstr(CRT_colors[SWAP], "used");
+ addattrstr(CRT_colors[BAR_SHADOW], " used/total");
+ addattrstr(CRT_colors[BAR_BORDER], "]");
+ attrset(CRT_colors[DEFAULT_COLOR]);
+ mvaddstr(6,0, "Type and layout of header meters are configurable in the setup screen.");
+ if (CRT_colorScheme == COLORSCHEME_MONOCHROME) {
+ mvaddstr(7, 0, "In monochrome, meters are displayed through different chars, in order: |#*@$%&");
+ }
+ mvaddstr( 8, 0, " Status: R: running; S: sleeping; T: traced/stopped; Z: zombie; D: disk sleep");
+ for (int i = 0; helpLeft[i].info; i++) { mvaddstr(9+i, 9, helpLeft[i].info); }
+ for (int i = 0; helpRight[i].info; i++) { mvaddstr(9+i, 49, helpRight[i].info); }
+ attrset(CRT_colors[HELP_BOLD]);
+ for (int i = 0; helpLeft[i].key; i++) { mvaddstr(9+i, 0, helpLeft[i].key); }
+ for (int i = 0; helpRight[i].key; i++) { mvaddstr(9+i, 40, helpRight[i].key); }
+
+ attrset(CRT_colors[HELP_BOLD]);
+ mvaddstr(23,0, "Press any key to return.");
+ attrset(CRT_colors[DEFAULT_COLOR]);
+ refresh();
+ CRT_readKey();
+ clear();
+
+ return HTOP_RECALCULATE | HTOP_REDRAW_BAR;
+}
+
+static Htop_Reaction actionUntagAll(State* st) {
+ for (int i = 0; i < Panel_size(st->panel); i++) {
+ Process* p = (Process*) Panel_get(st->panel, i);
+ p->tag = false;
+ }
+ return HTOP_REFRESH;
+}
+
+static Htop_Reaction actionTagAllChildren(State* st) {
+ Process* p = (Process*) Panel_getSelected(st->panel);
+ if (!p) return HTOP_OK;
+ tagAllChildren(st->panel, p);
+ return HTOP_OK;
+}
+
+void Action_setBindings(Htop_Action* keys) {
+ keys[KEY_RESIZE] = actionResize;
+ keys['M'] = actionSortByMemory;
+ keys['T'] = actionSortByTime;
+ keys['P'] = actionSortByCPU;
+ keys['H'] = actionToggleUserlandThreads;
+ keys['K'] = actionToggleKernelThreads;
+ keys['t'] = actionToggleTreeView;
+ keys[KEY_F(5)] = actionToggleTreeView;
+ keys[KEY_F(4)] = actionIncFilter;
+ keys['\\'] = actionIncFilter;
+ keys[KEY_F(3)] = actionIncSearch;
+ keys['/'] = actionIncSearch;
+
+ keys[']'] = actionHigherPriority;
+ keys[KEY_F(7)] = actionHigherPriority;
+ keys['['] = actionLowerPriority;
+ keys[KEY_F(8)] = actionLowerPriority;
+ keys['I'] = actionInvertSortOrder;
+ keys[KEY_F(6)] = actionExpandCollapseOrSortColumn;
+ keys[KEY_F(18)] = actionExpandCollapseOrSortColumn;
+ keys['<'] = actionSetSortColumn;
+ keys[','] = actionSetSortColumn;
+ keys['>'] = actionSetSortColumn;
+ keys['.'] = actionSetSortColumn;
+ keys[KEY_F(10)] = actionQuit;
+ keys['q'] = actionQuit;
+ keys['a'] = actionSetAffinity;
+ keys[KEY_F(9)] = actionKill;
+ keys['k'] = actionKill;
+ keys['+'] = actionExpandOrCollapse;
+ keys['='] = actionExpandOrCollapse;
+ keys['-'] = actionExpandOrCollapse;
+ keys['u'] = actionFilterByUser;
+ keys['F'] = actionFollow;
+ keys['S'] = actionSetup;
+ keys['C'] = actionSetup;
+ keys[KEY_F(2)] = actionSetup;
+ keys['l'] = actionLsof;
+ keys['s'] = actionStrace;
+ keys[' '] = actionTag;
+ keys['\014'] = actionRedraw; // Ctrl+L
+ keys[KEY_F(1)] = actionHelp;
+ keys['h'] = actionHelp;
+ keys['?'] = actionHelp;
+ keys['U'] = actionUntagAll;
+ keys['c'] = actionTagAllChildren;
+}
+
diff --git a/Action.h b/Action.h
index 7571ba41..dd11fdb4 100644
--- a/Action.h
+++ b/Action.h
@@ -12,7 +12,10 @@ in the source distribution for its full text.
#include "IncSet.h"
#include "Settings.h"
+#include "Header.h"
#include "UsersTable.h"
+#include "ProcessList.h"
+#include "Panel.h"
typedef enum {
HTOP_OK = 0x00,
@@ -31,15 +34,21 @@ typedef struct State_ {
IncSet* inc;
Settings* settings;
UsersTable* ut;
+ ProcessList* pl;
+ Panel* panel;
+ Header* header;
} State;
-typedef bool(*Action_ForeachProcessFn)(Process*, size_t);
+Object* Action_pickFromVector(State* st, Panel* list, int x, const char** keyLabels);
-int Action_selectedPid(Panel* panel);
+// ----------------------------------------
-bool Action_foreachProcess(Panel* panel, Action_ForeachProcessFn fn, int arg, bool* wasAnyTagged);
+bool Action_setUserOnly(const char* userName, uid_t* userId);
+
+// ----------------------------------------
+
+void Action_setBindings(Htop_Action* keys);
-Object* Action_pickFromVector(Panel* panel, Panel* list, int x, const char** keyLabels, Header* header);
#endif
diff --git a/Affinity.c b/Affinity.c
index 3b1e311a..8e8651be 100644
--- a/Affinity.c
+++ b/Affinity.c
@@ -9,9 +9,18 @@ in the source distribution for its full text.
#include <stdlib.h>
+#ifdef HAVE_LIBHWLOC
+#include <hwloc/linux.h>
+#elif HAVE_NATIVE_AFFINITY
+#include <sched.h>
+#endif
+
/*{
+#include "Process.h"
+#include "ProcessList.h"
typedef struct Affinity_ {
+ ProcessList* pl;
int size;
int used;
int* cpus;
@@ -19,10 +28,11 @@ typedef struct Affinity_ {
}*/
-Affinity* Affinity_new() {
+Affinity* Affinity_new(ProcessList* pl) {
Affinity* this = calloc(1, sizeof(Affinity));
this->size = 8;
this->cpus = calloc(this->size, sizeof(int));
+ this->pl = pl;
return this;
}
@@ -40,3 +50,62 @@ void Affinity_add(Affinity* this, int id) {
this->used++;
}
+
+#ifdef HAVE_LIBHWLOC
+
+Affinity* Affinity_get(Process* proc, ProcessList* pl) {
+ hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();
+ bool ok = (hwloc_linux_get_tid_cpubind(pl->topology, proc->pid, cpuset) == 0);
+ Affinity* affinity = NULL;
+ if (ok) {
+ affinity = Affinity_new(pl);
+ if (hwloc_bitmap_last(cpuset) == -1) {
+ for (int i = 0; i < pl->cpuCount; i++) {
+ Affinity_add(affini