├── .editorconfig ├── .gitignore ├── .travis.yml ├── AUTHORS ├── Action.c ├── Action.h ├── Affinity.c ├── Affinity.h ├── AffinityPanel.c ├── AffinityPanel.h ├── AvailableColumnsPanel.c ├── AvailableColumnsPanel.h ├── AvailableMetersPanel.c ├── AvailableMetersPanel.h ├── BatteryMeter.c ├── BatteryMeter.h ├── CONTRIBUTING.md ├── COPYING ├── CPUMeter.c ├── CPUMeter.h ├── CRT.c ├── CRT.h ├── CategoriesPanel.c ├── CategoriesPanel.h ├── ChangeLog ├── CheckItem.c ├── CheckItem.h ├── ClockMeter.c ├── ClockMeter.h ├── ColorsPanel.c ├── ColorsPanel.h ├── ColumnsPanel.c ├── ColumnsPanel.h ├── DisplayOptionsPanel.c ├── DisplayOptionsPanel.h ├── EnvScreen.c ├── EnvScreen.h ├── FunctionBar.c ├── FunctionBar.h ├── Hashtable.c ├── Hashtable.h ├── Header.c ├── Header.h ├── HostnameMeter.c ├── HostnameMeter.h ├── IncSet.c ├── IncSet.h ├── InfoScreen.c ├── InfoScreen.h ├── ListItem.c ├── ListItem.h ├── LoadAverageMeter.c ├── LoadAverageMeter.h ├── MainPanel.c ├── MainPanel.h ├── Makefile.am ├── MemoryMeter.c ├── MemoryMeter.h ├── Meter.c ├── Meter.h ├── MetersPanel.c ├── MetersPanel.h ├── NEWS ├── Object.c ├── Object.h ├── OpenFilesScreen.c ├── OpenFilesScreen.h ├── Panel.c ├── Panel.h ├── Process.c ├── Process.h ├── ProcessList.c ├── ProcessList.h ├── README ├── README.md ├── RichString.c ├── RichString.h ├── ScreenManager.c ├── ScreenManager.h ├── Settings.c ├── Settings.h ├── SignalsPanel.c ├── SignalsPanel.h ├── StringUtils.c ├── StringUtils.h ├── SwapMeter.c ├── SwapMeter.h ├── TESTPLAN ├── TasksMeter.c ├── TasksMeter.h ├── TraceScreen.c ├── TraceScreen.h ├── UptimeMeter.c ├── UptimeMeter.h ├── UsersTable.c ├── UsersTable.h ├── Vector.c ├── Vector.h ├── XAlloc.c ├── XAlloc.h ├── autogen.sh ├── configure.ac ├── darwin ├── Battery.c ├── Battery.h ├── DarwinCRT.c ├── DarwinCRT.h ├── DarwinProcess.c ├── DarwinProcess.h ├── DarwinProcessList.c ├── DarwinProcessList.h ├── Platform.c └── Platform.h ├── dragonflybsd ├── Battery.c ├── Battery.h ├── DragonFlyBSDCRT.c ├── DragonFlyBSDCRT.h ├── DragonFlyBSDProcess.c ├── DragonFlyBSDProcess.h ├── DragonFlyBSDProcessList.c ├── DragonFlyBSDProcessList.h ├── Platform.c └── Platform.h ├── freebsd ├── Battery.c ├── Battery.h ├── FreeBSDCRT.c ├── FreeBSDCRT.h ├── FreeBSDProcess.c ├── FreeBSDProcess.h ├── FreeBSDProcessList.c ├── FreeBSDProcessList.h ├── Platform.c └── Platform.h ├── htop.1.in ├── htop.c ├── htop.desktop ├── htop.h ├── htop.png ├── linux ├── Battery.c ├── Battery.h ├── IOPriority.c ├── IOPriority.h ├── IOPriorityPanel.c ├── IOPriorityPanel.h ├── LinuxCRT.c ├── LinuxCRT.h ├── LinuxProcess.c ├── LinuxProcess.h ├── LinuxProcessList.c ├── LinuxProcessList.h ├── Platform.c └── Platform.h ├── openbsd ├── Battery.c ├── Battery.h ├── OpenBSDCRT.c ├── OpenBSDCRT.h ├── OpenBSDProcess.c ├── OpenBSDProcess.h ├── OpenBSDProcessList.c ├── OpenBSDProcessList.h ├── Platform.c └── Platform.h ├── scripts └── MakeHeader.py ├── solaris ├── Battery.c ├── Battery.h ├── Platform.c ├── Platform.h ├── SolarisCRT.c ├── SolarisCRT.h ├── SolarisProcess.c ├── SolarisProcess.h ├── SolarisProcessList.c └── SolarisProcessList.h ├── test_spec.lua └── unsupported ├── Battery.c ├── Battery.h ├── Platform.c ├── Platform.h ├── UnsupportedCRT.c ├── UnsupportedCRT.h ├── UnsupportedProcess.c ├── UnsupportedProcess.h ├── UnsupportedProcessList.c └── UnsupportedProcessList.h /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig configuration for htop 2 | # http://EditorConfig.org 3 | 4 | # top-most EditorConfig file 5 | root = true 6 | 7 | # Unix-style newlines with a newline ending every file, utf-8 charset 8 | [*] 9 | end_of_line = lf 10 | insert_final_newline = true 11 | charset = utf-8 12 | 13 | # match C source and header files, set indent to three spaces 14 | [*.{c,h}] 15 | indent_style = space 16 | indent_size = 3 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # the binary: 2 | htop 3 | 4 | # all object files 5 | *.o 6 | 7 | # skip all backups 8 | *.bak 9 | *~ 10 | .*.sw? 11 | 12 | # skip coverage files 13 | *.gcda 14 | */*.gcda 15 | *.gcno 16 | */*.gcno 17 | *.h.gch 18 | */.dirstamp 19 | 20 | .deps/ 21 | Makefile 22 | Makefile.in 23 | INSTALL 24 | aclocal.m4 25 | autom4te.cache/ 26 | compile 27 | config.guess 28 | config.h 29 | config.h.in 30 | config.log 31 | config.status 32 | config.cache 33 | config.sub 34 | configure 35 | depcomp 36 | htop.1 37 | install-sh 38 | libtool 39 | ltmain.sh 40 | m4/ 41 | missing 42 | stamp-h1 43 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | compiler: 4 | - clang 5 | - gcc 6 | 7 | os: 8 | - linux 9 | - osx 10 | 11 | script: ./autogen.sh && ./configure && make 12 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Hisham H. Muhammad 2 | -------------------------------------------------------------------------------- /Action.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Action 4 | #define HEADER_Action 5 | /* 6 | htop - Action.h 7 | (C) 2015 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | 13 | #include "IncSet.h" 14 | #include "Settings.h" 15 | #include "Header.h" 16 | #include "UsersTable.h" 17 | #include "ProcessList.h" 18 | #include "Panel.h" 19 | 20 | typedef enum { 21 | HTOP_OK = 0x00, 22 | HTOP_REFRESH = 0x01, 23 | HTOP_RECALCULATE = 0x03, // implies HTOP_REFRESH 24 | HTOP_SAVE_SETTINGS = 0x04, 25 | HTOP_KEEP_FOLLOWING = 0x08, 26 | HTOP_QUIT = 0x10, 27 | HTOP_REDRAW_BAR = 0x20, 28 | HTOP_UPDATE_PANELHDR = 0x41, // implies HTOP_REFRESH 29 | } Htop_Reaction; 30 | 31 | typedef Htop_Reaction (*Htop_Action)(); 32 | 33 | typedef struct State_ { 34 | Settings* settings; 35 | UsersTable* ut; 36 | ProcessList* pl; 37 | Panel* panel; 38 | Header* header; 39 | } State; 40 | 41 | 42 | Object* Action_pickFromVector(State* st, Panel* list, int x); 43 | 44 | // ---------------------------------------- 45 | 46 | bool Action_setUserOnly(const char* userName, uid_t* userId); 47 | 48 | Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey); 49 | 50 | // ---------------------------------------- 51 | 52 | Htop_Reaction Action_follow(State* st); 53 | 54 | 55 | void Action_setBindings(Htop_Action* keys); 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /Affinity.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - Affinity.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "Affinity.h" 9 | 10 | #include 11 | 12 | #ifdef HAVE_LIBHWLOC 13 | #include 14 | #if __linux__ 15 | #define HTOP_HWLOC_CPUBIND_FLAG HWLOC_CPUBIND_THREAD 16 | #else 17 | #define HTOP_HWLOC_CPUBIND_FLAG HWLOC_CPUBIND_PROCESS 18 | #endif 19 | #elif HAVE_LINUX_AFFINITY 20 | #include 21 | #endif 22 | 23 | /*{ 24 | #include "Process.h" 25 | #include "ProcessList.h" 26 | 27 | typedef struct Affinity_ { 28 | ProcessList* pl; 29 | int size; 30 | int used; 31 | int* cpus; 32 | } Affinity; 33 | 34 | }*/ 35 | 36 | Affinity* Affinity_new(ProcessList* pl) { 37 | Affinity* this = xCalloc(1, sizeof(Affinity)); 38 | this->size = 8; 39 | this->cpus = xCalloc(this->size, sizeof(int)); 40 | this->pl = pl; 41 | return this; 42 | } 43 | 44 | void Affinity_delete(Affinity* this) { 45 | free(this->cpus); 46 | free(this); 47 | } 48 | 49 | void Affinity_add(Affinity* this, int id) { 50 | if (this->used == this->size) { 51 | this->size *= 2; 52 | this->cpus = xRealloc(this->cpus, sizeof(int) * this->size); 53 | } 54 | this->cpus[this->used] = id; 55 | this->used++; 56 | } 57 | 58 | 59 | #ifdef HAVE_LIBHWLOC 60 | 61 | Affinity* Affinity_get(Process* proc, ProcessList* pl) { 62 | hwloc_cpuset_t cpuset = hwloc_bitmap_alloc(); 63 | bool ok = (hwloc_get_proc_cpubind(pl->topology, proc->pid, cpuset, HTOP_HWLOC_CPUBIND_FLAG) == 0); 64 | Affinity* affinity = NULL; 65 | if (ok) { 66 | affinity = Affinity_new(pl); 67 | if (hwloc_bitmap_last(cpuset) == -1) { 68 | for (int i = 0; i < pl->cpuCount; i++) { 69 | Affinity_add(affinity, i); 70 | } 71 | } else { 72 | unsigned int id; 73 | hwloc_bitmap_foreach_begin(id, cpuset); 74 | Affinity_add(affinity, id); 75 | hwloc_bitmap_foreach_end(); 76 | } 77 | } 78 | hwloc_bitmap_free(cpuset); 79 | return affinity; 80 | } 81 | 82 | bool Affinity_set(Process* proc, Affinity* this) { 83 | hwloc_cpuset_t cpuset = hwloc_bitmap_alloc(); 84 | for (int i = 0; i < this->used; i++) { 85 | hwloc_bitmap_set(cpuset, this->cpus[i]); 86 | } 87 | bool ok = (hwloc_set_proc_cpubind(this->pl->topology, proc->pid, cpuset, HTOP_HWLOC_CPUBIND_FLAG) == 0); 88 | hwloc_bitmap_free(cpuset); 89 | return ok; 90 | } 91 | 92 | #elif HAVE_LINUX_AFFINITY 93 | 94 | Affinity* Affinity_get(Process* proc, ProcessList* pl) { 95 | cpu_set_t cpuset; 96 | bool ok = (sched_getaffinity(proc->pid, sizeof(cpu_set_t), &cpuset) == 0); 97 | if (!ok) return NULL; 98 | Affinity* affinity = Affinity_new(pl); 99 | for (int i = 0; i < pl->cpuCount; i++) { 100 | if (CPU_ISSET(i, &cpuset)) 101 | Affinity_add(affinity, i); 102 | } 103 | return affinity; 104 | } 105 | 106 | bool Affinity_set(Process* proc, Affinity* this) { 107 | cpu_set_t cpuset; 108 | CPU_ZERO(&cpuset); 109 | for (int i = 0; i < this->used; i++) { 110 | CPU_SET(this->cpus[i], &cpuset); 111 | } 112 | bool ok = (sched_setaffinity(proc->pid, sizeof(unsigned long), &cpuset) == 0); 113 | return ok; 114 | } 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /Affinity.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Affinity 4 | #define HEADER_Affinity 5 | /* 6 | htop - Affinity.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #ifdef HAVE_LIBHWLOC 13 | #if __linux__ 14 | #define HTOP_HWLOC_CPUBIND_FLAG HWLOC_CPUBIND_THREAD 15 | #else 16 | #define HTOP_HWLOC_CPUBIND_FLAG HWLOC_CPUBIND_PROCESS 17 | #endif 18 | #elif HAVE_LINUX_AFFINITY 19 | #endif 20 | 21 | #include "Process.h" 22 | #include "ProcessList.h" 23 | 24 | typedef struct Affinity_ { 25 | ProcessList* pl; 26 | int size; 27 | int used; 28 | int* cpus; 29 | } Affinity; 30 | 31 | 32 | Affinity* Affinity_new(ProcessList* pl); 33 | 34 | void Affinity_delete(Affinity* this); 35 | 36 | void Affinity_add(Affinity* this, int id); 37 | 38 | #ifdef HAVE_LIBHWLOC 39 | 40 | Affinity* Affinity_get(Process* proc, ProcessList* pl); 41 | 42 | bool Affinity_set(Process* proc, Affinity* this); 43 | 44 | #elif HAVE_LINUX_AFFINITY 45 | 46 | Affinity* Affinity_get(Process* proc, ProcessList* pl); 47 | 48 | bool Affinity_set(Process* proc, Affinity* this); 49 | 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /AffinityPanel.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - AffinityPanel.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "AffinityPanel.h" 9 | #include "CRT.h" 10 | 11 | #include "CheckItem.h" 12 | 13 | #include 14 | #include 15 | 16 | /*{ 17 | #include "Panel.h" 18 | #include "Affinity.h" 19 | #include "ProcessList.h" 20 | #include "ListItem.h" 21 | }*/ 22 | 23 | static HandlerResult AffinityPanel_eventHandler(Panel* this, int ch) { 24 | CheckItem* selected = (CheckItem*) Panel_getSelected(this); 25 | switch(ch) { 26 | case KEY_MOUSE: 27 | case KEY_RECLICK: 28 | case ' ': 29 | CheckItem_set(selected, ! (CheckItem_get(selected)) ); 30 | return HANDLED; 31 | case 0x0a: 32 | case 0x0d: 33 | case KEY_ENTER: 34 | return BREAK_LOOP; 35 | } 36 | return IGNORED; 37 | } 38 | 39 | PanelClass AffinityPanel_class = { 40 | .super = { 41 | .extends = Class(Panel), 42 | .delete = Panel_delete 43 | }, 44 | .eventHandler = AffinityPanel_eventHandler 45 | }; 46 | 47 | Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity) { 48 | Panel* this = Panel_new(1, 1, 1, 1, true, Class(CheckItem), FunctionBar_newEnterEsc("Set ", "Cancel ")); 49 | Object_setClass(this, Class(AffinityPanel)); 50 | 51 | Panel_setHeader(this, "Use CPUs:"); 52 | int curCpu = 0; 53 | for (int i = 0; i < pl->cpuCount; i++) { 54 | char number[10]; 55 | xSnprintf(number, 9, "%d", Settings_cpuId(pl->settings, i)); 56 | bool mode; 57 | if (curCpu < affinity->used && affinity->cpus[curCpu] == i) { 58 | mode = true; 59 | curCpu++; 60 | } else { 61 | mode = false; 62 | } 63 | Panel_add(this, (Object*) CheckItem_newByVal(xStrdup(number), mode)); 64 | } 65 | return this; 66 | } 67 | 68 | Affinity* AffinityPanel_getAffinity(Panel* this, ProcessList* pl) { 69 | Affinity* affinity = Affinity_new(pl); 70 | int size = Panel_size(this); 71 | for (int i = 0; i < size; i++) { 72 | if (CheckItem_get((CheckItem*)Panel_get(this, i))) 73 | Affinity_add(affinity, i); 74 | } 75 | return affinity; 76 | } 77 | -------------------------------------------------------------------------------- /AffinityPanel.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_AffinityPanel 4 | #define HEADER_AffinityPanel 5 | /* 6 | htop - AffinityPanel.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Panel.h" 13 | #include "Affinity.h" 14 | #include "ProcessList.h" 15 | #include "ListItem.h" 16 | 17 | extern PanelClass AffinityPanel_class; 18 | 19 | Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity); 20 | 21 | Affinity* AffinityPanel_getAffinity(Panel* this, ProcessList* pl); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /AvailableColumnsPanel.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - AvailableColumnsPanel.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "AvailableColumnsPanel.h" 9 | #include "Platform.h" 10 | 11 | #include "Header.h" 12 | #include "ColumnsPanel.h" 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | /*{ 20 | #include "Panel.h" 21 | 22 | typedef struct AvailableColumnsPanel_ { 23 | Panel super; 24 | Panel* columns; 25 | } AvailableColumnsPanel; 26 | 27 | }*/ 28 | 29 | static const char* const AvailableColumnsFunctions[] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done ", NULL}; 30 | 31 | static void AvailableColumnsPanel_delete(Object* object) { 32 | Panel* super = (Panel*) object; 33 | AvailableColumnsPanel* this = (AvailableColumnsPanel*) object; 34 | Panel_done(super); 35 | free(this); 36 | } 37 | 38 | static HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) { 39 | AvailableColumnsPanel* this = (AvailableColumnsPanel*) super; 40 | int key = ((ListItem*) Panel_getSelected(super))->key; 41 | HandlerResult result = IGNORED; 42 | 43 | switch(ch) { 44 | case 13: 45 | case KEY_ENTER: 46 | case KEY_F(5): 47 | { 48 | int at = Panel_getSelectedIndex(this->columns); 49 | Panel_insert(this->columns, at, (Object*) ListItem_new(Process_fields[key].name, key)); 50 | Panel_setSelected(this->columns, at+1); 51 | ColumnsPanel_update(this->columns); 52 | result = HANDLED; 53 | break; 54 | } 55 | default: 56 | { 57 | if (ch < 255 && isalpha(ch)) 58 | result = Panel_selectByTyping(super, ch); 59 | break; 60 | } 61 | } 62 | return result; 63 | } 64 | 65 | PanelClass AvailableColumnsPanel_class = { 66 | .super = { 67 | .extends = Class(Panel), 68 | .delete = AvailableColumnsPanel_delete 69 | }, 70 | .eventHandler = AvailableColumnsPanel_eventHandler 71 | }; 72 | 73 | AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns) { 74 | AvailableColumnsPanel* this = AllocThis(AvailableColumnsPanel); 75 | Panel* super = (Panel*) this; 76 | FunctionBar* fuBar = FunctionBar_new(AvailableColumnsFunctions, NULL, NULL); 77 | Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar); 78 | 79 | Panel_setHeader(super, "Available Columns"); 80 | 81 | for (int i = 1; i < Platform_numberOfFields; i++) { 82 | if (i != COMM && Process_fields[i].description) { 83 | char description[256]; 84 | xSnprintf(description, sizeof(description), "%s - %s", Process_fields[i].name, Process_fields[i].description); 85 | Panel_add(super, (Object*) ListItem_new(description, i)); 86 | } 87 | } 88 | this->columns = columns; 89 | return this; 90 | } 91 | -------------------------------------------------------------------------------- /AvailableColumnsPanel.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_AvailableColumnsPanel 4 | #define HEADER_AvailableColumnsPanel 5 | /* 6 | htop - AvailableColumnsPanel.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Panel.h" 13 | 14 | typedef struct AvailableColumnsPanel_ { 15 | Panel super; 16 | Panel* columns; 17 | } AvailableColumnsPanel; 18 | 19 | 20 | extern PanelClass AvailableColumnsPanel_class; 21 | 22 | AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /AvailableMetersPanel.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - AvailableMetersPanel.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "AvailableMetersPanel.h" 9 | #include "MetersPanel.h" 10 | 11 | #include "CPUMeter.h" 12 | #include "Header.h" 13 | #include "ListItem.h" 14 | #include "Platform.h" 15 | 16 | #include 17 | #include 18 | 19 | /*{ 20 | #include "Settings.h" 21 | #include "Panel.h" 22 | #include "ScreenManager.h" 23 | #include "ProcessList.h" 24 | 25 | typedef struct AvailableMetersPanel_ { 26 | Panel super; 27 | ScreenManager* scr; 28 | 29 | Settings* settings; 30 | Header* header; 31 | Panel* leftPanel; 32 | Panel* rightPanel; 33 | } AvailableMetersPanel; 34 | 35 | }*/ 36 | 37 | static void AvailableMetersPanel_delete(Object* object) { 38 | Panel* super = (Panel*) object; 39 | AvailableMetersPanel* this = (AvailableMetersPanel*) object; 40 | Panel_done(super); 41 | free(this); 42 | } 43 | 44 | static inline void AvailableMetersPanel_addMeter(Header* header, Panel* panel, MeterClass* type, int param, int column) { 45 | Meter* meter = (Meter*) Header_addMeterByClass(header, type, param, column); 46 | Panel_add(panel, (Object*) Meter_toListItem(meter, false)); 47 | Panel_setSelected(panel, Panel_size(panel) - 1); 48 | MetersPanel_setMoving((MetersPanel*)panel, true); 49 | FunctionBar_draw(panel->currentBar, NULL); 50 | } 51 | 52 | static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) { 53 | AvailableMetersPanel* this = (AvailableMetersPanel*) super; 54 | Header* header = this->header; 55 | 56 | ListItem* selected = (ListItem*) Panel_getSelected(super); 57 | int param = selected->key & 0xff; 58 | int type = selected->key >> 16; 59 | HandlerResult result = IGNORED; 60 | bool update = false; 61 | 62 | switch(ch) { 63 | case KEY_F(5): 64 | case 'l': 65 | case 'L': 66 | { 67 | AvailableMetersPanel_addMeter(header, this->leftPanel, Platform_meterTypes[type], param, 0); 68 | result = HANDLED; 69 | update = true; 70 | break; 71 | } 72 | case 0x0a: 73 | case 0x0d: 74 | case KEY_ENTER: 75 | case KEY_F(6): 76 | case 'r': 77 | case 'R': 78 | { 79 | AvailableMetersPanel_addMeter(header, this->rightPanel, Platform_meterTypes[type], param, 1); 80 | result = (KEY_LEFT << 16) | SYNTH_KEY; 81 | update = true; 82 | break; 83 | } 84 | } 85 | if (update) { 86 | this->settings->changed = true; 87 | Header_calculateHeight(header); 88 | Header_draw(header); 89 | ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2); 90 | } 91 | return result; 92 | } 93 | 94 | PanelClass AvailableMetersPanel_class = { 95 | .super = { 96 | .extends = Class(Panel), 97 | .delete = AvailableMetersPanel_delete 98 | }, 99 | .eventHandler = AvailableMetersPanel_eventHandler 100 | }; 101 | 102 | AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl) { 103 | AvailableMetersPanel* this = AllocThis(AvailableMetersPanel); 104 | Panel* super = (Panel*) this; 105 | FunctionBar* fuBar = FunctionBar_newEnterEsc("Add ", "Done "); 106 | Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar); 107 | 108 | this->settings = settings; 109 | this->header = header; 110 | this->leftPanel = leftMeters; 111 | this->rightPanel = rightMeters; 112 | this->scr = scr; 113 | 114 | Panel_setHeader(super, "Available meters"); 115 | // Platform_meterTypes[0] should be always (&CPUMeter_class), which we will 116 | // handle separately in the code below. 117 | for (int i = 1; Platform_meterTypes[i]; i++) { 118 | MeterClass* type = Platform_meterTypes[i]; 119 | assert(type != &CPUMeter_class); 120 | const char* label = type->description ? type->description : type->uiName; 121 | Panel_add(super, (Object*) ListItem_new(label, i << 16)); 122 | } 123 | // Handle (&CPUMeter_class) 124 | MeterClass* type = &CPUMeter_class; 125 | int cpus = pl->cpuCount; 126 | if (cpus > 1) { 127 | Panel_add(super, (Object*) ListItem_new("CPU average", 0)); 128 | for (int i = 1; i <= cpus; i++) { 129 | char buffer[50]; 130 | xSnprintf(buffer, 50, "%s %d", type->uiName, i); 131 | Panel_add(super, (Object*) ListItem_new(buffer, i)); 132 | } 133 | } else { 134 | Panel_add(super, (Object*) ListItem_new("CPU", 1)); 135 | } 136 | return this; 137 | } 138 | -------------------------------------------------------------------------------- /AvailableMetersPanel.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_AvailableMetersPanel 4 | #define HEADER_AvailableMetersPanel 5 | /* 6 | htop - AvailableMetersPanel.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Settings.h" 13 | #include "Panel.h" 14 | #include "ScreenManager.h" 15 | #include "ProcessList.h" 16 | 17 | typedef struct AvailableMetersPanel_ { 18 | Panel super; 19 | ScreenManager* scr; 20 | 21 | Settings* settings; 22 | Header* header; 23 | Panel* leftPanel; 24 | Panel* rightPanel; 25 | } AvailableMetersPanel; 26 | 27 | 28 | extern PanelClass AvailableMetersPanel_class; 29 | 30 | AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /BatteryMeter.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - BatteryMeter.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | 7 | This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). 8 | */ 9 | 10 | #include "BatteryMeter.h" 11 | 12 | #include "Battery.h" 13 | #include "ProcessList.h" 14 | #include "CRT.h" 15 | #include "StringUtils.h" 16 | #include "Platform.h" 17 | 18 | #include 19 | #include 20 | 21 | /*{ 22 | #include "Meter.h" 23 | 24 | typedef enum ACPresence_ { 25 | AC_ABSENT, 26 | AC_PRESENT, 27 | AC_ERROR 28 | } ACPresence; 29 | }*/ 30 | 31 | int BatteryMeter_attributes[] = { 32 | BATTERY 33 | }; 34 | 35 | static void BatteryMeter_updateValues(Meter * this, char *buffer, int len) { 36 | ACPresence isOnAC; 37 | double percent; 38 | 39 | Battery_getData(&percent, &isOnAC); 40 | 41 | if (percent == -1) { 42 | this->values[0] = 0; 43 | xSnprintf(buffer, len, "n/a"); 44 | return; 45 | } 46 | 47 | this->values[0] = percent; 48 | 49 | const char *onAcText, *onBatteryText, *unknownText; 50 | 51 | unknownText = "%.1f%%"; 52 | if (this->mode == TEXT_METERMODE) { 53 | onAcText = "%.1f%% (Running on A/C)"; 54 | onBatteryText = "%.1f%% (Running on battery)"; 55 | } else { 56 | onAcText = "%.1f%%(A/C)"; 57 | onBatteryText = "%.1f%%(bat)"; 58 | } 59 | 60 | if (isOnAC == AC_PRESENT) { 61 | xSnprintf(buffer, len, onAcText, percent); 62 | } else if (isOnAC == AC_ABSENT) { 63 | xSnprintf(buffer, len, onBatteryText, percent); 64 | } else { 65 | xSnprintf(buffer, len, unknownText, percent); 66 | } 67 | 68 | return; 69 | } 70 | 71 | MeterClass BatteryMeter_class = { 72 | .super = { 73 | .extends = Class(Meter), 74 | .delete = Meter_delete 75 | }, 76 | .updateValues = BatteryMeter_updateValues, 77 | .defaultMode = TEXT_METERMODE, 78 | .maxItems = 1, 79 | .total = 100.0, 80 | .attributes = BatteryMeter_attributes, 81 | .name = "Battery", 82 | .uiName = "Battery", 83 | .caption = "Battery: " 84 | }; 85 | -------------------------------------------------------------------------------- /BatteryMeter.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_BatteryMeter 4 | #define HEADER_BatteryMeter 5 | /* 6 | htop - BatteryMeter.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | 11 | This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). 12 | */ 13 | 14 | #include "Meter.h" 15 | 16 | typedef enum ACPresence_ { 17 | AC_ABSENT, 18 | AC_PRESENT, 19 | AC_ERROR 20 | } ACPresence; 21 | 22 | extern int BatteryMeter_attributes[]; 23 | 24 | extern MeterClass BatteryMeter_class; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | Contributing Guide 3 | ================== 4 | 5 | Hello, and thank you so much for taking your time to contribute in any way to 6 | htop! There are many ways to contribute, and I'll try to list them below. The 7 | support from the free software community has been amazing over the years and 8 | it is the number one thing that keeps me going, maintaining and improving 9 | something that started as a tiny pet project back in 2004 and that nowadays is 10 | a piece of software used all over the world, in both reality [and 11 | fiction!](http://hisham.hm/htop/index.php?page=sightings). Cheers! 12 | 13 | -- Hisham Muhammad 14 | 15 | Bug Reports 16 | ----------- 17 | 18 | Bug reports should be posted in the [Github issue 19 | tracker](http://github.com/hishamhm/htop/issues). (I reply to them all, but I 20 | usually do it in batches! :) ) Bug reports are extremely important since it's 21 | impossible for me to test htop in every possible system, distribution and 22 | scenario. Your feedback is what keeps the tool stable and always improving! 23 | Thank you! 24 | 25 | Pull Requests 26 | ------------- 27 | 28 | Code contributions are most welcome! Just [fork the 29 | repo](http://github.com/hishamhm/htop) and send a [pull 30 | request](https://github.com/hishamhm/htop/pulls). Help is especially 31 | appreciated for support of platforms other than Linux. If proposing new 32 | features, please be mindful that htop is a system tool that needs to keep a 33 | small footprint and perform well on systems under stress -- so unfortunately I 34 | can't accept every new feature proposed, as I need to keep the tool slim and 35 | maintainable. Great ideas backed by a PR are always carefully considered for 36 | inclusion, though! Also, PRs containing bug fixes and portability tweaks are a 37 | no-brainer, please send those in! 38 | 39 | Feature Requests 40 | ---------------- 41 | 42 | Back when htop was hosted in SourceForge, there used to be separate Bug 43 | Tracker and Feature Request pages. These go all lumped together under "Issues" 44 | in Github, which is a bit confusing. For this reason, I close Feature Requests 45 | and file them with the [`feature 46 | request`](https://github.com/hishamhm/htop/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22feature+request%22+) 47 | label, where they remain accessible, but not mixed with actual bug reports. 48 | This doesn't mean I'm dismissing or ignoring feature requests right away! It's 49 | just an organizational issue (with Github, really!). 50 | 51 | Donations 52 | --------- 53 | 54 | If you like htop, feel free to [buy the author a 55 | beer](http://hisham.hm/htop/index.php?page=donate). :-) 56 | 57 | -------------------------------------------------------------------------------- /CPUMeter.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_CPUMeter 4 | #define HEADER_CPUMeter 5 | /* 6 | htop - CPUMeter.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Meter.h" 13 | 14 | typedef enum { 15 | CPU_METER_NICE = 0, 16 | CPU_METER_NORMAL = 1, 17 | CPU_METER_KERNEL = 2, 18 | CPU_METER_IRQ = 3, 19 | CPU_METER_SOFTIRQ = 4, 20 | CPU_METER_STEAL = 5, 21 | CPU_METER_GUEST = 6, 22 | CPU_METER_IOWAIT = 7, 23 | CPU_METER_ITEMCOUNT = 8, // number of entries in this enum 24 | } CPUMeterValues; 25 | 26 | 27 | extern int CPUMeter_attributes[]; 28 | 29 | #ifndef MIN 30 | #define MIN(a,b) ((a)<(b)?(a):(b)) 31 | #endif 32 | #ifndef MAX 33 | #define MAX(a,b) ((a)>(b)?(a):(b)) 34 | #endif 35 | 36 | extern MeterClass CPUMeter_class; 37 | 38 | extern MeterClass AllCPUsMeter_class; 39 | 40 | extern MeterClass AllCPUs2Meter_class; 41 | 42 | extern MeterClass LeftCPUsMeter_class; 43 | 44 | extern MeterClass RightCPUsMeter_class; 45 | 46 | extern MeterClass LeftCPUs2Meter_class; 47 | 48 | extern MeterClass RightCPUs2Meter_class; 49 | 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /CRT.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_CRT 4 | #define HEADER_CRT 5 | /* 6 | htop - CRT.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #if HAVE_SETUID_ENABLED 13 | #endif 14 | 15 | #define ColorIndex(i,j) ((7-i)*8+j) 16 | 17 | #define ColorPair(i,j) COLOR_PAIR(ColorIndex(i,j)) 18 | 19 | #define Black COLOR_BLACK 20 | #define Red COLOR_RED 21 | #define Green COLOR_GREEN 22 | #define Yellow COLOR_YELLOW 23 | #define Blue COLOR_BLUE 24 | #define Magenta COLOR_MAGENTA 25 | #define Cyan COLOR_CYAN 26 | #define White COLOR_WHITE 27 | 28 | #define ColorPairGrayBlack ColorPair(Magenta,Magenta) 29 | #define ColorIndexGrayBlack ColorIndex(Magenta,Magenta) 30 | 31 | #define KEY_WHEELUP KEY_F(20) 32 | #define KEY_WHEELDOWN KEY_F(21) 33 | #define KEY_RECLICK KEY_F(22) 34 | 35 | //#link curses 36 | 37 | #include 38 | 39 | typedef enum TreeStr_ { 40 | TREE_STR_HORZ, 41 | TREE_STR_VERT, 42 | TREE_STR_RTEE, 43 | TREE_STR_BEND, 44 | TREE_STR_TEND, 45 | TREE_STR_OPEN, 46 | TREE_STR_SHUT, 47 | TREE_STR_COUNT 48 | } TreeStr; 49 | 50 | typedef enum ColorSchemes_ { 51 | COLORSCHEME_DEFAULT = 0, 52 | COLORSCHEME_MONOCHROME = 1, 53 | COLORSCHEME_BLACKONWHITE = 2, 54 | COLORSCHEME_LIGHTTERMINAL = 3, 55 | COLORSCHEME_MIDNIGHT = 4, 56 | COLORSCHEME_BLACKNIGHT = 5, 57 | COLORSCHEME_BROKENGRAY = 6, 58 | LAST_COLORSCHEME = 7, 59 | } ColorSchemes; 60 | 61 | typedef enum ColorElements_ { 62 | RESET_COLOR, 63 | DEFAULT_COLOR, 64 | FUNCTION_BAR, 65 | FUNCTION_KEY, 66 | FAILED_SEARCH, 67 | PANEL_HEADER_FOCUS, 68 | PANEL_HEADER_UNFOCUS, 69 | PANEL_SELECTION_FOCUS, 70 | PANEL_SELECTION_FOLLOW, 71 | PANEL_SELECTION_UNFOCUS, 72 | LARGE_NUMBER, 73 | METER_TEXT, 74 | METER_VALUE, 75 | LED_COLOR, 76 | UPTIME, 77 | BATTERY, 78 | TASKS_RUNNING, 79 | SWAP, 80 | PROCESS, 81 | PROCESS_SHADOW, 82 | PROCESS_TAG, 83 | PROCESS_MEGABYTES, 84 | PROCESS_TREE, 85 | PROCESS_R_STATE, 86 | PROCESS_D_STATE, 87 | PROCESS_BASENAME, 88 | PROCESS_HIGH_PRIORITY, 89 | PROCESS_LOW_PRIORITY, 90 | PROCESS_THREAD, 91 | PROCESS_THREAD_BASENAME, 92 | BAR_BORDER, 93 | BAR_SHADOW, 94 | GRAPH_1, 95 | GRAPH_2, 96 | MEMORY_USED, 97 | MEMORY_BUFFERS, 98 | MEMORY_BUFFERS_TEXT, 99 | MEMORY_CACHE, 100 | LOAD, 101 | LOAD_AVERAGE_FIFTEEN, 102 | LOAD_AVERAGE_FIVE, 103 | LOAD_AVERAGE_ONE, 104 | CHECK_BOX, 105 | CHECK_MARK, 106 | CHECK_TEXT, 107 | CLOCK, 108 | HELP_BOLD, 109 | HOSTNAME, 110 | CPU_NICE, 111 | CPU_NICE_TEXT, 112 | CPU_NORMAL, 113 | CPU_KERNEL, 114 | CPU_IOWAIT, 115 | CPU_IRQ, 116 | CPU_SOFTIRQ, 117 | CPU_STEAL, 118 | CPU_GUEST, 119 | LAST_COLORELEMENT 120 | } ColorElements; 121 | 122 | void CRT_fatalError(const char* note) __attribute__ ((noreturn)); 123 | 124 | void CRT_handleSIGSEGV(int sgn); 125 | 126 | #define KEY_ALT(x) (KEY_F(64 - 26) + (x - 'A')) 127 | 128 | 129 | extern const char *CRT_treeStrAscii[TREE_STR_COUNT]; 130 | 131 | #ifdef HAVE_LIBNCURSESW 132 | 133 | extern const char *CRT_treeStrUtf8[TREE_STR_COUNT]; 134 | 135 | extern bool CRT_utf8; 136 | 137 | #endif 138 | 139 | extern const char **CRT_treeStr; 140 | 141 | extern int CRT_delay; 142 | 143 | int* CRT_colors; 144 | 145 | extern int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT]; 146 | 147 | extern int CRT_cursorX; 148 | 149 | extern int CRT_scrollHAmount; 150 | 151 | extern int CRT_scrollWheelVAmount; 152 | 153 | char* CRT_termType; 154 | 155 | // TODO move color scheme to Settings, perhaps? 156 | 157 | extern int CRT_colorScheme; 158 | 159 | void *backtraceArray[128]; 160 | 161 | #if HAVE_SETUID_ENABLED 162 | 163 | #define DIE(msg) do { CRT_done(); fprintf(stderr, msg); exit(1); } while(0) 164 | 165 | void CRT_dropPrivileges(); 166 | 167 | void CRT_restorePrivileges(); 168 | 169 | #else 170 | 171 | /* Turn setuid operations into NOPs */ 172 | 173 | #ifndef CRT_dropPrivileges 174 | #define CRT_dropPrivileges() 175 | #define CRT_restorePrivileges() 176 | #endif 177 | 178 | #endif 179 | 180 | // TODO: pass an instance of Settings instead. 181 | 182 | void CRT_init(int delay, int colorScheme); 183 | 184 | void CRT_done(); 185 | 186 | void CRT_fatalError(const char* note); 187 | 188 | int CRT_readKey(); 189 | 190 | void CRT_disableDelay(); 191 | 192 | void CRT_enableDelay(); 193 | 194 | void CRT_setColors(int colorScheme); 195 | 196 | #endif 197 | -------------------------------------------------------------------------------- /CategoriesPanel.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - CategoriesPanel.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "CategoriesPanel.h" 9 | 10 | #include "AvailableMetersPanel.h" 11 | #include "MetersPanel.h" 12 | #include "DisplayOptionsPanel.h" 13 | #include "ColumnsPanel.h" 14 | #include "ColorsPanel.h" 15 | #include "AvailableColumnsPanel.h" 16 | 17 | #include 18 | #include 19 | 20 | /*{ 21 | #include "Panel.h" 22 | #include "Settings.h" 23 | #include "ScreenManager.h" 24 | #include "ProcessList.h" 25 | 26 | typedef struct CategoriesPanel_ { 27 | Panel super; 28 | ScreenManager* scr; 29 | 30 | Settings* settings; 31 | Header* header; 32 | ProcessList* pl; 33 | } CategoriesPanel; 34 | 35 | }*/ 36 | 37 | static const char* const CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; 38 | 39 | static void CategoriesPanel_delete(Object* object) { 40 | Panel* super = (Panel*) object; 41 | CategoriesPanel* this = (CategoriesPanel*) object; 42 | Panel_done(super); 43 | free(this); 44 | } 45 | 46 | void CategoriesPanel_makeMetersPage(CategoriesPanel* this) { 47 | MetersPanel* leftMeters = MetersPanel_new(this->settings, "Left column", this->header->columns[0], this->scr); 48 | MetersPanel* rightMeters = MetersPanel_new(this->settings, "Right column", this->header->columns[1], this->scr); 49 | leftMeters->rightNeighbor = rightMeters; 50 | rightMeters->leftNeighbor = leftMeters; 51 | Panel* availableMeters = (Panel*) AvailableMetersPanel_new(this->settings, this->header, (Panel*) leftMeters, (Panel*) rightMeters, this->scr, this->pl); 52 | ScreenManager_add(this->scr, (Panel*) leftMeters, 20); 53 | ScreenManager_add(this->scr, (Panel*) rightMeters, 20); 54 | ScreenManager_add(this->scr, availableMeters, -1); 55 | } 56 | 57 | static void CategoriesPanel_makeDisplayOptionsPage(CategoriesPanel* this) { 58 | Panel* displayOptions = (Panel*) DisplayOptionsPanel_new(this->settings, this->scr); 59 | ScreenManager_add(this->scr, displayOptions, -1); 60 | } 61 | 62 | static void CategoriesPanel_makeColorsPage(CategoriesPanel* this) { 63 | Panel* colors = (Panel*) ColorsPanel_new(this->settings, this->scr); 64 | ScreenManager_add(this->scr, colors, -1); 65 | } 66 | 67 | static void CategoriesPanel_makeColumnsPage(CategoriesPanel* this) { 68 | Panel* columns = (Panel*) ColumnsPanel_new(this->settings); 69 | Panel* availableColumns = (Panel*) AvailableColumnsPanel_new(columns); 70 | ScreenManager_add(this->scr, columns, 20); 71 | ScreenManager_add(this->scr, availableColumns, -1); 72 | } 73 | 74 | static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) { 75 | CategoriesPanel* this = (CategoriesPanel*) super; 76 | 77 | HandlerResult result = IGNORED; 78 | 79 | int selected = Panel_getSelectedIndex(super); 80 | switch (ch) { 81 | case EVENT_SET_SELECTED: 82 | result = HANDLED; 83 | break; 84 | case KEY_UP: 85 | case KEY_CTRL('P'): 86 | case KEY_DOWN: 87 | case KEY_CTRL('N'): 88 | case KEY_NPAGE: 89 | case KEY_PPAGE: 90 | case KEY_HOME: 91 | case KEY_END: { 92 | int previous = selected; 93 | Panel_onKey(super, ch); 94 | selected = Panel_getSelectedIndex(super); 95 | if (previous != selected) 96 | result = HANDLED; 97 | break; 98 | } 99 | default: 100 | if (ch < 255 && isalpha(ch)) 101 | result = Panel_selectByTyping(super, ch); 102 | if (result == BREAK_LOOP) 103 | result = IGNORED; 104 | break; 105 | } 106 | if (result == HANDLED) { 107 | int size = ScreenManager_size(this->scr); 108 | for (int i = 1; i < size; i++) 109 | ScreenManager_remove(this->scr, 1); 110 | switch (selected) { 111 | case 0: 112 | CategoriesPanel_makeMetersPage(this); 113 | break; 114 | case 1: 115 | CategoriesPanel_makeDisplayOptionsPage(this); 116 | break; 117 | case 2: 118 | CategoriesPanel_makeColorsPage(this); 119 | break; 120 | case 3: 121 | CategoriesPanel_makeColumnsPage(this); 122 | break; 123 | } 124 | } 125 | return result; 126 | } 127 | 128 | PanelClass CategoriesPanel_class = { 129 | .super = { 130 | .extends = Class(Panel), 131 | .delete = CategoriesPanel_delete 132 | }, 133 | .eventHandler = CategoriesPanel_eventHandler 134 | }; 135 | 136 | CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Header* header, ProcessList* pl) { 137 | CategoriesPanel* this = AllocThis(CategoriesPanel); 138 | Panel* super = (Panel*) this; 139 | FunctionBar* fuBar = FunctionBar_new(CategoriesFunctions, NULL, NULL); 140 | Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar); 141 | 142 | this->scr = scr; 143 | this->settings = settings; 144 | this->header = header; 145 | this->pl = pl; 146 | Panel_setHeader(super, "Setup"); 147 | Panel_add(super, (Object*) ListItem_new("Meters", 0)); 148 | Panel_add(super, (Object*) ListItem_new("Display options", 0)); 149 | Panel_add(super, (Object*) ListItem_new("Colors", 0)); 150 | Panel_add(super, (Object*) ListItem_new("Columns", 0)); 151 | return this; 152 | } 153 | -------------------------------------------------------------------------------- /CategoriesPanel.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_CategoriesPanel 4 | #define HEADER_CategoriesPanel 5 | /* 6 | htop - CategoriesPanel.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Panel.h" 13 | #include "Settings.h" 14 | #include "ScreenManager.h" 15 | #include "ProcessList.h" 16 | 17 | typedef struct CategoriesPanel_ { 18 | Panel super; 19 | ScreenManager* scr; 20 | 21 | Settings* settings; 22 | Header* header; 23 | ProcessList* pl; 24 | } CategoriesPanel; 25 | 26 | 27 | void CategoriesPanel_makeMetersPage(CategoriesPanel* this); 28 | 29 | extern PanelClass CategoriesPanel_class; 30 | 31 | CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Header* header, ProcessList* pl); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /CheckItem.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - CheckItem.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "CheckItem.h" 9 | 10 | #include "CRT.h" 11 | 12 | #include 13 | #include 14 | 15 | /*{ 16 | #include "Object.h" 17 | 18 | typedef struct CheckItem_ { 19 | Object super; 20 | char* text; 21 | bool* ref; 22 | bool value; 23 | } CheckItem; 24 | 25 | }*/ 26 | 27 | static void CheckItem_delete(Object* cast) { 28 | CheckItem* this = (CheckItem*)cast; 29 | assert (this != NULL); 30 | 31 | free(this->text); 32 | free(this); 33 | } 34 | 35 | static void CheckItem_display(Object* cast, RichString* out) { 36 | CheckItem* this = (CheckItem*)cast; 37 | assert (this != NULL); 38 | RichString_write(out, CRT_colors[CHECK_BOX], "["); 39 | if (CheckItem_get(this)) 40 | RichString_append(out, CRT_colors[CHECK_MARK], "x"); 41 | else 42 | RichString_append(out, CRT_colors[CHECK_MARK], " "); 43 | RichString_append(out, CRT_colors[CHECK_BOX], "] "); 44 | RichString_append(out, CRT_colors[CHECK_TEXT], this->text); 45 | } 46 | 47 | ObjectClass CheckItem_class = { 48 | .display = CheckItem_display, 49 | .delete = CheckItem_delete 50 | }; 51 | 52 | CheckItem* CheckItem_newByRef(char* text, bool* ref) { 53 | CheckItem* this = AllocThis(CheckItem); 54 | this->text = text; 55 | this->value = false; 56 | this->ref = ref; 57 | return this; 58 | } 59 | 60 | CheckItem* CheckItem_newByVal(char* text, bool value) { 61 | CheckItem* this = AllocThis(CheckItem); 62 | this->text = text; 63 | this->value = value; 64 | this->ref = NULL; 65 | return this; 66 | } 67 | 68 | void CheckItem_set(CheckItem* this, bool value) { 69 | if (this->ref) 70 | *(this->ref) = value; 71 | else 72 | this->value = value; 73 | } 74 | 75 | bool CheckItem_get(CheckItem* this) { 76 | if (this->ref) 77 | return *(this->ref); 78 | else 79 | return this->value; 80 | } 81 | -------------------------------------------------------------------------------- /CheckItem.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_CheckItem 4 | #define HEADER_CheckItem 5 | /* 6 | htop - CheckItem.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Object.h" 13 | 14 | typedef struct CheckItem_ { 15 | Object super; 16 | char* text; 17 | bool* ref; 18 | bool value; 19 | } CheckItem; 20 | 21 | 22 | extern ObjectClass CheckItem_class; 23 | 24 | CheckItem* CheckItem_newByRef(char* text, bool* ref); 25 | 26 | CheckItem* CheckItem_newByVal(char* text, bool value); 27 | 28 | void CheckItem_set(CheckItem* this, bool value); 29 | 30 | bool CheckItem_get(CheckItem* this); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /ClockMeter.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - ClockMeter.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "ClockMeter.h" 9 | 10 | #include "CRT.h" 11 | 12 | #include 13 | 14 | /*{ 15 | #include "Meter.h" 16 | }*/ 17 | 18 | int ClockMeter_attributes[] = { 19 | CLOCK 20 | }; 21 | 22 | static void ClockMeter_updateValues(Meter* this, char* buffer, int size) { 23 | time_t t = time(NULL); 24 | struct tm result; 25 | struct tm *lt = localtime_r(&t, &result); 26 | this->values[0] = lt->tm_hour * 60 + lt->tm_min; 27 | strftime(buffer, size, "%H:%M:%S", lt); 28 | } 29 | 30 | MeterClass ClockMeter_class = { 31 | .super = { 32 | .extends = Class(Meter), 33 | .delete = Meter_delete 34 | }, 35 | .updateValues = ClockMeter_updateValues, 36 | .defaultMode = TEXT_METERMODE, 37 | .maxItems = 1, 38 | .total = 1440, /* 24*60 */ 39 | .attributes = ClockMeter_attributes, 40 | .name = "Clock", 41 | .uiName = "Clock", 42 | .caption = "Time: ", 43 | }; 44 | -------------------------------------------------------------------------------- /ClockMeter.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_ClockMeter 4 | #define HEADER_ClockMeter 5 | /* 6 | htop - ClockMeter.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Meter.h" 13 | 14 | extern int ClockMeter_attributes[]; 15 | 16 | extern MeterClass ClockMeter_class; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /ColorsPanel.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - ColorsPanel.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "ColorsPanel.h" 9 | 10 | #include "CRT.h" 11 | #include "CheckItem.h" 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | // TO ADD A NEW SCHEME: 18 | // * Increment the size of bool check in ColorsPanel.h 19 | // * Add the entry in the ColorSchemeNames array below in the file 20 | // * Add a define in CRT.h that matches the order of the array 21 | // * Add the colors in CRT_setColors 22 | 23 | /*{ 24 | #include "Panel.h" 25 | #include "Settings.h" 26 | #include "ScreenManager.h" 27 | 28 | typedef struct ColorsPanel_ { 29 | Panel super; 30 | 31 | Settings* settings; 32 | ScreenManager* scr; 33 | } ColorsPanel; 34 | 35 | }*/ 36 | 37 | static const char* const ColorsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; 38 | 39 | static const char* const ColorSchemeNames[] = { 40 | "Default", 41 | "Monochromatic", 42 | "Black on White", 43 | "Light Terminal", 44 | "MC", 45 | "Black Night", 46 | "Broken Gray", 47 | NULL 48 | }; 49 | 50 | static void ColorsPanel_delete(Object* object) { 51 | Panel* super = (Panel*) object; 52 | ColorsPanel* this = (ColorsPanel*) object; 53 | Panel_done(super); 54 | free(this); 55 | } 56 | 57 | static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) { 58 | ColorsPanel* this = (ColorsPanel*) super; 59 | 60 | HandlerResult result = IGNORED; 61 | int mark = Panel_getSelectedIndex(super); 62 | 63 | switch(ch) { 64 | case 0x0a: 65 | case 0x0d: 66 | case KEY_ENTER: 67 | case KEY_MOUSE: 68 | case KEY_RECLICK: 69 | case ' ': 70 | for (int i = 0; ColorSchemeNames[i] != NULL; i++) 71 | CheckItem_set((CheckItem*)Panel_get(super, i), false); 72 | CheckItem_set((CheckItem*)Panel_get(super, mark), true); 73 | this->settings->colorScheme = mark; 74 | result = HANDLED; 75 | } 76 | 77 | if (result == HANDLED) { 78 | this->settings->changed = true; 79 | const Header* header = this->scr->header; 80 | CRT_setColors(mark); 81 | clear(); 82 | Panel* menu = (Panel*) Vector_get(this->scr->panels, 0); 83 | Header_draw(header); 84 | RichString_setAttr(&(super->header), CRT_colors[PANEL_HEADER_FOCUS]); 85 | RichString_setAttr(&(menu->header), CRT_colors[PANEL_HEADER_UNFOCUS]); 86 | ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2); 87 | } 88 | return result; 89 | } 90 | 91 | PanelClass ColorsPanel_class = { 92 | .super = { 93 | .extends = Class(Panel), 94 | .delete = ColorsPanel_delete 95 | }, 96 | .eventHandler = ColorsPanel_eventHandler 97 | }; 98 | 99 | ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr) { 100 | ColorsPanel* this = AllocThis(ColorsPanel); 101 | Panel* super = (Panel*) this; 102 | FunctionBar* fuBar = FunctionBar_new(ColorsFunctions, NULL, NULL); 103 | Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true, fuBar); 104 | 105 | this->settings = settings; 106 | this->scr = scr; 107 | 108 | Panel_setHeader(super, "Colors"); 109 | for (int i = 0; ColorSchemeNames[i] != NULL; i++) { 110 | Panel_add(super, (Object*) CheckItem_newByVal(xStrdup(ColorSchemeNames[i]), false)); 111 | } 112 | CheckItem_set((CheckItem*)Panel_get(super, settings->colorScheme), true); 113 | return this; 114 | } 115 | -------------------------------------------------------------------------------- /ColorsPanel.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_ColorsPanel 4 | #define HEADER_ColorsPanel 5 | /* 6 | htop - ColorsPanel.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | // TO ADD A NEW SCHEME: 13 | // * Increment the size of bool check in ColorsPanel.h 14 | // * Add the entry in the ColorSchemeNames array below in the file 15 | // * Add a define in CRT.h that matches the order of the array 16 | // * Add the colors in CRT_setColors 17 | 18 | #include "Panel.h" 19 | #include "Settings.h" 20 | #include "ScreenManager.h" 21 | 22 | typedef struct ColorsPanel_ { 23 | Panel super; 24 | 25 | Settings* settings; 26 | ScreenManager* scr; 27 | } ColorsPanel; 28 | 29 | 30 | extern PanelClass ColorsPanel_class; 31 | 32 | ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /ColumnsPanel.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - ColumnsPanel.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "ColumnsPanel.h" 9 | #include "Platform.h" 10 | 11 | #include "StringUtils.h" 12 | #include "ListItem.h" 13 | #include "CRT.h" 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | /*{ 20 | #include "Panel.h" 21 | #include "Settings.h" 22 | 23 | typedef struct ColumnsPanel_ { 24 | Panel super; 25 | 26 | Settings* settings; 27 | bool moving; 28 | } ColumnsPanel; 29 | 30 | }*/ 31 | 32 | static const char* const ColumnsFunctions[] = {" ", " ", " ", " ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL}; 33 | 34 | static void ColumnsPanel_delete(Object* object) { 35 | Panel* super = (Panel*) object; 36 | ColumnsPanel* this = (ColumnsPanel*) object; 37 | Panel_done(super); 38 | free(this); 39 | } 40 | 41 | static HandlerResult ColumnsPanel_eventHandler(Panel* super, int ch) { 42 | ColumnsPanel* const this = (ColumnsPanel*) super; 43 | 44 | int selected = Panel_getSelectedIndex(super); 45 | HandlerResult result = IGNORED; 46 | int size = Panel_size(super); 47 | 48 | switch(ch) { 49 | case 0x0a: 50 | case 0x0d: 51 | case KEY_ENTER: 52 | case KEY_MOUSE: 53 | case KEY_RECLICK: 54 | { 55 | if (selected < size - 1) { 56 | this->moving = !(this->moving); 57 | Panel_setSelectionColor(super, this->moving ? CRT_colors[PANEL_SELECTION_FOLLOW] : CRT_colors[PANEL_SELECTION_FOCUS]); 58 | ((ListItem*)Panel_getSelected(super))->moving = this->moving; 59 | result = HANDLED; 60 | } 61 | break; 62 | } 63 | case KEY_UP: 64 | { 65 | if (!this->moving) { 66 | break; 67 | } 68 | } 69 | /* else fallthrough */ 70 | case KEY_F(7): 71 | case '[': 72 | case '-': 73 | { 74 | if (selected < size - 1) 75 | Panel_moveSelectedUp(super); 76 | result = HANDLED; 77 | break; 78 | } 79 | case KEY_DOWN: 80 | { 81 | if (!this->moving) { 82 | break; 83 | } 84 | } 85 | /* else fallthrough */ 86 | case KEY_F(8): 87 | case ']': 88 | case '+': 89 | { 90 | if (selected < size - 2) 91 | Panel_moveSelectedDown(super); 92 | result = HANDLED; 93 | break; 94 | } 95 | case KEY_F(9): 96 | case KEY_DC: 97 | { 98 | if (selected < size - 1) { 99 | Panel_remove(super, selected); 100 | } 101 | result = HANDLED; 102 | break; 103 | } 104 | default: 105 | { 106 | if (ch < 255 && isalpha(ch)) 107 | result = Panel_selectByTyping(super, ch); 108 | if (result == BREAK_LOOP) 109 | result = IGNORED; 110 | break; 111 | } 112 | } 113 | if (result == HANDLED) 114 | ColumnsPanel_update(super); 115 | return result; 116 | } 117 | 118 | PanelClass ColumnsPanel_class = { 119 | .super = { 120 | .extends = Class(Panel), 121 | .delete = ColumnsPanel_delete 122 | }, 123 | .eventHandler = ColumnsPanel_eventHandler 124 | }; 125 | 126 | ColumnsPanel* ColumnsPanel_new(Settings* settings) { 127 | ColumnsPanel* this = AllocThis(ColumnsPanel); 128 | Panel* super = (Panel*) this; 129 | FunctionBar* fuBar = FunctionBar_new(ColumnsFunctions, NULL, NULL); 130 | Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar); 131 | 132 | this->settings = settings; 133 | this->moving = false; 134 | Panel_setHeader(super, "Active Columns"); 135 | 136 | ProcessField* fields = this->settings->fields; 137 | for (; *fields; fields++) { 138 | if (Process_fields[*fields].name) { 139 | Panel_add(super, (Object*) ListItem_new(Process_fields[*fields].name, *fields)); 140 | } 141 | } 142 | return this; 143 | } 144 | 145 | int ColumnsPanel_fieldNameToIndex(const char* name) { 146 | for (int j = 1; j <= Platform_numberOfFields; j++) { 147 | if (String_eq(name, Process_fields[j].name)) { 148 | return j; 149 | } 150 | } 151 | return -1; 152 | } 153 | 154 | void ColumnsPanel_update(Panel* super) { 155 | ColumnsPanel* this = (ColumnsPanel*) super; 156 | int size = Panel_size(super); 157 | this->settings->changed = true; 158 | this->settings->fields = xRealloc(this->settings->fields, sizeof(ProcessField) * (size+1)); 159 | this->settings->flags = 0; 160 | for (int i = 0; i < size; i++) { 161 | int key = ((ListItem*) Panel_get(super, i))->key; 162 | this->settings->fields[i] = key; 163 | this->settings->flags |= Process_fields[key].flags; 164 | } 165 | this->settings->fields[size] = 0; 166 | } 167 | 168 | -------------------------------------------------------------------------------- /ColumnsPanel.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_ColumnsPanel 4 | #define HEADER_ColumnsPanel 5 | /* 6 | htop - ColumnsPanel.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Panel.h" 13 | #include "Settings.h" 14 | 15 | typedef struct ColumnsPanel_ { 16 | Panel super; 17 | 18 | Settings* settings; 19 | bool moving; 20 | } ColumnsPanel; 21 | 22 | 23 | extern PanelClass ColumnsPanel_class; 24 | 25 | ColumnsPanel* ColumnsPanel_new(Settings* settings); 26 | 27 | int ColumnsPanel_fieldNameToIndex(const char* name); 28 | 29 | void ColumnsPanel_update(Panel* super); 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /DisplayOptionsPanel.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - DisplayOptionsPanel.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "DisplayOptionsPanel.h" 9 | 10 | #include "CheckItem.h" 11 | #include "CRT.h" 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | /*{ 18 | #include "Panel.h" 19 | #include "Settings.h" 20 | #include "ScreenManager.h" 21 | 22 | typedef struct DisplayOptionsPanel_ { 23 | Panel super; 24 | 25 | Settings* settings; 26 | ScreenManager* scr; 27 | } DisplayOptionsPanel; 28 | 29 | }*/ 30 | 31 | static const char* const DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; 32 | 33 | static void DisplayOptionsPanel_delete(Object* object) { 34 | Panel* super = (Panel*) object; 35 | DisplayOptionsPanel* this = (DisplayOptionsPanel*) object; 36 | Panel_done(super); 37 | free(this); 38 | } 39 | 40 | static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) { 41 | DisplayOptionsPanel* this = (DisplayOptionsPanel*) super; 42 | 43 | HandlerResult result = IGNORED; 44 | CheckItem* selected = (CheckItem*) Panel_getSelected(super); 45 | 46 | switch(ch) { 47 | case 0x0a: 48 | case 0x0d: 49 | case KEY_ENTER: 50 | case KEY_MOUSE: 51 | case KEY_RECLICK: 52 | case ' ': 53 | CheckItem_set(selected, ! (CheckItem_get(selected)) ); 54 | result = HANDLED; 55 | } 56 | 57 | if (result == HANDLED) { 58 | this->settings->changed = true; 59 | const Header* header = this->scr->header; 60 | Header_calculateHeight((Header*) header); 61 | Header_reinit((Header*) header); 62 | Header_draw(header); 63 | ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2); 64 | } 65 | return result; 66 | } 67 | 68 | PanelClass DisplayOptionsPanel_class = { 69 | .super = { 70 | .extends = Class(Panel), 71 | .delete = DisplayOptionsPanel_delete 72 | }, 73 | .eventHandler = DisplayOptionsPanel_eventHandler 74 | }; 75 | 76 | DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) { 77 | DisplayOptionsPanel* this = AllocThis(DisplayOptionsPanel); 78 | Panel* super = (Panel*) this; 79 | FunctionBar* fuBar = FunctionBar_new(DisplayOptionsFunctions, NULL, NULL); 80 | Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true, fuBar); 81 | 82 | this->settings = settings; 83 | this->scr = scr; 84 | 85 | Panel_setHeader(super, "Display options"); 86 | Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Tree view"), &(settings->treeView))); 87 | Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Shadow other users' processes"), &(settings->shadowOtherUsers))); 88 | Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Hide kernel threads"), &(settings->hideKernelThreads))); 89 | Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Hide userland process threads"), &(settings->hideUserlandThreads))); 90 | Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Display threads in a different color"), &(settings->highlightThreads))); 91 | Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Show custom thread names"), &(settings->showThreadNames))); 92 | Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Show program path"), &(settings->showProgramPath))); 93 | Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Highlight program \"basename\""), &(settings->highlightBaseName))); 94 | Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Highlight large numbers in memory counters"), &(settings->highlightMegabytes))); 95 | Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Leave a margin around header"), &(settings->headerMargin))); 96 | Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->detailedCPUTime))); 97 | Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Count CPUs from 0 instead of 1"), &(settings->countCPUsFromZero))); 98 | Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Update process names on every refresh"), &(settings->updateProcessNames))); 99 | Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Add guest time in CPU meter percentage"), &(settings->accountGuestInCPUMeter))); 100 | return this; 101 | } 102 | -------------------------------------------------------------------------------- /DisplayOptionsPanel.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_DisplayOptionsPanel 4 | #define HEADER_DisplayOptionsPanel 5 | /* 6 | htop - DisplayOptionsPanel.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Panel.h" 13 | #include "Settings.h" 14 | #include "ScreenManager.h" 15 | 16 | typedef struct DisplayOptionsPanel_ { 17 | Panel super; 18 | 19 | Settings* settings; 20 | ScreenManager* scr; 21 | } DisplayOptionsPanel; 22 | 23 | 24 | extern PanelClass DisplayOptionsPanel_class; 25 | 26 | DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /EnvScreen.c: -------------------------------------------------------------------------------- 1 | #include "EnvScreen.h" 2 | 3 | #include "config.h" 4 | #include "CRT.h" 5 | #include "IncSet.h" 6 | #include "ListItem.h" 7 | #include "Platform.h" 8 | #include "StringUtils.h" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | /*{ 15 | #include "InfoScreen.h" 16 | 17 | typedef struct EnvScreen_ { 18 | InfoScreen super; 19 | } EnvScreen; 20 | }*/ 21 | 22 | InfoScreenClass EnvScreen_class = { 23 | .super = { 24 | .extends = Class(Object), 25 | .delete = EnvScreen_delete 26 | }, 27 | .scan = EnvScreen_scan, 28 | .draw = EnvScreen_draw 29 | }; 30 | 31 | EnvScreen* EnvScreen_new(Process* process) { 32 | EnvScreen* this = xMalloc(sizeof(EnvScreen)); 33 | Object_setClass(this, Class(EnvScreen)); 34 | return (EnvScreen*) InfoScreen_init(&this->super, process, NULL, LINES-3, " "); 35 | } 36 | 37 | void EnvScreen_delete(Object* this) { 38 | free(InfoScreen_done((InfoScreen*)this)); 39 | } 40 | 41 | void EnvScreen_draw(InfoScreen* this) { 42 | InfoScreen_drawTitled(this, "Environment of process %d - %s", this->process->pid, this->process->comm); 43 | } 44 | 45 | void EnvScreen_scan(InfoScreen* this) { 46 | Panel* panel = this->display; 47 | int idx = MAX(Panel_getSelectedIndex(panel), 0); 48 | 49 | Panel_prune(panel); 50 | 51 | CRT_dropPrivileges(); 52 | char* env = Platform_getProcessEnv(this->process->pid); 53 | CRT_restorePrivileges(); 54 | if (env) { 55 | for (char *p = env; *p; p = strrchr(p, 0)+1) 56 | InfoScreen_addLine(this, p); 57 | free(env); 58 | } 59 | else { 60 | InfoScreen_addLine(this, "Could not read process environment."); 61 | } 62 | 63 | Vector_insertionSort(this->lines); 64 | Vector_insertionSort(panel->items); 65 | Panel_setSelected(panel, idx); 66 | } 67 | -------------------------------------------------------------------------------- /EnvScreen.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_EnvScreen 4 | #define HEADER_EnvScreen 5 | 6 | #include "InfoScreen.h" 7 | 8 | typedef struct EnvScreen_ { 9 | InfoScreen super; 10 | } EnvScreen; 11 | 12 | extern InfoScreenClass EnvScreen_class; 13 | 14 | EnvScreen* EnvScreen_new(Process* process); 15 | 16 | void EnvScreen_delete(Object* this); 17 | 18 | void EnvScreen_draw(InfoScreen* this); 19 | 20 | void EnvScreen_scan(InfoScreen* this); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /FunctionBar.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - FunctionBar.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "FunctionBar.h" 9 | #include "CRT.h" 10 | #include "RichString.h" 11 | #include "XAlloc.h" 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | /*{ 18 | 19 | #include 20 | 21 | typedef struct FunctionBar_ { 22 | int size; 23 | char** functions; 24 | char** keys; 25 | int* events; 26 | bool staticData; 27 | } FunctionBar; 28 | 29 | }*/ 30 | 31 | static const char* const FunctionBar_FKeys[] = {"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", NULL}; 32 | 33 | static const char* const FunctionBar_FLabels[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", NULL}; 34 | 35 | static int FunctionBar_FEvents[] = {KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5), KEY_F(6), KEY_F(7), KEY_F(8), KEY_F(9), KEY_F(10)}; 36 | 37 | static const char* const FunctionBar_EnterEscKeys[] = {"Enter", "Esc", NULL}; 38 | static const int FunctionBar_EnterEscEvents[] = {13, 27}; 39 | 40 | FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc) { 41 | const char* functions[] = {enter, esc, NULL}; 42 | return FunctionBar_new(functions, FunctionBar_EnterEscKeys, FunctionBar_EnterEscEvents); 43 | } 44 | 45 | FunctionBar* FunctionBar_new(const char* const* functions, const char* const* keys, const int* events) { 46 | FunctionBar* this = xCalloc(1, sizeof(FunctionBar)); 47 | this->functions = xCalloc(16, sizeof(char*)); 48 | if (!functions) { 49 | functions = FunctionBar_FLabels; 50 | } 51 | for (int i = 0; i < 15 && functions[i]; i++) { 52 | this->functions[i] = xStrdup(functions[i]); 53 | } 54 | if (keys && events) { 55 | this->staticData = false; 56 | this->keys = xCalloc(15, sizeof(char*)); 57 | this->events = xCalloc(15, sizeof(int)); 58 | int i = 0; 59 | while (i < 15 && functions[i]) { 60 | this->keys[i] = xStrdup(keys[i]); 61 | this->events[i] = events[i]; 62 | i++; 63 | } 64 | this->size = i; 65 | } else { 66 | this->staticData = true; 67 | this->keys = (char**) FunctionBar_FKeys; 68 | this->events = FunctionBar_FEvents; 69 | this->size = 10; 70 | } 71 | return this; 72 | } 73 | 74 | void FunctionBar_delete(FunctionBar* this) { 75 | for (int i = 0; i < 15 && this->functions[i]; i++) { 76 | free(this->functions[i]); 77 | } 78 | free(this->functions); 79 | if (!this->staticData) { 80 | for (int i = 0; i < this->size; i++) { 81 | free(this->keys[i]); 82 | } 83 | free(this->keys); 84 | free(this->events); 85 | } 86 | free(this); 87 | } 88 | 89 | void FunctionBar_setLabel(FunctionBar* this, int event, const char* text) { 90 | for (int i = 0; i < this->size; i++) { 91 | if (this->events[i] == event) { 92 | free(this->functions[i]); 93 | this->functions[i] = xStrdup(text); 94 | break; 95 | } 96 | } 97 | } 98 | 99 | void FunctionBar_draw(const FunctionBar* this, char* buffer) { 100 | FunctionBar_drawAttr(this, buffer, CRT_colors[FUNCTION_BAR]); 101 | } 102 | 103 | void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr) { 104 | attrset(CRT_colors[FUNCTION_BAR]); 105 | mvhline(LINES-1, 0, ' ', COLS); 106 | int x = 0; 107 | for (int i = 0; i < this->size; i++) { 108 | attrset(CRT_colors[FUNCTION_KEY]); 109 | mvaddstr(LINES-1, x, this->keys[i]); 110 | x += strlen(this->keys[i]); 111 | attrset(CRT_colors[FUNCTION_BAR]); 112 | mvaddstr(LINES-1, x, this->functions[i]); 113 | x += strlen(this->functions[i]); 114 | } 115 | if (buffer) { 116 | attrset(attr); 117 | mvaddstr(LINES-1, x, buffer); 118 | CRT_cursorX = x + strlen(buffer); 119 | curs_set(1); 120 | } else { 121 | curs_set(0); 122 | } 123 | attrset(CRT_colors[RESET_COLOR]); 124 | } 125 | 126 | int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos) { 127 | int x = 0; 128 | for (int i = 0; i < this->size; i++) { 129 | x += strlen(this->keys[i]); 130 | x += strlen(this->functions[i]); 131 | if (pos < x) { 132 | return this->events[i]; 133 | } 134 | } 135 | return ERR; 136 | } 137 | -------------------------------------------------------------------------------- /FunctionBar.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_FunctionBar 4 | #define HEADER_FunctionBar 5 | /* 6 | htop - FunctionBar.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | 13 | #include 14 | 15 | typedef struct FunctionBar_ { 16 | int size; 17 | char** functions; 18 | char** keys; 19 | int* events; 20 | bool staticData; 21 | } FunctionBar; 22 | 23 | 24 | 25 | FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc); 26 | 27 | FunctionBar* FunctionBar_new(const char* const* functions, const char* const* keys, const int* events); 28 | 29 | void FunctionBar_delete(FunctionBar* this); 30 | 31 | void FunctionBar_setLabel(FunctionBar* this, int event, const char* text); 32 | 33 | void FunctionBar_draw(const FunctionBar* this, char* buffer); 34 | 35 | void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr); 36 | 37 | int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /Hashtable.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - Hashtable.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "Hashtable.h" 9 | #include "XAlloc.h" 10 | 11 | #include 12 | #include 13 | 14 | /*{ 15 | #include 16 | 17 | typedef struct Hashtable_ Hashtable; 18 | 19 | typedef void(*Hashtable_PairFunction)(int, void*, void*); 20 | 21 | typedef struct HashtableItem { 22 | unsigned int key; 23 | void* value; 24 | struct HashtableItem* next; 25 | } HashtableItem; 26 | 27 | struct Hashtable_ { 28 | int size; 29 | HashtableItem** buckets; 30 | int items; 31 | bool owner; 32 | }; 33 | }*/ 34 | 35 | #ifdef DEBUG 36 | 37 | static bool Hashtable_isConsistent(Hashtable* this) { 38 | int items = 0; 39 | for (int i = 0; i < this->size; i++) { 40 | HashtableItem* bucket = this->buckets[i]; 41 | while (bucket) { 42 | items++; 43 | bucket = bucket->next; 44 | } 45 | } 46 | return items == this->items; 47 | } 48 | 49 | int Hashtable_count(Hashtable* this) { 50 | int items = 0; 51 | for (int i = 0; i < this->size; i++) { 52 | HashtableItem* bucket = this->buckets[i]; 53 | while (bucket) { 54 | items++; 55 | bucket = bucket->next; 56 | } 57 | } 58 | assert(items == this->items); 59 | return items; 60 | } 61 | 62 | #endif 63 | 64 | static HashtableItem* HashtableItem_new(unsigned int key, void* value) { 65 | HashtableItem* this; 66 | 67 | this = xMalloc(sizeof(HashtableItem)); 68 | this->key = key; 69 | this->value = value; 70 | this->next = NULL; 71 | return this; 72 | } 73 | 74 | Hashtable* Hashtable_new(int size, bool owner) { 75 | Hashtable* this; 76 | 77 | this = xMalloc(sizeof(Hashtable)); 78 | this->items = 0; 79 | this->size = size; 80 | this->buckets = (HashtableItem**) xCalloc(size, sizeof(HashtableItem*)); 81 | this->owner = owner; 82 | assert(Hashtable_isConsistent(this)); 83 | return this; 84 | } 85 | 86 | void Hashtable_delete(Hashtable* this) { 87 | assert(Hashtable_isConsistent(this)); 88 | for (int i = 0; i < this->size; i++) { 89 | HashtableItem* walk = this->buckets[i]; 90 | while (walk != NULL) { 91 | if (this->owner) 92 | free(walk->value); 93 | HashtableItem* savedWalk = walk; 94 | walk = savedWalk->next; 95 | free(savedWalk); 96 | } 97 | } 98 | free(this->buckets); 99 | free(this); 100 | } 101 | 102 | void Hashtable_put(Hashtable* this, unsigned int key, void* value) { 103 | unsigned int index = key % this->size; 104 | HashtableItem** bucketPtr = &(this->buckets[index]); 105 | while (true) 106 | if (*bucketPtr == NULL) { 107 | *bucketPtr = HashtableItem_new(key, value); 108 | this->items++; 109 | break; 110 | } else if ((*bucketPtr)->key == key) { 111 | if (this->owner) 112 | free((*bucketPtr)->value); 113 | (*bucketPtr)->value = value; 114 | break; 115 | } else 116 | bucketPtr = &((*bucketPtr)->next); 117 | assert(Hashtable_isConsistent(this)); 118 | } 119 | 120 | void* Hashtable_remove(Hashtable* this, unsigned int key) { 121 | unsigned int index = key % this->size; 122 | 123 | assert(Hashtable_isConsistent(this)); 124 | 125 | HashtableItem** bucket; 126 | for (bucket = &(this->buckets[index]); *bucket; bucket = &((*bucket)->next) ) { 127 | if ((*bucket)->key == key) { 128 | void* value = (*bucket)->value; 129 | HashtableItem* next = (*bucket)->next; 130 | free(*bucket); 131 | (*bucket) = next; 132 | this->items--; 133 | if (this->owner) { 134 | free(value); 135 | assert(Hashtable_isConsistent(this)); 136 | return NULL; 137 | } else { 138 | assert(Hashtable_isConsistent(this)); 139 | return value; 140 | } 141 | } 142 | } 143 | assert(Hashtable_isConsistent(this)); 144 | return NULL; 145 | } 146 | 147 | inline void* Hashtable_get(Hashtable* this, unsigned int key) { 148 | unsigned int index = key % this->size; 149 | HashtableItem* bucketPtr = this->buckets[index]; 150 | while (true) { 151 | if (bucketPtr == NULL) { 152 | assert(Hashtable_isConsistent(this)); 153 | return NULL; 154 | } else if (bucketPtr->key == key) { 155 | assert(Hashtable_isConsistent(this)); 156 | return bucketPtr->value; 157 | } else 158 | bucketPtr = bucketPtr->next; 159 | } 160 | } 161 | 162 | void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData) { 163 | assert(Hashtable_isConsistent(this)); 164 | for (int i = 0; i < this->size; i++) { 165 | HashtableItem* walk = this->buckets[i]; 166 | while (walk != NULL) { 167 | f(walk->key, walk->value, userData); 168 | walk = walk->next; 169 | } 170 | } 171 | assert(Hashtable_isConsistent(this)); 172 | } 173 | -------------------------------------------------------------------------------- /Hashtable.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Hashtable 4 | #define HEADER_Hashtable 5 | /* 6 | htop - Hashtable.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include 13 | 14 | typedef struct Hashtable_ Hashtable; 15 | 16 | typedef void(*Hashtable_PairFunction)(int, void*, void*); 17 | 18 | typedef struct HashtableItem { 19 | unsigned int key; 20 | void* value; 21 | struct HashtableItem* next; 22 | } HashtableItem; 23 | 24 | struct Hashtable_ { 25 | int size; 26 | HashtableItem** buckets; 27 | int items; 28 | bool owner; 29 | }; 30 | 31 | #ifdef DEBUG 32 | 33 | int Hashtable_count(Hashtable* this); 34 | 35 | #endif 36 | 37 | Hashtable* Hashtable_new(int size, bool owner); 38 | 39 | void Hashtable_delete(Hashtable* this); 40 | 41 | void Hashtable_put(Hashtable* this, unsigned int key, void* value); 42 | 43 | void* Hashtable_remove(Hashtable* this, unsigned int key); 44 | 45 | extern void* Hashtable_get(Hashtable* this, unsigned int key); 46 | 47 | void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /Header.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Header 4 | #define HEADER_Header 5 | /* 6 | htop - Header.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Meter.h" 13 | #include "Settings.h" 14 | #include "Vector.h" 15 | 16 | typedef struct Header_ { 17 | Vector** columns; 18 | Settings* settings; 19 | struct ProcessList_* pl; 20 | int nrColumns; 21 | int pad; 22 | int height; 23 | } Header; 24 | 25 | 26 | #ifndef MAX 27 | #define MAX(a,b) ((a)>(b)?(a):(b)) 28 | #endif 29 | 30 | #ifndef Header_forEachColumn 31 | #define Header_forEachColumn(this_, i_) for (int (i_)=0; (i_) < (this_)->nrColumns; ++(i_)) 32 | #endif 33 | 34 | Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns); 35 | 36 | void Header_delete(Header* this); 37 | 38 | void Header_populateFromSettings(Header* this); 39 | 40 | void Header_writeBackToSettings(const Header* this); 41 | 42 | MeterModeId Header_addMeterByName(Header* this, char* name, int column); 43 | 44 | void Header_setMode(Header* this, int i, MeterModeId mode, int column); 45 | 46 | Meter* Header_addMeterByClass(Header* this, MeterClass* type, int param, int column); 47 | 48 | int Header_size(Header* this, int column); 49 | 50 | char* Header_readMeterName(Header* this, int i, int column); 51 | 52 | MeterModeId Header_readMeterMode(Header* this, int i, int column); 53 | 54 | void Header_reinit(Header* this); 55 | 56 | void Header_draw(const Header* this); 57 | 58 | int Header_calculateHeight(Header* this); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /HostnameMeter.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - HostnameMeter.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "HostnameMeter.h" 9 | 10 | #include "CRT.h" 11 | 12 | #include 13 | 14 | /*{ 15 | #include "Meter.h" 16 | }*/ 17 | 18 | int HostnameMeter_attributes[] = { 19 | HOSTNAME 20 | }; 21 | 22 | static void HostnameMeter_updateValues(Meter* this, char* buffer, int size) { 23 | (void) this; 24 | gethostname(buffer, size-1); 25 | } 26 | 27 | MeterClass HostnameMeter_class = { 28 | .super = { 29 | .extends = Class(Meter), 30 | .delete = Meter_delete 31 | }, 32 | .updateValues = HostnameMeter_updateValues, 33 | .defaultMode = TEXT_METERMODE, 34 | .maxItems = 0, 35 | .total = 100.0, 36 | .attributes = HostnameMeter_attributes, 37 | .name = "Hostname", 38 | .uiName = "Hostname", 39 | .caption = "Hostname: ", 40 | }; 41 | -------------------------------------------------------------------------------- /HostnameMeter.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_HostnameMeter 4 | #define HEADER_HostnameMeter 5 | /* 6 | htop - HostnameMeter.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Meter.h" 13 | 14 | extern int HostnameMeter_attributes[]; 15 | 16 | extern MeterClass HostnameMeter_class; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /IncSet.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_IncSet 4 | #define HEADER_IncSet 5 | /* 6 | htop - IncSet.h 7 | (C) 2005-2012 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | 13 | #include "FunctionBar.h" 14 | #include "Panel.h" 15 | #include 16 | 17 | #define INCMODE_MAX 40 18 | 19 | typedef enum { 20 | INC_SEARCH = 0, 21 | INC_FILTER = 1 22 | } IncType; 23 | 24 | #define IncSet_filter(inc_) (inc_->filtering ? inc_->modes[INC_FILTER].buffer : NULL) 25 | 26 | typedef struct IncMode_ { 27 | char buffer[INCMODE_MAX+1]; 28 | int index; 29 | FunctionBar* bar; 30 | bool isFilter; 31 | } IncMode; 32 | 33 | typedef struct IncSet_ { 34 | IncMode modes[2]; 35 | IncMode* active; 36 | FunctionBar* defaultBar; 37 | bool filtering; 38 | bool found; 39 | } IncSet; 40 | 41 | typedef const char* (*IncMode_GetPanelValue)(Panel*, int); 42 | 43 | 44 | IncSet* IncSet_new(FunctionBar* bar); 45 | 46 | void IncSet_delete(IncSet* this); 47 | 48 | bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines); 49 | 50 | const char* IncSet_getListItemValue(Panel* panel, int i); 51 | 52 | void IncSet_activate(IncSet* this, IncType type, Panel* panel); 53 | 54 | void IncSet_drawBar(IncSet* this); 55 | 56 | int IncSet_synthesizeEvent(IncSet* this, int x); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /InfoScreen.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_InfoScreen 4 | #define HEADER_InfoScreen 5 | 6 | #include "Process.h" 7 | #include "Panel.h" 8 | #include "FunctionBar.h" 9 | #include "IncSet.h" 10 | 11 | typedef struct InfoScreen_ InfoScreen; 12 | 13 | typedef void(*InfoScreen_Scan)(InfoScreen*); 14 | typedef void(*InfoScreen_Draw)(InfoScreen*); 15 | typedef void(*InfoScreen_OnErr)(InfoScreen*); 16 | typedef bool(*InfoScreen_OnKey)(InfoScreen*, int); 17 | 18 | typedef struct InfoScreenClass_ { 19 | ObjectClass super; 20 | const InfoScreen_Scan scan; 21 | const InfoScreen_Draw draw; 22 | const InfoScreen_OnErr onErr; 23 | const InfoScreen_OnKey onKey; 24 | } InfoScreenClass; 25 | 26 | #define As_InfoScreen(this_) ((InfoScreenClass*)(((InfoScreen*)(this_))->super.klass)) 27 | #define InfoScreen_scan(this_) As_InfoScreen(this_)->scan((InfoScreen*)(this_)) 28 | #define InfoScreen_draw(this_) As_InfoScreen(this_)->draw((InfoScreen*)(this_)) 29 | #define InfoScreen_onErr(this_) As_InfoScreen(this_)->onErr((InfoScreen*)(this_)) 30 | #define InfoScreen_onKey(this_, ch_) As_InfoScreen(this_)->onKey((InfoScreen*)(this_), ch_) 31 | 32 | struct InfoScreen_ { 33 | Object super; 34 | Process* process; 35 | Panel* display; 36 | FunctionBar* bar; 37 | IncSet* inc; 38 | Vector* lines; 39 | }; 40 | 41 | InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, char* panelHeader); 42 | 43 | InfoScreen* InfoScreen_done(InfoScreen* this); 44 | 45 | void InfoScreen_drawTitled(InfoScreen* this, char* fmt, ...); 46 | 47 | void InfoScreen_addLine(InfoScreen* this, const char* line); 48 | 49 | void InfoScreen_appendLine(InfoScreen* this, const char* line); 50 | 51 | void InfoScreen_run(InfoScreen* this); 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /ListItem.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - ListItem.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "ListItem.h" 9 | 10 | #include "CRT.h" 11 | #include "StringUtils.h" 12 | #include "RichString.h" 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | /*{ 19 | #include "Object.h" 20 | 21 | typedef struct ListItem_ { 22 | Object super; 23 | char* value; 24 | int key; 25 | bool moving; 26 | } ListItem; 27 | 28 | }*/ 29 | 30 | static void ListItem_delete(Object* cast) { 31 | ListItem* this = (ListItem*)cast; 32 | free(this->value); 33 | free(this); 34 | } 35 | 36 | static void ListItem_display(Object* cast, RichString* out) { 37 | ListItem* const this = (ListItem*)cast; 38 | assert (this != NULL); 39 | /* 40 | int len = strlen(this->value)+1; 41 | char buffer[len+1]; 42 | xSnprintf(buffer, len, "%s", this->value); 43 | */ 44 | if (this->moving) { 45 | RichString_write(out, CRT_colors[DEFAULT_COLOR], 46 | #ifdef HAVE_LIBNCURSESW 47 | CRT_utf8 ? "↕ " : 48 | #endif 49 | "+ "); 50 | } else { 51 | RichString_prune(out); 52 | } 53 | RichString_append(out, CRT_colors[DEFAULT_COLOR], this->value/*buffer*/); 54 | } 55 | 56 | ObjectClass ListItem_class = { 57 | .display = ListItem_display, 58 | .delete = ListItem_delete, 59 | .compare = ListItem_compare 60 | }; 61 | 62 | ListItem* ListItem_new(const char* value, int key) { 63 | ListItem* this = AllocThis(ListItem); 64 | this->value = xStrdup(value); 65 | this->key = key; 66 | this->moving = false; 67 | return this; 68 | } 69 | 70 | void ListItem_append(ListItem* this, const char* text) { 71 | int oldLen = strlen(this->value); 72 | int textLen = strlen(text); 73 | int newLen = strlen(this->value) + textLen; 74 | this->value = xRealloc(this->value, newLen + 1); 75 | memcpy(this->value + oldLen, text, textLen); 76 | this->value[newLen] = '\0'; 77 | } 78 | 79 | const char* ListItem_getRef(ListItem* this) { 80 | return this->value; 81 | } 82 | 83 | long ListItem_compare(const void* cast1, const void* cast2) { 84 | ListItem* obj1 = (ListItem*) cast1; 85 | ListItem* obj2 = (ListItem*) cast2; 86 | return strcmp(obj1->value, obj2->value); 87 | } 88 | 89 | -------------------------------------------------------------------------------- /ListItem.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_ListItem 4 | #define HEADER_ListItem 5 | /* 6 | htop - ListItem.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Object.h" 13 | 14 | typedef struct ListItem_ { 15 | Object super; 16 | char* value; 17 | int key; 18 | bool moving; 19 | } ListItem; 20 | 21 | 22 | extern ObjectClass ListItem_class; 23 | 24 | ListItem* ListItem_new(const char* value, int key); 25 | 26 | void ListItem_append(ListItem* this, const char* text); 27 | 28 | const char* ListItem_getRef(ListItem* this); 29 | 30 | long ListItem_compare(const void* cast1, const void* cast2); 31 | 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /LoadAverageMeter.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - LoadAverageMeter.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "LoadAverageMeter.h" 9 | 10 | #include "CRT.h" 11 | #include "Platform.h" 12 | 13 | /*{ 14 | #include "Meter.h" 15 | }*/ 16 | 17 | int LoadAverageMeter_attributes[] = { 18 | LOAD_AVERAGE_ONE, LOAD_AVERAGE_FIVE, LOAD_AVERAGE_FIFTEEN 19 | }; 20 | 21 | int LoadMeter_attributes[] = { LOAD }; 22 | 23 | static void LoadAverageMeter_updateValues(Meter* this, char* buffer, int size) { 24 | Platform_getLoadAverage(&this->values[0], &this->values[1], &this->values[2]); 25 | xSnprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[0], this->values[1], this->values[2]); 26 | } 27 | 28 | static void LoadAverageMeter_display(Object* cast, RichString* out) { 29 | Meter* this = (Meter*)cast; 30 | char buffer[20]; 31 | xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[0]); 32 | RichString_write(out, CRT_colors[LOAD_AVERAGE_ONE], buffer); 33 | xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[1]); 34 | RichString_append(out, CRT_colors[LOAD_AVERAGE_FIVE], buffer); 35 | xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[2]); 36 | RichString_append(out, CRT_colors[LOAD_AVERAGE_FIFTEEN], buffer); 37 | } 38 | 39 | static void LoadMeter_updateValues(Meter* this, char* buffer, int size) { 40 | double five, fifteen; 41 | Platform_getLoadAverage(&this->values[0], &five, &fifteen); 42 | if (this->values[0] > this->total) { 43 | this->total = this->values[0]; 44 | } 45 | xSnprintf(buffer, size, "%.2f", this->values[0]); 46 | } 47 | 48 | static void LoadMeter_display(Object* cast, RichString* out) { 49 | Meter* this = (Meter*)cast; 50 | char buffer[20]; 51 | xSnprintf(buffer, sizeof(buffer), "%.2f ", ((Meter*)this)->values[0]); 52 | RichString_write(out, CRT_colors[LOAD], buffer); 53 | } 54 | 55 | MeterClass LoadAverageMeter_class = { 56 | .super = { 57 | .extends = Class(Meter), 58 | .delete = Meter_delete, 59 | .display = LoadAverageMeter_display, 60 | }, 61 | .updateValues = LoadAverageMeter_updateValues, 62 | .defaultMode = TEXT_METERMODE, 63 | .maxItems = 3, 64 | .total = 100.0, 65 | .attributes = LoadAverageMeter_attributes, 66 | .name = "LoadAverage", 67 | .uiName = "Load average", 68 | .description = "Load averages: 1 minute, 5 minutes, 15 minutes", 69 | .caption = "Load average: " 70 | }; 71 | 72 | MeterClass LoadMeter_class = { 73 | .super = { 74 | .extends = Class(Meter), 75 | .delete = Meter_delete, 76 | .display = LoadMeter_display, 77 | }, 78 | .updateValues = LoadMeter_updateValues, 79 | .defaultMode = TEXT_METERMODE, 80 | .maxItems = 1, 81 | .total = 100.0, 82 | .attributes = LoadMeter_attributes, 83 | .name = "Load", 84 | .uiName = "Load", 85 | .description = "Load: average of ready processes in the last minute", 86 | .caption = "Load: " 87 | }; 88 | -------------------------------------------------------------------------------- /LoadAverageMeter.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_LoadAverageMeter 4 | #define HEADER_LoadAverageMeter 5 | /* 6 | htop - LoadAverageMeter.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Meter.h" 13 | 14 | extern int LoadAverageMeter_attributes[]; 15 | 16 | extern int LoadMeter_attributes[]; 17 | 18 | extern MeterClass LoadAverageMeter_class; 19 | 20 | extern MeterClass LoadMeter_class; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /MainPanel.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_MainPanel 4 | #define HEADER_MainPanel 5 | /* 6 | htop - ColumnsPanel.h 7 | (C) 2004-2015 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Panel.h" 13 | #include "Action.h" 14 | #include "Settings.h" 15 | 16 | typedef struct MainPanel_ { 17 | Panel super; 18 | State* state; 19 | IncSet* inc; 20 | Htop_Action *keys; 21 | pid_t pidSearch; 22 | } MainPanel; 23 | 24 | typedef union { 25 | int i; 26 | void* v; 27 | } Arg; 28 | 29 | typedef bool(*MainPanel_ForeachProcessFn)(Process*, Arg); 30 | 31 | #define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar) 32 | 33 | 34 | void MainPanel_updateTreeFunctions(MainPanel* this, bool mode); 35 | 36 | void MainPanel_pidSearch(MainPanel* this, int ch); 37 | 38 | int MainPanel_selectedPid(MainPanel* this); 39 | 40 | const char* MainPanel_getValue(MainPanel* this, int i); 41 | 42 | bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Arg arg, bool* wasAnyTagged); 43 | 44 | extern PanelClass MainPanel_class; 45 | 46 | MainPanel* MainPanel_new(); 47 | 48 | void MainPanel_setState(MainPanel* this, State* state); 49 | 50 | void MainPanel_delete(Object* object); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /MemoryMeter.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - MemoryMeter.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "MemoryMeter.h" 9 | 10 | #include "CRT.h" 11 | #include "Platform.h" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | /*{ 20 | #include "Meter.h" 21 | }*/ 22 | 23 | int MemoryMeter_attributes[] = { 24 | MEMORY_USED, MEMORY_BUFFERS, MEMORY_CACHE 25 | }; 26 | 27 | static void MemoryMeter_updateValues(Meter* this, char* buffer, int size) { 28 | int written; 29 | Platform_setMemoryValues(this); 30 | 31 | written = Meter_humanUnit(buffer, this->values[0], size); 32 | buffer += written; 33 | if ((size -= written) > 0) { 34 | *buffer++ = '/'; 35 | size--; 36 | Meter_humanUnit(buffer, this->total, size); 37 | } 38 | } 39 | 40 | static void MemoryMeter_display(Object* cast, RichString* out) { 41 | char buffer[50]; 42 | Meter* this = (Meter*)cast; 43 | RichString_write(out, CRT_colors[METER_TEXT], ":"); 44 | Meter_humanUnit(buffer, this->total, 50); 45 | RichString_append(out, CRT_colors[METER_VALUE], buffer); 46 | Meter_humanUnit(buffer, this->values[0], 50); 47 | RichString_append(out, CRT_colors[METER_TEXT], " used:"); 48 | RichString_append(out, CRT_colors[MEMORY_USED], buffer); 49 | Meter_humanUnit(buffer, this->values[1], 50); 50 | RichString_append(out, CRT_colors[METER_TEXT], " buffers:"); 51 | RichString_append(out, CRT_colors[MEMORY_BUFFERS_TEXT], buffer); 52 | Meter_humanUnit(buffer, this->values[2], 50); 53 | RichString_append(out, CRT_colors[METER_TEXT], " cache:"); 54 | RichString_append(out, CRT_colors[MEMORY_CACHE], buffer); 55 | } 56 | 57 | MeterClass MemoryMeter_class = { 58 | .super = { 59 | .extends = Class(Meter), 60 | .delete = Meter_delete, 61 | .display = MemoryMeter_display, 62 | }, 63 | .updateValues = MemoryMeter_updateValues, 64 | .defaultMode = BAR_METERMODE, 65 | .maxItems = 3, 66 | .total = 100.0, 67 | .attributes = MemoryMeter_attributes, 68 | .name = "Memory", 69 | .uiName = "Memory", 70 | .caption = "Mem" 71 | }; 72 | -------------------------------------------------------------------------------- /MemoryMeter.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_MemoryMeter 4 | #define HEADER_MemoryMeter 5 | /* 6 | htop - MemoryMeter.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Meter.h" 13 | 14 | extern int MemoryMeter_attributes[]; 15 | 16 | extern MeterClass MemoryMeter_class; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /Meter.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Meter 4 | #define HEADER_Meter 5 | /* 6 | htop - Meter.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #define METER_BUFFER_LEN 256 13 | 14 | #define GRAPH_DELAY (DEFAULT_DELAY/2) 15 | 16 | #define GRAPH_HEIGHT 4 /* Unit: rows (lines) */ 17 | 18 | #include "ListItem.h" 19 | 20 | #include 21 | 22 | typedef struct Meter_ Meter; 23 | 24 | typedef void(*Meter_Init)(Meter*); 25 | typedef void(*Meter_Done)(Meter*); 26 | typedef void(*Meter_UpdateMode)(Meter*, int); 27 | typedef void(*Meter_UpdateValues)(Meter*, char*, int); 28 | typedef void(*Meter_Draw)(Meter*, int, int, int); 29 | 30 | typedef struct MeterClass_ { 31 | ObjectClass super; 32 | const Meter_Init init; 33 | const Meter_Done done; 34 | const Meter_UpdateMode updateMode; 35 | const Meter_Draw draw; 36 | const Meter_UpdateValues updateValues; 37 | const int defaultMode; 38 | const double total; 39 | const int* attributes; 40 | const char* name; 41 | const char* uiName; 42 | const char* caption; 43 | const char* description; 44 | const char maxItems; 45 | char curItems; 46 | } MeterClass; 47 | 48 | #define As_Meter(this_) ((MeterClass*)((this_)->super.klass)) 49 | #define Meter_initFn(this_) As_Meter(this_)->init 50 | #define Meter_init(this_) As_Meter(this_)->init((Meter*)(this_)) 51 | #define Meter_done(this_) As_Meter(this_)->done((Meter*)(this_)) 52 | #define Meter_updateModeFn(this_) As_Meter(this_)->updateMode 53 | #define Meter_updateMode(this_, m_) As_Meter(this_)->updateMode((Meter*)(this_), m_) 54 | #define Meter_drawFn(this_) As_Meter(this_)->draw 55 | #define Meter_doneFn(this_) As_Meter(this_)->done 56 | #define Meter_updateValues(this_, buf_, sz_) \ 57 | As_Meter(this_)->updateValues((Meter*)(this_), buf_, sz_) 58 | #define Meter_defaultMode(this_) As_Meter(this_)->defaultMode 59 | #define Meter_getItems(this_) As_Meter(this_)->curItems 60 | #define Meter_setItems(this_, n_) As_Meter(this_)->curItems = (n_) 61 | #define Meter_attributes(this_) As_Meter(this_)->attributes 62 | #define Meter_name(this_) As_Meter(this_)->name 63 | #define Meter_uiName(this_) As_Meter(this_)->uiName 64 | 65 | struct Meter_ { 66 | Object super; 67 | Meter_Draw draw; 68 | 69 | char* caption; 70 | int mode; 71 | int param; 72 | void* drawData; 73 | int h; 74 | struct ProcessList_* pl; 75 | double* values; 76 | double total; 77 | }; 78 | 79 | typedef struct MeterMode_ { 80 | Meter_Draw draw; 81 | const char* uiName; 82 | int h; 83 | } MeterMode; 84 | 85 | typedef enum { 86 | CUSTOM_METERMODE = 0, 87 | BAR_METERMODE, 88 | TEXT_METERMODE, 89 | GRAPH_METERMODE, 90 | LED_METERMODE, 91 | LAST_METERMODE 92 | } MeterModeId; 93 | 94 | typedef struct GraphData_ { 95 | struct timeval time; 96 | double values[METER_BUFFER_LEN]; 97 | } GraphData; 98 | 99 | 100 | #ifndef MIN 101 | #define MIN(a,b) ((a)<(b)?(a):(b)) 102 | #endif 103 | #ifndef MAX 104 | #define MAX(a,b) ((a)>(b)?(a):(b)) 105 | #endif 106 | #ifndef CLAMP 107 | #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) 108 | #endif 109 | 110 | extern MeterClass Meter_class; 111 | 112 | Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type); 113 | 114 | int Meter_humanUnit(char* buffer, unsigned long int value, int size); 115 | 116 | void Meter_delete(Object* cast); 117 | 118 | void Meter_setCaption(Meter* this, const char* caption); 119 | 120 | void Meter_setMode(Meter* this, int modeIndex); 121 | 122 | ListItem* Meter_toListItem(Meter* this, bool moving); 123 | 124 | /* ---------- TextMeterMode ---------- */ 125 | 126 | /* ---------- BarMeterMode ---------- */ 127 | 128 | /* ---------- GraphMeterMode ---------- */ 129 | 130 | #ifdef HAVE_LIBNCURSESW 131 | 132 | #define PIXPERROW_UTF8 4 133 | #endif 134 | 135 | #define PIXPERROW_ASCII 2 136 | 137 | /* ---------- LEDMeterMode ---------- */ 138 | 139 | #ifdef HAVE_LIBNCURSESW 140 | 141 | #endif 142 | 143 | extern MeterMode* Meter_modes[]; 144 | 145 | /* Blank meter */ 146 | 147 | extern int BlankMeter_attributes[]; 148 | 149 | extern MeterClass BlankMeter_class; 150 | 151 | #endif 152 | -------------------------------------------------------------------------------- /MetersPanel.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_MetersPanel 4 | #define HEADER_MetersPanel 5 | /* 6 | htop - MetersPanel.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Panel.h" 13 | #include "Settings.h" 14 | #include "ScreenManager.h" 15 | 16 | typedef struct MetersPanel_ MetersPanel; 17 | 18 | struct MetersPanel_ { 19 | Panel super; 20 | 21 | Settings* settings; 22 | Vector* meters; 23 | ScreenManager* scr; 24 | MetersPanel* leftNeighbor; 25 | MetersPanel* rightNeighbor; 26 | bool moving; 27 | }; 28 | 29 | 30 | // Note: In code the meters are known to have bar/text/graph "Modes", but in UI 31 | // we call them "Styles". 32 | // We avoid UTF-8 arrows ← → here as they might display full-width on Chinese 33 | // terminals, breaking our aligning. 34 | // In , arrows (U+2019..U+2199) are 35 | // considered "Ambiguous characters". 36 | 37 | void MetersPanel_setMoving(MetersPanel* this, bool moving); 38 | 39 | extern PanelClass MetersPanel_class; 40 | 41 | MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | 2 | See the commit history for news of the past. 3 | See the bug tracker for news of the future. 4 | Run the program for news of the present. 5 | 6 | -------------------------------------------------------------------------------- /Object.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - Object.c 3 | (C) 2004-2012 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "Object.h" 9 | 10 | /*{ 11 | #include "RichString.h" 12 | #include "XAlloc.h" 13 | 14 | typedef struct Object_ Object; 15 | 16 | typedef void(*Object_Display)(Object*, RichString*); 17 | typedef long(*Object_Compare)(const void*, const void*); 18 | typedef void(*Object_Delete)(Object*); 19 | 20 | #define Object_getClass(obj_) ((Object*)(obj_))->klass 21 | #define Object_setClass(obj_, class_) Object_getClass(obj_) = (ObjectClass*) class_ 22 | 23 | #define Object_delete(obj_) Object_getClass(obj_)->delete((Object*)(obj_)) 24 | #define Object_displayFn(obj_) Object_getClass(obj_)->display 25 | #define Object_display(obj_, str_) Object_getClass(obj_)->display((Object*)(obj_), str_) 26 | #define Object_compare(obj_, other_) Object_getClass(obj_)->compare((const void*)(obj_), other_) 27 | 28 | #define Class(class_) ((ObjectClass*)(&(class_ ## _class))) 29 | 30 | #define AllocThis(class_) (class_*) xMalloc(sizeof(class_)); Object_setClass(this, Class(class_)); 31 | 32 | typedef struct ObjectClass_ { 33 | const void* extends; 34 | const Object_Display display; 35 | const Object_Delete delete; 36 | const Object_Compare compare; 37 | } ObjectClass; 38 | 39 | struct Object_ { 40 | ObjectClass* klass; 41 | }; 42 | 43 | }*/ 44 | 45 | ObjectClass Object_class = { 46 | .extends = NULL 47 | }; 48 | 49 | #ifdef DEBUG 50 | 51 | bool Object_isA(Object* o, const ObjectClass* klass) { 52 | if (!o) 53 | return false; 54 | const ObjectClass* type = o->klass; 55 | while (type) { 56 | if (type == klass) 57 | return true; 58 | type = type->extends; 59 | } 60 | return false; 61 | } 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /Object.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Object 4 | #define HEADER_Object 5 | /* 6 | htop - Object.h 7 | (C) 2004-2012 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "RichString.h" 13 | #include "XAlloc.h" 14 | 15 | typedef struct Object_ Object; 16 | 17 | typedef void(*Object_Display)(Object*, RichString*); 18 | typedef long(*Object_Compare)(const void*, const void*); 19 | typedef void(*Object_Delete)(Object*); 20 | 21 | #define Object_getClass(obj_) ((Object*)(obj_))->klass 22 | #define Object_setClass(obj_, class_) Object_getClass(obj_) = (ObjectClass*) class_ 23 | 24 | #define Object_delete(obj_) Object_getClass(obj_)->delete((Object*)(obj_)) 25 | #define Object_displayFn(obj_) Object_getClass(obj_)->display 26 | #define Object_display(obj_, str_) Object_getClass(obj_)->display((Object*)(obj_), str_) 27 | #define Object_compare(obj_, other_) Object_getClass(obj_)->compare((const void*)(obj_), other_) 28 | 29 | #define Class(class_) ((ObjectClass*)(&(class_ ## _class))) 30 | 31 | #define AllocThis(class_) (class_*) xMalloc(sizeof(class_)); Object_setClass(this, Class(class_)); 32 | 33 | typedef struct ObjectClass_ { 34 | const void* extends; 35 | const Object_Display display; 36 | const Object_Delete delete; 37 | const Object_Compare compare; 38 | } ObjectClass; 39 | 40 | struct Object_ { 41 | ObjectClass* klass; 42 | }; 43 | 44 | 45 | extern ObjectClass Object_class; 46 | 47 | #ifdef DEBUG 48 | 49 | bool Object_isA(Object* o, const ObjectClass* klass); 50 | 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /OpenFilesScreen.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_OpenFilesScreen 4 | #define HEADER_OpenFilesScreen 5 | /* 6 | htop - OpenFilesScreen.h 7 | (C) 2005-2006 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "InfoScreen.h" 13 | 14 | typedef struct OpenFiles_Data_ { 15 | char* data[256]; 16 | } OpenFiles_Data; 17 | 18 | typedef struct OpenFiles_ProcessData_ { 19 | OpenFiles_Data data; 20 | int error; 21 | struct OpenFiles_FileData_* files; 22 | } OpenFiles_ProcessData; 23 | 24 | typedef struct OpenFiles_FileData_ { 25 | OpenFiles_Data data; 26 | struct OpenFiles_FileData_* next; 27 | } OpenFiles_FileData; 28 | 29 | typedef struct OpenFilesScreen_ { 30 | InfoScreen super; 31 | pid_t pid; 32 | } OpenFilesScreen; 33 | 34 | 35 | extern InfoScreenClass OpenFilesScreen_class; 36 | 37 | OpenFilesScreen* OpenFilesScreen_new(Process* process); 38 | 39 | void OpenFilesScreen_delete(Object* this); 40 | 41 | void OpenFilesScreen_draw(InfoScreen* this); 42 | 43 | void OpenFilesScreen_scan(InfoScreen* this); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /Panel.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Panel 4 | #define HEADER_Panel 5 | /* 6 | htop - Panel.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | //#link curses 13 | 14 | #include "Object.h" 15 | #include "Vector.h" 16 | #include "FunctionBar.h" 17 | 18 | typedef struct Panel_ Panel; 19 | 20 | typedef enum HandlerResult_ { 21 | HANDLED = 0x01, 22 | IGNORED = 0x02, 23 | BREAK_LOOP = 0x04, 24 | REDRAW = 0x08, 25 | RESCAN = 0x10, 26 | SYNTH_KEY = 0x20, 27 | } HandlerResult; 28 | 29 | #define EVENT_SET_SELECTED -1 30 | 31 | #define EVENT_HEADER_CLICK(x_) (-10000 + x_) 32 | #define EVENT_IS_HEADER_CLICK(ev_) (ev_ >= -10000 && ev_ <= -9000) 33 | #define EVENT_HEADER_CLICK_GET_X(ev_) (ev_ + 10000) 34 | 35 | typedef HandlerResult(*Panel_EventHandler)(Panel*, int); 36 | 37 | typedef struct PanelClass_ { 38 | const ObjectClass super; 39 | const Panel_EventHandler eventHandler; 40 | } PanelClass; 41 | 42 | #define As_Panel(this_) ((PanelClass*)((this_)->super.klass)) 43 | #define Panel_eventHandlerFn(this_) As_Panel(this_)->eventHandler 44 | #define Panel_eventHandler(this_, ev_) As_Panel(this_)->eventHandler((Panel*)(this_), ev_) 45 | 46 | struct Panel_ { 47 | Object super; 48 | int x, y, w, h; 49 | WINDOW* window; 50 | Vector* items; 51 | int selected; 52 | int oldSelected; 53 | int selectedLen; 54 | void* eventHandlerState; 55 | int scrollV; 56 | short scrollH; 57 | bool needsRedraw; 58 | FunctionBar* currentBar; 59 | FunctionBar* defaultBar; 60 | RichString header; 61 | int selectionColor; 62 | }; 63 | 64 | #define Panel_setDefaultBar(this_) do{ (this_)->currentBar = (this_)->defaultBar; }while(0) 65 | 66 | 67 | #ifndef MIN 68 | #define MIN(a,b) ((a)<(b)?(a):(b)) 69 | #endif 70 | #ifndef MAX 71 | #define MAX(a,b) ((a)>(b)?(a):(b)) 72 | #endif 73 | 74 | #define KEY_CTRL(l) ((l)-'A'+1) 75 | 76 | extern PanelClass Panel_class; 77 | 78 | Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type, FunctionBar* fuBar); 79 | 80 | void Panel_delete(Object* cast); 81 | 82 | void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool owner, FunctionBar* fuBar); 83 | 84 | void Panel_done(Panel* this); 85 | 86 | void Panel_setSelectionColor(Panel* this, int color); 87 | 88 | RichString* Panel_getHeader(Panel* this); 89 | 90 | extern void Panel_setHeader(Panel* this, const char* header); 91 | 92 | void Panel_move(Panel* this, int x, int y); 93 | 94 | void Panel_resize(Panel* this, int w, int h); 95 | 96 | void Panel_prune(Panel* this); 97 | 98 | void Panel_add(Panel* this, Object* o); 99 | 100 | void Panel_insert(Panel* this, int i, Object* o); 101 | 102 | void Panel_set(Panel* this, int i, Object* o); 103 | 104 | Object* Panel_get(Panel* this, int i); 105 | 106 | Object* Panel_remove(Panel* this, int i); 107 | 108 | Object* Panel_getSelected(Panel* this); 109 | 110 | void Panel_moveSelectedUp(Panel* this); 111 | 112 | void Panel_moveSelectedDown(Panel* this); 113 | 114 | int Panel_getSelectedIndex(Panel* this); 115 | 116 | int Panel_size(Panel* this); 117 | 118 | void Panel_setSelected(Panel* this, int selected); 119 | 120 | void Panel_draw(Panel* this, bool focus); 121 | 122 | bool Panel_onKey(Panel* this, int key); 123 | 124 | HandlerResult Panel_selectByTyping(Panel* this, int ch); 125 | 126 | #endif 127 | -------------------------------------------------------------------------------- /ProcessList.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_ProcessList 4 | #define HEADER_ProcessList 5 | /* 6 | htop - ProcessList.h 7 | (C) 2004,2005 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Vector.h" 13 | #include "Hashtable.h" 14 | #include "UsersTable.h" 15 | #include "Panel.h" 16 | #include "Process.h" 17 | #include "Settings.h" 18 | 19 | #ifdef HAVE_LIBHWLOC 20 | #include 21 | #endif 22 | 23 | #ifndef MAX_NAME 24 | #define MAX_NAME 128 25 | #endif 26 | 27 | #ifndef MAX_READ 28 | #define MAX_READ 2048 29 | #endif 30 | 31 | typedef struct ProcessList_ { 32 | Settings* settings; 33 | 34 | Vector* processes; 35 | Vector* processes2; 36 | Hashtable* processTable; 37 | UsersTable* usersTable; 38 | 39 | Panel* panel; 40 | int following; 41 | uid_t userId; 42 | const char* incFilter; 43 | Hashtable* pidWhiteList; 44 | 45 | #ifdef HAVE_LIBHWLOC 46 | hwloc_topology_t topology; 47 | bool topologyOk; 48 | #endif 49 | 50 | int totalTasks; 51 | int runningTasks; 52 | int userlandThreads; 53 | int kernelThreads; 54 | 55 | unsigned long long int totalMem; 56 | unsigned long long int usedMem; 57 | unsigned long long int freeMem; 58 | unsigned long long int sharedMem; 59 | unsigned long long int buffersMem; 60 | unsigned long long int cachedMem; 61 | unsigned long long int totalSwap; 62 | unsigned long long int usedSwap; 63 | unsigned long long int freeSwap; 64 | 65 | int cpuCount; 66 | 67 | } ProcessList; 68 | 69 | ProcessList* ProcessList_new(UsersTable* ut, Hashtable* pidWhiteList, uid_t userId); 70 | void ProcessList_delete(ProcessList* pl); 71 | void ProcessList_goThroughEntries(ProcessList* pl); 72 | 73 | 74 | ProcessList* ProcessList_init(ProcessList* this, ObjectClass* klass, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); 75 | 76 | void ProcessList_done(ProcessList* this); 77 | 78 | void ProcessList_setPanel(ProcessList* this, Panel* panel); 79 | 80 | void ProcessList_printHeader(ProcessList* this, RichString* header); 81 | 82 | void ProcessList_add(ProcessList* this, Process* p); 83 | 84 | void ProcessList_remove(ProcessList* this, Process* p); 85 | 86 | Process* ProcessList_get(ProcessList* this, int idx); 87 | 88 | int ProcessList_size(ProcessList* this); 89 | 90 | void ProcessList_sort(ProcessList* this); 91 | 92 | ProcessField ProcessList_keyAt(ProcessList* this, int at); 93 | 94 | void ProcessList_expandTree(ProcessList* this); 95 | 96 | void ProcessList_rebuildPanel(ProcessList* this); 97 | 98 | Process* ProcessList_getProcess(ProcessList* this, pid_t pid, bool* preExisting, Process_New constructor); 99 | 100 | void ProcessList_scan(ProcessList* this); 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | htop 2 | ==== 3 | 4 | by Hisham Muhammad 5 | 6 | **This repository is archived as htop is now maintained by a team of 7 | volunteers at [htop.dev](https://htop.dev/) using an organisation-based 8 | git [repository](https://github.com/htop-dev/htop/)**. 9 | 10 | ## License 11 | 12 | GNU General Public License, version 2 (GPL-2.0) 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | README -------------------------------------------------------------------------------- /RichString.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_RichString 4 | #define HEADER_RichString 5 | /* 6 | htop - RichString.h 7 | (C) 2004,2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #define RICHSTRING_MAXLEN 350 13 | 14 | #include "config.h" 15 | #include 16 | 17 | #include 18 | #ifdef HAVE_NCURSESW_CURSES_H 19 | #include 20 | #elif HAVE_NCURSES_NCURSES_H 21 | #include 22 | #elif HAVE_NCURSES_CURSES_H 23 | #include 24 | #elif HAVE_NCURSES_H 25 | #include 26 | #elif HAVE_CURSES_H 27 | #include 28 | #endif 29 | 30 | #ifdef HAVE_LIBNCURSESW 31 | #include 32 | #endif 33 | 34 | #define RichString_size(this) ((this)->chlen) 35 | #define RichString_sizeVal(this) ((this).chlen) 36 | 37 | #define RichString_begin(this) RichString (this); memset(&this, 0, sizeof(RichString)); (this).chptr = (this).chstr; 38 | #define RichString_beginAllocated(this) memset(&this, 0, sizeof(RichString)); (this).chptr = (this).chstr; 39 | #define RichString_end(this) RichString_prune(&(this)); 40 | 41 | #ifdef HAVE_LIBNCURSESW 42 | #define RichString_printVal(this, y, x) mvadd_wchstr(y, x, (this).chptr) 43 | #define RichString_printoffnVal(this, y, x, off, n) mvadd_wchnstr(y, x, (this).chptr + off, n) 44 | #define RichString_getCharVal(this, i) ((this).chptr[i].chars[0] & 255) 45 | #define RichString_setChar(this, at, ch) do{ (this)->chptr[(at)] = (CharType) { .chars = { ch, 0 } }; } while(0) 46 | #define CharType cchar_t 47 | #else 48 | #define RichString_printVal(this, y, x) mvaddchstr(y, x, (this).chptr) 49 | #define RichString_printoffnVal(this, y, x, off, n) mvaddchnstr(y, x, (this).chptr + off, n) 50 | #define RichString_getCharVal(this, i) ((this).chptr[i]) 51 | #define RichString_setChar(this, at, ch) do{ (this)->chptr[(at)] = ch; } while(0) 52 | #define CharType chtype 53 | #endif 54 | 55 | typedef struct RichString_ { 56 | int chlen; 57 | CharType* chptr; 58 | CharType chstr[RICHSTRING_MAXLEN+1]; 59 | } RichString; 60 | 61 | 62 | #ifndef CLAMP 63 | #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) 64 | #endif 65 | 66 | #define charBytes(n) (sizeof(CharType) * (n)) 67 | 68 | #define RichString_setLen(this, len) do{ if(len < RICHSTRING_MAXLEN && this->chlen < RICHSTRING_MAXLEN) { RichString_setChar(this,len,0); this->chlen=len; } else RichString_extendLen(this,len); }while(0) 69 | 70 | #ifdef HAVE_LIBNCURSESW 71 | 72 | extern void RichString_setAttrn(RichString* this, int attrs, int start, int finish); 73 | 74 | int RichString_findChar(RichString* this, char c, int start); 75 | 76 | #else 77 | 78 | void RichString_setAttrn(RichString* this, int attrs, int start, int finish); 79 | 80 | int RichString_findChar(RichString* this, char c, int start); 81 | 82 | #endif 83 | 84 | void RichString_prune(RichString* this); 85 | 86 | void RichString_setAttr(RichString* this, int attrs); 87 | 88 | void RichString_append(RichString* this, int attrs, const char* data); 89 | 90 | void RichString_appendn(RichString* this, int attrs, const char* data, int len); 91 | 92 | void RichString_write(RichString* this, int attrs, const char* data); 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /ScreenManager.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_ScreenManager 4 | #define HEADER_ScreenManager 5 | /* 6 | htop - ScreenManager.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "FunctionBar.h" 13 | #include "Vector.h" 14 | #include "Header.h" 15 | #include "Settings.h" 16 | #include "Panel.h" 17 | 18 | typedef enum Orientation_ { 19 | VERTICAL, 20 | HORIZONTAL 21 | } Orientation; 22 | 23 | typedef struct ScreenManager_ { 24 | int x1; 25 | int y1; 26 | int x2; 27 | int y2; 28 | Orientation orientation; 29 | Vector* panels; 30 | int panelCount; 31 | const Header* header; 32 | const Settings* settings; 33 | bool owner; 34 | bool allowFocusChange; 35 | } ScreenManager; 36 | 37 | 38 | ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, const Settings* settings, bool owner); 39 | 40 | void ScreenManager_delete(ScreenManager* this); 41 | 42 | extern int ScreenManager_size(ScreenManager* this); 43 | 44 | void ScreenManager_add(ScreenManager* this, Panel* item, int size); 45 | 46 | Panel* ScreenManager_remove(ScreenManager* this, int idx); 47 | 48 | void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2); 49 | 50 | void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /Settings.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Settings 4 | #define HEADER_Settings 5 | /* 6 | htop - Settings.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #define DEFAULT_DELAY 15 13 | 14 | #include "Process.h" 15 | #include 16 | 17 | typedef struct { 18 | int len; 19 | char** names; 20 | int* modes; 21 | } MeterColumnSettings; 22 | 23 | typedef struct Settings_ { 24 | char* filename; 25 | 26 | MeterColumnSettings columns[2]; 27 | 28 | ProcessField* fields; 29 | int flags; 30 | int colorScheme; 31 | int delay; 32 | 33 | int cpuCount; 34 | int direction; 35 | ProcessField sortKey; 36 | 37 | bool countCPUsFromZero; 38 | bool detailedCPUTime; 39 | bool treeView; 40 | bool showProgramPath; 41 | bool hideThreads; 42 | bool shadowOtherUsers; 43 | bool showThreadNames; 44 | bool hideKernelThreads; 45 | bool hideUserlandThreads; 46 | bool highlightBaseName; 47 | bool highlightMegabytes; 48 | bool highlightThreads; 49 | bool updateProcessNames; 50 | bool accountGuestInCPUMeter; 51 | bool headerMargin; 52 | 53 | bool changed; 54 | } Settings; 55 | 56 | #ifndef Settings_cpuId 57 | #define Settings_cpuId(settings, cpu) ((settings)->countCPUsFromZero ? (cpu) : (cpu)+1) 58 | #endif 59 | 60 | 61 | void Settings_delete(Settings* this); 62 | 63 | bool Settings_write(Settings* this); 64 | 65 | Settings* Settings_new(int cpuCount); 66 | 67 | void Settings_invertSortOrder(Settings* this); 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /SignalsPanel.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - SignalsPanel.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "Panel.h" 9 | #include "SignalsPanel.h" 10 | #include "Platform.h" 11 | 12 | #include "ListItem.h" 13 | #include "RichString.h" 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | /*{ 22 | 23 | typedef struct SignalItem_ { 24 | const char* name; 25 | int number; 26 | } SignalItem; 27 | 28 | }*/ 29 | 30 | Panel* SignalsPanel_new() { 31 | Panel* this = Panel_new(1, 1, 1, 1, true, Class(ListItem), FunctionBar_newEnterEsc("Send ", "Cancel ")); 32 | const int defaultSignal = SIGTERM; 33 | int defaultPosition = 15; 34 | unsigned int i; 35 | for (i = 0; i < Platform_numberOfSignals; i++) { 36 | Panel_set(this, i, (Object*) ListItem_new(Platform_signals[i].name, Platform_signals[i].number)); 37 | // signal 15 is not always the 15th signal in the table 38 | if (Platform_signals[i].number == defaultSignal) { 39 | defaultPosition = i; 40 | } 41 | } 42 | #if (defined(SIGRTMIN) && defined(SIGRTMAX)) 43 | if (SIGRTMAX - SIGRTMIN <= 100) { 44 | static char buf[16]; 45 | for (int sig = SIGRTMIN; sig <= SIGRTMAX; i++, sig++) { 46 | int n = sig - SIGRTMIN; 47 | xSnprintf(buf, 16, "%2d SIGRTMIN%-+3d", sig, n); 48 | if (n == 0) { 49 | buf[11] = '\0'; 50 | } 51 | Panel_set(this, i, (Object*) ListItem_new(buf, sig)); 52 | } 53 | } 54 | #endif 55 | Panel_setHeader(this, "Send signal:"); 56 | Panel_setSelected(this, defaultPosition); 57 | return this; 58 | } 59 | -------------------------------------------------------------------------------- /SignalsPanel.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_SignalsPanel 4 | #define HEADER_SignalsPanel 5 | /* 6 | htop - SignalsPanel.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | 13 | typedef struct SignalItem_ { 14 | const char* name; 15 | int number; 16 | } SignalItem; 17 | 18 | 19 | Panel* SignalsPanel_new(); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /StringUtils.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - StringUtils.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "StringUtils.h" 9 | #include "XAlloc.h" 10 | 11 | #include "config.h" 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | /*{ 18 | #include 19 | 20 | #define String_startsWith(s, match) (strncmp((s),(match),strlen(match)) == 0) 21 | #define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL) 22 | }*/ 23 | 24 | /* 25 | * String_startsWith gives better performance if strlen(match) can be computed 26 | * at compile time (e.g. when they are immutable string literals). :) 27 | */ 28 | 29 | char* String_cat(const char* s1, const char* s2) { 30 | int l1 = strlen(s1); 31 | int l2 = strlen(s2); 32 | char* out = xMalloc(l1 + l2 + 1); 33 | strncpy(out, s1, l1); 34 | strncpy(out+l1, s2, l2+1); 35 | return out; 36 | } 37 | 38 | char* String_trim(const char* in) { 39 | while (in[0] == ' ' || in[0] == '\t' || in[0] == '\n') { 40 | in++; 41 | } 42 | int len = strlen(in); 43 | while (len > 0 && (in[len-1] == ' ' || in[len-1] == '\t' || in[len-1] == '\n')) { 44 | len--; 45 | } 46 | char* out = xMalloc(len+1); 47 | strncpy(out, in, len); 48 | out[len] = '\0'; 49 | return out; 50 | } 51 | 52 | inline int String_eq(const char* s1, const char* s2) { 53 | if (s1 == NULL || s2 == NULL) { 54 | if (s1 == NULL && s2 == NULL) 55 | return 1; 56 | else 57 | return 0; 58 | } 59 | return (strcmp(s1, s2) == 0); 60 | } 61 | 62 | char** String_split(const char* s, char sep, int* n) { 63 | *n = 0; 64 | const int rate = 10; 65 | char** out = xCalloc(rate, sizeof(char*)); 66 | int ctr = 0; 67 | int blocks = rate; 68 | char* where; 69 | while ((where = strchr(s, sep)) != NULL) { 70 | int size = where - s; 71 | char* token = xMalloc(size + 1); 72 | strncpy(token, s, size); 73 | token[size] = '\0'; 74 | out[ctr] = token; 75 | ctr++; 76 | if (ctr == blocks) { 77 | blocks += rate; 78 | out = (char**) xRealloc(out, sizeof(char*) * blocks); 79 | } 80 | s += size + 1; 81 | } 82 | if (s[0] != '\0') { 83 | int size = strlen(s); 84 | char* token = xMalloc(size + 1); 85 | strncpy(token, s, size + 1); 86 | out[ctr] = token; 87 | ctr++; 88 | } 89 | out = xRealloc(out, sizeof(char*) * (ctr + 1)); 90 | out[ctr] = NULL; 91 | *n = ctr; 92 | return out; 93 | } 94 | 95 | void String_freeArray(char** s) { 96 | if (!s) { 97 | return; 98 | } 99 | for (int i = 0; s[i] != NULL; i++) { 100 | free(s[i]); 101 | } 102 | free(s); 103 | } 104 | 105 | char* String_getToken(const char* line, const unsigned short int numMatch) { 106 | const unsigned short int len = strlen(line); 107 | char inWord = 0; 108 | unsigned short int count = 0; 109 | char match[50]; 110 | 111 | unsigned short int foundCount = 0; 112 | 113 | for (unsigned short int i = 0; i < len; i++) { 114 | char lastState = inWord; 115 | inWord = line[i] == ' ' ? 0:1; 116 | 117 | if (lastState == 0 && inWord == 1) 118 | count++; 119 | 120 | if(inWord == 1){ 121 | if (count == numMatch && line[i] != ' ' && line[i] != '\0' && line[i] != '\n' && line[i] != (char)EOF) { 122 | match[foundCount] = line[i]; 123 | foundCount++; 124 | } 125 | } 126 | } 127 | 128 | match[foundCount] = '\0'; 129 | return((char*)xStrdup(match)); 130 | } 131 | 132 | char* String_readLine(FILE* fd) { 133 | const int step = 1024; 134 | int bufSize = step; 135 | char* buffer = xMalloc(step + 1); 136 | char* at = buffer; 137 | for (;;) { 138 | char* ok = fgets(at, step + 1, fd); 139 | if (!ok) { 140 | free(buffer); 141 | return NULL; 142 | } 143 | char* newLine = strrchr(at, '\n'); 144 | if (newLine) { 145 | *newLine = '\0'; 146 | return buffer; 147 | } else { 148 | if (feof(fd)) { 149 | return buffer; 150 | } 151 | } 152 | bufSize += step; 153 | buffer = xRealloc(buffer, bufSize + 1); 154 | at = buffer + bufSize - step; 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /StringUtils.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_StringUtils 4 | #define HEADER_StringUtils 5 | /* 6 | htop - StringUtils.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include 13 | 14 | #define String_startsWith(s, match) (strncmp((s),(match),strlen(match)) == 0) 15 | #define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL) 16 | 17 | /* 18 | * String_startsWith gives better performance if strlen(match) can be computed 19 | * at compile time (e.g. when they are immutable string literals). :) 20 | */ 21 | 22 | char* String_cat(const char* s1, const char* s2); 23 | 24 | char* String_trim(const char* in); 25 | 26 | extern int String_eq(const char* s1, const char* s2); 27 | 28 | char** String_split(const char* s, char sep, int* n); 29 | 30 | void String_freeArray(char** s); 31 | 32 | char* String_getToken(const char* line, const unsigned short int numMatch); 33 | 34 | char* String_readLine(FILE* fd); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /SwapMeter.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - SwapMeter.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "SwapMeter.h" 9 | 10 | #include "CRT.h" 11 | #include "Platform.h" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | /*{ 20 | #include "Meter.h" 21 | }*/ 22 | 23 | int SwapMeter_attributes[] = { 24 | SWAP 25 | }; 26 | 27 | static void SwapMeter_updateValues(Meter* this, char* buffer, int size) { 28 | int written; 29 | Platform_setSwapValues(this); 30 | 31 | written = Meter_humanUnit(buffer, this->values[0], size); 32 | buffer += written; 33 | if ((size -= written) > 0) { 34 | *buffer++ = '/'; 35 | size--; 36 | Meter_humanUnit(buffer, this->total, size); 37 | } 38 | } 39 | 40 | static void SwapMeter_display(Object* cast, RichString* out) { 41 | char buffer[50]; 42 | Meter* this = (Meter*)cast; 43 | RichString_write(out, CRT_colors[METER_TEXT], ":"); 44 | Meter_humanUnit(buffer, this->total, 50); 45 | RichString_append(out, CRT_colors[METER_VALUE], buffer); 46 | Meter_humanUnit(buffer, this->values[0], 50); 47 | RichString_append(out, CRT_colors[METER_TEXT], " used:"); 48 | RichString_append(out, CRT_colors[METER_VALUE], buffer); 49 | } 50 | 51 | MeterClass SwapMeter_class = { 52 | .super = { 53 | .extends = Class(Meter), 54 | .delete = Meter_delete, 55 | .display = SwapMeter_display, 56 | }, 57 | .updateValues = SwapMeter_updateValues, 58 | .defaultMode = BAR_METERMODE, 59 | .maxItems = 1, 60 | .total = 100.0, 61 | .attributes = SwapMeter_attributes, 62 | .name = "Swap", 63 | .uiName = "Swap", 64 | .caption = "Swp" 65 | }; 66 | -------------------------------------------------------------------------------- /SwapMeter.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_SwapMeter 4 | #define HEADER_SwapMeter 5 | /* 6 | htop - SwapMeter.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Meter.h" 13 | 14 | extern int SwapMeter_attributes[]; 15 | 16 | extern MeterClass SwapMeter_class; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /TESTPLAN: -------------------------------------------------------------------------------- 1 | 2 | Main screen: 3 | 4 | For all views, all modes: 5 | 6 | Mouse click header - nothing happens. 7 | 8 | Mouse click on ProcessList title bar - exit Tree view, update FunctionBar, title bar updates, sort by clicked field. 9 | *** FAILING: wrong FB update depending on mode; does not change sort in wip branch 10 | click on same entry - invert sort. 11 | click on another entry - sort another field. 12 | 13 | Mouse click on a process - select that process. 14 | 15 | for each entry in FunctionBar: 16 | Mouse click entry - perform action of associated key. 17 | 18 | In Normal mode, Sorted view: 19 | 20 | <+> or <-> - do nothing. 21 | 22 | - enter SortBy screen. 23 | 24 | In Normal mode, Tree view: 25 | 26 | select process - update F6 in FunctionBar if subtree is collapsed or expanded. 27 | 28 | , <+> or <-> - expand/collapse subtree. 29 | 30 | In Normal mode, either Sorted or Tree view: 31 | 32 | , - activate Search mode. 33 | 34 | , <\> - activate Filter mode. 35 | 36 | , <]> - as root only, decrease process NICE value. 37 | 38 | , <[> - increase process NICE value. 39 | 40 | - enter Affinity screen. 41 | 42 | - do nothing. 43 | 44 | - select process and all its children. 45 | 46 | , , , - do nothing. 47 | 48 | , , - enter Help screen. 49 | 50 | - on Linux, enter IOPriority screen. 51 | 52 | - do nothing. 53 | 54 | , - enter Kill screen. 55 | 56 | - enter LSOF screen. 57 | 58 | , , ,

- enter Sorted view, update function bar, sort by CPU%. 97 | 98 | , - do nothing. 99 | 100 | - enter Sorted view, update function bar, sort by TIME. 101 | 102 | - untag all processes. 103 | 104 | , , , , - do nothing. 105 | 106 | <<>, <>>, <,>, <.> - enter SortBy screen. 107 | 108 | space - tag current process, move down cursor. 109 | 110 | numbers - incremental PID search. 111 | 112 | In Search mode: 113 | 114 | TODO 115 | 116 | In Filter mode: 117 | 118 | TODO 119 | 120 | Setup screen: 121 | 122 | TODO 123 | 124 | SortBy screen: 125 | 126 | TODO 127 | 128 | User screen: 129 | 130 | TODO 131 | 132 | Kill screen: 133 | 134 | TODO 135 | 136 | Affinity screen: 137 | 138 | TODO 139 | 140 | Help screen: 141 | 142 | any key - back to Main screen. 143 | 144 | IOPriority screen: 145 | 146 | TODO 147 | 148 | STrace screen: 149 | 150 | TODO 151 | 152 | LSOF screen: 153 | 154 | TODO 155 | 156 | -------------------------------------------------------------------------------- /TasksMeter.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - TasksMeter.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "TasksMeter.h" 9 | 10 | #include "Platform.h" 11 | #include "CRT.h" 12 | 13 | /*{ 14 | #include "Meter.h" 15 | }*/ 16 | 17 | int TasksMeter_attributes[] = { 18 | CPU_KERNEL, PROCESS_THREAD, PROCESS, TASKS_RUNNING 19 | }; 20 | 21 | static void TasksMeter_updateValues(Meter* this, char* buffer, int len) { 22 | ProcessList* pl = this->pl; 23 | this->values[0] = pl->kernelThreads; 24 | this->values[1] = pl->userlandThreads; 25 | this->values[2] = pl->totalTasks - pl->kernelThreads - pl->userlandThreads; 26 | this->values[3] = MIN(pl->runningTasks, pl->cpuCount); 27 | if (pl->totalTasks > this->total) { 28 | this->total = pl->totalTasks; 29 | } 30 | if (this->pl->settings->hideKernelThreads) { 31 | this->values[0] = 0; 32 | } 33 | xSnprintf(buffer, len, "%d/%d", (int) this->values[3], (int) this->total); 34 | } 35 | 36 | static void TasksMeter_display(Object* cast, RichString* out) { 37 | Meter* this = (Meter*)cast; 38 | Settings* settings = this->pl->settings; 39 | char buffer[20]; 40 | 41 | int processes = (int) this->values[2]; 42 | 43 | xSnprintf(buffer, sizeof(buffer), "%d", processes); 44 | RichString_write(out, CRT_colors[METER_VALUE], buffer); 45 | int threadValueColor = CRT_colors[METER_VALUE]; 46 | int threadCaptionColor = CRT_colors[METER_TEXT]; 47 | if (settings->highlightThreads) { 48 | threadValueColor = CRT_colors[PROCESS_THREAD_BASENAME]; 49 | threadCaptionColor = CRT_colors[PROCESS_THREAD]; 50 | } 51 | if (!settings->hideUserlandThreads) { 52 | RichString_append(out, CRT_colors[METER_TEXT], ", "); 53 | xSnprintf(buffer, sizeof(buffer), "%d", (int)this->values[1]); 54 | RichString_append(out, threadValueColor, buffer); 55 | RichString_append(out, threadCaptionColor, " thr"); 56 | } 57 | if (!settings->hideKernelThreads) { 58 | RichString_append(out, CRT_colors[METER_TEXT], ", "); 59 | xSnprintf(buffer, sizeof(buffer), "%d", (int)this->values[0]); 60 | RichString_append(out, threadValueColor, buffer); 61 | RichString_append(out, threadCaptionColor, " kthr"); 62 | } 63 | RichString_append(out, CRT_colors[METER_TEXT], "; "); 64 | xSnprintf(buffer, sizeof(buffer), "%d", (int)this->values[3]); 65 | RichString_append(out, CRT_colors[TASKS_RUNNING], buffer); 66 | RichString_append(out, CRT_colors[METER_TEXT], " running"); 67 | } 68 | 69 | MeterClass TasksMeter_class = { 70 | .super = { 71 | .extends = Class(Meter), 72 | .delete = Meter_delete, 73 | .display = TasksMeter_display, 74 | }, 75 | .updateValues = TasksMeter_updateValues, 76 | .defaultMode = TEXT_METERMODE, 77 | .maxItems = 4, 78 | .total = 100.0, 79 | .attributes = TasksMeter_attributes, 80 | .name = "Tasks", 81 | .uiName = "Task counter", 82 | .caption = "Tasks: " 83 | }; 84 | -------------------------------------------------------------------------------- /TasksMeter.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_TasksMeter 4 | #define HEADER_TasksMeter 5 | /* 6 | htop - TasksMeter.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Meter.h" 13 | 14 | extern int TasksMeter_attributes[]; 15 | 16 | extern MeterClass TasksMeter_class; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /TraceScreen.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - TraceScreen.c 3 | (C) 2005-2006 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "TraceScreen.h" 9 | 10 | #include "CRT.h" 11 | #include "InfoScreen.h" 12 | #include "ProcessList.h" 13 | #include "ListItem.h" 14 | #include "IncSet.h" 15 | #include "StringUtils.h" 16 | #include "FunctionBar.h" 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | /*{ 31 | #include "InfoScreen.h" 32 | 33 | typedef struct TraceScreen_ { 34 | InfoScreen super; 35 | bool tracing; 36 | int fdpair[2]; 37 | int child; 38 | FILE* strace; 39 | int fd_strace; 40 | bool contLine; 41 | bool follow; 42 | } TraceScreen; 43 | 44 | }*/ 45 | 46 | static const char* const TraceScreenFunctions[] = {"Search ", "Filter ", "AutoScroll ", "Stop Tracing ", "Done ", NULL}; 47 | 48 | static const char* const TraceScreenKeys[] = {"F3", "F4", "F8", "F9", "Esc"}; 49 | 50 | static int TraceScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(8), KEY_F(9), 27}; 51 | 52 | InfoScreenClass TraceScreen_class = { 53 | .super = { 54 | .extends = Class(Object), 55 | .delete = TraceScreen_delete 56 | }, 57 | .draw = TraceScreen_draw, 58 | .onErr = TraceScreen_updateTrace, 59 | .onKey = TraceScreen_onKey, 60 | }; 61 | 62 | TraceScreen* TraceScreen_new(Process* process) { 63 | TraceScreen* this = xMalloc(sizeof(TraceScreen)); 64 | Object_setClass(this, Class(TraceScreen)); 65 | this->tracing = true; 66 | this->contLine = false; 67 | this->follow = false; 68 | FunctionBar* fuBar = FunctionBar_new(TraceScreenFunctions, TraceScreenKeys, TraceScreenEvents); 69 | CRT_disableDelay(); 70 | return (TraceScreen*) InfoScreen_init(&this->super, process, fuBar, LINES-2, ""); 71 | } 72 | 73 | void TraceScreen_delete(Object* cast) { 74 | TraceScreen* this = (TraceScreen*) cast; 75 | if (this->child > 0) { 76 | kill(this->child, SIGTERM); 77 | waitpid(this->child, NULL, 0); 78 | fclose(this->strace); 79 | } 80 | CRT_enableDelay(); 81 | free(InfoScreen_done((InfoScreen*)cast)); 82 | } 83 | 84 | void TraceScreen_draw(InfoScreen* this) { 85 | attrset(CRT_colors[PANEL_HEADER_FOCUS]); 86 | mvhline(0, 0, ' ', COLS); 87 | mvprintw(0, 0, "Trace of process %d - %s", this->process->pid, this->process->comm); 88 | attrset(CRT_colors[DEFAULT_COLOR]); 89 | IncSet_drawBar(this->inc); 90 | } 91 | 92 | bool TraceScreen_forkTracer(TraceScreen* this) { 93 | char buffer[1001]; 94 | int error = pipe(this->fdpair); 95 | if (error == -1) return false; 96 | this->child = fork(); 97 | if (this->child == -1) return false; 98 | if (this->child == 0) { 99 | CRT_dropPrivileges(); 100 | dup2(this->fdpair[1], STDERR_FILENO); 101 | int ok = fcntl(this->fdpair[1], F_SETFL, O_NONBLOCK); 102 | if (ok != -1) { 103 | xSnprintf(buffer, sizeof(buffer), "%d", this->super.process->pid); 104 | execlp("strace", "strace", "-s", "512", "-p", buffer, NULL); 105 | } 106 | const char* message = "Could not execute 'strace'. Please make sure it is available in your $PATH."; 107 | ssize_t written = write(this->fdpair[1], message, strlen(message)); 108 | (void) written; 109 | exit(1); 110 | } 111 | int ok = fcntl(this->fdpair[0], F_SETFL, O_NONBLOCK); 112 | if (ok == -1) return false; 113 | this->strace = fdopen(this->fdpair[0], "r"); 114 | this->fd_strace = fileno(this->strace); 115 | return true; 116 | } 117 | 118 | void TraceScreen_updateTrace(InfoScreen* super) { 119 | TraceScreen* this = (TraceScreen*) super; 120 | char buffer[1001]; 121 | fd_set fds; 122 | FD_ZERO(&fds); 123 | // FD_SET(STDIN_FILENO, &fds); 124 | FD_SET(this->fd_strace, &fds); 125 | struct timeval tv; 126 | tv.tv_sec = 0; tv.tv_usec = 500; 127 | int ready = select(this->fd_strace+1, &fds, NULL, NULL, &tv); 128 | int nread = 0; 129 | if (ready > 0 && FD_ISSET(this->fd_strace, &fds)) 130 | nread = fread(buffer, 1, 1000, this->strace); 131 | if (nread && this->tracing) { 132 | char* line = buffer; 133 | buffer[nread] = '\0'; 134 | for (int i = 0; i < nread; i++) { 135 | if (buffer[i] == '\n') { 136 | buffer[i] = '\0'; 137 | if (this->contLine) { 138 | InfoScreen_appendLine(&this->super, line); 139 | this->contLine = false; 140 | } else { 141 | InfoScreen_addLine(&this->super, line); 142 | } 143 | line = buffer+i+1; 144 | } 145 | } 146 | if (line < buffer+nread) { 147 | InfoScreen_addLine(&this->super, line); 148 | buffer[nread] = '\0'; 149 | this->contLine = true; 150 | } 151 | if (this->follow) 152 | Panel_setSelected(this->super.display, Panel_size(this->super.display)-1); 153 | } 154 | } 155 | 156 | bool TraceScreen_onKey(InfoScreen* super, int ch) { 157 | TraceScreen* this = (TraceScreen*) super; 158 | switch(ch) { 159 | case 'f': 160 | case KEY_F(8): 161 | this->follow = !(this->follow); 162 | if (this->follow) 163 | Panel_setSelected(super->display, Panel_size(super->display)-1); 164 | return true; 165 | case 't': 166 | case KEY_F(9): 167 | this->tracing = !this->tracing; 168 | FunctionBar_setLabel(super->display->defaultBar, KEY_F(9), this->tracing?"Stop Tracing ":"Resume Tracing "); 169 | InfoScreen_draw(this); 170 | return true; 171 | } 172 | this->follow = false; 173 | return false; 174 | } 175 | -------------------------------------------------------------------------------- /TraceScreen.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_TraceScreen 4 | #define HEADER_TraceScreen 5 | /* 6 | htop - TraceScreen.h 7 | (C) 2005-2006 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "InfoScreen.h" 13 | 14 | typedef struct TraceScreen_ { 15 | InfoScreen super; 16 | bool tracing; 17 | int fdpair[2]; 18 | int child; 19 | FILE* strace; 20 | int fd_strace; 21 | bool contLine; 22 | bool follow; 23 | } TraceScreen; 24 | 25 | 26 | extern InfoScreenClass TraceScreen_class; 27 | 28 | TraceScreen* TraceScreen_new(Process* process); 29 | 30 | void TraceScreen_delete(Object* cast); 31 | 32 | void TraceScreen_draw(InfoScreen* this); 33 | 34 | bool TraceScreen_forkTracer(TraceScreen* this); 35 | 36 | void TraceScreen_updateTrace(InfoScreen* super); 37 | 38 | bool TraceScreen_onKey(InfoScreen* super, int ch); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /UptimeMeter.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - UptimeMeter.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "UptimeMeter.h" 9 | #include "Platform.h" 10 | #include "CRT.h" 11 | 12 | /*{ 13 | #include "Meter.h" 14 | }*/ 15 | 16 | int UptimeMeter_attributes[] = { 17 | UPTIME 18 | }; 19 | 20 | static void UptimeMeter_updateValues(Meter* this, char* buffer, int len) { 21 | int totalseconds = Platform_getUptime(); 22 | if (totalseconds == -1) { 23 | xSnprintf(buffer, len, "(unknown)"); 24 | return; 25 | } 26 | int seconds = totalseconds % 60; 27 | int minutes = (totalseconds/60) % 60; 28 | int hours = (totalseconds/3600) % 24; 29 | int days = (totalseconds/86400); 30 | this->values[0] = days; 31 | if (days > this->total) { 32 | this->total = days; 33 | } 34 | char daysbuf[32]; 35 | if (days > 100) { 36 | xSnprintf(daysbuf, sizeof(daysbuf), "%d days(!), ", days); 37 | } else if (days > 1) { 38 | xSnprintf(daysbuf, sizeof(daysbuf), "%d days, ", days); 39 | } else if (days == 1) { 40 | xSnprintf(daysbuf, sizeof(daysbuf), "1 day, "); 41 | } else { 42 | daysbuf[0] = '\0'; 43 | } 44 | xSnprintf(buffer, len, "%s%02d:%02d:%02d", daysbuf, hours, minutes, seconds); 45 | } 46 | 47 | MeterClass UptimeMeter_class = { 48 | .super = { 49 | .extends = Class(Meter), 50 | .delete = Meter_delete 51 | }, 52 | .updateValues = UptimeMeter_updateValues, 53 | .defaultMode = TEXT_METERMODE, 54 | .maxItems = 1, 55 | .total = 100.0, 56 | .attributes = UptimeMeter_attributes, 57 | .name = "Uptime", 58 | .uiName = "Uptime", 59 | .caption = "Uptime: " 60 | }; 61 | -------------------------------------------------------------------------------- /UptimeMeter.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_UptimeMeter 4 | #define HEADER_UptimeMeter 5 | /* 6 | htop - UptimeMeter.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Meter.h" 13 | 14 | extern int UptimeMeter_attributes[]; 15 | 16 | extern MeterClass UptimeMeter_class; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /UsersTable.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - UsersTable.c 3 | (C) 2004-2011 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "UsersTable.h" 9 | #include "XAlloc.h" 10 | 11 | #include "config.h" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | /*{ 22 | #include "Hashtable.h" 23 | 24 | typedef struct UsersTable_ { 25 | Hashtable* users; 26 | } UsersTable; 27 | }*/ 28 | 29 | UsersTable* UsersTable_new() { 30 | UsersTable* this; 31 | this = xMalloc(sizeof(UsersTable)); 32 | this->users = Hashtable_new(20, true); 33 | return this; 34 | } 35 | 36 | void UsersTable_delete(UsersTable* this) { 37 | Hashtable_delete(this->users); 38 | free(this); 39 | } 40 | 41 | char* UsersTable_getRef(UsersTable* this, unsigned int uid) { 42 | char* name = (char*) (Hashtable_get(this->users, uid)); 43 | if (name == NULL) { 44 | struct passwd* userData = getpwuid(uid); 45 | if (userData != NULL) { 46 | name = xStrdup(userData->pw_name); 47 | Hashtable_put(this->users, uid, name); 48 | } 49 | } 50 | return name; 51 | } 52 | 53 | inline void UsersTable_foreach(UsersTable* this, Hashtable_PairFunction f, void* userData) { 54 | Hashtable_foreach(this->users, f, userData); 55 | } 56 | -------------------------------------------------------------------------------- /UsersTable.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_UsersTable 4 | #define HEADER_UsersTable 5 | /* 6 | htop - UsersTable.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Hashtable.h" 13 | 14 | typedef struct UsersTable_ { 15 | Hashtable* users; 16 | } UsersTable; 17 | 18 | UsersTable* UsersTable_new(); 19 | 20 | void UsersTable_delete(UsersTable* this); 21 | 22 | char* UsersTable_getRef(UsersTable* this, unsigned int uid); 23 | 24 | extern void UsersTable_foreach(UsersTable* this, Hashtable_PairFunction f, void* userData); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /Vector.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Vector 4 | #define HEADER_Vector 5 | /* 6 | htop - Vector.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Object.h" 13 | 14 | #define swap(a_,x_,y_) do{ void* tmp_ = a_[x_]; a_[x_] = a_[y_]; a_[y_] = tmp_; }while(0) 15 | 16 | #ifndef DEFAULT_SIZE 17 | #define DEFAULT_SIZE -1 18 | #endif 19 | 20 | typedef struct Vector_ { 21 | Object **array; 22 | ObjectClass* type; 23 | int arraySize; 24 | int growthRate; 25 | int items; 26 | bool owner; 27 | } Vector; 28 | 29 | 30 | Vector* Vector_new(ObjectClass* type, bool owner, int size); 31 | 32 | void Vector_delete(Vector* this); 33 | 34 | #ifdef DEBUG 35 | 36 | int Vector_count(Vector* this); 37 | 38 | #endif 39 | 40 | void Vector_prune(Vector* this); 41 | 42 | // If I were to use only one sorting algorithm for both cases, it would probably be this one: 43 | /* 44 | 45 | */ 46 | 47 | void Vector_quickSort(Vector* this); 48 | 49 | void Vector_insertionSort(Vector* this); 50 | 51 | void Vector_insert(Vector* this, int idx, void* data_); 52 | 53 | Object* Vector_take(Vector* this, int idx); 54 | 55 | Object* Vector_remove(Vector* this, int idx); 56 | 57 | void Vector_moveUp(Vector* this, int idx); 58 | 59 | void Vector_moveDown(Vector* this, int idx); 60 | 61 | void Vector_set(Vector* this, int idx, void* data_); 62 | 63 | #ifdef DEBUG 64 | 65 | extern Object* Vector_get(Vector* this, int idx); 66 | 67 | #else 68 | 69 | #define Vector_get(v_, idx_) ((v_)->array[idx_]) 70 | 71 | #endif 72 | 73 | #ifdef DEBUG 74 | 75 | extern int Vector_size(Vector* this); 76 | 77 | #else 78 | 79 | #define Vector_size(v_) ((v_)->items) 80 | 81 | #endif 82 | 83 | /* 84 | 85 | */ 86 | 87 | void Vector_add(Vector* this, void* data_); 88 | 89 | extern int Vector_indexOf(Vector* this, void* search_, Object_Compare compare); 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /XAlloc.c: -------------------------------------------------------------------------------- 1 | 2 | #include "XAlloc.h" 3 | #include "RichString.h" 4 | 5 | #ifndef _GNU_SOURCE 6 | #define _GNU_SOURCE 7 | #endif 8 | #include 9 | #include 10 | 11 | /*{ 12 | #include 13 | #include 14 | #include 15 | }*/ 16 | 17 | static inline void fail() { 18 | curs_set(1); 19 | endwin(); 20 | err(1, NULL); 21 | } 22 | 23 | void* xMalloc(size_t size) { 24 | void* data = malloc(size); 25 | if (!data && size > 0) { 26 | fail(); 27 | } 28 | return data; 29 | } 30 | 31 | void* xCalloc(size_t nmemb, size_t size) { 32 | void* data = calloc(nmemb, size); 33 | if (!data && nmemb > 0 && size > 0) { 34 | fail(); 35 | } 36 | return data; 37 | } 38 | 39 | void* xRealloc(void* ptr, size_t size) { 40 | void* data = realloc(ptr, size); 41 | if (!data && size > 0) { 42 | fail(); 43 | } 44 | return data; 45 | } 46 | 47 | #define xSnprintf(fmt, len, ...) do { int _l=len; int _n=snprintf(fmt, _l, __VA_ARGS__); if (!(_n > -1 && _n < _l)) { curs_set(1); endwin(); err(1, NULL); } } while(0) 48 | 49 | #undef xStrdup 50 | #undef xStrdup_ 51 | #ifdef NDEBUG 52 | # define xStrdup_ xStrdup 53 | #else 54 | # define xStrdup(str_) (assert(str_), xStrdup_(str_)) 55 | #endif 56 | 57 | #ifndef __has_attribute // Clang's macro 58 | # define __has_attribute(x) 0 59 | #endif 60 | #if (__has_attribute(nonnull) || \ 61 | ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))) 62 | char* xStrdup_(const char* str) __attribute__((nonnull)); 63 | #endif // __has_attribute(nonnull) || GNU C 3.3 or later 64 | 65 | char* xStrdup_(const char* str) { 66 | char* data = strdup(str); 67 | if (!data) { 68 | fail(); 69 | } 70 | return data; 71 | } 72 | -------------------------------------------------------------------------------- /XAlloc.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_XAlloc 4 | #define HEADER_XAlloc 5 | 6 | #ifndef _GNU_SOURCE 7 | #define _GNU_SOURCE 8 | #endif 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | void* xMalloc(size_t size); 15 | 16 | void* xCalloc(size_t nmemb, size_t size); 17 | 18 | void* xRealloc(void* ptr, size_t size); 19 | 20 | #define xSnprintf(fmt, len, ...) do { int _l=len; int _n=snprintf(fmt, _l, __VA_ARGS__); if (!(_n > -1 && _n < _l)) { curs_set(1); endwin(); err(1, NULL); } } while(0) 21 | 22 | #undef xStrdup 23 | #undef xStrdup_ 24 | #ifdef NDEBUG 25 | # define xStrdup_ xStrdup 26 | #else 27 | # define xStrdup(str_) (assert(str_), xStrdup_(str_)) 28 | #endif 29 | 30 | #ifndef __has_attribute // Clang's macro 31 | # define __has_attribute(x) 0 32 | #endif 33 | #if (__has_attribute(nonnull) || \ 34 | ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))) 35 | char* xStrdup_(const char* str) __attribute__((nonnull)); 36 | #endif // __has_attribute(nonnull) || GNU C 3.3 or later 37 | 38 | char* xStrdup_(const char* str); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | mkdir -p m4 3 | autoreconf --install --force 4 | -------------------------------------------------------------------------------- /darwin/Battery.c: -------------------------------------------------------------------------------- 1 | 2 | #include "BatteryMeter.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void Battery_getData(double* level, ACPresence* isOnAC) { 10 | CFTypeRef power_sources = IOPSCopyPowerSourcesInfo(); 11 | 12 | *level = -1; 13 | *isOnAC = AC_ERROR; 14 | 15 | if(NULL == power_sources) { 16 | return; 17 | } 18 | 19 | if(power_sources != NULL) { 20 | CFArrayRef list = IOPSCopyPowerSourcesList(power_sources); 21 | CFDictionaryRef battery = NULL; 22 | int len; 23 | 24 | if(NULL == list) { 25 | CFRelease(power_sources); 26 | 27 | return; 28 | } 29 | 30 | len = CFArrayGetCount(list); 31 | 32 | /* Get the battery */ 33 | for(int i = 0; i < len && battery == NULL; ++i) { 34 | CFDictionaryRef candidate = IOPSGetPowerSourceDescription(power_sources, 35 | CFArrayGetValueAtIndex(list, i)); /* GET rule */ 36 | CFStringRef type; 37 | 38 | if(NULL != candidate) { 39 | type = (CFStringRef) CFDictionaryGetValue(candidate, 40 | CFSTR(kIOPSTransportTypeKey)); /* GET rule */ 41 | 42 | if(kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) { 43 | CFRetain(candidate); 44 | battery = candidate; 45 | } 46 | } 47 | } 48 | 49 | if(NULL != battery) { 50 | /* Determine the AC state */ 51 | CFStringRef power_state = CFDictionaryGetValue(battery, CFSTR(kIOPSPowerSourceStateKey)); 52 | 53 | *isOnAC = (kCFCompareEqualTo == CFStringCompare(power_state, CFSTR(kIOPSACPowerValue), 0)) 54 | ? AC_PRESENT 55 | : AC_ABSENT; 56 | 57 | /* Get the percentage remaining */ 58 | double current; 59 | double max; 60 | 61 | CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSCurrentCapacityKey)), 62 | kCFNumberDoubleType, ¤t); 63 | CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSMaxCapacityKey)), 64 | kCFNumberDoubleType, &max); 65 | 66 | *level = (current * 100.0) / max; 67 | 68 | CFRelease(battery); 69 | } 70 | 71 | CFRelease(list); 72 | CFRelease(power_sources); 73 | } 74 | } 75 | 76 | -------------------------------------------------------------------------------- /darwin/Battery.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Battery 4 | #define HEADER_Battery 5 | 6 | void Battery_getData(double* level, ACPresence* isOnAC); 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /darwin/DarwinCRT.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - DarwinCRT.c 3 | (C) 2014 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "config.h" 9 | #include "CRT.h" 10 | #include 11 | #include 12 | #include 13 | 14 | void CRT_handleSIGSEGV(int sgn) { 15 | (void) sgn; 16 | CRT_done(); 17 | #ifdef __APPLE__ 18 | fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at http://hisham.hm/htop\n"); 19 | #ifdef HAVE_EXECINFO_H 20 | size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *)); 21 | fprintf(stderr, "\n Please include in your report the following backtrace: \n"); 22 | backtrace_symbols_fd(backtraceArray, size, 2); 23 | fprintf(stderr, "\nAdditionally, in order to make the above backtrace useful,"); 24 | fprintf(stderr, "\nplease also run the following command to generate a disassembly of your binary:"); 25 | fprintf(stderr, "\n\n otool -tvV `which htop` > ~/htop.otool"); 26 | fprintf(stderr, "\n\nand then attach the file ~/htop.otool to your bug report."); 27 | fprintf(stderr, "\n\nThank you for helping to improve htop!\n\n"); 28 | #endif 29 | #else 30 | fprintf(stderr, "\nUnfortunately, you seem to be using an unsupported platform!"); 31 | fprintf(stderr, "\nPlease contact your platform package maintainer!\n\n"); 32 | #endif 33 | abort(); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /darwin/DarwinCRT.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_DarwinCRT 4 | #define HEADER_DarwinCRT 5 | /* 6 | htop - DarwinCRT.h 7 | (C) 2014 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | void CRT_handleSIGSEGV(int sgn); 13 | 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /darwin/DarwinProcess.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_DarwinProcess 4 | #define HEADER_DarwinProcess 5 | /* 6 | htop - DarwinProcess.h 7 | (C) 2015 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Settings.h" 13 | #include "DarwinProcessList.h" 14 | 15 | #include 16 | 17 | typedef struct DarwinProcess_ { 18 | Process super; 19 | 20 | uint64_t utime; 21 | uint64_t stime; 22 | bool taskAccess; 23 | } DarwinProcess; 24 | 25 | 26 | extern ProcessClass DarwinProcess_class; 27 | 28 | DarwinProcess* DarwinProcess_new(Settings* settings); 29 | 30 | void Process_delete(Object* cast); 31 | 32 | bool Process_isThread(Process* this); 33 | 34 | void DarwinProcess_setStartTime(Process *proc, struct extern_proc *ep, time_t now); 35 | 36 | char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset); 37 | 38 | void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, time_t now, bool exists); 39 | 40 | void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList *dpl); 41 | 42 | /* 43 | * Scan threads for process state information. 44 | * Based on: http://stackoverflow.com/questions/6788274/ios-mac-cpu-usage-for-thread 45 | * and https://github.com/max-horvath/htop-osx/blob/e86692e869e30b0bc7264b3675d2a4014866ef46/ProcessList.c 46 | */ 47 | void DarwinProcess_scanThreads(DarwinProcess *dp); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /darwin/DarwinProcessList.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_DarwinProcessList 4 | #define HEADER_DarwinProcessList 5 | /* 6 | htop - DarwinProcessList.h 7 | (C) 2014 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "ProcessList.h" 13 | #include 14 | #include 15 | 16 | typedef struct DarwinProcessList_ { 17 | ProcessList super; 18 | 19 | host_basic_info_data_t host_info; 20 | vm_statistics_data_t vm_stats; 21 | processor_cpu_load_info_t prev_load; 22 | processor_cpu_load_info_t curr_load; 23 | uint64_t kernel_threads; 24 | uint64_t user_threads; 25 | uint64_t global_diff; 26 | } DarwinProcessList; 27 | 28 | 29 | void ProcessList_getHostInfo(host_basic_info_data_t *p); 30 | 31 | void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p); 32 | 33 | unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p); 34 | 35 | void ProcessList_getVMStats(vm_statistics_t p); 36 | 37 | struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count); 38 | 39 | ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); 40 | 41 | void ProcessList_delete(ProcessList* this); 42 | 43 | void ProcessList_goThroughEntries(ProcessList* super); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /darwin/Platform.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Platform 4 | #define HEADER_Platform 5 | /* 6 | htop - darwin/Platform.h 7 | (C) 2014 Hisham H. Muhammad 8 | (C) 2015 David C. Hunt 9 | Released under the GNU GPL, see the COPYING file 10 | in the source distribution for its full text. 11 | */ 12 | 13 | #include "Action.h" 14 | #include "SignalsPanel.h" 15 | #include "CPUMeter.h" 16 | #include "BatteryMeter.h" 17 | #include "DarwinProcess.h" 18 | 19 | #ifndef CLAMP 20 | #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) 21 | #endif 22 | 23 | extern ProcessField Platform_defaultFields[]; 24 | 25 | extern const SignalItem Platform_signals[]; 26 | 27 | extern const unsigned int Platform_numberOfSignals; 28 | 29 | extern ProcessFieldData Process_fields[]; 30 | 31 | extern MeterClass* Platform_meterTypes[]; 32 | 33 | void Platform_setBindings(Htop_Action* keys); 34 | 35 | extern int Platform_numberOfFields; 36 | 37 | int Platform_getUptime(); 38 | 39 | void Platform_getLoadAverage(double* one, double* five, double* fifteen); 40 | 41 | int Platform_getMaxPid(); 42 | 43 | extern ProcessPidColumn Process_pidColumns[]; 44 | 45 | double Platform_setCPUValues(Meter* mtr, int cpu); 46 | 47 | void Platform_setMemoryValues(Meter* mtr); 48 | 49 | void Platform_setSwapValues(Meter* mtr); 50 | 51 | char* Platform_getProcessEnv(pid_t pid); 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /dragonflybsd/Battery.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - dragonflybsd/Battery.c 3 | (C) 2015 Hisham H. Muhammad 4 | (C) 2017 Diederik de Groot 5 | Released under the GNU GPL, see the COPYING file 6 | in the source distribution for its full text. 7 | */ 8 | 9 | #include "BatteryMeter.h" 10 | #include 11 | 12 | void Battery_getData(double* level, ACPresence* isOnAC) { 13 | int life; 14 | size_t life_len = sizeof(life); 15 | if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) 16 | *level = -1; 17 | else 18 | *level = life; 19 | 20 | int acline; 21 | size_t acline_len = sizeof(acline); 22 | if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1) 23 | *isOnAC = AC_ERROR; 24 | else 25 | *isOnAC = acline == 0 ? AC_ABSENT : AC_PRESENT; 26 | } 27 | -------------------------------------------------------------------------------- /dragonflybsd/Battery.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Battery 4 | #define HEADER_Battery 5 | /* 6 | htop - dragonflybsd/Battery.h 7 | (C) 2015 Hisham H. Muhammad 8 | (C) 2017 Diederik de Groot 9 | Released under the GNU GPL, see the COPYING file 10 | in the source distribution for its full text. 11 | */ 12 | 13 | void Battery_getData(double* level, ACPresence* isOnAC); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /dragonflybsd/DragonFlyBSDCRT.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - dragonflybsd/DragonFlyBSDCRT.c 3 | (C) 2014 Hisham H. Muhammad 4 | (C) 2017 Diederik de Groot 5 | Released under the GNU GPL, see the COPYING file 6 | in the source distribution for its full text. 7 | */ 8 | 9 | #include "config.h" 10 | #include "CRT.h" 11 | #include 12 | #include 13 | #ifdef HAVE_EXECINFO_H 14 | #include 15 | #endif 16 | 17 | void CRT_handleSIGSEGV(int sgn) { 18 | (void) sgn; 19 | CRT_done(); 20 | fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at http://hisham.hm/htop\n"); 21 | #ifdef HAVE_EXECINFO_H 22 | size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *)); 23 | fprintf(stderr, "\n Please include in your report the following backtrace: \n"); 24 | backtrace_symbols_fd(backtraceArray, size, 2); 25 | fprintf(stderr, "\nAdditionally, in order to make the above backtrace useful,"); 26 | fprintf(stderr, "\nplease also run the following command to generate a disassembly of your binary:"); 27 | fprintf(stderr, "\n\n objdump -d `which htop` > ~/htop.objdump"); 28 | fprintf(stderr, "\n\nand then attach the file ~/htop.objdump to your bug report."); 29 | fprintf(stderr, "\n\nThank you for helping to improve htop!\n\n"); 30 | #else 31 | fprintf(stderr, "\nPlease contact your DragonFlyBSD package maintainer!\n\n"); 32 | #endif 33 | abort(); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /dragonflybsd/DragonFlyBSDCRT.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_DragonFlyBSDCRT 4 | #define HEADER_DragonFlyBSDCRT 5 | /* 6 | htop - dragonflybsd/DragonFlyBSDCRT.h 7 | (C) 2014 Hisham H. Muhammad 8 | (C) 2017 Diederik de Groot 9 | Released under the GNU GPL, see the COPYING file 10 | in the source distribution for its full text. 11 | */ 12 | 13 | #ifdef HAVE_EXECINFO_H 14 | #endif 15 | 16 | void CRT_handleSIGSEGV(int sgn); 17 | 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /dragonflybsd/DragonFlyBSDProcess.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_DragonFlyBSDProcess 4 | #define HEADER_DragonFlyBSDProcess 5 | /* 6 | htop - dragonflybsd/DragonFlyBSDProcess.h 7 | (C) 2015 Hisham H. Muhammad 8 | (C) 2017 Diederik de Groot 9 | Released under the GNU GPL, see the COPYING file 10 | in the source distribution for its full text. 11 | */ 12 | 13 | 14 | typedef enum DragonFlyBSDProcessFields { 15 | // Add platform-specific fields here, with ids >= 100 16 | JID = 100, 17 | JAIL = 101, 18 | LAST_PROCESSFIELD = 102, 19 | } DragonFlyBSDProcessField; 20 | 21 | 22 | typedef struct DragonFlyBSDProcess_ { 23 | Process super; 24 | int kernel; 25 | int jid; 26 | char* jname; 27 | } DragonFlyBSDProcess; 28 | 29 | 30 | #ifndef Process_isKernelThread 31 | #define Process_isKernelThread(_process) (_process->kernel == 1) 32 | #endif 33 | 34 | #ifndef Process_isUserlandThread 35 | //#define Process_isUserlandThread(_process) (_process->pid != _process->tgid) 36 | #define Process_isUserlandThread(_process) (_process->nlwp > 1) 37 | #endif 38 | 39 | 40 | extern ProcessClass DragonFlyBSDProcess_class; 41 | 42 | extern ProcessFieldData Process_fields[]; 43 | 44 | extern ProcessPidColumn Process_pidColumns[]; 45 | 46 | DragonFlyBSDProcess* DragonFlyBSDProcess_new(Settings* settings); 47 | 48 | void Process_delete(Object* cast); 49 | 50 | void DragonFlyBSDProcess_writeField(Process* this, RichString* str, ProcessField field); 51 | 52 | long DragonFlyBSDProcess_compare(const void* v1, const void* v2); 53 | 54 | bool Process_isThread(Process* this); 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /dragonflybsd/DragonFlyBSDProcessList.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_DragonFlyBSDProcessList 4 | #define HEADER_DragonFlyBSDProcessList 5 | /* 6 | htop - DragonFlyBSDProcessList.h 7 | (C) 2014 Hisham H. Muhammad 8 | (C) 2017 Diederik de Groot 9 | Released under the GNU GPL, see the COPYING file 10 | in the source distribution for its full text. 11 | */ 12 | 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "Hashtable.h" 23 | #include "DragonFlyBSDProcess.h" 24 | 25 | #define JAIL_ERRMSGLEN 1024 26 | char jail_errmsg[JAIL_ERRMSGLEN]; 27 | 28 | typedef struct CPUData_ { 29 | 30 | double userPercent; 31 | double nicePercent; 32 | double systemPercent; 33 | double irqPercent; 34 | double idlePercent; 35 | double systemAllPercent; 36 | 37 | } CPUData; 38 | 39 | typedef struct DragonFlyBSDProcessList_ { 40 | ProcessList super; 41 | kvm_t* kd; 42 | 43 | unsigned long long int memWire; 44 | unsigned long long int memActive; 45 | unsigned long long int memInactive; 46 | unsigned long long int memFree; 47 | 48 | CPUData* cpus; 49 | 50 | unsigned long *cp_time_o; 51 | unsigned long *cp_time_n; 52 | 53 | unsigned long *cp_times_o; 54 | unsigned long *cp_times_n; 55 | 56 | Hashtable *jails; 57 | } DragonFlyBSDProcessList; 58 | 59 | 60 | #define _UNUSED_ __attribute__((unused)) 61 | 62 | 63 | ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); 64 | 65 | void ProcessList_delete(ProcessList* this); 66 | 67 | char* DragonFlyBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd); 68 | 69 | char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int jailid); 70 | 71 | void ProcessList_goThroughEntries(ProcessList* this); 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /dragonflybsd/Platform.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Platform 4 | #define HEADER_Platform 5 | /* 6 | htop - dragonflybsd/Platform.h 7 | (C) 2014 Hisham H. Muhammad 8 | (C) 2017 Diederik de Groot 9 | Released under the GNU GPL, see the COPYING file 10 | in the source distribution for its full text. 11 | */ 12 | 13 | #include "Action.h" 14 | #include "BatteryMeter.h" 15 | #include "SignalsPanel.h" 16 | 17 | extern ProcessFieldData Process_fields[]; 18 | 19 | 20 | #ifndef CLAMP 21 | #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) 22 | #endif 23 | 24 | extern ProcessField Platform_defaultFields[]; 25 | 26 | extern int Platform_numberOfFields; 27 | 28 | extern const SignalItem Platform_signals[]; 29 | 30 | extern const unsigned int Platform_numberOfSignals; 31 | 32 | void Platform_setBindings(Htop_Action* keys); 33 | 34 | extern MeterClass* Platform_meterTypes[]; 35 | 36 | int Platform_getUptime(); 37 | 38 | void Platform_getLoadAverage(double* one, double* five, double* fifteen); 39 | 40 | int Platform_getMaxPid(); 41 | 42 | double Platform_setCPUValues(Meter* this, int cpu); 43 | 44 | void Platform_setMemoryValues(Meter* this); 45 | 46 | void Platform_setSwapValues(Meter* this); 47 | 48 | void Platform_setTasksValues(Meter* this); 49 | 50 | char* Platform_getProcessEnv(pid_t pid); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /freebsd/Battery.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - freebsd/Battery.c 3 | (C) 2015 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "BatteryMeter.h" 9 | #include 10 | 11 | void Battery_getData(double* level, ACPresence* isOnAC) { 12 | int life; 13 | size_t life_len = sizeof(life); 14 | if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) 15 | *level = -1; 16 | else 17 | *level = life; 18 | 19 | int acline; 20 | size_t acline_len = sizeof(acline); 21 | if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1) 22 | *isOnAC = AC_ERROR; 23 | else 24 | *isOnAC = acline == 0 ? AC_ABSENT : AC_PRESENT; 25 | } 26 | -------------------------------------------------------------------------------- /freebsd/Battery.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Battery 4 | #define HEADER_Battery 5 | /* 6 | htop - freebsd/Battery.h 7 | (C) 2015 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | void Battery_getData(double* level, ACPresence* isOnAC); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /freebsd/FreeBSDCRT.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - UnsupportedCRT.c 3 | (C) 2014 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "config.h" 9 | #include "CRT.h" 10 | #include 11 | #include 12 | 13 | void CRT_handleSIGSEGV(int sgn) { 14 | (void) sgn; 15 | CRT_done(); 16 | fprintf(stderr, "\n\nhtop " VERSION " aborting.\n"); 17 | fprintf(stderr, "\nUnfortunately, you seem to be using an unsupported platform!"); 18 | fprintf(stderr, "\nPlease contact your platform package maintainer!\n\n"); 19 | abort(); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /freebsd/FreeBSDCRT.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_FreeBSDCRT 4 | #define HEADER_FreeBSDCRT 5 | /* 6 | htop - UnsupportedCRT.h 7 | (C) 2014 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | void CRT_handleSIGSEGV(int sgn); 13 | 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /freebsd/FreeBSDProcess.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_FreeBSDProcess 4 | #define HEADER_FreeBSDProcess 5 | /* 6 | htop - FreeBSDProcess.h 7 | (C) 2015 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | 13 | typedef enum FreeBSDProcessFields { 14 | // Add platform-specific fields here, with ids >= 100 15 | JID = 100, 16 | JAIL = 101, 17 | LAST_PROCESSFIELD = 102, 18 | } FreeBSDProcessField; 19 | 20 | 21 | typedef struct FreeBSDProcess_ { 22 | Process super; 23 | int kernel; 24 | int jid; 25 | char* jname; 26 | } FreeBSDProcess; 27 | 28 | 29 | #ifndef Process_isKernelThread 30 | #define Process_isKernelThread(_process) (_process->kernel == 1) 31 | #endif 32 | 33 | #ifndef Process_isUserlandThread 34 | #define Process_isUserlandThread(_process) (_process->pid != _process->tgid) 35 | #endif 36 | 37 | 38 | extern ProcessClass FreeBSDProcess_class; 39 | 40 | extern ProcessFieldData Process_fields[]; 41 | 42 | extern ProcessPidColumn Process_pidColumns[]; 43 | 44 | FreeBSDProcess* FreeBSDProcess_new(Settings* settings); 45 | 46 | void Process_delete(Object* cast); 47 | 48 | void FreeBSDProcess_writeField(Process* this, RichString* str, ProcessField field); 49 | 50 | long FreeBSDProcess_compare(const void* v1, const void* v2); 51 | 52 | bool Process_isThread(Process* this); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /freebsd/FreeBSDProcessList.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_FreeBSDProcessList 4 | #define HEADER_FreeBSDProcessList 5 | /* 6 | htop - FreeBSDProcessList.h 7 | (C) 2014 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #define JAIL_ERRMSGLEN 1024 20 | char jail_errmsg[JAIL_ERRMSGLEN]; 21 | 22 | typedef struct CPUData_ { 23 | 24 | double userPercent; 25 | double nicePercent; 26 | double systemPercent; 27 | double irqPercent; 28 | double idlePercent; 29 | double systemAllPercent; 30 | 31 | } CPUData; 32 | 33 | typedef struct FreeBSDProcessList_ { 34 | ProcessList super; 35 | kvm_t* kd; 36 | 37 | int zfsArcEnabled; 38 | 39 | unsigned long long int memWire; 40 | unsigned long long int memActive; 41 | unsigned long long int memInactive; 42 | unsigned long long int memFree; 43 | unsigned long long int memZfsArc; 44 | 45 | 46 | CPUData* cpus; 47 | 48 | unsigned long *cp_time_o; 49 | unsigned long *cp_time_n; 50 | 51 | unsigned long *cp_times_o; 52 | unsigned long *cp_times_n; 53 | 54 | } FreeBSDProcessList; 55 | 56 | 57 | 58 | ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); 59 | 60 | void ProcessList_delete(ProcessList* this); 61 | 62 | char* FreeBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd); 63 | 64 | char* FreeBSDProcessList_readJailName(struct kinfo_proc* kproc); 65 | 66 | void ProcessList_goThroughEntries(ProcessList* this); 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /freebsd/Platform.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Platform 4 | #define HEADER_Platform 5 | /* 6 | htop - freebsd/Platform.h 7 | (C) 2014 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Action.h" 13 | #include "BatteryMeter.h" 14 | #include "SignalsPanel.h" 15 | 16 | extern ProcessFieldData Process_fields[]; 17 | 18 | 19 | #ifndef CLAMP 20 | #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) 21 | #endif 22 | 23 | extern ProcessField Platform_defaultFields[]; 24 | 25 | extern int Platform_numberOfFields; 26 | 27 | extern const SignalItem Platform_signals[]; 28 | 29 | extern const unsigned int Platform_numberOfSignals; 30 | 31 | void Platform_setBindings(Htop_Action* keys); 32 | 33 | extern MeterClass* Platform_meterTypes[]; 34 | 35 | int Platform_getUptime(); 36 | 37 | void Platform_getLoadAverage(double* one, double* five, double* fifteen); 38 | 39 | int Platform_getMaxPid(); 40 | 41 | double Platform_setCPUValues(Meter* this, int cpu); 42 | 43 | void Platform_setMemoryValues(Meter* this); 44 | 45 | void Platform_setSwapValues(Meter* this); 46 | 47 | void Platform_setTasksValues(Meter* this); 48 | 49 | char* Platform_getProcessEnv(pid_t pid); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /htop.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Type=Application 3 | Version=1.0 4 | Name=Htop 5 | GenericName=Process Viewer 6 | GenericName[ca]=Visualitzador de processos 7 | GenericName[de]=Prozessanzeige 8 | GenericName[en_GB]=Process Viewer 9 | GenericName[es]=Visor de procesos 10 | GenericName[fi]=Prosessikatselin 11 | GenericName[fr]=Visualiseur de processus 12 | GenericName[gl]=Visor de procesos 13 | GenericName[it]=Visore dei processi 14 | GenericName[ko]=프로세스 뷰어 15 | GenericName[nb]=Prosessviser 16 | GenericName[nl]=Viewer van processen 17 | GenericName[nn]=Prosessvisar 18 | GenericName[pl]=Przeglądarka procesów 19 | GenericName[pt]=Visualizador de Processos 20 | GenericName[pt_BR]=Visualizador de processos 21 | GenericName[ru]=Монитор процессов 22 | GenericName[sk]=Prehliadač procesov 23 | GenericName[sl]=Pregledovalnik opravil 24 | GenericName[sr@ijekavian]=Приказивач процеса 25 | GenericName[sr@ijekavianlatin]=Prikazivač procesa 26 | GenericName[sr@latin]=Prikazivač procesa 27 | GenericName[sr]=Приказивач процеса 28 | GenericName[sv]=Processvisning 29 | GenericName[tr]=Süreç Görüntüleyici 30 | GenericName[uk]=Перегляд процесів 31 | GenericName[zh_CN]=进程查看器 32 | GenericName[zh_TW]=行程檢視器 33 | Comment=Show System Processes 34 | Comment[ca]=Visualitzeu els processos del sistema 35 | Comment[de]=Systemprozesse anzeigen 36 | Comment[en_GB]=Show System Processes 37 | Comment[es]=Mostrar procesos del sistema 38 | Comment[fi]=Katsele järjestelmän prosesseja 39 | Comment[fr]=Affiche les processus système 40 | Comment[gl]=Mostrar os procesos do sistema. 41 | Comment[it]=Mostra processi di sistema 42 | Comment[ko]=시스템 프로세스 보기 43 | Comment[nb]=Vis systemprosesser 44 | Comment[nl]=Systeemprocessen tonen 45 | Comment[nn]=Vis systemprosessar 46 | Comment[pl]=Pokaż procesy systemowe 47 | Comment[pt]=Mostrar os Processos do Sistema 48 | Comment[pt_BR]=Mostra os processos do sistema 49 | Comment[ru]=Просмотр списка процессов в системе 50 | Comment[sk]=Zobraziť systémové procesy 51 | Comment[sl]=Prikaz sistemskih opravil 52 | Comment[sr@ijekavian]=Приказ системских процеса 53 | Comment[sr@ijekavianlatin]=Prikaz sistemskih procesa 54 | Comment[sr@latin]=Prikaz sistemskih procesa 55 | Comment[sr]=Приказ системских процеса 56 | Comment[sv]=Visa systemprocesser 57 | Comment[tr]=Sistem Süreçlerini Göster 58 | Comment[uk]=Перегляд системних процесів 59 | Comment[zh_CN]=显示系统进程 60 | Comment[zh_TW]=顯示系統行程 61 | Icon=htop 62 | Exec=htop 63 | Terminal=true 64 | Categories=System;Monitor;ConsoleOnly; 65 | Keywords=system;process;task 66 | -------------------------------------------------------------------------------- /htop.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_htop 4 | #define HEADER_htop 5 | /* 6 | htop - htop.h 7 | (C) 2004-2011 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | //#link m 13 | 14 | // ---------------------------------------- 15 | 16 | 17 | int main(int argc, char** argv); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /htop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hishamhm/htop/59166da773d8a9a97c8f1b087346865bc8cda9fa/htop.png -------------------------------------------------------------------------------- /linux/Battery.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Battery 4 | #define HEADER_Battery 5 | /* 6 | htop - linux/Battery.h 7 | (C) 2004-2014 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | 11 | Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). 12 | */ 13 | 14 | #ifndef _GNU_SOURCE 15 | #define _GNU_SOURCE 16 | #endif 17 | 18 | #define SYS_POWERSUPPLY_DIR "/sys/class/power_supply" 19 | 20 | // ---------------------------------------- 21 | // READ FROM /proc 22 | // ---------------------------------------- 23 | 24 | // This implementation reading from from /proc/acpi is really inefficient, 25 | // but I think this is on the way out so I did not rewrite it. 26 | // The /sys implementation below does things the right way. 27 | 28 | // ---------------------------------------- 29 | // READ FROM /sys 30 | // ---------------------------------------- 31 | 32 | void Battery_getData(double* level, ACPresence* isOnAC); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /linux/IOPriority.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - IOPriority.c 3 | (C) 2004-2012 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | 7 | Based on ionice, 8 | Copyright (C) 2005 Jens Axboe 9 | Released under the terms of the GNU General Public License version 2 10 | */ 11 | 12 | #include "IOPriority.h" 13 | 14 | /*{ 15 | 16 | enum { 17 | IOPRIO_CLASS_NONE, 18 | IOPRIO_CLASS_RT, 19 | IOPRIO_CLASS_BE, 20 | IOPRIO_CLASS_IDLE, 21 | }; 22 | 23 | #define IOPRIO_WHO_PROCESS 1 24 | 25 | #define IOPRIO_CLASS_SHIFT (13) 26 | #define IOPRIO_PRIO_MASK ((1UL << IOPRIO_CLASS_SHIFT) - 1) 27 | 28 | #define IOPriority_class(ioprio_) ((int) ((ioprio_) >> IOPRIO_CLASS_SHIFT) ) 29 | #define IOPriority_data(ioprio_) ((int) ((ioprio_) & IOPRIO_PRIO_MASK) ) 30 | 31 | typedef int IOPriority; 32 | 33 | #define IOPriority_tuple(class_, data_) (((class_) << IOPRIO_CLASS_SHIFT) | data_) 34 | 35 | #define IOPriority_error 0xffffffff 36 | 37 | #define IOPriority_None IOPriority_tuple(IOPRIO_CLASS_NONE, 0) 38 | #define IOPriority_Idle IOPriority_tuple(IOPRIO_CLASS_IDLE, 7) 39 | 40 | }*/ 41 | 42 | -------------------------------------------------------------------------------- /linux/IOPriority.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_IOPriority 4 | #define HEADER_IOPriority 5 | /* 6 | htop - IOPriority.h 7 | (C) 2004-2012 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | 11 | Based on ionice, 12 | Copyright (C) 2005 Jens Axboe 13 | Released under the terms of the GNU General Public License version 2 14 | */ 15 | 16 | 17 | enum { 18 | IOPRIO_CLASS_NONE, 19 | IOPRIO_CLASS_RT, 20 | IOPRIO_CLASS_BE, 21 | IOPRIO_CLASS_IDLE, 22 | }; 23 | 24 | #define IOPRIO_WHO_PROCESS 1 25 | 26 | #define IOPRIO_CLASS_SHIFT (13) 27 | #define IOPRIO_PRIO_MASK ((1UL << IOPRIO_CLASS_SHIFT) - 1) 28 | 29 | #define IOPriority_class(ioprio_) ((int) ((ioprio_) >> IOPRIO_CLASS_SHIFT) ) 30 | #define IOPriority_data(ioprio_) ((int) ((ioprio_) & IOPRIO_PRIO_MASK) ) 31 | 32 | typedef int IOPriority; 33 | 34 | #define IOPriority_tuple(class_, data_) (((class_) << IOPRIO_CLASS_SHIFT) | data_) 35 | 36 | #define IOPriority_error 0xffffffff 37 | 38 | #define IOPriority_None IOPriority_tuple(IOPRIO_CLASS_NONE, 0) 39 | #define IOPriority_Idle IOPriority_tuple(IOPRIO_CLASS_IDLE, 7) 40 | 41 | 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /linux/IOPriorityPanel.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - IOPriorityPanel.c 3 | (C) 2004-2012 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "IOPriorityPanel.h" 9 | 10 | /*{ 11 | #include "Panel.h" 12 | #include "IOPriority.h" 13 | #include "ListItem.h" 14 | }*/ 15 | 16 | Panel* IOPriorityPanel_new(IOPriority currPrio) { 17 | Panel* this = Panel_new(1, 1, 1, 1, true, Class(ListItem), FunctionBar_newEnterEsc("Set ", "Cancel ")); 18 | 19 | Panel_setHeader(this, "IO Priority:"); 20 | Panel_add(this, (Object*) ListItem_new("None (based on nice)", IOPriority_None)); 21 | if (currPrio == IOPriority_None) Panel_setSelected(this, 0); 22 | static const struct { int klass; const char* name; } classes[] = { 23 | { .klass = IOPRIO_CLASS_RT, .name = "Realtime" }, 24 | { .klass = IOPRIO_CLASS_BE, .name = "Best-effort" }, 25 | { .klass = 0, .name = NULL } 26 | }; 27 | for (int c = 0; classes[c].name; c++) { 28 | for (int i = 0; i < 8; i++) { 29 | char name[50]; 30 | xSnprintf(name, sizeof(name)-1, "%s %d %s", classes[c].name, i, i == 0 ? "(High)" : (i == 7 ? "(Low)" : "")); 31 | IOPriority ioprio = IOPriority_tuple(classes[c].klass, i); 32 | Panel_add(this, (Object*) ListItem_new(name, ioprio)); 33 | if (currPrio == ioprio) Panel_setSelected(this, Panel_size(this) - 1); 34 | } 35 | } 36 | Panel_add(this, (Object*) ListItem_new("Idle", IOPriority_Idle)); 37 | if (currPrio == IOPriority_Idle) Panel_setSelected(this, Panel_size(this) - 1); 38 | return this; 39 | } 40 | 41 | IOPriority IOPriorityPanel_getIOPriority(Panel* this) { 42 | return (IOPriority) ( ((ListItem*) Panel_getSelected(this))->key ); 43 | } 44 | 45 | -------------------------------------------------------------------------------- /linux/IOPriorityPanel.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_IOPriorityPanel 4 | #define HEADER_IOPriorityPanel 5 | /* 6 | htop - IOPriorityPanel.h 7 | (C) 2004-2012 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Panel.h" 13 | #include "IOPriority.h" 14 | #include "ListItem.h" 15 | 16 | Panel* IOPriorityPanel_new(IOPriority currPrio); 17 | 18 | IOPriority IOPriorityPanel_getIOPriority(Panel* this); 19 | 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /linux/LinuxCRT.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - LinuxCRT.c 3 | (C) 2014 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "config.h" 9 | #include "CRT.h" 10 | #include 11 | #include 12 | #ifdef HAVE_EXECINFO_H 13 | #include 14 | #endif 15 | 16 | void CRT_handleSIGSEGV(int sgn) { 17 | (void) sgn; 18 | CRT_done(); 19 | #ifdef __linux 20 | fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at http://hisham.hm/htop\n"); 21 | #ifdef HAVE_EXECINFO_H 22 | size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *)); 23 | fprintf(stderr, "\n Please include in your report the following backtrace: \n"); 24 | backtrace_symbols_fd(backtraceArray, size, 2); 25 | fprintf(stderr, "\nAdditionally, in order to make the above backtrace useful,"); 26 | fprintf(stderr, "\nplease also run the following command to generate a disassembly of your binary:"); 27 | fprintf(stderr, "\n\n objdump -d `which htop` > ~/htop.objdump"); 28 | fprintf(stderr, "\n\nand then attach the file ~/htop.objdump to your bug report."); 29 | fprintf(stderr, "\n\nThank you for helping to improve htop!\n\n"); 30 | #endif 31 | #else 32 | fprintf(stderr, "\nUnfortunately, you seem to be using an unsupported platform!"); 33 | fprintf(stderr, "\nPlease contact your platform package maintainer!\n\n"); 34 | #endif 35 | abort(); 36 | } 37 | -------------------------------------------------------------------------------- /linux/LinuxCRT.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_LinuxCRT 4 | #define HEADER_LinuxCRT 5 | /* 6 | htop - LinuxCRT.h 7 | (C) 2014 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #ifdef HAVE_EXECINFO_H 13 | #endif 14 | 15 | void CRT_handleSIGSEGV(int sgn); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /linux/LinuxProcess.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_LinuxProcess 4 | #define HEADER_LinuxProcess 5 | /* 6 | htop - LinuxProcess.h 7 | (C) 2014 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | 13 | #define PROCESS_FLAG_LINUX_IOPRIO 0x0100 14 | #define PROCESS_FLAG_LINUX_OPENVZ 0x0200 15 | #define PROCESS_FLAG_LINUX_VSERVER 0x0400 16 | #define PROCESS_FLAG_LINUX_CGROUP 0x0800 17 | #define PROCESS_FLAG_LINUX_OOM 0x1000 18 | 19 | typedef enum UnsupportedProcessFields { 20 | FLAGS = 9, 21 | ITREALVALUE = 20, 22 | VSIZE = 22, 23 | RSS = 23, 24 | RLIM = 24, 25 | STARTCODE = 25, 26 | ENDCODE = 26, 27 | STARTSTACK = 27, 28 | KSTKESP = 28, 29 | KSTKEIP = 29, 30 | SIGNAL = 30, 31 | BLOCKED = 31, 32 | SSIGIGNORE = 32, 33 | SIGCATCH = 33, 34 | WCHAN = 34, 35 | NSWAP = 35, 36 | CNSWAP = 36, 37 | EXIT_SIGNAL = 37, 38 | } UnsupportedProcessField; 39 | 40 | typedef enum LinuxProcessFields { 41 | CMINFLT = 11, 42 | CMAJFLT = 13, 43 | UTIME = 14, 44 | STIME = 15, 45 | CUTIME = 16, 46 | CSTIME = 17, 47 | M_SHARE = 41, 48 | M_TRS = 42, 49 | M_DRS = 43, 50 | M_LRS = 44, 51 | M_DT = 45, 52 | #ifdef HAVE_OPENVZ 53 | CTID = 100, 54 | VPID = 101, 55 | #endif 56 | #ifdef HAVE_VSERVER 57 | VXID = 102, 58 | #endif 59 | #ifdef HAVE_TASKSTATS 60 | RCHAR = 103, 61 | WCHAR = 104, 62 | SYSCR = 105, 63 | SYSCW = 106, 64 | RBYTES = 107, 65 | WBYTES = 108, 66 | CNCLWB = 109, 67 | IO_READ_RATE = 110, 68 | IO_WRITE_RATE = 111, 69 | IO_RATE = 112, 70 | #endif 71 | #ifdef HAVE_CGROUP 72 | CGROUP = 113, 73 | #endif 74 | OOM = 114, 75 | IO_PRIORITY = 115, 76 | #ifdef HAVE_DELAYACCT 77 | PERCENT_CPU_DELAY = 116, 78 | PERCENT_IO_DELAY = 117, 79 | PERCENT_SWAP_DELAY = 118, 80 | #endif 81 | LAST_PROCESSFIELD = 119, 82 | } LinuxProcessField; 83 | 84 | #include "IOPriority.h" 85 | 86 | typedef struct LinuxProcess_ { 87 | Process super; 88 | bool isKernelThread; 89 | IOPriority ioPriority; 90 | unsigned long int cminflt; 91 | unsigned long int cmajflt; 92 | unsigned long long int utime; 93 | unsigned long long int stime; 94 | unsigned long long int cutime; 95 | unsigned long long int cstime; 96 | long m_share; 97 | long m_trs; 98 | long m_drs; 99 | long m_lrs; 100 | long m_dt; 101 | unsigned long long starttime; 102 | #ifdef HAVE_TASKSTATS 103 | unsigned long long io_rchar; 104 | unsigned long long io_wchar; 105 | unsigned long long io_syscr; 106 | unsigned long long io_syscw; 107 | unsigned long long io_read_bytes; 108 | unsigned long long io_write_bytes; 109 | unsigned long long io_cancelled_write_bytes; 110 | unsigned long long io_rate_read_time; 111 | unsigned long long io_rate_write_time; 112 | double io_rate_read_bps; 113 | double io_rate_write_bps; 114 | #endif 115 | #ifdef HAVE_OPENVZ 116 | unsigned int ctid; 117 | unsigned int vpid; 118 | #endif 119 | #ifdef HAVE_VSERVER 120 | unsigned int vxid; 121 | #endif 122 | #ifdef HAVE_CGROUP 123 | char* cgroup; 124 | #endif 125 | unsigned int oom; 126 | char* ttyDevice; 127 | #ifdef HAVE_DELAYACCT 128 | unsigned long long int delay_read_time; 129 | unsigned long long cpu_delay_total; 130 | unsigned long long blkio_delay_total; 131 | unsigned long long swapin_delay_total; 132 | float cpu_delay_percent; 133 | float blkio_delay_percent; 134 | float swapin_delay_percent; 135 | #endif 136 | } LinuxProcess; 137 | 138 | #ifndef Process_isKernelThread 139 | #define Process_isKernelThread(_process) (((LinuxProcess*)(_process))->isKernelThread) 140 | #endif 141 | 142 | #ifndef Process_isUserlandThread 143 | #define Process_isUserlandThread(_process) (_process->pid != _process->tgid) 144 | #endif 145 | 146 | 147 | long long btime; /* semi-global */ 148 | 149 | extern ProcessFieldData Process_fields[]; 150 | 151 | extern ProcessPidColumn Process_pidColumns[]; 152 | 153 | extern ProcessClass LinuxProcess_class; 154 | 155 | LinuxProcess* LinuxProcess_new(Settings* settings); 156 | 157 | void Process_delete(Object* cast); 158 | 159 | /* 160 | [1] Note that before kernel 2.6.26 a process that has not asked for 161 | an io priority formally uses "none" as scheduling class, but the 162 | io scheduler will treat such processes as if it were in the best 163 | effort class. The priority within the best effort class will be 164 | dynamically derived from the cpu nice level of the process: 165 | extern io_priority; 166 | */ 167 | #define LinuxProcess_effectiveIOPriority(p_) (IOPriority_class(p_->ioPriority) == IOPRIO_CLASS_NONE ? IOPriority_tuple(IOPRIO_CLASS_BE, (p_->super.nice + 20) / 5) : p_->ioPriority) 168 | 169 | IOPriority LinuxProcess_updateIOPriority(LinuxProcess* this); 170 | 171 | bool LinuxProcess_setIOPriority(LinuxProcess* this, IOPriority ioprio); 172 | 173 | #ifdef HAVE_DELAYACCT 174 | void LinuxProcess_printDelay(float delay_percent, char* buffer, int n); 175 | #endif 176 | 177 | void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field); 178 | 179 | long LinuxProcess_compare(const void* v1, const void* v2); 180 | 181 | bool Process_isThread(Process* this); 182 | 183 | 184 | #endif 185 | -------------------------------------------------------------------------------- /linux/LinuxProcessList.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_LinuxProcessList 4 | #define HEADER_LinuxProcessList 5 | /* 6 | htop - LinuxProcessList.h 7 | (C) 2014 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #ifdef MAJOR_IN_MKDEV 13 | #elif defined(MAJOR_IN_SYSMACROS) || \ 14 | (defined(HAVE_SYS_SYSMACROS_H) && HAVE_SYS_SYSMACROS_H) 15 | #endif 16 | 17 | #ifdef HAVE_DELAYACCT 18 | #endif 19 | 20 | 21 | #include "ProcessList.h" 22 | 23 | extern long long btime; 24 | 25 | typedef struct CPUData_ { 26 | unsigned long long int totalTime; 27 | unsigned long long int userTime; 28 | unsigned long long int systemTime; 29 | unsigned long long int systemAllTime; 30 | unsigned long long int idleAllTime; 31 | unsigned long long int idleTime; 32 | unsigned long long int niceTime; 33 | unsigned long long int ioWaitTime; 34 | unsigned long long int irqTime; 35 | unsigned long long int softIrqTime; 36 | unsigned long long int stealTime; 37 | unsigned long long int guestTime; 38 | 39 | unsigned long long int totalPeriod; 40 | unsigned long long int userPeriod; 41 | unsigned long long int systemPeriod; 42 | unsigned long long int systemAllPeriod; 43 | unsigned long long int idleAllPeriod; 44 | unsigned long long int idlePeriod; 45 | unsigned long long int nicePeriod; 46 | unsigned long long int ioWaitPeriod; 47 | unsigned long long int irqPeriod; 48 | unsigned long long int softIrqPeriod; 49 | unsigned long long int stealPeriod; 50 | unsigned long long int guestPeriod; 51 | } CPUData; 52 | 53 | typedef struct TtyDriver_ { 54 | char* path; 55 | unsigned int major; 56 | unsigned int minorFrom; 57 | unsigned int minorTo; 58 | } TtyDriver; 59 | 60 | typedef struct LinuxProcessList_ { 61 | ProcessList super; 62 | 63 | CPUData* cpus; 64 | TtyDriver* ttyDrivers; 65 | 66 | #ifdef HAVE_DELAYACCT 67 | struct nl_sock *netlink_socket; 68 | int netlink_family; 69 | #endif 70 | } LinuxProcessList; 71 | 72 | #ifndef PROCDIR 73 | #define PROCDIR "/proc" 74 | #endif 75 | 76 | #ifndef PROCSTATFILE 77 | #define PROCSTATFILE PROCDIR "/stat" 78 | #endif 79 | 80 | #ifndef PROCMEMINFOFILE 81 | #define PROCMEMINFOFILE PROCDIR "/meminfo" 82 | #endif 83 | 84 | #ifndef PROCTTYDRIVERSFILE 85 | #define PROCTTYDRIVERSFILE PROCDIR "/tty/drivers" 86 | #endif 87 | 88 | #ifndef PROC_LINE_LENGTH 89 | #define PROC_LINE_LENGTH 4096 90 | #endif 91 | 92 | 93 | #ifndef CLAMP 94 | #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) 95 | #endif 96 | 97 | #ifdef HAVE_DELAYACCT 98 | 99 | #endif 100 | 101 | ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); 102 | 103 | void ProcessList_delete(ProcessList* pl); 104 | 105 | 106 | #ifdef HAVE_TASKSTATS 107 | 108 | #endif 109 | 110 | #ifdef HAVE_OPENVZ 111 | 112 | #endif 113 | 114 | #ifdef HAVE_CGROUP 115 | 116 | #endif 117 | 118 | #ifdef HAVE_VSERVER 119 | 120 | #endif 121 | 122 | #ifdef HAVE_DELAYACCT 123 | 124 | #endif 125 | 126 | void ProcessList_goThroughEntries(ProcessList* super); 127 | 128 | #endif 129 | -------------------------------------------------------------------------------- /linux/Platform.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Platform 4 | #define HEADER_Platform 5 | /* 6 | htop - linux/Platform.h 7 | (C) 2014 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Action.h" 13 | #include "MainPanel.h" 14 | #include "BatteryMeter.h" 15 | #include "LinuxProcess.h" 16 | #include "SignalsPanel.h" 17 | 18 | #ifndef CLAMP 19 | #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) 20 | #endif 21 | 22 | extern ProcessField Platform_defaultFields[]; 23 | 24 | extern int Platform_numberOfFields; 25 | 26 | extern const SignalItem Platform_signals[]; 27 | 28 | extern const unsigned int Platform_numberOfSignals; 29 | 30 | void Platform_setBindings(Htop_Action* keys); 31 | 32 | extern MeterClass* Platform_meterTypes[]; 33 | 34 | int Platform_getUptime(); 35 | 36 | void Platform_getLoadAverage(double* one, double* five, double* fifteen); 37 | 38 | int Platform_getMaxPid(); 39 | 40 | double Platform_setCPUValues(Meter* this, int cpu); 41 | 42 | void Platform_setMemoryValues(Meter* this); 43 | 44 | void Platform_setSwapValues(Meter* this); 45 | 46 | char* Platform_getProcessEnv(pid_t pid); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /openbsd/Battery.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - openbsd/Battery.c 3 | (C) 2015 Hisham H. Muhammad 4 | (C) 2015 Michael McConville 5 | Released under the GNU GPL, see the COPYING file 6 | in the source distribution for its full text. 7 | */ 8 | 9 | #include "BatteryMeter.h" 10 | #include 11 | #include 12 | #include 13 | 14 | static bool findDevice(const char* name, int* mib, struct sensordev* snsrdev, size_t* sdlen) { 15 | for (int devn = 0;; devn++) { 16 | mib[2] = devn; 17 | if (sysctl(mib, 3, snsrdev, sdlen, NULL, 0) == -1) { 18 | if (errno == ENXIO) 19 | continue; 20 | if (errno == ENOENT) 21 | return false; 22 | } 23 | if (strcmp(name, snsrdev->xname) == 0) { 24 | return true; 25 | } 26 | } 27 | } 28 | 29 | void Battery_getData(double* level, ACPresence* isOnAC) { 30 | static int mib[] = {CTL_HW, HW_SENSORS, 0, 0, 0}; 31 | struct sensor s; 32 | size_t slen = sizeof(struct sensor); 33 | struct sensordev snsrdev; 34 | size_t sdlen = sizeof(struct sensordev); 35 | 36 | bool found = findDevice("acpibat0", mib, &snsrdev, &sdlen); 37 | 38 | *level = -1; 39 | if (found) { 40 | /* last full capacity */ 41 | mib[3] = 7; 42 | mib[4] = 0; 43 | double last_full_capacity = 0; 44 | if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) { 45 | last_full_capacity = s.value; 46 | } 47 | if (last_full_capacity > 0) { 48 | /* remaining capacity */ 49 | mib[3] = 7; 50 | mib[4] = 3; 51 | if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) { 52 | double charge = s.value; 53 | *level = 100*(charge / last_full_capacity); 54 | if (charge >= last_full_capacity) { 55 | *level = 100; 56 | } 57 | } 58 | } 59 | } 60 | 61 | found = findDevice("acpiac0", mib, &snsrdev, &sdlen); 62 | 63 | *isOnAC = AC_ERROR; 64 | if (found) { 65 | mib[3] = 9; 66 | mib[4] = 0; 67 | if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) { 68 | *isOnAC = s.value; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /openbsd/Battery.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Battery 4 | #define HEADER_Battery 5 | /* 6 | htop - openbsd/Battery.h 7 | (C) 2015 Hisham H. Muhammad 8 | (C) 2015 Michael McConville 9 | Released under the GNU GPL, see the COPYING file 10 | in the source distribution for its full text. 11 | */ 12 | 13 | void Battery_getData(double* level, ACPresence* isOnAC); 14 | 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /openbsd/OpenBSDCRT.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - UnsupportedCRT.c 3 | (C) 2014 Hisham H. Muhammad 4 | (C) 2015 Michael McConville 5 | Released under the GNU GPL, see the COPYING file 6 | in the source distribution for its full text. 7 | */ 8 | 9 | #include "config.h" 10 | #include "CRT.h" 11 | #include 12 | #include 13 | 14 | void CRT_handleSIGSEGV(int sgn) { 15 | (void) sgn; 16 | CRT_done(); 17 | fprintf(stderr, "\n\nhtop " VERSION " aborting.\n"); 18 | fprintf(stderr, "\nUnfortunately, you seem to be using an unsupported platform!"); 19 | fprintf(stderr, "\nPlease contact your platform package maintainer!\n\n"); 20 | abort(); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /openbsd/OpenBSDCRT.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_OpenBSDCRT 4 | #define HEADER_OpenBSDCRT 5 | /* 6 | htop - UnsupportedCRT.h 7 | (C) 2014 Hisham H. Muhammad 8 | (C) 2015 Michael McConville 9 | Released under the GNU GPL, see the COPYING file 10 | in the source distribution for its full text. 11 | */ 12 | 13 | void CRT_handleSIGSEGV(int sgn); 14 | 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /openbsd/OpenBSDProcess.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_OpenBSDProcess 4 | #define HEADER_OpenBSDProcess 5 | /* 6 | htop - OpenBSDProcess.h 7 | (C) 2015 Hisham H. Muhammad 8 | (C) 2015 Michael McConville 9 | Released under the GNU GPL, see the COPYING file 10 | in the source distribution for its full text. 11 | */ 12 | 13 | 14 | typedef enum OpenBSDProcessFields { 15 | // Add platform-specific fields here, with ids >= 100 16 | LAST_PROCESSFIELD = 100, 17 | } OpenBSDProcessField; 18 | 19 | typedef struct OpenBSDProcess_ { 20 | Process super; 21 | } OpenBSDProcess; 22 | 23 | #ifndef Process_isKernelThread 24 | #define Process_isKernelThread(_process) (_process->pgrp == 0) 25 | #endif 26 | 27 | #ifndef Process_isUserlandThread 28 | #define Process_isUserlandThread(_process) (_process->pid != _process->tgid) 29 | #endif 30 | 31 | 32 | extern ProcessClass OpenBSDProcess_class; 33 | 34 | extern ProcessFieldData Process_fields[]; 35 | 36 | extern ProcessPidColumn Process_pidColumns[]; 37 | 38 | OpenBSDProcess* OpenBSDProcess_new(Settings* settings); 39 | 40 | void Process_delete(Object* cast); 41 | 42 | void OpenBSDProcess_writeField(Process* this, RichString* str, ProcessField field); 43 | 44 | long OpenBSDProcess_compare(const void* v1, const void* v2); 45 | 46 | bool Process_isThread(Process* this); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /openbsd/OpenBSDProcessList.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_OpenBSDProcessList 4 | #define HEADER_OpenBSDProcessList 5 | /* 6 | htop - OpenBSDProcessList.h 7 | (C) 2014 Hisham H. Muhammad 8 | (C) 2015 Michael McConville 9 | Released under the GNU GPL, see the COPYING file 10 | in the source distribution for its full text. 11 | */ 12 | 13 | 14 | #include 15 | 16 | typedef struct CPUData_ { 17 | unsigned long long int totalTime; 18 | unsigned long long int totalPeriod; 19 | } CPUData; 20 | 21 | typedef struct OpenBSDProcessList_ { 22 | ProcessList super; 23 | kvm_t* kd; 24 | 25 | CPUData* cpus; 26 | 27 | } OpenBSDProcessList; 28 | 29 | 30 | /* 31 | * avoid relying on or conflicting with MIN() and MAX() in sys/param.h 32 | */ 33 | #ifndef MINIMUM 34 | #define MINIMUM(x, y) ((x) > (y) ? (y) : (x)) 35 | #endif 36 | 37 | #ifndef MAXIMUM 38 | #define MAXIMUM(x, y) ((x) > (y) ? (x) : (y)) 39 | #endif 40 | 41 | #ifndef CLAMP 42 | #define CLAMP(x, low, high) (((x) > (high)) ? (high) : MAXIMUM(x, low)) 43 | #endif 44 | 45 | ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); 46 | 47 | void ProcessList_delete(ProcessList* this); 48 | 49 | char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd); 50 | 51 | /* 52 | * Taken from OpenBSD's ps(1). 53 | */ 54 | double getpcpu(const struct kinfo_proc *kp); 55 | 56 | void ProcessList_goThroughEntries(ProcessList* this); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /openbsd/Platform.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Platform 4 | #define HEADER_Platform 5 | /* 6 | htop - openbsd/Platform.h 7 | (C) 2014 Hisham H. Muhammad 8 | (C) 2015 Michael McConville 9 | Released under the GNU GPL, see the COPYING file 10 | in the source distribution for its full text. 11 | */ 12 | 13 | #include "Action.h" 14 | #include "BatteryMeter.h" 15 | #include "SignalsPanel.h" 16 | 17 | extern ProcessFieldData Process_fields[]; 18 | 19 | 20 | #define MAXCPU 256 21 | // XXX: probably should be a struct member 22 | /* 23 | * Copyright (c) 1984, 1989, William LeFebvre, Rice University 24 | * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University 25 | * 26 | * Taken directly from OpenBSD's top(1). 27 | * 28 | * percentages(cnt, out, new, old, diffs) - calculate percentage change 29 | * between array "old" and "new", putting the percentages in "out". 30 | * "cnt" is size of each array and "diffs" is used for scratch space. 31 | * The array "old" is updated on each call. 32 | * The routine assumes modulo arithmetic. This function is especially 33 | * useful on BSD machines for calculating cpu state percentages. 34 | */ 35 | extern ProcessField Platform_defaultFields[]; 36 | 37 | extern int Platform_numberOfFields; 38 | 39 | /* 40 | * See /usr/include/sys/signal.h 41 | */ 42 | extern const SignalItem Platform_signals[]; 43 | 44 | extern const unsigned int Platform_numberOfSignals; 45 | 46 | void Platform_setBindings(Htop_Action* keys); 47 | 48 | extern MeterClass* Platform_meterTypes[]; 49 | 50 | // preserved from FreeBSD port 51 | int Platform_getUptime(); 52 | 53 | void Platform_getLoadAverage(double* one, double* five, double* fifteen); 54 | 55 | int Platform_getMaxPid(); 56 | 57 | double Platform_setCPUValues(Meter* this, int cpu); 58 | 59 | void Platform_setMemoryValues(Meter* this); 60 | 61 | /* 62 | * Copyright (c) 1994 Thorsten Lockert 63 | * All rights reserved. 64 | * 65 | * Taken almost directly from OpenBSD's top(1) 66 | */ 67 | void Platform_setSwapValues(Meter* this); 68 | 69 | void Platform_setTasksValues(Meter* this); 70 | 71 | char* Platform_getProcessEnv(pid_t pid); 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /scripts/MakeHeader.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os, sys, string, io 3 | try: 4 | from StringIO import StringIO 5 | except ImportError: 6 | StringIO = io.StringIO 7 | 8 | ANY=1 9 | COPY=2 10 | SKIP=3 11 | SKIPONE=4 12 | 13 | state = ANY 14 | static = 0 15 | 16 | file = io.open(sys.argv[1], "r", encoding="utf-8") 17 | name = sys.argv[1][:-2] 18 | 19 | out = StringIO() 20 | 21 | selfheader = '#include "' + name + '.h"' 22 | 23 | out.write( "/* Do not edit this file. It was automatically generated. */\n" ) 24 | out.write( "\n" ) 25 | 26 | out.write( "#ifndef HEADER_" + os.path.basename(name) + "\n") 27 | out.write( "#define HEADER_" + os.path.basename(name) + "\n") 28 | is_blank = False 29 | for line in file.readlines(): 30 | line = line[:-1] 31 | if state == ANY: 32 | if line == '/*{': 33 | state = COPY 34 | elif line == selfheader: 35 | pass 36 | elif line.find("#include") == 0: 37 | pass 38 | elif line.find("htop - ") == 0 and line[-2:] == ".c": 39 | out.write(line[:-2] + ".h\n") 40 | elif line.find("static ") != -1: 41 | if line[-1] == "{": 42 | state = SKIP 43 | static = 1 44 | else: 45 | state = SKIPONE 46 | elif len(line) > 1: 47 | static = 0 48 | equals = line.find(" = ") 49 | if line[-3:] == "= {": 50 | out.write( "extern " + line[:-4] + ";\n" ) 51 | state = SKIP 52 | elif equals != -1: 53 | out.write("extern " + line[:equals] + ";\n" ) 54 | elif line.startswith("typedef struct"): 55 | state = SKIP 56 | elif line[-1] == "{": 57 | out.write( line[:-2].replace("inline", "extern") + ";\n" ) 58 | state = SKIP 59 | else: 60 | out.write( line + "\n") 61 | is_blank = False 62 | elif line == "": 63 | if not is_blank: 64 | out.write( line + "\n") 65 | is_blank = True 66 | else: 67 | out.write( line + "\n") 68 | is_blank = False 69 | elif state == COPY: 70 | is_blank = False 71 | if line == "}*/": 72 | state = ANY 73 | else: 74 | out.write( line + "\n") 75 | elif state == SKIP: 76 | is_blank = False 77 | if len(line) >= 1 and line[0] == "}": 78 | if static == 1: 79 | state = SKIPONE 80 | else: 81 | state = ANY 82 | static = 0 83 | elif state == SKIPONE: 84 | is_blank = False 85 | state = ANY 86 | 87 | out.write( "\n" ) 88 | out.write( "#endif\n" ) 89 | 90 | # only write a new .h file if something changed. 91 | # This prevents a lot of recompilation during development 92 | out.seek(0) 93 | try: 94 | with io.open(name + ".h", "r", encoding="utf-8") as orig: 95 | origcontents = orig.readlines() 96 | except: 97 | origcontents = "" 98 | if origcontents != out.readlines(): 99 | with io.open(name + ".h", "w", encoding="utf-8") as new: 100 | print("Writing "+name+".h") 101 | new.write(out.getvalue()) 102 | out.close() 103 | -------------------------------------------------------------------------------- /solaris/Battery.c: -------------------------------------------------------------------------------- 1 | 2 | #include "BatteryMeter.h" 3 | 4 | void Battery_getData(double* level, ACPresence* isOnAC) { 5 | *level = -1; 6 | *isOnAC = AC_ERROR; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /solaris/Battery.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Battery 4 | #define HEADER_Battery 5 | 6 | void Battery_getData(double* level, ACPresence* isOnAC); 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /solaris/Platform.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Platform 4 | #define HEADER_Platform 5 | /* 6 | htop - solaris/Platform.h 7 | (C) 2014 Hisham H. Muhammad 8 | (C) 2015 David C. Hunt 9 | (C) 2017,2018 Guy M. Broome 10 | Released under the GNU GPL, see the COPYING file 11 | in the source distribution for its full text. 12 | */ 13 | 14 | #include "Action.h" 15 | #include "BatteryMeter.h" 16 | #include "SignalsPanel.h" 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #define kill(pid, signal) kill(pid / 1024, signal) 23 | 24 | extern ProcessFieldData Process_fields[]; 25 | typedef struct var kvar_t; 26 | 27 | typedef struct envAccum_ { 28 | size_t capacity; 29 | size_t size; 30 | size_t bytes; 31 | char *env; 32 | } envAccum; 33 | 34 | 35 | extern double plat_loadavg[3]; 36 | 37 | extern const SignalItem Platform_signals[]; 38 | 39 | extern const unsigned int Platform_numberOfSignals; 40 | 41 | extern ProcessField Platform_defaultFields[]; 42 | 43 | extern MeterClass* Platform_meterTypes[]; 44 | 45 | void Platform_setBindings(Htop_Action* keys); 46 | 47 | extern int Platform_numberOfFields; 48 | 49 | extern char Process_pidFormat[20]; 50 | 51 | int Platform_getUptime(); 52 | 53 | void Platform_getLoadAverage(double* one, double* five, double* fifteen); 54 | 55 | int Platform_getMaxPid(); 56 | 57 | double Platform_setCPUValues(Meter* this, int cpu); 58 | 59 | void Platform_setMemoryValues(Meter* this); 60 | 61 | void Platform_setSwapValues(Meter* this); 62 | 63 | char* Platform_getProcessEnv(pid_t pid); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /solaris/SolarisCRT.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - SolarisCRT.c 3 | (C) 2014 Hisham H. Muhammad 4 | (C) 2018 Guy M. Broome 5 | Released under the GNU GPL, see the COPYING file 6 | in the source distribution for its full text. 7 | */ 8 | 9 | #include "config.h" 10 | #include "CRT.h" 11 | #include 12 | #include 13 | #ifdef HAVE_EXECINFO_H 14 | #include 15 | #endif 16 | 17 | void CRT_handleSIGSEGV(int sgn) { 18 | (void) sgn; 19 | CRT_done(); 20 | fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at http://hisham.hm/htop\n"); 21 | #ifdef HAVE_EXECINFO_H 22 | size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *)); 23 | fprintf(stderr, "\n Please include in your report the following backtrace: \n"); 24 | backtrace_symbols_fd(backtraceArray, size, 2); 25 | fprintf(stderr, "\nAdditionally, in order to make the above backtrace useful,"); 26 | fprintf(stderr, "\nplease also run the following command to generate a disassembly of your binary:"); 27 | fprintf(stderr, "\n\n objdump -d `which htop` > ~/htop.objdump"); 28 | fprintf(stderr, "\n\nand then attach the file ~/htop.objdump to your bug report."); 29 | fprintf(stderr, "\n\nThank you for helping to improve htop!\n\n"); 30 | #endif 31 | abort(); 32 | } 33 | -------------------------------------------------------------------------------- /solaris/SolarisCRT.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_SolarisCRT 4 | #define HEADER_SolarisCRT 5 | /* 6 | htop - SolarisCRT.h 7 | (C) 2014 Hisham H. Muhammad 8 | (C) 2018 Guy M. Broome 9 | Released under the GNU GPL, see the COPYING file 10 | in the source distribution for its full text. 11 | */ 12 | 13 | #ifdef HAVE_EXECINFO_H 14 | #endif 15 | 16 | void CRT_handleSIGSEGV(int sgn); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /solaris/SolarisProcess.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_SolarisProcess 4 | #define HEADER_SolarisProcess 5 | /* 6 | htop - SolarisProcess.h 7 | (C) 2015 Hisham H. Muhammad 8 | (C) 2017,2018 Guy M. Broome 9 | Released under the GNU GPL, see the COPYING file 10 | in the source distribution for its full text. 11 | */ 12 | 13 | #include "Settings.h" 14 | #include 15 | #include 16 | #include 17 | 18 | typedef enum SolarisProcessFields { 19 | // Add platform-specific fields here, with ids >= 100 20 | ZONEID = 100, 21 | ZONE = 101, 22 | PROJID = 102, 23 | TASKID = 103, 24 | POOLID = 104, 25 | CONTID = 105, 26 | LWPID = 106, 27 | LAST_PROCESSFIELD = 107, 28 | } SolarisProcessField; 29 | 30 | 31 | typedef struct SolarisProcess_ { 32 | Process super; 33 | int kernel; 34 | zoneid_t zoneid; 35 | char* zname; 36 | taskid_t taskid; 37 | projid_t projid; 38 | poolid_t poolid; 39 | ctid_t contid; 40 | bool is_lwp; 41 | pid_t realpid; 42 | pid_t realppid; 43 | pid_t lwpid; 44 | } SolarisProcess; 45 | 46 | 47 | #ifndef Process_isKernelThread 48 | #define Process_isKernelThread(_process) (_process->kernel == 1) 49 | #endif 50 | 51 | #ifndef Process_isUserlandThread 52 | #define Process_isUserlandThread(_process) (_process->pid != _process->tgid) 53 | #endif 54 | 55 | 56 | extern ProcessClass SolarisProcess_class; 57 | 58 | extern ProcessFieldData Process_fields[]; 59 | 60 | extern ProcessPidColumn Process_pidColumns[]; 61 | 62 | SolarisProcess* SolarisProcess_new(Settings* settings); 63 | 64 | void Process_delete(Object* cast); 65 | 66 | void SolarisProcess_writeField(Process* this, RichString* str, ProcessField field); 67 | 68 | long SolarisProcess_compare(const void* v1, const void* v2); 69 | 70 | bool Process_isThread(Process* this); 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /solaris/SolarisProcessList.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_SolarisProcessList 4 | #define HEADER_SolarisProcessList 5 | /* 6 | htop - SolarisProcessList.h 7 | (C) 2014 Hisham H. Muhammad 8 | (C) 2017,2018 Guy M. Broome 9 | Released under the GNU GPL, see the COPYING file 10 | in the source distribution for its full text. 11 | */ 12 | 13 | #define MAXCMDLINE 255 14 | 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #define ZONE_ERRMSGLEN 1024 25 | char zone_errmsg[ZONE_ERRMSGLEN]; 26 | 27 | typedef struct CPUData_ { 28 | double userPercent; 29 | double nicePercent; 30 | double systemPercent; 31 | double irqPercent; 32 | double idlePercent; 33 | double systemAllPercent; 34 | uint64_t luser; 35 | uint64_t lkrnl; 36 | uint64_t lintr; 37 | uint64_t lidle; 38 | } CPUData; 39 | 40 | typedef struct SolarisProcessList_ { 41 | ProcessList super; 42 | kstat_ctl_t* kd; 43 | CPUData* cpus; 44 | } SolarisProcessList; 45 | 46 | 47 | char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc); 48 | 49 | ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); 50 | 51 | void ProcessList_delete(ProcessList* pl); 52 | 53 | /* NOTE: the following is a callback function of type proc_walk_f 54 | * and MUST conform to the appropriate definition in order 55 | * to work. See libproc(3LIB) on a Solaris or Illumos 56 | * system for more info. 57 | */ 58 | 59 | int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void *listptr); 60 | 61 | void ProcessList_goThroughEntries(ProcessList* this); 62 | 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /unsupported/Battery.c: -------------------------------------------------------------------------------- 1 | 2 | #include "BatteryMeter.h" 3 | 4 | void Battery_getData(double* level, ACPresence* isOnAC) { 5 | *level = -1; 6 | *isOnAC = AC_ERROR; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /unsupported/Battery.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Battery 4 | #define HEADER_Battery 5 | 6 | void Battery_getData(double* level, ACPresence* isOnAC); 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /unsupported/Platform.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_Platform 4 | #define HEADER_Platform 5 | /* 6 | htop - unsupported/Platform.h 7 | (C) 2014 Hisham H. Muhammad 8 | (C) 2015 David C. Hunt 9 | Released under the GNU GPL, see the COPYING file 10 | in the source distribution for its full text. 11 | */ 12 | 13 | #include "Action.h" 14 | #include "BatteryMeter.h" 15 | #include "SignalsPanel.h" 16 | #include "UnsupportedProcess.h" 17 | 18 | extern const SignalItem Platform_signals[]; 19 | 20 | extern const unsigned int Platform_numberOfSignals; 21 | 22 | extern ProcessField Platform_defaultFields[]; 23 | 24 | extern ProcessFieldData Process_fields[]; 25 | 26 | extern MeterClass* Platform_meterTypes[]; 27 | 28 | void Platform_setBindings(Htop_Action* keys); 29 | 30 | extern int Platform_numberOfFields; 31 | 32 | extern char Process_pidFormat[20]; 33 | 34 | extern ProcessPidColumn Process_pidColumns[]; 35 | 36 | int Platform_getUptime(); 37 | 38 | void Platform_getLoadAverage(double* one, double* five, double* fifteen); 39 | 40 | int Platform_getMaxPid(); 41 | 42 | double Platform_setCPUValues(Meter* this, int cpu); 43 | 44 | void Platform_setMemoryValues(Meter* this); 45 | 46 | void Platform_setSwapValues(Meter* this); 47 | 48 | bool Process_isThread(Process* this); 49 | 50 | char* Platform_getProcessEnv(pid_t pid); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /unsupported/UnsupportedCRT.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - UnsupportedCRT.c 3 | (C) 2014 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "config.h" 9 | #include "CRT.h" 10 | #include 11 | #include 12 | 13 | void CRT_handleSIGSEGV(int sgn) { 14 | (void) sgn; 15 | CRT_done(); 16 | fprintf(stderr, "\n\nhtop " VERSION " aborting.\n"); 17 | fprintf(stderr, "\nUnfortunately, you seem to be using an unsupported platform!"); 18 | fprintf(stderr, "\nPlease contact your platform package maintainer!\n\n"); 19 | abort(); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /unsupported/UnsupportedCRT.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_UnsupportedCRT 4 | #define HEADER_UnsupportedCRT 5 | /* 6 | htop - UnsupportedCRT.h 7 | (C) 2014 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | void CRT_handleSIGSEGV(int sgn); 13 | 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /unsupported/UnsupportedProcess.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - UnsupportedProcess.c 3 | (C) 2015 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "Process.h" 9 | #include "UnsupportedProcess.h" 10 | #include 11 | 12 | /*{ 13 | #include "Settings.h" 14 | 15 | #define Process_delete UnsupportedProcess_delete 16 | 17 | }*/ 18 | 19 | Process* UnsupportedProcess_new(Settings* settings) { 20 | Process* this = xCalloc(1, sizeof(Process)); 21 | Object_setClass(this, Class(Process)); 22 | Process_init(this, settings); 23 | return this; 24 | } 25 | 26 | void UnsupportedProcess_delete(Object* cast) { 27 | Process* this = (Process*) cast; 28 | Object_setClass(this, Class(Process)); 29 | Process_done((Process*)cast); 30 | // free platform-specific fields here 31 | free(this); 32 | } 33 | 34 | -------------------------------------------------------------------------------- /unsupported/UnsupportedProcess.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_UnsupportedProcess 4 | #define HEADER_UnsupportedProcess 5 | /* 6 | htop - UnsupportedProcess.h 7 | (C) 2015 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | #include "Settings.h" 13 | 14 | #define Process_delete UnsupportedProcess_delete 15 | 16 | 17 | Process* UnsupportedProcess_new(Settings* settings); 18 | 19 | void UnsupportedProcess_delete(Object* cast); 20 | 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /unsupported/UnsupportedProcessList.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - UnsupportedProcessList.c 3 | (C) 2014 Hisham H. Muhammad 4 | Released under the GNU GPL, see the COPYING file 5 | in the source distribution for its full text. 6 | */ 7 | 8 | #include "ProcessList.h" 9 | #include "UnsupportedProcess.h" 10 | 11 | #include 12 | #include 13 | 14 | /*{ 15 | 16 | }*/ 17 | 18 | ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { 19 | ProcessList* this = xCalloc(1, sizeof(ProcessList)); 20 | ProcessList_init(this, Class(Process), usersTable, pidWhiteList, userId); 21 | 22 | return this; 23 | } 24 | 25 | void ProcessList_delete(ProcessList* this) { 26 | ProcessList_done(this); 27 | free(this); 28 | } 29 | 30 | void ProcessList_goThroughEntries(ProcessList* super) { 31 | bool preExisting = true; 32 | Process *proc; 33 | 34 | proc = ProcessList_getProcess(super, 1, &preExisting, UnsupportedProcess_new); 35 | 36 | /* Empty values */ 37 | proc->time = proc->time + 10; 38 | proc->pid = 1; 39 | proc->ppid = 1; 40 | proc->tgid = 0; 41 | proc->comm = ""; 42 | proc->basenameOffset = 0; 43 | proc->updated = true; 44 | 45 | proc->state = 'R'; 46 | proc->show = true; /* Reflected in proc->settings-> "hideXXX" really */ 47 | proc->pgrp = 0; 48 | proc->session = 0; 49 | proc->tty_nr = 0; 50 | proc->tpgid = 0; 51 | proc->st_uid = 0; 52 | proc->flags = 0; 53 | proc->processor = 0; 54 | 55 | proc->percent_cpu = 2.5; 56 | proc->percent_mem = 2.5; 57 | proc->user = "nobody"; 58 | 59 | proc->priority = 0; 60 | proc->nice = 0; 61 | proc->nlwp = 1; 62 | strncpy(proc->starttime_show, "Jun 01 ", sizeof(proc->starttime_show)); 63 | proc->starttime_ctime = 1433116800; // Jun 01, 2015 64 | 65 | proc->m_size = 100; 66 | proc->m_resident = 100; 67 | 68 | proc->minflt = 20; 69 | proc->majflt = 20; 70 | } 71 | -------------------------------------------------------------------------------- /unsupported/UnsupportedProcessList.h: -------------------------------------------------------------------------------- 1 | /* Do not edit this file. It was automatically generated. */ 2 | 3 | #ifndef HEADER_UnsupportedProcessList 4 | #define HEADER_UnsupportedProcessList 5 | /* 6 | htop - UnsupportedProcessList.h 7 | (C) 2014 Hisham H. Muhammad 8 | Released under the GNU GPL, see the COPYING file 9 | in the source distribution for its full text. 10 | */ 11 | 12 | 13 | 14 | ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); 15 | 16 | void ProcessList_delete(ProcessList* this); 17 | 18 | void ProcessList_goThroughEntries(ProcessList* super); 19 | 20 | #endif 21 | --------------------------------------------------------------------------------

- do nothing. 59 | 60 | , - quit program. 61 | 62 | - do nothing. 63 | 64 | - enter STrace screen. 65 | 66 | , - toggle between Tree and Sorted view, update F5 in FunctionBar, follow process 67 | 68 | - enter User screen. 69 | 70 | , , , , - do nothing. 71 | 72 | , - do nothing. 73 | 74 | , , - enter Setup screen. 75 | 76 | , - do nothing. 77 | 78 | - follow process. 79 | 80 | - do nothing. 81 | 82 | - toggle show/hide userland threads. 83 | 84 | - invert sort order. 85 | 86 | - do nothing. 87 | 88 | - toggle show/hide kernel threads. 89 | 90 | - do nothing. 91 | 92 | - enter Sorted view, update function bar, sort by MEM%. 93 | 94 | , - do nothing. 95 | 96 |