├── htop ├── htop-2.1.1 │ ├── .pc │ │ ├── .version │ │ ├── .quilt_series │ │ ├── .quilt_patches │ │ └── applied-patches │ ├── debian │ │ ├── compat │ │ ├── clean │ │ ├── install │ │ ├── docs │ │ ├── source │ │ │ └── format │ │ ├── patches │ │ │ ├── series │ │ │ ├── fix-small-terminals.patch │ │ │ ├── fix-ldflags.patch │ │ │ ├── fix-isalnum-crash.patch │ │ │ └── 601-openvz-new-ctid-vpid.patch │ │ ├── watch │ │ ├── rules │ │ ├── control │ │ └── copyright │ ├── AUTHORS │ ├── autogen.sh │ ├── htop.png │ ├── NEWS │ ├── unsupported │ │ ├── Battery.c │ │ ├── UnsupportedCRT.c │ │ ├── UnsupportedProcess.c │ │ ├── UnsupportedProcessList.c │ │ └── Platform.c │ ├── openbsd │ │ ├── Battery.c │ │ └── OpenBSDCRT.c │ ├── freebsd │ │ ├── FreeBSDCRT.c │ │ ├── Battery.c │ │ ├── Platform.c │ │ └── FreeBSDProcess.c │ ├── dragonflybsd │ │ ├── Battery.c │ │ ├── DragonFlyBSDCRT.c │ │ └── Platform.c │ ├── CpuTempMeter.c │ ├── HostnameMeter.c │ ├── ClockMeter.c │ ├── linux │ │ ├── IOPriority.c │ │ ├── LinuxCRT.c │ │ └── IOPriorityPanel.c │ ├── UsersTable.c │ ├── darwin │ │ ├── DarwinCRT.c │ │ ├── Battery.c │ │ └── DarwinProcessList.c │ ├── XAlloc.c │ ├── UptimeMeter.c │ ├── SignalsPanel.c │ ├── SwapMeter.c │ ├── EnvScreen.c │ ├── Object.c │ ├── CheckItem.c │ ├── BatteryMeter.c │ ├── AffinityPanel.c │ ├── MemoryMeter.c │ ├── CpuVcoreMeter.c │ ├── ListItem.c │ ├── README │ ├── htop.desktop │ ├── AvailableColumnsPanel.c │ ├── LoadAverageMeter.c │ ├── TasksMeter.c │ ├── scripts │ │ └── MakeHeader.py │ ├── Affinity.c │ ├── CpuFreqMeter.c │ ├── ColorsPanel.c │ ├── StringUtils.c │ ├── FunctionBar.c │ ├── DisplayOptionsPanel.c │ ├── ColumnsPanel.c │ ├── AvailableMetersPanel.c │ ├── Hashtable.c │ ├── OpenFilesScreen.c │ ├── Makefile.am │ ├── CategoriesPanel.c │ ├── TraceScreen.c │ ├── RichString.c │ ├── InfoScreen.c │ ├── MainPanel.c │ ├── config.h.in │ ├── Header.c │ └── IncSet.c ├── htop_2.1.1-3_arm64.deb ├── htop-dbgsym_2.1.1-3_arm64.ddeb ├── htop_2.1.1-3_arm64.changes └── htop_2.1.1-3_arm64.buildinfo ├── img ├── vcore.gif ├── nanopi-m4.gif └── htop_setup.gif └── README.md /htop/htop-2.1.1/.pc/.version: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/debian/compat: -------------------------------------------------------------------------------- 1 | 11 2 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/.pc/.quilt_series: -------------------------------------------------------------------------------- 1 | series 2 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/AUTHORS: -------------------------------------------------------------------------------- 1 | Hisham H. Muhammad 2 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/debian/clean: -------------------------------------------------------------------------------- 1 | *.h 2 | */*.h 3 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/debian/install: -------------------------------------------------------------------------------- 1 | htop usr/bin 2 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/.pc/.quilt_patches: -------------------------------------------------------------------------------- 1 | debian/patches 2 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/debian/docs: -------------------------------------------------------------------------------- 1 | AUTHORS 2 | README 3 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (quilt) 2 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | mkdir -p m4 3 | autoreconf --install --force 4 | -------------------------------------------------------------------------------- /img/vcore.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avafinger/htop-2.1.1_enhanced-version/HEAD/img/vcore.gif -------------------------------------------------------------------------------- /img/nanopi-m4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avafinger/htop-2.1.1_enhanced-version/HEAD/img/nanopi-m4.gif -------------------------------------------------------------------------------- /img/htop_setup.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avafinger/htop-2.1.1_enhanced-version/HEAD/img/htop_setup.gif -------------------------------------------------------------------------------- /htop/htop-2.1.1/htop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avafinger/htop-2.1.1_enhanced-version/HEAD/htop/htop-2.1.1/htop.png -------------------------------------------------------------------------------- /htop/htop_2.1.1-3_arm64.deb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avafinger/htop-2.1.1_enhanced-version/HEAD/htop/htop_2.1.1-3_arm64.deb -------------------------------------------------------------------------------- /htop/htop-dbgsym_2.1.1-3_arm64.ddeb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avafinger/htop-2.1.1_enhanced-version/HEAD/htop/htop-dbgsym_2.1.1-3_arm64.ddeb -------------------------------------------------------------------------------- /htop/htop-2.1.1/.pc/applied-patches: -------------------------------------------------------------------------------- 1 | 601-openvz-new-ctid-vpid.patch 2 | fix-small-terminals.patch 3 | fix-ldflags.patch 4 | fix-isalnum-crash.patch 5 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/debian/patches/series: -------------------------------------------------------------------------------- 1 | 601-openvz-new-ctid-vpid.patch 2 | fix-small-terminals.patch 3 | fix-ldflags.patch 4 | fix-isalnum-crash.patch 5 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/debian/watch: -------------------------------------------------------------------------------- 1 | version=3 2 | opts=dversionmangle=s/\+svn(.*)// \ 3 | https://hisham.hm/htop/releases/([\d\.]+)/htop-([\d\.]+)\.tar\.gz 4 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | 11 | void Battery_getData(double* level, ACPresence* isOnAC) { 12 | // TODO 13 | *level = -1; 14 | *isOnAC = AC_ERROR; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | export DEB_BUILD_MAINT_OPTIONS = hardening=+all 4 | DPKG_EXPORT_BUILDFLAGS = 1 5 | include /usr/share/dpkg/buildflags.mk 6 | 7 | ifeq (linux,$(DEB_HOST_ARCH_OS)) 8 | ARCH_DEPENDENT_CONFIGURE_PARAMS = --enable-linux-affinity 9 | else 10 | ARCH_DEPENDENT_CONFIGURE_PARAMS = --enable-hwloc 11 | endif 12 | 13 | %: 14 | dh $@ 15 | 16 | override_dh_auto_configure: 17 | dh_auto_configure -- \ 18 | --enable-taskstats \ 19 | --enable-openvz \ 20 | --enable-vserver \ 21 | --enable-cgroup \ 22 | --enable-unicode \ 23 | $(ARCH_DEPENDENT_CONFIGURE_PARAMS) 24 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/debian/patches/fix-small-terminals.patch: -------------------------------------------------------------------------------- 1 | Description: Fix issue with small terminals 2 | Bug: https://github.com/hishamhm/htop/issues/733 3 | Bug-Debian: https://bugs.debian.org/889693 4 | Origin: upstream,https://github.com/hishamhm/htop/commit/b544c22c72613d561180738d8c31c97712b3c0ef 5 | Author: Hisham Muhammad 6 | Last-Update: 2018-02-13 7 | 8 | --- a/Meter.c 9 | +++ b/Meter.c 10 | @@ -287,7 +287,7 @@ 11 | 12 | int blockSizes[10]; 13 | 14 | - xSnprintf(bar, w + 1, "%*s", w, buffer); 15 | + xSnprintf(bar, w + 1, "%*.*s", w, w, buffer); 16 | 17 | // First draw in the bar[] buffer... 18 | int offset = 0; 19 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/debian/patches/fix-ldflags.patch: -------------------------------------------------------------------------------- 1 | Description: Fix preservation of LDFLAGS value during configure script 2 | Bug: https://github.com/hishamhm/htop/issues/738 3 | Origin: upstream,https://github.com/hishamhm/htop/commit/df9922a67eb8e02ab4cf1ff8f24b40f14094e699 4 | Author: Hisham Muhammad 5 | Last-Update: 2018-02-17 6 | 7 | --- a/configure.ac 8 | +++ b/configure.ac 9 | @@ -167,7 +167,7 @@ 10 | LIBS="$htop_config_script $LIBS " 11 | htop_script_success=yes 12 | ], []) 13 | - LDFLAGS="$save_LDFLAGS" 14 | + LDFLAGS="$htop_save_LDFLAGS" 15 | fi 16 | if test "x$htop_script_success" = xno; then 17 | [$5] 18 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/debian/patches/fix-isalnum-crash.patch: -------------------------------------------------------------------------------- 1 | Description: Handle unexpected values for character passed to isalnum 2 | Bug: https://github.com/hishamhm/htop/issues/711 3 | Origin: upstream,https://github.com/hishamhm/htop/commit/03f17688ada3800bdd344ec4397f81289977b153 4 | Author: Hisham Muhammad 5 | Last-Update: 2018-02-05 6 | 7 | --- a/Panel.c 8 | +++ b/Panel.c 9 | @@ -469,7 +469,7 @@ HandlerResult Panel_selectByTyping(Panel* this, int ch) { 10 | this->eventHandlerState = xCalloc(100, sizeof(char)); 11 | char* buffer = this->eventHandlerState; 12 | 13 | - if (ch < 255 && isalnum(ch)) { 14 | + if (ch > 0 && ch < 255 && isalnum(ch)) { 15 | int len = strlen(buffer); 16 | if (len < 99) { 17 | buffer[len] = ch; 18 | 19 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/CpuTempMeter.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - CpuTempMeter.c 3 | (C) 2018 @lex 4 | */ 5 | 6 | #include "CpuTempMeter.h" 7 | #include "Platform.h" 8 | #include "CRT.h" 9 | 10 | /*{ 11 | #include "Meter.h" 12 | }*/ 13 | 14 | int CpuTempMeter_attributes[] = { 15 | CPU_TEMP 16 | }; 17 | 18 | static void CpuTempMeter_setValues(Meter* this, char* buffer, int len) { 19 | int Temp = Platform_getCpuTemp(); 20 | if (Temp > 1000) { 21 | Temp /= 1000; 22 | } 23 | xSnprintf(buffer, len, "%4d C", Temp); 24 | } 25 | 26 | MeterClass CpuTempMeter_class = { 27 | .super = { 28 | .extends = Class(Meter), 29 | .delete = Meter_delete 30 | }, 31 | .updateValues = CpuTempMeter_setValues, 32 | .defaultMode = TEXT_METERMODE, 33 | .maxItems = 1, 34 | .total = 100.0, 35 | .attributes = CpuTempMeter_attributes, 36 | .name = "CpuTemp", 37 | .uiName = "CpuTemp", 38 | .caption = "Cpu Temp: " 39 | }; 40 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/debian/control: -------------------------------------------------------------------------------- 1 | Source: htop 2 | Section: utils 3 | Priority: optional 4 | Maintainer: Daniel Lange 5 | Uploaders: Eugene V. Lyubimkin , 6 | Graham Inggs 7 | Build-Depends: debhelper (>= 11), 8 | dpkg-dev (>= 1.16.1.1), 9 | libhwloc-dev [!linux-any], 10 | libkvm-dev [kfreebsd-any], 11 | libncurses5-dev, 12 | libncursesw5-dev, 13 | pkg-config, 14 | python-minimal:native 15 | Standards-Version: 4.1.3 16 | Homepage: https://hisham.hm/htop/ 17 | Vcs-Browser: https://salsa.debian.org/debian/htop 18 | Vcs-Git: https://salsa.debian.org/debian/htop.git 19 | 20 | Package: htop 21 | Architecture: any 22 | Depends: ${misc:Depends}, ${shlibs:Depends} 23 | Suggests: lsof, strace 24 | Description: interactive processes viewer 25 | Htop is an ncursed-based process viewer similar to top, but it 26 | allows one to scroll the list vertically and horizontally to see 27 | all processes and their full command lines. 28 | . 29 | Tasks related to processes (killing, renicing) can be done without 30 | entering their PIDs. 31 | -------------------------------------------------------------------------------- /htop/htop_2.1.1-3_arm64.changes: -------------------------------------------------------------------------------- 1 | Format: 1.8 2 | Date: Sun, 23 Aug 2018 12:38:25 -0300 3 | Source: htop 4 | Binary: htop 5 | Architecture: arm64 6 | Version: 2.1.1-3 7 | Distribution: unstable 8 | Urgency: medium 9 | Maintainer: Daniel Lange 10 | Changed-By: Alexander Finger 11 | Description: 12 | htop - interactive processes viewer 13 | Changes: 14 | htop (2.1.1-3) unstable; urgency=medium 15 | . 16 | * Add cpufreq cpucore and thermal monitoring for H6 mainline kernel 17 | (experimental only) 18 | Checksums-Sha1: 19 | ef0615d1fc48deedda5719e3911272bcec5d2586 274484 htop-dbgsym_2.1.1-3_arm64.ddeb 20 | ce8d60419ba8ff44a71f4479ecccaa869e5544bd 5378 htop_2.1.1-3_arm64.buildinfo 21 | dba6884aaca2c365cf6cb47235cae6315838cd70 75716 htop_2.1.1-3_arm64.deb 22 | Checksums-Sha256: 23 | 96d6e0393616c3b8cd932ea8940a23831328b14211311885bb68dd8e916732fd 274484 htop-dbgsym_2.1.1-3_arm64.ddeb 24 | ae244b955d91a82d2e8d0a5fcf0ba8009bd95060a8485c0254d3e121f2e69051 5378 htop_2.1.1-3_arm64.buildinfo 25 | e6798046760eed9b30b6444649d09c6d73dc38749e349270d70143d645ac6552 75716 htop_2.1.1-3_arm64.deb 26 | Files: 27 | 1dd8f479f7ae6dbeae0a40143453c4d0 274484 debug optional htop-dbgsym_2.1.1-3_arm64.ddeb 28 | 1159a416a38b99d8d88b6b51e052940a 5378 utils optional htop_2.1.1-3_arm64.buildinfo 29 | 035d6a67a27b0c74cacb2f57900d8ff1 75716 utils optional htop_2.1.1-3_arm64.deb 30 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/debian/copyright: -------------------------------------------------------------------------------- 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: htop 3 | Upstream-Contact: Hisham Muhammad 4 | Source: http://hisham.hm/htop/releases/ 5 | 6 | Files: * 7 | License: GPL-2+ 8 | Copyright: 2004-2018 Hisham Muhammad 9 | 10 | Files: debian/* 11 | License: GPL-2+ 12 | Copyright: 2016 Daniel Lange 13 | 2018 Graham Inggs 14 | 2008-2016 Eugene V. Lyubimkin 15 | 2004-2008 Bartosz Fenski 16 | 17 | License: GPL-2+ 18 | This program is free software; you can redistribute it and/or modify 19 | it under the terms of the GNU General Public License as published by 20 | the Free Software Foundation; either version 2 of the License, or 21 | (at your option) any later version. 22 | . 23 | This program is distributed in the hope that it will be useful, 24 | but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | GNU General Public License for more details. 27 | . 28 | You should have received a copy of the GNU General Public License along 29 | with this program; if not, write to the Free Software Foundation, Inc., 30 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 31 | . 32 | On Debian systems, the full text of the GNU General Public 33 | License version 2 can be found in the file 34 | `/usr/share/common-licenses/GPL-2'. 35 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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[15]; 45 | for (int sig = SIGRTMIN; sig <= SIGRTMAX; i++, sig++) { 46 | int n = sig - SIGRTMIN; 47 | xSnprintf(buf, 15, "%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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | 72 | void UnsupportedProcessList_scan(ProcessList* this) { 73 | (void) this; 74 | // stub! 75 | } 76 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/CpuVcoreMeter.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - CpuVcoreMeter.c 3 | (C) 2018 @lex 4 | */ 5 | 6 | #include "CpuVcoreMeter.h" 7 | #include "Platform.h" 8 | #include "CRT.h" 9 | 10 | /*{ 11 | #include "Meter.h" 12 | }*/ 13 | 14 | 15 | int CpuVcoreMeter_attributes[] = { 16 | CPU_VCORE 17 | }; 18 | 19 | static void CpuVcoreMeter_setValues(Meter* this, char* buffer, int len) { 20 | int v1,v2; 21 | int Vcore, Vcore_l, Vcore_b; 22 | char buf1[80], buf2[80]; 23 | int h; 24 | 25 | if (Platform_getCpuBigLITTLE()) { 26 | h = len / 2; 27 | if (h > 79) 28 | h = 79; 29 | Vcore_b = Platform_getCpuVcore_b(); 30 | if (Vcore_b > 1000) { 31 | Vcore_b /= 1000; 32 | } 33 | if (Vcore_b >= 1000) { 34 | Vcore_b /= 10; 35 | v1 = Vcore_b / 100; 36 | v2 = Vcore_b % 100; 37 | xSnprintf(buf1, h, "%d.%02d V", v1, v2); 38 | } else { 39 | xSnprintf(buf1, h, "%4d mV", Vcore_b); 40 | } 41 | Vcore_l = Platform_getCpuVcore_l(); 42 | if (Vcore_l > 1000) { 43 | Vcore_l /= 1000; 44 | } 45 | if (Vcore_l >= 1000) { 46 | Vcore_l /= 10; 47 | v1 = Vcore_l / 100; 48 | v2 = Vcore_l % 100; 49 | xSnprintf(buf2, h, "%d.%02d V ", v1, v2); 50 | } else { 51 | xSnprintf(buf2, h, "%4d mV", Vcore_l); 52 | } 53 | xSnprintf(buffer, len, "%s,%s (big.LITTLE)", buf1, buf2); 54 | return; 55 | } 56 | 57 | Vcore = Platform_getCpuVcore(); 58 | if (Vcore > 1000) { 59 | Vcore /= 1000; 60 | } 61 | if (Vcore >= 1000) { 62 | Vcore /= 10; 63 | v1 = Vcore / 100; 64 | v2 = Vcore % 100; 65 | xSnprintf(buffer, len, "%d.%02d V", v1, v2); 66 | } else { 67 | xSnprintf(buffer, len, "%4d mV", Vcore); 68 | } 69 | } 70 | 71 | MeterClass CpuVcoreMeter_class = { 72 | .super = { 73 | .extends = Class(Meter), 74 | .delete = Meter_delete 75 | }, 76 | .updateValues = CpuVcoreMeter_setValues, 77 | .defaultMode = TEXT_METERMODE, 78 | .maxItems = 1, 79 | .total = 100.0, 80 | .attributes = CpuVcoreMeter_attributes, 81 | .name = "CpuVcore", 82 | .uiName = "CpuVcore", 83 | .caption = "Cpu Vcor: " 84 | }; 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # htop-2.1.1_enhanced-version 2 | An enhanced version of htop 2.1.0 to monitor the system health of your big.LITTLE arm64 core. 3 | 4 | Monitor the health of your RK3399 board Real-Time and watch CPU Temp, CPU VCore and CPU Freq (big.LITTLE) to find out when throttling occurs and which task is time-consuming. 5 | 6 | Screenshot of NanoPi M4 (arm64) 7 | 8 | ![NanoPi M4 7z benchmark](https://github.com/avafinger/htop-2.1.1_enhanced-version/raw/master/img/nanopi-m4.gif) 9 | 10 | # Installing Deb Package 11 | Deb package for Bionic (Ubuntu 18.04) arm64. It may work on Debian, but i have not tested it 12 | 13 | * **Install htop-2.1.1 deb package** 14 | 15 | 16 | git clone https://github.com/avafinger/htop-2.1.1_enhanced-version 17 | cd htop-2.1.1_enhanced-version/htop 18 | sudo dpkg -i htop_2.1.1-3_arm64.deb 19 | 20 | 21 | 22 | # Building the package from source code 23 | 24 | You can modify, fix or enhance the source code to run on any arm/arm64 single board and distro 25 | 26 | 27 | * **Build the package** 28 | 29 | 30 | cd htop-2.1.1_enhanced-version/htop/htop-2.1.1/ 31 | sudo dpkg-buildpackage -b -uc -us 32 | 33 | 34 | * **Deb packages** 35 | 36 | 37 | ll ../ 38 | -rw-r--r-- 1 root root 267K Oct 13 20:56 htop-dbgsym_2.1.1-3_arm64.ddeb 39 | -rw-r--r-- 1 root root 5.3K Oct 13 20:56 htop_2.1.1-3_arm64.buildinfo 40 | -rw-r--r-- 1 ubuntu ubuntu 1.3K Oct 13 20:56 htop_2.1.1-3_arm64.changes 41 | -rw-r--r-- 1 ubuntu ubuntu 74K Oct 13 20:56 htop_2.1.1-3_arm64.deb 42 | 43 | 44 | * **Install** 45 | 46 | 47 | cd .. 48 | sudo dpkg -i htop_2.1.1-3_arm64.deb 49 | 50 | 51 | 52 | Before you build the package, make sure you install all depencies: 53 | 54 | 55 | sudo apt-get install dbhelper libncurses5-dev libncursesw5-dev python-minimal:native 56 | 57 | 58 | 59 | # Running htop-2.1.1 60 | 61 | You must run htop with root privileges to have access to vital information of the board 62 | 63 | * Run: **sudo htop** 64 | 65 | ![Htop setup](https://github.com/avafinger/htop-2.1.1_enhanced-version/raw/master/img/vcore.gif) 66 | 67 | 68 | * To Display CPU Freq, CPU Temp. and CPU VCore (big.LITTLE) you have to enter Configuration setup **F2** 69 | and add the desired info. 70 | 71 | ![Htop setup](https://github.com/avafinger/htop-2.1.1_enhanced-version/raw/master/img/htop_setup.gif) 72 | 73 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/README: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/hishamhm/htop.svg?branch=master)](https://travis-ci.org/hishamhm/htop) 2 | [![PayPal donate](https://img.shields.io/badge/paypal-donate-green.svg)](http://hisham.hm/htop/index.php?page=donate) 3 | 4 | [htop](http://hisham.hm/htop/) 5 | ==== 6 | 7 | by Hisham Muhammad (2004 - 2016) 8 | 9 | Introduction 10 | ------------ 11 | 12 | This is `htop`, an interactive process viewer. 13 | It requires `ncurses`. It is developed primarily on Linux, 14 | but we also have code for running under FreeBSD and Mac OS X 15 | (help and testing are wanted for these platforms!) 16 | 17 | This software has evolved considerably over the years, 18 | and is reasonably complete, but there is always room for improvement. 19 | 20 | Comparison between `htop` and classic `top` 21 | ------------------------------------------- 22 | 23 | * In `htop` you can scroll the list vertically and horizontally 24 | to see all processes and full command lines. 25 | * In `top` you are subject to a delay for each unassigned 26 | key you press (especially annoying when multi-key escape 27 | sequences are triggered by accident). 28 | * `htop` starts faster (`top` seems to collect data for a while 29 | before displaying anything). 30 | * In `htop` you don't need to type the process number to 31 | kill a process, in `top` you do. 32 | * In `htop` you don't need to type the process number or 33 | the priority value to renice a process, in `top` you do. 34 | * In `htop` you can kill multiple processes at once. 35 | * `top` is older, hence, more tested. 36 | 37 | Compilation instructions 38 | ------------------------ 39 | 40 | This program is distributed as a standard autotools-based package. 41 | See the [INSTALL](/INSTALL) file for detailed instructions. 42 | 43 | When compiling from a [release tarball](https://hisham.hm/htop/releases/), run: 44 | 45 | ./configure && make 46 | 47 | For compiling sources downloaded from the Git repository, run: 48 | 49 | ./autogen.sh && ./configure && make 50 | 51 | By default `make install` will install into `/usr/local`, for changing 52 | the path use `./configure --prefix=/some/path`. 53 | 54 | See the manual page (`man htop`) or the on-line help ('F1' or 'h' 55 | inside `htop`) for a list of supported key commands. 56 | 57 | If not all keys work check your curses configuration. 58 | 59 | ## License 60 | 61 | GNU General Public License, version 2 (GPL-2.0) 62 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/htop.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Version=1.0 3 | Name=Htop 4 | Type=Application 5 | Comment=Show System Processes 6 | Comment[ca]=Mostra els processos del sistema 7 | Comment[de]=Systemprozesse anzeigen 8 | Comment[en_GB]=Show System Processes 9 | Comment[es]=Mostrar procesos del sistema 10 | Comment[fi]=Katsele järjestelmän prosesseja 11 | Comment[fr]=Affiche les processus système 12 | Comment[gl]=Mostrar os procesos do sistema. 13 | Comment[it]=Mostra processi di sistema 14 | Comment[ko]=시스템 프로세스 보기 15 | Comment[nb]=Vis systemprosesser 16 | Comment[nl]=Systeemprocessen tonen 17 | Comment[nn]=Vis systemprosessar 18 | Comment[pl]=Pokaż procesy systemowe 19 | Comment[pt]=Mostrar os Processos do Sistema 20 | Comment[pt_BR]=Mostra os processos do sistema 21 | Comment[ru]=Просмотр списка процессов в системе 22 | Comment[sk]=Zobraziť systémové procesy 23 | Comment[sl]=Prikaz sistemskih opravil 24 | Comment[sr]=Приказ системских процеса 25 | Comment[sr@ijekavian]=Приказ системских процеса 26 | Comment[sr@ijekavianlatin]=Prikaz sistemskih procesa 27 | Comment[sr@latin]=Prikaz sistemskih procesa 28 | Comment[sv]=Visa systemprocesser 29 | Comment[tr]=Sistem Süreçlerini Göster 30 | Comment[uk]=Перегляд системних процесів 31 | Comment[zh_CN]=显示系统进程 32 | Comment[zh_TW]=顯示系統行程 33 | Terminal=true 34 | Exec=htop 35 | Icon=htop 36 | Categories=ConsoleOnly;System; 37 | GenericName=Process Viewer 38 | GenericName[ca]=Visor de processos 39 | GenericName[de]=Prozessanzeige 40 | GenericName[en_GB]=Process Viewer 41 | GenericName[es]=Visor de procesos 42 | GenericName[fi]=Prosessikatselin 43 | GenericName[fr]=Visualiseur de processus 44 | GenericName[gl]=Visor de procesos 45 | GenericName[it]=Visore dei processi 46 | GenericName[ko]=프로세스 뷰어 47 | GenericName[nb]=Prosessviser 48 | GenericName[nl]=Viewer van processen 49 | GenericName[nn]=Prosessvisar 50 | GenericName[pl]=Przeglądarka procesów 51 | GenericName[pt]=Visualizador de Processos 52 | GenericName[pt_BR]=Visualizador de processos 53 | GenericName[ru]=Монитор процессов 54 | GenericName[sk]=Prehliadač procesov 55 | GenericName[sl]=Pregledovalnik opravil 56 | GenericName[sr]=Приказивач процеса 57 | GenericName[sr@ijekavian]=Приказивач процеса 58 | GenericName[sr@ijekavianlatin]=Prikazivač procesa 59 | GenericName[sr@latin]=Prikazivač procesa 60 | GenericName[sv]=Processvisning 61 | GenericName[tr]=Süreç Görüntüleyici 62 | GenericName[uk]=Перегляд процесів 63 | GenericName[zh_CN]=进程查看器 64 | GenericName[zh_TW]=行程檢視器 65 | Keywords=system;process;task 66 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/scripts/MakeHeader.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os, sys, string 3 | try: 4 | from cStringIO import StringIO 5 | except ImportError: 6 | try: 7 | from StringIO import StringIO 8 | except ImportError: 9 | from io import StringIO 10 | 11 | ANY=1 12 | COPY=2 13 | SKIP=3 14 | SKIPONE=4 15 | 16 | state = ANY 17 | static = 0 18 | 19 | file = open(sys.argv[1]) 20 | name = sys.argv[1][:-2] 21 | 22 | out = StringIO() 23 | 24 | selfheader = '#include "' + name + '.h"' 25 | 26 | out.write( "/* Do not edit this file. It was automatically generated. */\n" ) 27 | out.write( "\n" ) 28 | 29 | out.write( "#ifndef HEADER_" + os.path.basename(name) + "\n") 30 | out.write( "#define HEADER_" + os.path.basename(name) + "\n") 31 | is_blank = False 32 | for line in file.readlines(): 33 | line = line[:-1] 34 | if state == ANY: 35 | if line == '/*{': 36 | state = COPY 37 | elif line == selfheader: 38 | pass 39 | elif line.find("#include") == 0: 40 | pass 41 | elif line.find("htop - ") == 0 and line[-2:] == ".c": 42 | out.write(line[:-2] + ".h\n") 43 | elif line.find("static ") != -1: 44 | if line[-1] == "{": 45 | state = SKIP 46 | static = 1 47 | else: 48 | state = SKIPONE 49 | elif len(line) > 1: 50 | static = 0 51 | equals = line.find(" = ") 52 | if line[-3:] == "= {": 53 | out.write( "extern " + line[:-4] + ";\n" ) 54 | state = SKIP 55 | elif equals != -1: 56 | out.write("extern " + line[:equals] + ";\n" ) 57 | elif line.startswith("typedef struct"): 58 | state = SKIP 59 | elif line[-1] == "{": 60 | out.write( line[:-2].replace("inline", "extern") + ";\n" ) 61 | state = SKIP 62 | else: 63 | out.write( line + "\n") 64 | is_blank = False 65 | elif line == "": 66 | if not is_blank: 67 | out.write( line + "\n") 68 | is_blank = True 69 | else: 70 | out.write( line + "\n") 71 | is_blank = False 72 | elif state == COPY: 73 | is_blank = False 74 | if line == "}*/": 75 | state = ANY 76 | else: 77 | out.write( line + "\n") 78 | elif state == SKIP: 79 | is_blank = False 80 | if len(line) >= 1 and line[0] == "}": 81 | if static == 1: 82 | state = SKIPONE 83 | else: 84 | state = ANY 85 | static = 0 86 | elif state == SKIPONE: 87 | is_blank = False 88 | state = ANY 89 | 90 | out.write( "\n" ) 91 | out.write( "#endif\n" ) 92 | 93 | # only write a new .h file if something changed. 94 | # This prevents a lot of recompilation during development 95 | out.seek(0) 96 | try: 97 | with open(name + ".h", "r") as orig: 98 | origcontents = orig.readlines() 99 | except: 100 | origcontents = "" 101 | if origcontents != out.readlines(): 102 | with open(name + ".h", "w") as new: 103 | print("Writing "+name+".h") 104 | new.write(out.getvalue()) 105 | out.close() 106 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/CpuFreqMeter.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - CpuFreqMeter.c 3 | (C) 2018 @lex 4 | */ 5 | 6 | #include "CpuFreqMeter.h" 7 | #include "Platform.h" 8 | #include "CRT.h" 9 | 10 | /*{ 11 | #include "Meter.h" 12 | }*/ 13 | 14 | 15 | int CpuFreqMeter_attributes[] = { 16 | CPU_FREQ 17 | }; 18 | 19 | static void CpuFreqMeter_setValues(Meter* this, char* buffer, int len) { 20 | int ghz,mhz,roundup; 21 | int cpu, Freq; 22 | int bigLITTLE; 23 | char buf[32]; 24 | 25 | cpu = this->param; 26 | cpu--; 27 | if (cpu < 0) { 28 | // xSnprintf(buffer, len, "cpu: %d",cpu); 29 | cpu = 0; 30 | } 31 | bigLITTLE = Platform_getCpuBigLITTLE(); 32 | if (bigLITTLE) { 33 | if (bigLITTLE > 0) { 34 | if (cpu < bigLITTLE) { 35 | strcpy(buf, "( .LITTLE)"); 36 | } else { 37 | strcpy(buf, "(big. )"); 38 | } 39 | } 40 | } 41 | Freq = Platform_getCpuFreq(cpu); 42 | if (Freq > 1000) { 43 | Freq /= 1000; 44 | } 45 | if (Freq > 1000) { 46 | ghz = Freq / 1000; 47 | mhz = Freq % 1000; 48 | roundup = ((mhz % 10) > 5); 49 | mhz /= 10; 50 | mhz += roundup; 51 | if (bigLITTLE) { 52 | xSnprintf(buffer, len, "%d.%02d GHz %s", ghz, mhz, buf); 53 | } else { 54 | xSnprintf(buffer, len, "%d.%02d GHz", ghz, mhz); 55 | } 56 | } else { 57 | if (bigLITTLE) { 58 | xSnprintf(buffer, len, "%4d MHz %s", Freq, buf); 59 | } else { 60 | xSnprintf(buffer, len, "%4d MHz", Freq); 61 | } 62 | } 63 | } 64 | 65 | static void CpuFreqMeter_init(Meter* this) { 66 | int cpu = this->param; 67 | if (cpu > 0) { 68 | char caption[16]; 69 | xSnprintf(caption, sizeof(caption), "CpuFreq%d: ", cpu); 70 | Meter_setCaption(this, caption); 71 | } 72 | } 73 | 74 | MeterClass CpuFreqMeter_class = { 75 | .super = { 76 | .extends = Class(Meter), 77 | .delete = Meter_delete 78 | }, 79 | .updateValues = CpuFreqMeter_setValues, 80 | .defaultMode = TEXT_METERMODE, 81 | .maxItems = 8, 82 | .total = 100.0, 83 | .attributes = CpuFreqMeter_attributes, 84 | .name = "CpuFreq", 85 | .uiName = "CpuFreq", 86 | .caption = "Cpu Freq: ", 87 | .init = CpuFreqMeter_init 88 | }; 89 | 90 | static void AllCpuFreqMeter_init(Meter* this) { 91 | int cpus = this->pl->cpuCount; 92 | if (!this->drawData) 93 | this->drawData = xCalloc(cpus, sizeof(Meter*)); 94 | Meter** meters = (Meter**) this->drawData; 95 | for (int i = 0; i < cpus; i++) { 96 | if (!meters[i]) 97 | meters[i] = Meter_new(this->pl, i+1, (MeterClass*) Class(CpuFreqMeter)); 98 | Meter_init(meters[i]); 99 | } 100 | } 101 | 102 | static void AllCpuFreqMeter_done(Meter* this) { 103 | int cpus = this->pl->cpuCount; 104 | Meter** meters = (Meter**) this->drawData; 105 | if (meters) { 106 | for (int i = 0; i < cpus; i++) 107 | Meter_delete((Object*)meters[i]); 108 | } 109 | } 110 | 111 | 112 | MeterClass AllCpuFreqMeter_class = { 113 | .super = { 114 | .extends = Class(Meter), 115 | .delete = Meter_delete 116 | }, 117 | .updateValues = CpuFreqMeter_setValues, 118 | .defaultMode = TEXT_METERMODE, 119 | .maxItems = 8, 120 | .total = 100.0, 121 | .attributes = CpuFreqMeter_attributes, 122 | .name = "AllCpuFreq", 123 | .uiName = "AllCpuFreq", 124 | .caption = "AllCpu Freq: ", 125 | .init = AllCpuFreqMeter_init, 126 | .done = AllCpuFreqMeter_done 127 | }; 128 | 129 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | Panel* menu = (Panel*) Vector_get(this->scr->panels, 0); 82 | Header_draw(header); 83 | RichString_setAttr(&(super->header), CRT_colors[PANEL_HEADER_FOCUS]); 84 | RichString_setAttr(&(menu->header), CRT_colors[PANEL_HEADER_UNFOCUS]); 85 | ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2); 86 | } 87 | return result; 88 | } 89 | 90 | PanelClass ColorsPanel_class = { 91 | .super = { 92 | .extends = Class(Panel), 93 | .delete = ColorsPanel_delete 94 | }, 95 | .eventHandler = ColorsPanel_eventHandler 96 | }; 97 | 98 | ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr) { 99 | ColorsPanel* this = AllocThis(ColorsPanel); 100 | Panel* super = (Panel*) this; 101 | FunctionBar* fuBar = FunctionBar_new(ColorsFunctions, NULL, NULL); 102 | Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true, fuBar); 103 | 104 | this->settings = settings; 105 | this->scr = scr; 106 | 107 | Panel_setHeader(super, "Colors"); 108 | for (int i = 0; ColorSchemeNames[i] != NULL; i++) { 109 | Panel_add(super, (Object*) CheckItem_newByVal(xStrdup(ColorSchemeNames[i]), false)); 110 | } 111 | CheckItem_set((CheckItem*)Panel_get(super, settings->colorScheme), true); 112 | return this; 113 | } 114 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/debian/patches/601-openvz-new-ctid-vpid.patch: -------------------------------------------------------------------------------- 1 | This replaces the old 600-openvz-veid-on-kernels-gt-2.6.18.patch 2 | Source: https://patch-diff.githubusercontent.com/raw/hishamhm/htop/pull/464.patch 3 | From: Alexander Pisarev 4 | Date: Wed, 6 Apr 2016 14:47:28 +0300 5 | Subject: [PATCH] Add support of UUID CTID used in the new version of OpenVZ 6 | 7 | In the new version of OpenVZ (Virtuozzo 7), containers could be identified by UUIDs and integer numbers like before (so called legacy CTID). Existing support of OpenVZ can't work with UUIDs. This patch fix it. 8 | 9 | CTIDs and VPIDs are now read from /proc/[id]/status instead of /proc/[id]/stat because of the following reasons: 10 | * the /proc/[id]/status has named fields and OpenVZ kernel writes either CTID or UUID to envID field (depending on which type is used); 11 | * OpenVZ kernel appends own data to /proc/[id]/stat file, a change in parameters reported by vanilla kernel would also shift the position of OpenVZ data so it would not be read correctly. 12 | 13 | As UUIDs are much longer than old numerical CTIDs, the UUID strings will get truncated in output (although sorting is still done using complete UUIDs). 14 | 15 | --- a/linux/LinuxProcess.c 16 | +++ b/linux/LinuxProcess.c 17 | @@ -119,7 +119,7 @@ 18 | double io_rate_write_bps; 19 | #endif 20 | #ifdef HAVE_OPENVZ 21 | - unsigned int ctid; 22 | + char* ctid; 23 | unsigned int vpid; 24 | #endif 25 | #ifdef HAVE_VSERVER 26 | @@ -271,6 +271,9 @@ 27 | void Process_delete(Object* cast) { 28 | LinuxProcess* this = (LinuxProcess*) cast; 29 | Process_done((Process*)cast); 30 | +#ifdef HAVE_OPENVZ 31 | + free(this->ctid); 32 | +#endif 33 | #ifdef HAVE_CGROUP 34 | free(this->cgroup); 35 | #endif 36 | @@ -361,7 +364,7 @@ 37 | } 38 | #endif 39 | #ifdef HAVE_OPENVZ 40 | - case CTID: xSnprintf(buffer, n, "%7u ", lp->ctid); break; 41 | + case CTID: xSnprintf(buffer, n, "%8.8s ", lp->ctid); break; 42 | case VPID: xSnprintf(buffer, n, Process_pidFormat, lp->vpid); break; 43 | #endif 44 | #ifdef HAVE_VSERVER 45 | @@ -441,7 +444,7 @@ 46 | #endif 47 | #ifdef HAVE_OPENVZ 48 | case CTID: 49 | - return (p2->ctid - p1->ctid); 50 | + return strcmp(p1->ctid ?: "", p2->ctid ?: ""); 51 | case VPID: 52 | return (p2->vpid - p1->vpid); 53 | #endif 54 | --- a/linux/LinuxProcessList.c 55 | +++ b/linux/LinuxProcessList.c 56 | @@ -480,27 +480,35 @@ 57 | #ifdef HAVE_OPENVZ 58 | 59 | static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* dirname, const char* name) { 60 | - if ( (access("/proc/vz", R_OK) != 0)) { 61 | - process->vpid = process->super.pid; 62 | - process->ctid = 0; 63 | + process->vpid = process->super.pid; 64 | + free(process->ctid); 65 | + process->ctid = xStrdup("0"); 66 | + if ( (access("/proc/vz", R_OK) != 0)) 67 | return; 68 | - } 69 | char filename[MAX_NAME+1]; 70 | - xSnprintf(filename, MAX_NAME, "%s/%s/stat", dirname, name); 71 | + xSnprintf(filename, MAX_NAME, "%s/%s/status", dirname, name); 72 | FILE* file = fopen(filename, "r"); 73 | if (!file) 74 | return; 75 | - (void) fscanf(file, 76 | - "%*32u %*32s %*1c %*32u %*32u %*32u %*32u %*32u %*32u %*32u " 77 | - "%*32u %*32u %*32u %*32u %*32u %*32u %*32u %*32u " 78 | - "%*32u %*32u %*32u %*32u %*32u %*32u %*32u %*32u " 79 | - "%*32u %*32u %*32u %*32u %*32u %*32u %*32u %*32u " 80 | - "%*32u %*32u %*32u %*32u %*32u %*32u %*32u %*32u " 81 | - "%*32u %*32u %*32u %*32u %*32u %*32u %*32u " 82 | - "%*32u %*32u %32u %32u", 83 | - &process->vpid, &process->ctid); 84 | + char buffer[PROC_LINE_LENGTH + 1]; 85 | + while (fgets(buffer, PROC_LINE_LENGTH, file)) { 86 | + if (String_startsWith(buffer, "envID:")) { 87 | + char ctid[PROC_LINE_LENGTH + 1]; 88 | + int ok = sscanf(buffer, "envID:\t%36s", ctid); 89 | + if (ok == 1) { 90 | + free(process->ctid); 91 | + process->ctid = xStrdup(ctid); 92 | + } 93 | + } 94 | + else if (String_startsWith(buffer, "VPid:")) { 95 | + unsigned int vpid; 96 | + int ok = sscanf(buffer, "VPid:\t%32u", &vpid); 97 | + if (ok == 1) { 98 | + process->vpid = vpid; 99 | + } 100 | + } 101 | + } 102 | fclose(file); 103 | - return; 104 | } 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 "CpuFreqMeter.h" 13 | #include "Header.h" 14 | #include "ListItem.h" 15 | #include "Platform.h" 16 | 17 | #include 18 | #include 19 | 20 | /*{ 21 | #include "Settings.h" 22 | #include "Panel.h" 23 | #include "ScreenManager.h" 24 | #include "ProcessList.h" 25 | 26 | typedef struct AvailableMetersPanel_ { 27 | Panel super; 28 | ScreenManager* scr; 29 | 30 | Settings* settings; 31 | Header* header; 32 | Panel* leftPanel; 33 | Panel* rightPanel; 34 | } AvailableMetersPanel; 35 | 36 | }*/ 37 | 38 | static void AvailableMetersPanel_delete(Object* object) { 39 | Panel* super = (Panel*) object; 40 | AvailableMetersPanel* this = (AvailableMetersPanel*) object; 41 | Panel_done(super); 42 | free(this); 43 | } 44 | 45 | static inline void AvailableMetersPanel_addMeter(Header* header, Panel* panel, MeterClass* type, int param, int column) { 46 | Meter* meter = (Meter*) Header_addMeterByClass(header, type, param, column); 47 | Panel_add(panel, (Object*) Meter_toListItem(meter, false)); 48 | Panel_setSelected(panel, Panel_size(panel) - 1); 49 | MetersPanel_setMoving((MetersPanel*)panel, true); 50 | FunctionBar_draw(panel->currentBar, NULL); 51 | } 52 | 53 | static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) { 54 | AvailableMetersPanel* this = (AvailableMetersPanel*) super; 55 | Header* header = this->header; 56 | 57 | ListItem* selected = (ListItem*) Panel_getSelected(super); 58 | int param = selected->key & 0xff; 59 | int type = selected->key >> 16; 60 | HandlerResult result = IGNORED; 61 | bool update = false; 62 | 63 | switch(ch) { 64 | case KEY_F(5): 65 | case 'l': 66 | case 'L': 67 | { 68 | AvailableMetersPanel_addMeter(header, this->leftPanel, Platform_meterTypes[type], param, 0); 69 | result = HANDLED; 70 | update = true; 71 | break; 72 | } 73 | case 0x0a: 74 | case 0x0d: 75 | case KEY_ENTER: 76 | case KEY_F(6): 77 | case 'r': 78 | case 'R': 79 | { 80 | AvailableMetersPanel_addMeter(header, this->rightPanel, Platform_meterTypes[type], param, 1); 81 | result = (KEY_LEFT << 16) | SYNTH_KEY; 82 | update = true; 83 | break; 84 | } 85 | } 86 | if (update) { 87 | this->settings->changed = true; 88 | Header_calculateHeight(header); 89 | Header_draw(header); 90 | ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2); 91 | } 92 | return result; 93 | } 94 | 95 | PanelClass AvailableMetersPanel_class = { 96 | .super = { 97 | .extends = Class(Panel), 98 | .delete = AvailableMetersPanel_delete 99 | }, 100 | .eventHandler = AvailableMetersPanel_eventHandler 101 | }; 102 | 103 | AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl) { 104 | int i; 105 | 106 | AvailableMetersPanel* this = AllocThis(AvailableMetersPanel); 107 | Panel* super = (Panel*) this; 108 | FunctionBar* fuBar = FunctionBar_newEnterEsc("Add ", "Done "); 109 | Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar); 110 | 111 | this->settings = settings; 112 | this->header = header; 113 | this->leftPanel = leftMeters; 114 | this->rightPanel = rightMeters; 115 | this->scr = scr; 116 | 117 | Panel_setHeader(super, "Available meters"); 118 | // Platform_meterTypes[0] should be always (&CPUMeter_class), which we will 119 | // handle separately in the code below. 120 | for (i = 1; Platform_meterTypes[i]; i++) { 121 | MeterClass* type = Platform_meterTypes[i]; 122 | assert(type != &CPUMeter_class); 123 | const char* label = type->description ? type->description : type->uiName; 124 | Panel_add(super, (Object*) ListItem_new(label, i << 16)); 125 | } 126 | MeterClass* type = &CpuFreqMeter_class; 127 | int cpus = pl->cpuCount; 128 | if (cpus > 1) { 129 | for ( int z = 1; z <= cpus; z++) { 130 | char buffer[50]; 131 | xSnprintf(buffer, 50, "%s %d", type->uiName, z); 132 | Panel_add(super, (Object*) ListItem_new(buffer, z | (18 << 16))); 133 | } 134 | } 135 | // Handle (&CPUMeter_class) 136 | type = &CPUMeter_class; 137 | if (cpus > 1) { 138 | Panel_add(super, (Object*) ListItem_new("CPU average", 0)); 139 | for (i = 1; i <= cpus; i++) { 140 | char buffer[50]; 141 | xSnprintf(buffer, 50, "%s %d", type->uiName, i); 142 | Panel_add(super, (Object*) ListItem_new(buffer, i)); 143 | } 144 | } else { 145 | Panel_add(super, (Object*) ListItem_new("CPU", 1)); 146 | } 147 | return this; 148 | } 149 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/OpenFilesScreen.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - OpenFilesScreen.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 "OpenFilesScreen.h" 9 | 10 | #include "CRT.h" 11 | #include "ProcessList.h" 12 | #include "IncSet.h" 13 | #include "StringUtils.h" 14 | #include "FunctionBar.h" 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | /*{ 27 | #include "InfoScreen.h" 28 | 29 | typedef struct OpenFiles_Data_ { 30 | char* data[256]; 31 | } OpenFiles_Data; 32 | 33 | typedef struct OpenFiles_ProcessData_ { 34 | OpenFiles_Data data; 35 | int error; 36 | struct OpenFiles_FileData_* files; 37 | } OpenFiles_ProcessData; 38 | 39 | typedef struct OpenFiles_FileData_ { 40 | OpenFiles_Data data; 41 | struct OpenFiles_FileData_* next; 42 | } OpenFiles_FileData; 43 | 44 | typedef struct OpenFilesScreen_ { 45 | InfoScreen super; 46 | pid_t pid; 47 | } OpenFilesScreen; 48 | 49 | }*/ 50 | 51 | InfoScreenClass OpenFilesScreen_class = { 52 | .super = { 53 | .extends = Class(Object), 54 | .delete = OpenFilesScreen_delete 55 | }, 56 | .scan = OpenFilesScreen_scan, 57 | .draw = OpenFilesScreen_draw 58 | }; 59 | 60 | OpenFilesScreen* OpenFilesScreen_new(Process* process) { 61 | OpenFilesScreen* this = xMalloc(sizeof(OpenFilesScreen)); 62 | Object_setClass(this, Class(OpenFilesScreen)); 63 | if (Process_isThread(process)) 64 | this->pid = process->tgid; 65 | else 66 | this->pid = process->pid; 67 | return (OpenFilesScreen*) InfoScreen_init(&this->super, process, NULL, LINES-3, " FD TYPE DEVICE SIZE NODE NAME"); 68 | } 69 | 70 | void OpenFilesScreen_delete(Object* this) { 71 | free(InfoScreen_done((InfoScreen*)this)); 72 | } 73 | 74 | void OpenFilesScreen_draw(InfoScreen* this) { 75 | InfoScreen_drawTitled(this, "Snapshot of files open in process %d - %s", ((OpenFilesScreen*)this)->pid, this->process->comm); 76 | } 77 | 78 | static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) { 79 | char command[1025]; 80 | xSnprintf(command, 1024, "lsof -P -p %d -F 2> /dev/null", pid); 81 | FILE* fd = popen(command, "r"); 82 | OpenFiles_ProcessData* pdata = xCalloc(1, sizeof(OpenFiles_ProcessData)); 83 | OpenFiles_FileData* fdata = NULL; 84 | OpenFiles_Data* item = &(pdata->data); 85 | if (!fd) { 86 | pdata->error = 127; 87 | return pdata; 88 | } 89 | for (;;) { 90 | char* line = String_readLine(fd); 91 | if (!line) { 92 | break; 93 | } 94 | unsigned char cmd = line[0]; 95 | if (cmd == 'f') { 96 | OpenFiles_FileData* nextFile = xCalloc(1, sizeof(OpenFiles_FileData)); 97 | if (fdata == NULL) { 98 | pdata->files = nextFile; 99 | } else { 100 | fdata->next = nextFile; 101 | } 102 | fdata = nextFile; 103 | item = &(fdata->data); 104 | } 105 | item->data[cmd] = xStrdup(line + 1); 106 | free(line); 107 | } 108 | pdata->error = pclose(fd); 109 | return pdata; 110 | } 111 | 112 | static inline void OpenFiles_Data_clear(OpenFiles_Data* data) { 113 | for (int i = 0; i < 255; i++) 114 | if (data->data[i]) 115 | free(data->data[i]); 116 | } 117 | 118 | void OpenFilesScreen_scan(InfoScreen* this) { 119 | Panel* panel = this->display; 120 | int idx = Panel_getSelectedIndex(panel); 121 | Panel_prune(panel); 122 | OpenFiles_ProcessData* pdata = OpenFilesScreen_getProcessData(((OpenFilesScreen*)this)->pid); 123 | if (pdata->error == 127) { 124 | InfoScreen_addLine(this, "Could not execute 'lsof'. Please make sure it is available in your $PATH."); 125 | } else if (pdata->error == 1) { 126 | InfoScreen_addLine(this, "Failed listing open files."); 127 | } else { 128 | OpenFiles_FileData* fdata = pdata->files; 129 | while (fdata) { 130 | char** data = fdata->data.data; 131 | int lenN = data['n'] ? strlen(data['n']) : 0; 132 | int sizeEntry = 5 + 7 + 10 + 10 + 10 + lenN + 5 /*spaces*/ + 1 /*null*/; 133 | char* entry = xMalloc(sizeEntry); 134 | xSnprintf(entry, sizeEntry, "%5.5s %7.7s %10.10s %10.10s %10.10s %s", 135 | data['f'] ? data['f'] : "", 136 | data['t'] ? data['t'] : "", 137 | data['D'] ? data['D'] : "", 138 | data['s'] ? data['s'] : "", 139 | data['i'] ? data['i'] : "", 140 | data['n'] ? data['n'] : ""); 141 | InfoScreen_addLine(this, entry); 142 | OpenFiles_Data_clear(&fdata->data); 143 | OpenFiles_FileData* old = fdata; 144 | fdata = fdata->next; 145 | free(old); 146 | } 147 | OpenFiles_Data_clear(&pdata->data); 148 | } 149 | free(pdata); 150 | Vector_insertionSort(this->lines); 151 | Vector_insertionSort(panel->items); 152 | Panel_setSelected(panel, idx); 153 | } 154 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | ACLOCAL_AMFLAGS = -I m4 3 | AUTOMAKE_OPTIONS = subdir-objects 4 | 5 | bin_PROGRAMS = htop 6 | 7 | dist_man_MANS = htop.1 8 | EXTRA_DIST = $(dist_man_MANS) htop.desktop htop.png scripts/MakeHeader.py \ 9 | install-sh autogen.sh missing 10 | applicationsdir = $(datadir)/applications 11 | applications_DATA = htop.desktop 12 | pixmapdir = $(datadir)/pixmaps 13 | pixmap_DATA = htop.png 14 | 15 | htop_CFLAGS = -pedantic -Wall $(wextra_flag) -std=c99 -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(top_srcdir)/$(my_htop_platform)" 16 | htop_LDFLAGS = 17 | AM_CPPFLAGS = -DNDEBUG 18 | 19 | myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \ 20 | ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c MainPanel.c \ 21 | DisplayOptionsPanel.c FunctionBar.c Hashtable.c Header.c htop.c ListItem.c \ 22 | LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \ 23 | BatteryMeter.c Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \ 24 | SignalsPanel.c StringUtils.c SwapMeter.c TasksMeter.c UptimeMeter.c CpuFreqMeter.c CpuTempMeter.c CpuVcoreMeter.c \ 25 | TraceScreen.c UsersTable.c Vector.c AvailableColumnsPanel.c AffinityPanel.c \ 26 | HostnameMeter.c OpenFilesScreen.c Affinity.c IncSet.c Action.c EnvScreen.c \ 27 | InfoScreen.c XAlloc.c 28 | 29 | myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \ 30 | CategoriesPanel.h CheckItem.h ClockMeter.h ColorsPanel.h ColumnsPanel.h \ 31 | CPUMeter.h CRT.h MainPanel.h DisplayOptionsPanel.h FunctionBar.h \ 32 | Hashtable.h Header.h htop.h ListItem.h LoadAverageMeter.h MemoryMeter.h \ 33 | BatteryMeter.h Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \ 34 | ScreenManager.h Settings.h SignalsPanel.h StringUtils.h SwapMeter.h \ 35 | TasksMeter.h UptimeMeter.h CpuFreqMeter.h CpuTempMeter.h CpuVcoreMeter.h TraceScreen.h UsersTable.h Vector.h Process.h \ 36 | AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h \ 37 | EnvScreen.h InfoScreen.h XAlloc.h 38 | 39 | if HTOP_LINUX 40 | htop_CFLAGS += -rdynamic 41 | myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \ 42 | linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c 43 | 44 | myhtopplatheaders = linux/Platform.h linux/IOPriorityPanel.h linux/IOPriority.h \ 45 | linux/LinuxProcess.h linux/LinuxProcessList.h linux/LinuxCRT.h linux/Battery.h 46 | endif 47 | 48 | if HTOP_FREEBSD 49 | myhtopplatsources = freebsd/Platform.c freebsd/FreeBSDProcessList.c \ 50 | freebsd/FreeBSDProcess.c freebsd/FreeBSDCRT.c freebsd/Battery.c 51 | 52 | myhtopplatheaders = freebsd/Platform.h freebsd/FreeBSDProcessList.h \ 53 | freebsd/FreeBSDProcess.h freebsd/FreeBSDCRT.h freebsd/Battery.h 54 | endif 55 | 56 | if HTOP_DRAGONFLYBSD 57 | htop_LDFLAGS += -lkvm -lkinfo -lexecinfo 58 | myhtopplatsources = dragonflybsd/Platform.c dragonflybsd/DragonFlyBSDProcessList.c \ 59 | dragonflybsd/DragonFlyBSDProcess.c dragonflybsd/DragonFlyBSDCRT.c dragonflybsd/Battery.c 60 | 61 | myhtopplatheaders = dragonflybsd/Platform.h dragonflybsd/DragonFlyBSDProcessList.h \ 62 | dragonflybsd/DragonFlyBSDProcess.h dragonflybsd/DragonFlyBSDCRT.h dragonflybsd/Battery.h 63 | endif 64 | 65 | if HTOP_OPENBSD 66 | myhtopplatsources = openbsd/Platform.c openbsd/OpenBSDProcessList.c \ 67 | openbsd/OpenBSDProcess.c openbsd/OpenBSDCRT.c openbsd/Battery.c 68 | 69 | myhtopplatheaders = openbsd/Platform.h openbsd/OpenBSDProcessList.h \ 70 | openbsd/OpenBSDProcess.h openbsd/OpenBSDCRT.h openbsd/Battery.h 71 | endif 72 | 73 | if HTOP_DARWIN 74 | htop_LDFLAGS += -framework IOKit -framework CoreFoundation 75 | myhtopplatsources = darwin/Platform.c darwin/DarwinProcess.c \ 76 | darwin/DarwinProcessList.c darwin/DarwinCRT.c darwin/Battery.c 77 | 78 | myhtopplatheaders = darwin/Platform.h darwin/DarwinProcess.h \ 79 | darwin/DarwinProcessList.h darwin/DarwinCRT.h darwin/Battery.h 80 | endif 81 | 82 | if HTOP_UNSUPPORTED 83 | myhtopplatsources = unsupported/Platform.c \ 84 | unsupported/UnsupportedProcess.c unsupported/UnsupportedProcessList.c \ 85 | unsupported/UnsupportedCRT.c unsupported/Battery.c 86 | 87 | myhtopplatheaders = unsupported/Platform.h \ 88 | unsupported/UnsupportedProcess.h unsupported/UnsupportedProcessList.h \ 89 | unsupported/UnsupportedCRT.h unsupported/Battery.h 90 | endif 91 | 92 | SUFFIXES = .h 93 | 94 | BUILT_SOURCES = $(myhtopheaders) $(myhtopplatheaders) 95 | htop_SOURCES = $(myhtopheaders) $(myhtopplatheaders) $(myhtopsources) $(myhtopplatsources) config.h 96 | 97 | target: 98 | echo $(htop_SOURCES) 99 | 100 | profile: 101 | $(MAKE) all CFLAGS="-pg" AM_CPPFLAGS="-pg -O2 -DNDEBUG" 102 | 103 | debug: 104 | $(MAKE) all CFLAGS="" AM_CPPFLAGS="-ggdb -DDEBUG" 105 | 106 | coverage: 107 | $(MAKE) all CFLAGS="" AM_CPPFLAGS="-fprofile-arcs -ftest-coverage -DDEBUG" LDFLAGS="-lgcov" 108 | 109 | .c.h: 110 | @srcdir@/scripts/MakeHeader.py $< 111 | 112 | cppcheck: 113 | cppcheck -q -v . --enable=all -DHAVE_CGROUP -DHAVE_OPENVZ -DHAVE_TASKSTATS 114 | 115 | .PHONY: lcov 116 | 117 | lcov: 118 | mkdir -p lcov 119 | lcov --capture --directory . --output-file coverage.info 120 | genhtml coverage.info --output-directory lcov 121 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/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", "-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 | fcntl(this->fdpair[0], F_SETFL, O_NONBLOCK); 112 | this->strace = fdopen(this->fdpair[0], "r"); 113 | this->fd_strace = fileno(this->strace); 114 | return true; 115 | } 116 | 117 | void TraceScreen_updateTrace(InfoScreen* super) { 118 | TraceScreen* this = (TraceScreen*) super; 119 | char buffer[1001]; 120 | fd_set fds; 121 | FD_ZERO(&fds); 122 | // FD_SET(STDIN_FILENO, &fds); 123 | FD_SET(this->fd_strace, &fds); 124 | struct timeval tv; 125 | tv.tv_sec = 0; tv.tv_usec = 500; 126 | int ready = select(this->fd_strace+1, &fds, NULL, NULL, &tv); 127 | int nread = 0; 128 | if (ready > 0 && FD_ISSET(this->fd_strace, &fds)) 129 | nread = fread(buffer, 1, 1000, this->strace); 130 | if (nread && this->tracing) { 131 | char* line = buffer; 132 | buffer[nread] = '\0'; 133 | for (int i = 0; i < nread; i++) { 134 | if (buffer[i] == '\n') { 135 | buffer[i] = '\0'; 136 | if (this->contLine) { 137 | InfoScreen_appendLine(&this->super, line); 138 | this->contLine = false; 139 | } else { 140 | InfoScreen_addLine(&this->super, line); 141 | } 142 | line = buffer+i+1; 143 | } 144 | } 145 | if (line < buffer+nread) { 146 | InfoScreen_addLine(&this->super, line); 147 | buffer[nread] = '\0'; 148 | this->contLine = true; 149 | } 150 | if (this->follow) 151 | Panel_setSelected(this->super.display, Panel_size(this->super.display)-1); 152 | } 153 | } 154 | 155 | bool TraceScreen_onKey(InfoScreen* super, int ch) { 156 | TraceScreen* this = (TraceScreen*) super; 157 | switch(ch) { 158 | case 'f': 159 | case KEY_F(8): 160 | this->follow = !(this->follow); 161 | if (this->follow) 162 | Panel_setSelected(super->display, Panel_size(super->display)-1); 163 | return true; 164 | case 't': 165 | case KEY_F(9): 166 | this->tracing = !this->tracing; 167 | FunctionBar_setLabel(super->display->defaultBar, KEY_F(9), this->tracing?"Stop Tracing ":"Resume Tracing "); 168 | InfoScreen_draw(this); 169 | return true; 170 | } 171 | this->follow = false; 172 | return false; 173 | } 174 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/unsupported/Platform.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - unsupported/Platform.c 3 | (C) 2014 Hisham H. Muhammad 4 | (C) 2015 David C. Hunt 5 | Released under the GNU GPL, see the COPYING file 6 | in the source distribution for its full text. 7 | */ 8 | 9 | #include "Platform.h" 10 | #include "CPUMeter.h" 11 | #include "MemoryMeter.h" 12 | #include "SwapMeter.h" 13 | #include "TasksMeter.h" 14 | #include "LoadAverageMeter.h" 15 | #include "ClockMeter.h" 16 | #include "HostnameMeter.h" 17 | #include "UptimeMeter.h" 18 | 19 | /*{ 20 | #include "Action.h" 21 | #include "BatteryMeter.h" 22 | #include "SignalsPanel.h" 23 | #include "UnsupportedProcess.h" 24 | }*/ 25 | 26 | const SignalItem Platform_signals[] = { 27 | { .name = " 0 Cancel", .number = 0 }, 28 | }; 29 | 30 | const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem); 31 | 32 | ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; 33 | 34 | ProcessFieldData Process_fields[] = { 35 | [0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, }, 36 | [PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, }, 37 | [COMM] = { .name = "Command", .title = "Command ", .description = "Command line", .flags = 0, }, 38 | [STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging)", .flags = 0, }, 39 | [PPID] = { .name = "PPID", .title = " PPID ", .description = "Parent process ID", .flags = 0, }, 40 | [PGRP] = { .name = "PGRP", .title = " PGRP ", .description = "Process group ID", .flags = 0, }, 41 | [SESSION] = { .name = "SESSION", .title = " SID ", .description = "Process's session ID", .flags = 0, }, 42 | [TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", .flags = 0, }, 43 | [TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, }, 44 | [MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, }, 45 | [MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, }, 46 | [PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, }, 47 | [NICE] = { .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", .flags = 0, }, 48 | [STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", .flags = 0, }, 49 | 50 | [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, }, 51 | [M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, }, 52 | [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, }, 53 | [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, }, 54 | [PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, }, 55 | [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, }, 56 | [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, }, 57 | [TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, }, 58 | [NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, }, 59 | [TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, }, 60 | [100] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, }, 61 | }; 62 | 63 | MeterClass* Platform_meterTypes[] = { 64 | &CPUMeter_class, 65 | &ClockMeter_class, 66 | &LoadAverageMeter_class, 67 | &LoadMeter_class, 68 | &MemoryMeter_class, 69 | &SwapMeter_class, 70 | &TasksMeter_class, 71 | &BatteryMeter_class, 72 | &HostnameMeter_class, 73 | &UptimeMeter_class, 74 | &AllCPUsMeter_class, 75 | &AllCPUs2Meter_class, 76 | &LeftCPUsMeter_class, 77 | &RightCPUsMeter_class, 78 | &LeftCPUs2Meter_class, 79 | &RightCPUs2Meter_class, 80 | &BlankMeter_class, 81 | NULL 82 | }; 83 | 84 | void Platform_setBindings(Htop_Action* keys) { 85 | (void) keys; 86 | } 87 | 88 | int Platform_numberOfFields = 100; 89 | 90 | extern char Process_pidFormat[20]; 91 | 92 | ProcessPidColumn Process_pidColumns[] = { 93 | { .id = 0, .label = NULL }, 94 | }; 95 | 96 | int Platform_getUptime() { 97 | return 0; 98 | } 99 | 100 | void Platform_getLoadAverage(double* one, double* five, double* fifteen) { 101 | *one = 0; 102 | *five = 0; 103 | *fifteen = 0; 104 | } 105 | 106 | int Platform_getMaxPid() { 107 | return 1; 108 | } 109 | 110 | double Platform_setCPUValues(Meter* this, int cpu) { 111 | (void) this; 112 | (void) cpu; 113 | return 0.0; 114 | } 115 | 116 | void Platform_setMemoryValues(Meter* this) { 117 | (void) this; 118 | } 119 | 120 | void Platform_setSwapValues(Meter* this) { 121 | (void) this; 122 | } 123 | 124 | bool Process_isThread(Process* this) { 125 | (void) this; 126 | return false; 127 | } 128 | 129 | char* Platform_getProcessEnv(pid_t pid) { 130 | (void) pid; 131 | return NULL; 132 | } 133 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/RichString.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - RichString.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 "RichString.h" 9 | #include "XAlloc.h" 10 | 11 | #include 12 | #include 13 | 14 | #define RICHSTRING_MAXLEN 350 15 | 16 | /*{ 17 | #include "config.h" 18 | #include 19 | 20 | #include 21 | #ifdef HAVE_NCURSESW_CURSES_H 22 | #include 23 | #elif HAVE_NCURSES_NCURSES_H 24 | #include 25 | #elif HAVE_NCURSES_CURSES_H 26 | #include 27 | #elif HAVE_NCURSES_H 28 | #include 29 | #elif HAVE_CURSES_H 30 | #include 31 | #endif 32 | 33 | #ifdef HAVE_LIBNCURSESW 34 | #include 35 | #endif 36 | 37 | #define RichString_size(this) ((this)->chlen) 38 | #define RichString_sizeVal(this) ((this).chlen) 39 | 40 | #define RichString_begin(this) RichString (this); memset(&this, 0, sizeof(RichString)); (this).chptr = (this).chstr; 41 | #define RichString_beginAllocated(this) memset(&this, 0, sizeof(RichString)); (this).chptr = (this).chstr; 42 | #define RichString_end(this) RichString_prune(&(this)); 43 | 44 | #ifdef HAVE_LIBNCURSESW 45 | #define RichString_printVal(this, y, x) mvadd_wchstr(y, x, (this).chptr) 46 | #define RichString_printoffnVal(this, y, x, off, n) mvadd_wchnstr(y, x, (this).chptr + off, n) 47 | #define RichString_getCharVal(this, i) ((this).chptr[i].chars[0] & 255) 48 | #define RichString_setChar(this, at, ch) do{ (this)->chptr[(at)] = (CharType) { .chars = { ch, 0 } }; } while(0) 49 | #define CharType cchar_t 50 | #else 51 | #define RichString_printVal(this, y, x) mvaddchstr(y, x, (this).chptr) 52 | #define RichString_printoffnVal(this, y, x, off, n) mvaddchnstr(y, x, (this).chptr + off, n) 53 | #define RichString_getCharVal(this, i) ((this).chptr[i]) 54 | #define RichString_setChar(this, at, ch) do{ (this)->chptr[(at)] = ch; } while(0) 55 | #define CharType chtype 56 | #endif 57 | 58 | typedef struct RichString_ { 59 | int chlen; 60 | CharType* chptr; 61 | CharType chstr[RICHSTRING_MAXLEN+1]; 62 | } RichString; 63 | 64 | }*/ 65 | 66 | #define charBytes(n) (sizeof(CharType) * (n)) 67 | 68 | static void RichString_extendLen(RichString* this, int len) { 69 | if (this->chlen <= RICHSTRING_MAXLEN) { 70 | if (len > RICHSTRING_MAXLEN) { 71 | this->chptr = xMalloc(charBytes(len + 1)); 72 | memcpy(this->chptr, this->chstr, charBytes(this->chlen)); 73 | } 74 | } else { 75 | if (len <= RICHSTRING_MAXLEN) { 76 | memcpy(this->chstr, this->chptr, charBytes(len)); 77 | free(this->chptr); 78 | this->chptr = this->chstr; 79 | } else { 80 | this->chptr = xRealloc(this->chptr, charBytes(len + 1)); 81 | } 82 | } 83 | 84 | RichString_setChar(this, len, 0); 85 | this->chlen = len; 86 | } 87 | 88 | #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) 89 | 90 | #ifdef HAVE_LIBNCURSESW 91 | 92 | static inline void RichString_writeFrom(RichString* this, int attrs, const char* data_c, int from, int len) { 93 | wchar_t data[len+1]; 94 | len = mbstowcs(data, data_c, len); 95 | if (len < 0) 96 | return; 97 | int newLen = from + len; 98 | RichString_setLen(this, newLen); 99 | for (int i = from, j = 0; i < newLen; i++, j++) { 100 | this->chptr[i] = (CharType) { .attr = attrs & 0xffffff, .chars = { (iswprint(data[j]) ? data[j] : '?') } }; 101 | } 102 | } 103 | 104 | inline void RichString_setAttrn(RichString* this, int attrs, int start, int finish) { 105 | cchar_t* ch = this->chptr + start; 106 | for (int i = start; i <= finish; i++) { 107 | ch->attr = attrs; 108 | ch++; 109 | } 110 | } 111 | 112 | int RichString_findChar(RichString* this, char c, int start) { 113 | wchar_t wc = btowc(c); 114 | cchar_t* ch = this->chptr + start; 115 | for (int i = start; i < this->chlen; i++) { 116 | if (ch->chars[0] == wc) 117 | return i; 118 | ch++; 119 | } 120 | return -1; 121 | } 122 | 123 | #else 124 | 125 | static inline void RichString_writeFrom(RichString* this, int attrs, const char* data_c, int from, int len) { 126 | int newLen = from + len; 127 | RichString_setLen(this, newLen); 128 | for (int i = from, j = 0; i < newLen; i++, j++) 129 | this->chptr[i] = (data_c[j] >= 32 ? data_c[j] : '?') | attrs; 130 | this->chptr[newLen] = 0; 131 | } 132 | 133 | void RichString_setAttrn(RichString* this, int attrs, int start, int finish) { 134 | chtype* ch = this->chptr + start; 135 | for (int i = start; i <= finish; i++) { 136 | *ch = (*ch & 0xff) | attrs; 137 | ch++; 138 | } 139 | } 140 | 141 | int RichString_findChar(RichString* this, char c, int start) { 142 | chtype* ch = this->chptr + start; 143 | for (int i = start; i < this->chlen; i++) { 144 | if ((*ch & 0xff) == (chtype) c) 145 | return i; 146 | ch++; 147 | } 148 | return -1; 149 | } 150 | 151 | #endif 152 | 153 | void RichString_prune(RichString* this) { 154 | if (this->chlen > RICHSTRING_MAXLEN) 155 | free(this->chptr); 156 | memset(this, 0, sizeof(RichString)); 157 | this->chptr = this->chstr; 158 | } 159 | 160 | void RichString_setAttr(RichString* this, int attrs) { 161 | RichString_setAttrn(this, attrs, 0, this->chlen - 1); 162 | } 163 | 164 | void RichString_append(RichString* this, int attrs, const char* data) { 165 | RichString_writeFrom(this, attrs, data, this->chlen, strlen(data)); 166 | } 167 | 168 | void RichString_appendn(RichString* this, int attrs, const char* data, int len) { 169 | RichString_writeFrom(this, attrs, data, this->chlen, len); 170 | } 171 | 172 | void RichString_write(RichString* this, int attrs, const char* data) { 173 | RichString_writeFrom(this, attrs, data, 0, strlen(data)); 174 | } 175 | -------------------------------------------------------------------------------- /htop/htop_2.1.1-3_arm64.buildinfo: -------------------------------------------------------------------------------- 1 | Format: 1.0 2 | Source: htop 3 | Binary: htop 4 | Architecture: arm64 5 | Version: 2.1.1-3 6 | Checksums-Md5: 7 | 1dd8f479f7ae6dbeae0a40143453c4d0 274484 htop-dbgsym_2.1.1-3_arm64.ddeb 8 | 035d6a67a27b0c74cacb2f57900d8ff1 75716 htop_2.1.1-3_arm64.deb 9 | Checksums-Sha1: 10 | ef0615d1fc48deedda5719e3911272bcec5d2586 274484 htop-dbgsym_2.1.1-3_arm64.ddeb 11 | dba6884aaca2c365cf6cb47235cae6315838cd70 75716 htop_2.1.1-3_arm64.deb 12 | Checksums-Sha256: 13 | 96d6e0393616c3b8cd932ea8940a23831328b14211311885bb68dd8e916732fd 274484 htop-dbgsym_2.1.1-3_arm64.ddeb 14 | e6798046760eed9b30b6444649d09c6d73dc38749e349270d70143d645ac6552 75716 htop_2.1.1-3_arm64.deb 15 | Build-Origin: Ubuntu 16 | Build-Architecture: arm64 17 | Build-Date: Sun, 14 Oct 2018 19:08:18 +0000 18 | Installed-Build-Depends: 19 | autoconf (= 2.69-11), 20 | automake (= 1:1.15.1-3ubuntu2), 21 | autopoint (= 0.19.8.1-6), 22 | autotools-dev (= 20180224.1), 23 | base-files (= 10.1ubuntu2.3), 24 | base-passwd (= 3.5.44), 25 | bash (= 4.4.18-2ubuntu1), 26 | binutils (= 2.30-21ubuntu1~18.04), 27 | binutils-aarch64-linux-gnu (= 2.30-21ubuntu1~18.04), 28 | binutils-common (= 2.30-21ubuntu1~18.04), 29 | bsdmainutils (= 11.1.2ubuntu1), 30 | bsdutils (= 1:2.31.1-0.4ubuntu3.2), 31 | build-essential (= 12.4ubuntu1), 32 | bzip2 (= 1.0.6-8.1), 33 | coreutils (= 8.28-1ubuntu1), 34 | cpp (= 4:7.3.0-3ubuntu2.1), 35 | cpp-7 (= 7.3.0-27ubuntu1~18.04), 36 | dash (= 0.5.8-2.10), 37 | debconf (= 1.5.66), 38 | debhelper (= 11.1.6ubuntu2), 39 | debianutils (= 4.8.4), 40 | dh-autoreconf (= 17), 41 | dh-strip-nondeterminism (= 0.040-1.1~build1), 42 | diffutils (= 1:3.6-1), 43 | dpkg (= 1.19.0.5ubuntu2), 44 | dpkg-dev (= 1.19.0.5ubuntu2), 45 | e2fsprogs (= 1.44.1-1), 46 | fdisk (= 2.31.1-0.4ubuntu3.2), 47 | file (= 1:5.32-2ubuntu0.1), 48 | findutils (= 4.6.0+git+20170828-2), 49 | g++ (= 4:7.3.0-3ubuntu2.1), 50 | g++-7 (= 7.3.0-27ubuntu1~18.04), 51 | gcc (= 4:7.3.0-3ubuntu2.1), 52 | gcc-7 (= 7.3.0-27ubuntu1~18.04), 53 | gcc-7-base (= 7.3.0-27ubuntu1~18.04), 54 | gcc-8-base (= 8.2.0-1ubuntu2~18.04), 55 | gettext (= 0.19.8.1-6), 56 | gettext-base (= 0.19.8.1-6), 57 | grep (= 3.1-2), 58 | groff-base (= 1.22.3-10), 59 | gzip (= 1.6-5ubuntu1), 60 | hostname (= 3.20), 61 | init-system-helpers (= 1.51), 62 | intltool-debian (= 0.35.0+20060710.4), 63 | libacl1 (= 2.2.52-3build1), 64 | libarchive-zip-perl (= 1.60-1ubuntu0.1), 65 | libasan4 (= 7.3.0-27ubuntu1~18.04), 66 | libatomic1 (= 8.2.0-1ubuntu2~18.04), 67 | libattr1 (= 1:2.4.47-2build1), 68 | libaudit-common (= 1:2.8.2-1ubuntu1), 69 | libaudit1 (= 1:2.8.2-1ubuntu1), 70 | libbinutils (= 2.30-21ubuntu1~18.04), 71 | libblkid1 (= 2.31.1-0.4ubuntu3.2), 72 | libbsd0 (= 0.8.7-1), 73 | libbz2-1.0 (= 1.0.6-8.1), 74 | libc-bin (= 2.27-3ubuntu1), 75 | libc-dev-bin (= 2.27-3ubuntu1), 76 | libc6 (= 2.27-3ubuntu1), 77 | libc6-dev (= 2.27-3ubuntu1), 78 | libcap-ng0 (= 0.7.7-3.1), 79 | libcc1-0 (= 8.2.0-1ubuntu2~18.04), 80 | libcom-err2 (= 1.44.1-1), 81 | libcroco3 (= 0.6.12-2), 82 | libdb5.3 (= 5.3.28-13.1ubuntu1), 83 | libdebconfclient0 (= 0.213ubuntu1), 84 | libdpkg-perl (= 1.19.0.5ubuntu2), 85 | libext2fs2 (= 1.44.1-1), 86 | libfdisk1 (= 2.31.1-0.4ubuntu3.2), 87 | libffi6 (= 3.2.1-8), 88 | libfile-stripnondeterminism-perl (= 0.040-1.1~build1), 89 | libgcc-7-dev (= 7.3.0-27ubuntu1~18.04), 90 | libgcc1 (= 1:8.2.0-1ubuntu2~18.04), 91 | libgcrypt20 (= 1.8.1-4ubuntu1.1), 92 | libgdbm-compat4 (= 1.14.1-6), 93 | libgdbm5 (= 1.14.1-6), 94 | libglib2.0-0 (= 2.56.2-0ubuntu0.18.04.2), 95 | libgmp10 (= 2:6.1.2+dfsg-2), 96 | libgomp1 (= 8.2.0-1ubuntu2~18.04), 97 | libgpg-error0 (= 1.27-6), 98 | libicu60 (= 60.2-3ubuntu3), 99 | libisl19 (= 0.19-1), 100 | libitm1 (= 8.2.0-1ubuntu2~18.04), 101 | liblsan0 (= 8.2.0-1ubuntu2~18.04), 102 | liblz4-1 (= 0.0~r131-2ubuntu3), 103 | liblzma5 (= 5.2.2-1.3), 104 | libmagic-mgc (= 1:5.32-2ubuntu0.1), 105 | libmagic1 (= 1:5.32-2ubuntu0.1), 106 | libmount1 (= 2.31.1-0.4ubuntu3.2), 107 | libmpc3 (= 1.1.0-1), 108 | libmpfr6 (= 4.0.1-1), 109 | libncurses5 (= 6.1-1ubuntu1.18.04), 110 | libncurses5-dev (= 6.1-1ubuntu1.18.04), 111 | libncursesw5 (= 6.1-1ubuntu1.18.04), 112 | libncursesw5-dev (= 6.1-1ubuntu1.18.04), 113 | libpam-modules (= 1.1.8-3.6ubuntu2), 114 | libpam-modules-bin (= 1.1.8-3.6ubuntu2), 115 | libpam-runtime (= 1.1.8-3.6ubuntu2), 116 | libpam0g (= 1.1.8-3.6ubuntu2), 117 | libpcre3 (= 2:8.39-9), 118 | libperl5.26 (= 5.26.1-6ubuntu0.2), 119 | libpipeline1 (= 1.5.0-1), 120 | libpython2.7-minimal (= 2.7.15~rc1-1), 121 | libseccomp2 (= 2.3.1-2.1ubuntu4), 122 | libselinux1 (= 2.7-2build2), 123 | libsigsegv2 (= 2.12-1), 124 | libsmartcols1 (= 2.31.1-0.4ubuntu3.2), 125 | libss2 (= 1.44.1-1), 126 | libstdc++-7-dev (= 7.3.0-27ubuntu1~18.04), 127 | libstdc++6 (= 8.2.0-1ubuntu2~18.04), 128 | libsystemd0 (= 237-3ubuntu10.3), 129 | libtimedate-perl (= 2.3000-2), 130 | libtinfo-dev (= 6.1-1ubuntu1.18.04), 131 | libtinfo5 (= 6.1-1ubuntu1.18.04), 132 | libtool (= 2.4.6-2), 133 | libtsan0 (= 8.2.0-1ubuntu2~18.04), 134 | libubsan0 (= 7.3.0-27ubuntu1~18.04), 135 | libudev1 (= 237-3ubuntu10.3), 136 | libunistring2 (= 0.9.9-0ubuntu1), 137 | libuuid1 (= 2.31.1-0.4ubuntu3.2), 138 | libxml2 (= 2.9.4+dfsg1-6.1ubuntu1.2), 139 | libzstd1 (= 1.3.3+dfsg-2ubuntu1), 140 | linux-libc-dev (= 4.15.0-38.41), 141 | login (= 1:4.5-1ubuntu1), 142 | m4 (= 1.4.18-1), 143 | make (= 4.1-9.1ubuntu1), 144 | man-db (= 2.8.3-2ubuntu0.1), 145 | mawk (= 1.3.3-17ubuntu3), 146 | ncurses-base (= 6.1-1ubuntu1.18.04), 147 | ncurses-bin (= 6.1-1ubuntu1.18.04), 148 | patch (= 2.7.6-2ubuntu1), 149 | perl (= 5.26.1-6ubuntu0.2), 150 | perl-base (= 5.26.1-6ubuntu0.2), 151 | perl-modules-5.26 (= 5.26.1-6ubuntu0.2), 152 | pkg-config (= 0.29.1-0ubuntu2), 153 | po-debconf (= 1.0.20), 154 | python-minimal (= 2.7.15~rc1-1), 155 | python2.7-minimal (= 2.7.15~rc1-1), 156 | sed (= 4.4-2), 157 | sysvinit-utils (= 2.88dsf-59.10ubuntu1), 158 | tar (= 1.29b-2), 159 | util-linux (= 2.31.1-0.4ubuntu3.2), 160 | xz-utils (= 5.2.2-1.3), 161 | zlib1g (= 1:1.2.11.dfsg-0ubuntu2) 162 | Environment: 163 | DEB_BUILD_OPTIONS="parallel=6" 164 | SOURCE_DATE_EPOCH="1535038705" 165 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/InfoScreen.c: -------------------------------------------------------------------------------- 1 | #include "InfoScreen.h" 2 | 3 | #include "config.h" 4 | #include "Object.h" 5 | #include "CRT.h" 6 | #include "IncSet.h" 7 | #include "ListItem.h" 8 | #include "Platform.h" 9 | #include "StringUtils.h" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | /*{ 17 | #include "Process.h" 18 | #include "Panel.h" 19 | #include "FunctionBar.h" 20 | #include "IncSet.h" 21 | 22 | typedef struct InfoScreen_ InfoScreen; 23 | 24 | typedef void(*InfoScreen_Scan)(InfoScreen*); 25 | typedef void(*InfoScreen_Draw)(InfoScreen*); 26 | typedef void(*InfoScreen_OnErr)(InfoScreen*); 27 | typedef bool(*InfoScreen_OnKey)(InfoScreen*, int); 28 | 29 | typedef struct InfoScreenClass_ { 30 | ObjectClass super; 31 | const InfoScreen_Scan scan; 32 | const InfoScreen_Draw draw; 33 | const InfoScreen_OnErr onErr; 34 | const InfoScreen_OnKey onKey; 35 | } InfoScreenClass; 36 | 37 | #define As_InfoScreen(this_) ((InfoScreenClass*)(((InfoScreen*)(this_))->super.klass)) 38 | #define InfoScreen_scan(this_) As_InfoScreen(this_)->scan((InfoScreen*)(this_)) 39 | #define InfoScreen_draw(this_) As_InfoScreen(this_)->draw((InfoScreen*)(this_)) 40 | #define InfoScreen_onErr(this_) As_InfoScreen(this_)->onErr((InfoScreen*)(this_)) 41 | #define InfoScreen_onKey(this_, ch_) As_InfoScreen(this_)->onKey((InfoScreen*)(this_), ch_) 42 | 43 | struct InfoScreen_ { 44 | Object super; 45 | Process* process; 46 | Panel* display; 47 | FunctionBar* bar; 48 | IncSet* inc; 49 | Vector* lines; 50 | }; 51 | }*/ 52 | 53 | static const char* const InfoScreenFunctions[] = {"Search ", "Filter ", "Refresh", "Done ", NULL}; 54 | 55 | static const char* const InfoScreenKeys[] = {"F3", "F4", "F5", "Esc"}; 56 | 57 | static int InfoScreenEvents[] = {KEY_F(3), KEY_F(4), KEY_F(5), 27}; 58 | 59 | InfoScreen* InfoScreen_init(InfoScreen* this, Process* process, FunctionBar* bar, int height, char* panelHeader) { 60 | this->process = process; 61 | if (!bar) { 62 | bar = FunctionBar_new(InfoScreenFunctions, InfoScreenKeys, InfoScreenEvents); 63 | } 64 | this->display = Panel_new(0, 1, COLS, height, false, Class(ListItem), bar); 65 | this->inc = IncSet_new(bar); 66 | this->lines = Vector_new(this->display->items->type, true, DEFAULT_SIZE); 67 | Panel_setHeader(this->display, panelHeader); 68 | return this; 69 | } 70 | 71 | InfoScreen* InfoScreen_done(InfoScreen* this) { 72 | Panel_delete((Object*)this->display); 73 | IncSet_delete(this->inc); 74 | Vector_delete(this->lines); 75 | return this; 76 | } 77 | 78 | void InfoScreen_drawTitled(InfoScreen* this, char* fmt, ...) { 79 | va_list ap; 80 | va_start(ap, fmt); 81 | attrset(CRT_colors[METER_TEXT]); 82 | mvhline(0, 0, ' ', COLS); 83 | wmove(stdscr, 0, 0); 84 | vw_printw(stdscr, fmt, ap); 85 | attrset(CRT_colors[DEFAULT_COLOR]); 86 | this->display->needsRedraw = true; 87 | Panel_draw(this->display, true); 88 | IncSet_drawBar(this->inc); 89 | va_end(ap); 90 | } 91 | 92 | void InfoScreen_addLine(InfoScreen* this, const char* line) { 93 | Vector_add(this->lines, (Object*) ListItem_new(line, 0)); 94 | const char* incFilter = IncSet_filter(this->inc); 95 | if (!incFilter || String_contains_i(line, incFilter)) 96 | Panel_add(this->display, (Object*)Vector_get(this->lines, Vector_size(this->lines)-1)); 97 | } 98 | 99 | void InfoScreen_appendLine(InfoScreen* this, const char* line) { 100 | ListItem* last = (ListItem*)Vector_get(this->lines, Vector_size(this->lines)-1); 101 | ListItem_append(last, line); 102 | const char* incFilter = IncSet_filter(this->inc); 103 | if (incFilter && Panel_get(this->display, Panel_size(this->display)-1) != (Object*)last && String_contains_i(line, incFilter)) 104 | Panel_add(this->display, (Object*)last); 105 | } 106 | 107 | void InfoScreen_run(InfoScreen* this) { 108 | Panel* panel = this->display; 109 | 110 | if (As_InfoScreen(this)->scan) InfoScreen_scan(this); 111 | InfoScreen_draw(this); 112 | 113 | bool looping = true; 114 | while (looping) { 115 | 116 | Panel_draw(panel, true); 117 | 118 | if (this->inc->active) 119 | move(LINES-1, CRT_cursorX); 120 | set_escdelay(25); 121 | int ch = getch(); 122 | 123 | if (ch == ERR) { 124 | if (As_InfoScreen(this)->onErr) { 125 | InfoScreen_onErr(this); 126 | continue; 127 | } 128 | } 129 | 130 | if (ch == KEY_MOUSE) { 131 | MEVENT mevent; 132 | int ok = getmouse(&mevent); 133 | if (ok == OK) 134 | if (mevent.y >= panel->y && mevent.y < LINES - 1) { 135 | Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV); 136 | ch = 0; 137 | } if (mevent.y == LINES - 1) 138 | ch = IncSet_synthesizeEvent(this->inc, mevent.x); 139 | } 140 | 141 | if (this->inc->active) { 142 | IncSet_handleKey(this->inc, ch, panel, IncSet_getListItemValue, this->lines); 143 | continue; 144 | } 145 | 146 | switch(ch) { 147 | case ERR: 148 | continue; 149 | case KEY_F(3): 150 | case '/': 151 | IncSet_activate(this->inc, INC_SEARCH, panel); 152 | break; 153 | case KEY_F(4): 154 | case '\\': 155 | IncSet_activate(this->inc, INC_FILTER, panel); 156 | break; 157 | case KEY_F(5): 158 | clear(); 159 | if (As_InfoScreen(this)->scan) InfoScreen_scan(this); 160 | InfoScreen_draw(this); 161 | break; 162 | case '\014': // Ctrl+L 163 | clear(); 164 | InfoScreen_draw(this); 165 | break; 166 | case 'q': 167 | case 27: 168 | case KEY_F(10): 169 | looping = false; 170 | break; 171 | case KEY_RESIZE: 172 | Panel_resize(panel, COLS, LINES-2); 173 | InfoScreen_draw(this); 174 | break; 175 | default: 176 | if (As_InfoScreen(this)->onKey && InfoScreen_onKey(this, ch)) { 177 | continue; 178 | } 179 | Panel_onKey(panel, ch); 180 | } 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/darwin/DarwinProcessList.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - DarwinProcessList.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 "DarwinProcess.h" 10 | #include "DarwinProcessList.h" 11 | #include "CRT.h" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | /*{ 23 | #include "ProcessList.h" 24 | #include 25 | #include 26 | 27 | typedef struct DarwinProcessList_ { 28 | ProcessList super; 29 | 30 | host_basic_info_data_t host_info; 31 | vm_statistics_data_t vm_stats; 32 | processor_cpu_load_info_t prev_load; 33 | processor_cpu_load_info_t curr_load; 34 | uint64_t kernel_threads; 35 | uint64_t user_threads; 36 | uint64_t global_diff; 37 | } DarwinProcessList; 38 | 39 | }*/ 40 | 41 | void ProcessList_getHostInfo(host_basic_info_data_t *p) { 42 | mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT; 43 | 44 | if(0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) { 45 | CRT_fatalError("Unable to retrieve host info\n"); 46 | } 47 | } 48 | 49 | void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) { 50 | if(NULL != p && NULL != *p) { 51 | if(0 != munmap(*p, vm_page_size)) { 52 | CRT_fatalError("Unable to free old CPU load information\n"); 53 | } 54 | } 55 | 56 | *p = NULL; 57 | } 58 | 59 | unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) { 60 | mach_msg_type_number_t info_size = sizeof(processor_cpu_load_info_t); 61 | unsigned cpu_count; 62 | 63 | // TODO Improving the accuracy of the load counts woule help a lot. 64 | if(0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t *)p, &info_size)) { 65 | CRT_fatalError("Unable to retrieve CPU info\n"); 66 | } 67 | 68 | return cpu_count; 69 | } 70 | 71 | void ProcessList_getVMStats(vm_statistics_t p) { 72 | mach_msg_type_number_t info_size = HOST_VM_INFO_COUNT; 73 | 74 | if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)p, &info_size) != 0) 75 | CRT_fatalError("Unable to retrieve VM statistics\n"); 76 | } 77 | 78 | struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) { 79 | int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 }; 80 | struct kinfo_proc *processes = NULL; 81 | 82 | /* Note the two calls to sysctl(). One to get length and one to get the 83 | * data. This -does- mean that the second call could end up with a missing 84 | * process entry or two. 85 | */ 86 | *count = 0; 87 | if (sysctl(mib, 4, NULL, count, NULL, 0) < 0) 88 | CRT_fatalError("Unable to get size of kproc_infos"); 89 | 90 | processes = xMalloc(*count); 91 | if (processes == NULL) 92 | CRT_fatalError("Out of memory for kproc_infos"); 93 | 94 | if (sysctl(mib, 4, processes, count, NULL, 0) < 0) 95 | CRT_fatalError("Unable to get kinfo_procs"); 96 | 97 | *count = *count / sizeof(struct kinfo_proc); 98 | 99 | return processes; 100 | } 101 | 102 | 103 | ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { 104 | DarwinProcessList* this = xCalloc(1, sizeof(DarwinProcessList)); 105 | 106 | ProcessList_init(&this->super, Class(Process), usersTable, pidWhiteList, userId); 107 | 108 | /* Initialize the CPU information */ 109 | this->super.cpuCount = ProcessList_allocateCPULoadInfo(&this->prev_load); 110 | ProcessList_getHostInfo(&this->host_info); 111 | ProcessList_allocateCPULoadInfo(&this->curr_load); 112 | 113 | /* Initialize the VM statistics */ 114 | ProcessList_getVMStats(&this->vm_stats); 115 | 116 | this->super.kernelThreads = 0; 117 | this->super.userlandThreads = 0; 118 | this->super.totalTasks = 0; 119 | this->super.runningTasks = 0; 120 | 121 | return &this->super; 122 | } 123 | 124 | void ProcessList_delete(ProcessList* this) { 125 | ProcessList_done(this); 126 | free(this); 127 | } 128 | 129 | void ProcessList_goThroughEntries(ProcessList* super) { 130 | DarwinProcessList *dpl = (DarwinProcessList *)super; 131 | bool preExisting = true; 132 | struct kinfo_proc *ps; 133 | size_t count; 134 | DarwinProcess *proc; 135 | struct timeval tv; 136 | 137 | gettimeofday(&tv, NULL); /* Start processing time */ 138 | 139 | /* Update the global data (CPU times and VM stats) */ 140 | ProcessList_freeCPULoadInfo(&dpl->prev_load); 141 | dpl->prev_load = dpl->curr_load; 142 | ProcessList_allocateCPULoadInfo(&dpl->curr_load); 143 | ProcessList_getVMStats(&dpl->vm_stats); 144 | 145 | /* Get the time difference */ 146 | dpl->global_diff = 0; 147 | for(int i = 0; i < dpl->super.cpuCount; ++i) { 148 | for(size_t j = 0; j < CPU_STATE_MAX; ++j) { 149 | dpl->global_diff += dpl->curr_load[i].cpu_ticks[j] - dpl->prev_load[i].cpu_ticks[j]; 150 | } 151 | } 152 | 153 | /* Clear the thread counts */ 154 | super->kernelThreads = 0; 155 | super->userlandThreads = 0; 156 | super->totalTasks = 0; 157 | super->runningTasks = 0; 158 | 159 | /* We use kinfo_procs for initial data since : 160 | * 161 | * 1) They always succeed. 162 | * 2) The contain the basic information. 163 | * 164 | * We attempt to fill-in additional information with libproc. 165 | */ 166 | ps = ProcessList_getKInfoProcs(&count); 167 | 168 | for(size_t i = 0; i < count; ++i) { 169 | proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, (Process_New)DarwinProcess_new); 170 | 171 | DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], tv.tv_sec, preExisting); 172 | DarwinProcess_setFromLibprocPidinfo(proc, dpl); 173 | 174 | // Disabled due to bug in macOS High Sierra 175 | // DarwinProcess_scanThreads(proc); 176 | 177 | super->totalTasks += 1; 178 | 179 | if(!preExisting) { 180 | proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid); 181 | 182 | ProcessList_add(super, &proc->super); 183 | } 184 | } 185 | 186 | free(ps); 187 | } 188 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/MainPanel.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - ColumnsPanel.c 3 | (C) 2004-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 "MainPanel.h" 9 | #include "Process.h" 10 | #include "Platform.h" 11 | #include "CRT.h" 12 | 13 | #include 14 | 15 | /*{ 16 | #include "Panel.h" 17 | #include "Action.h" 18 | #include "Settings.h" 19 | 20 | typedef struct MainPanel_ { 21 | Panel super; 22 | State* state; 23 | IncSet* inc; 24 | Htop_Action *keys; 25 | pid_t pidSearch; 26 | } MainPanel; 27 | 28 | typedef bool(*MainPanel_ForeachProcessFn)(Process*, size_t); 29 | 30 | #define MainPanel_getFunctionBar(this_) (((Panel*)(this_))->defaultBar) 31 | 32 | }*/ 33 | 34 | static const char* const MainFunctions[] = {"Help ", "Setup ", "Search", "Filter", "Tree ", "SortBy", "Nice -", "Nice +", "Kill ", "Quit ", NULL}; 35 | 36 | void MainPanel_updateTreeFunctions(MainPanel* this, bool mode) { 37 | FunctionBar* bar = MainPanel_getFunctionBar(this); 38 | if (mode) { 39 | FunctionBar_setLabel(bar, KEY_F(5), "Sorted"); 40 | FunctionBar_setLabel(bar, KEY_F(6), "Collap"); 41 | } else { 42 | FunctionBar_setLabel(bar, KEY_F(5), "Tree "); 43 | FunctionBar_setLabel(bar, KEY_F(6), "SortBy"); 44 | } 45 | } 46 | 47 | void MainPanel_pidSearch(MainPanel* this, int ch) { 48 | Panel* super = (Panel*) this; 49 | pid_t pid = ch-48 + this->pidSearch; 50 | for (int i = 0; i < Panel_size(super); i++) { 51 | Process* p = (Process*) Panel_get(super, i); 52 | if (p && p->pid == pid) { 53 | Panel_setSelected(super, i); 54 | break; 55 | } 56 | } 57 | this->pidSearch = pid * 10; 58 | if (this->pidSearch > 10000000) { 59 | this->pidSearch = 0; 60 | } 61 | } 62 | 63 | static HandlerResult MainPanel_eventHandler(Panel* super, int ch) { 64 | MainPanel* this = (MainPanel*) super; 65 | 66 | HandlerResult result = IGNORED; 67 | 68 | Htop_Reaction reaction = HTOP_OK; 69 | 70 | if (EVENT_IS_HEADER_CLICK(ch)) { 71 | int x = EVENT_HEADER_CLICK_GET_X(ch); 72 | ProcessList* pl = this->state->pl; 73 | Settings* settings = this->state->settings; 74 | int hx = super->scrollH + x + 1; 75 | ProcessField field = ProcessList_keyAt(pl, hx); 76 | if (field == settings->sortKey) { 77 | Settings_invertSortOrder(settings); 78 | settings->treeView = false; 79 | } else { 80 | reaction |= Action_setSortKey(settings, field); 81 | } 82 | reaction |= HTOP_RECALCULATE | HTOP_REDRAW_BAR | HTOP_SAVE_SETTINGS; 83 | result = HANDLED; 84 | } else if (ch != ERR && this->inc->active) { 85 | bool filterChanged = IncSet_handleKey(this->inc, ch, super, (IncMode_GetPanelValue) MainPanel_getValue, NULL); 86 | if (filterChanged) { 87 | this->state->pl->incFilter = IncSet_filter(this->inc); 88 | reaction = HTOP_REFRESH | HTOP_REDRAW_BAR; 89 | } 90 | if (this->inc->found) { 91 | reaction |= Action_follow(this->state); 92 | reaction |= HTOP_KEEP_FOLLOWING; 93 | } 94 | result = HANDLED; 95 | } else if (ch == 27) { 96 | return HANDLED; 97 | } else if (ch != ERR && ch > 0 && ch < KEY_MAX && this->keys[ch]) { 98 | reaction |= (this->keys[ch])(this->state); 99 | result = HANDLED; 100 | } else if (isdigit(ch)) { 101 | MainPanel_pidSearch(this, ch); 102 | } else { 103 | if (ch != ERR) { 104 | this->pidSearch = 0; 105 | } else { 106 | reaction |= HTOP_KEEP_FOLLOWING; 107 | } 108 | } 109 | 110 | if (reaction & HTOP_REDRAW_BAR) { 111 | MainPanel_updateTreeFunctions(this, this->state->settings->treeView); 112 | IncSet_drawBar(this->inc); 113 | } 114 | if (reaction & HTOP_UPDATE_PANELHDR) { 115 | ProcessList_printHeader(this->state->pl, Panel_getHeader(super)); 116 | } 117 | if (reaction & HTOP_REFRESH) { 118 | result |= REDRAW; 119 | } 120 | if (reaction & HTOP_RECALCULATE) { 121 | result |= RESCAN; 122 | } 123 | if (reaction & HTOP_SAVE_SETTINGS) { 124 | this->state->settings->changed = true; 125 | } 126 | if (reaction & HTOP_QUIT) { 127 | return BREAK_LOOP; 128 | } 129 | if (!(reaction & HTOP_KEEP_FOLLOWING)) { 130 | this->state->pl->following = -1; 131 | Panel_setSelectionColor(super, CRT_colors[PANEL_SELECTION_FOCUS]); 132 | } 133 | return result; 134 | } 135 | 136 | int MainPanel_selectedPid(MainPanel* this) { 137 | Process* p = (Process*) Panel_getSelected((Panel*)this); 138 | if (p) { 139 | return p->pid; 140 | } 141 | return -1; 142 | } 143 | 144 | const char* MainPanel_getValue(MainPanel* this, int i) { 145 | Process* p = (Process*) Panel_get((Panel*)this, i); 146 | if (p) 147 | return p->comm; 148 | return ""; 149 | } 150 | 151 | bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, size_t arg, bool* wasAnyTagged) { 152 | Panel* super = (Panel*) this; 153 | bool ok = true; 154 | bool anyTagged = false; 155 | for (int i = 0; i < Panel_size(super); i++) { 156 | Process* p = (Process*) Panel_get(super, i); 157 | if (p->tag) { 158 | ok = fn(p, arg) && ok; 159 | anyTagged = true; 160 | } 161 | } 162 | if (!anyTagged) { 163 | Process* p = (Process*) Panel_getSelected(super); 164 | if (p) ok = fn(p, arg) && ok; 165 | } 166 | if (wasAnyTagged) 167 | *wasAnyTagged = anyTagged; 168 | return ok; 169 | } 170 | 171 | PanelClass MainPanel_class = { 172 | .super = { 173 | .extends = Class(Panel), 174 | .delete = MainPanel_delete 175 | }, 176 | .eventHandler = MainPanel_eventHandler 177 | }; 178 | 179 | MainPanel* MainPanel_new() { 180 | MainPanel* this = AllocThis(MainPanel); 181 | Panel_init((Panel*) this, 1, 1, 1, 1, Class(Process), false, FunctionBar_new(MainFunctions, NULL, NULL)); 182 | this->keys = xCalloc(KEY_MAX, sizeof(Htop_Action)); 183 | this->inc = IncSet_new(MainPanel_getFunctionBar(this)); 184 | 185 | Action_setBindings(this->keys); 186 | Platform_setBindings(this->keys); 187 | 188 | return this; 189 | } 190 | 191 | void MainPanel_setState(MainPanel* this, State* state) { 192 | this->state = state; 193 | } 194 | 195 | void MainPanel_delete(Object* object) { 196 | Panel* super = (Panel*) object; 197 | MainPanel* this = (MainPanel*) object; 198 | Panel_done(super); 199 | IncSet_delete(this->inc); 200 | free(this->keys); 201 | free(this); 202 | } 203 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/freebsd/Platform.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - freebsd/Platform.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 "Platform.h" 9 | #include "Meter.h" 10 | #include "CPUMeter.h" 11 | #include "MemoryMeter.h" 12 | #include "SwapMeter.h" 13 | #include "TasksMeter.h" 14 | #include "LoadAverageMeter.h" 15 | #include "UptimeMeter.h" 16 | #include "ClockMeter.h" 17 | #include "HostnameMeter.h" 18 | #include "FreeBSDProcess.h" 19 | #include "FreeBSDProcessList.h" 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | /*{ 30 | #include "Action.h" 31 | #include "BatteryMeter.h" 32 | #include "SignalsPanel.h" 33 | 34 | extern ProcessFieldData Process_fields[]; 35 | 36 | }*/ 37 | 38 | #ifndef CLAMP 39 | #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) 40 | #endif 41 | 42 | ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; 43 | 44 | int Platform_numberOfFields = LAST_PROCESSFIELD; 45 | 46 | const SignalItem Platform_signals[] = { 47 | { .name = " 0 Cancel", .number = 0 }, 48 | { .name = " 1 SIGHUP", .number = 1 }, 49 | { .name = " 2 SIGINT", .number = 2 }, 50 | { .name = " 3 SIGQUIT", .number = 3 }, 51 | { .name = " 4 SIGILL", .number = 4 }, 52 | { .name = " 5 SIGTRAP", .number = 5 }, 53 | { .name = " 6 SIGABRT", .number = 6 }, 54 | { .name = " 7 SIGEMT", .number = 7 }, 55 | { .name = " 8 SIGFPE", .number = 8 }, 56 | { .name = " 9 SIGKILL", .number = 9 }, 57 | { .name = "10 SIGBUS", .number = 10 }, 58 | { .name = "11 SIGSEGV", .number = 11 }, 59 | { .name = "12 SIGSYS", .number = 12 }, 60 | { .name = "13 SIGPIPE", .number = 13 }, 61 | { .name = "14 SIGALRM", .number = 14 }, 62 | { .name = "15 SIGTERM", .number = 15 }, 63 | { .name = "16 SIGURG", .number = 16 }, 64 | { .name = "17 SIGSTOP", .number = 17 }, 65 | { .name = "18 SIGTSTP", .number = 18 }, 66 | { .name = "19 SIGCONT", .number = 19 }, 67 | { .name = "20 SIGCHLD", .number = 20 }, 68 | { .name = "21 SIGTTIN", .number = 21 }, 69 | { .name = "22 SIGTTOU", .number = 22 }, 70 | { .name = "23 SIGIO", .number = 23 }, 71 | { .name = "24 SIGXCPU", .number = 24 }, 72 | { .name = "25 SIGXFSZ", .number = 25 }, 73 | { .name = "26 SIGVTALRM", .number = 26 }, 74 | { .name = "27 SIGPROF", .number = 27 }, 75 | { .name = "28 SIGWINCH", .number = 28 }, 76 | { .name = "29 SIGINFO", .number = 29 }, 77 | { .name = "30 SIGUSR1", .number = 30 }, 78 | { .name = "31 SIGUSR2", .number = 31 }, 79 | { .name = "32 SIGTHR", .number = 32 }, 80 | { .name = "33 SIGLIBRT", .number = 33 }, 81 | }; 82 | 83 | const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem); 84 | 85 | void Platform_setBindings(Htop_Action* keys) { 86 | (void) keys; 87 | } 88 | 89 | MeterClass* Platform_meterTypes[] = { 90 | &CPUMeter_class, 91 | &ClockMeter_class, 92 | &LoadAverageMeter_class, 93 | &LoadMeter_class, 94 | &MemoryMeter_class, 95 | &SwapMeter_class, 96 | &TasksMeter_class, 97 | &UptimeMeter_class, 98 | &BatteryMeter_class, 99 | &HostnameMeter_class, 100 | &AllCPUsMeter_class, 101 | &AllCPUs2Meter_class, 102 | &LeftCPUsMeter_class, 103 | &RightCPUsMeter_class, 104 | &LeftCPUs2Meter_class, 105 | &RightCPUs2Meter_class, 106 | &BlankMeter_class, 107 | NULL 108 | }; 109 | 110 | int Platform_getUptime() { 111 | struct timeval bootTime, currTime; 112 | int mib[2] = { CTL_KERN, KERN_BOOTTIME }; 113 | size_t size = sizeof(bootTime); 114 | 115 | int err = sysctl(mib, 2, &bootTime, &size, NULL, 0); 116 | if (err) { 117 | return -1; 118 | } 119 | gettimeofday(&currTime, NULL); 120 | 121 | return (int) difftime(currTime.tv_sec, bootTime.tv_sec); 122 | } 123 | 124 | void Platform_getLoadAverage(double* one, double* five, double* fifteen) { 125 | struct loadavg loadAverage; 126 | int mib[2] = { CTL_VM, VM_LOADAVG }; 127 | size_t size = sizeof(loadAverage); 128 | 129 | int err = sysctl(mib, 2, &loadAverage, &size, NULL, 0); 130 | if (err) { 131 | *one = 0; 132 | *five = 0; 133 | *fifteen = 0; 134 | return; 135 | } 136 | *one = (double) loadAverage.ldavg[0] / loadAverage.fscale; 137 | *five = (double) loadAverage.ldavg[1] / loadAverage.fscale; 138 | *fifteen = (double) loadAverage.ldavg[2] / loadAverage.fscale; 139 | } 140 | 141 | int Platform_getMaxPid() { 142 | int maxPid; 143 | size_t size = sizeof(maxPid); 144 | int err = sysctlbyname("kern.pid_max", &maxPid, &size, NULL, 0); 145 | if (err) { 146 | return 99999; 147 | } 148 | return maxPid; 149 | } 150 | 151 | double Platform_setCPUValues(Meter* this, int cpu) { 152 | FreeBSDProcessList* fpl = (FreeBSDProcessList*) this->pl; 153 | int cpus = this->pl->cpuCount; 154 | CPUData* cpuData; 155 | 156 | if (cpus == 1) { 157 | // single CPU box has everything in fpl->cpus[0] 158 | cpuData = &(fpl->cpus[0]); 159 | } else { 160 | cpuData = &(fpl->cpus[cpu]); 161 | } 162 | 163 | double percent; 164 | double* v = this->values; 165 | 166 | v[CPU_METER_NICE] = cpuData->nicePercent; 167 | v[CPU_METER_NORMAL] = cpuData->userPercent; 168 | if (this->pl->settings->detailedCPUTime) { 169 | v[CPU_METER_KERNEL] = cpuData->systemPercent; 170 | v[CPU_METER_IRQ] = cpuData->irqPercent; 171 | Meter_setItems(this, 4); 172 | percent = v[0]+v[1]+v[2]+v[3]; 173 | } else { 174 | v[2] = cpuData->systemAllPercent; 175 | Meter_setItems(this, 3); 176 | percent = v[0]+v[1]+v[2]; 177 | } 178 | 179 | percent = CLAMP(percent, 0.0, 100.0); 180 | if (isnan(percent)) percent = 0.0; 181 | return percent; 182 | } 183 | 184 | void Platform_setMemoryValues(Meter* this) { 185 | // TODO 186 | ProcessList* pl = (ProcessList*) this->pl; 187 | 188 | this->total = pl->totalMem; 189 | this->values[0] = pl->usedMem; 190 | this->values[1] = pl->buffersMem; 191 | this->values[2] = pl->cachedMem; 192 | } 193 | 194 | void Platform_setSwapValues(Meter* this) { 195 | ProcessList* pl = (ProcessList*) this->pl; 196 | this->total = pl->totalSwap; 197 | this->values[0] = pl->usedSwap; 198 | } 199 | 200 | void Platform_setTasksValues(Meter* this) { 201 | // TODO 202 | } 203 | 204 | char* Platform_getProcessEnv(pid_t pid) { 205 | // TODO 206 | return NULL; 207 | } 208 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* Define to 1 if the `closedir' function returns void instead of `int'. */ 4 | #undef CLOSEDIR_VOID 5 | 6 | /* Copyright message. */ 7 | #undef COPYRIGHT 8 | 9 | /* Define if ancient vserver support enabled. */ 10 | #undef HAVE_ANCIENT_VSERVER 11 | 12 | /* Define if cgroup support enabled. */ 13 | #undef HAVE_CGROUP 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_CURSES_H 17 | 18 | /* Define if delay accounting support should be enabled. */ 19 | #undef HAVE_DELAYACCT 20 | 21 | /* Define to 1 if you have the header file, and it defines `DIR'. 22 | */ 23 | #undef HAVE_DIRENT_H 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #undef HAVE_EXECINFO_H 27 | 28 | /* Define to 1 if you have the header file. */ 29 | #undef HAVE_HWLOC_H 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #undef HAVE_INTTYPES_H 33 | 34 | /* Define to 1 if you have the `hwloc' library (-lhwloc). */ 35 | #undef HAVE_LIBHWLOC 36 | 37 | /* Define to 1 if you have the `kvm' library (-lkvm). */ 38 | #undef HAVE_LIBKVM 39 | 40 | /* Define to 1 if you have the `m' library (-lm). */ 41 | #undef HAVE_LIBM 42 | 43 | /* The library is present. */ 44 | #undef HAVE_LIBNCURSES 45 | 46 | /* The library is present. */ 47 | #undef HAVE_LIBNCURSESW 48 | 49 | /* Define if Linux sched_setaffinity and sched_getaffinity are to be used. */ 50 | #undef HAVE_LINUX_AFFINITY 51 | 52 | /* Define to 1 if you have the `memmove' function. */ 53 | #undef HAVE_MEMMOVE 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #undef HAVE_MEMORY_H 57 | 58 | /* Define to 1 if you have the header file. */ 59 | #undef HAVE_NCURSESW_CURSES_H 60 | 61 | /* Define to 1 if you have the header file. */ 62 | #undef HAVE_NCURSES_CURSES_H 63 | 64 | /* Define to 1 if you have the header file. */ 65 | #undef HAVE_NCURSES_H 66 | 67 | /* Define to 1 if you have the header file. */ 68 | #undef HAVE_NCURSES_NCURSES_H 69 | 70 | /* Define to 1 if you have the header file, and it defines `DIR'. */ 71 | #undef HAVE_NDIR_H 72 | 73 | /* Define if openvz support enabled. */ 74 | #undef HAVE_OPENVZ 75 | 76 | /* Define if using a Linux-compatible proc filesystem. */ 77 | #undef HAVE_PROC 78 | 79 | /* Define if setuid support should be enabled. */ 80 | #undef HAVE_SETUID_ENABLED 81 | 82 | /* Define to 1 if `stat' has the bug that it succeeds when given the 83 | zero-length file name argument. */ 84 | #undef HAVE_STAT_EMPTY_STRING_BUG 85 | 86 | /* Define to 1 if stdbool.h conforms to C99. */ 87 | #undef HAVE_STDBOOL_H 88 | 89 | /* Define to 1 if you have the header file. */ 90 | #undef HAVE_STDINT_H 91 | 92 | /* Define to 1 if you have the header file. */ 93 | #undef HAVE_STDLIB_H 94 | 95 | /* Define to 1 if you have the `strdup' function. */ 96 | #undef HAVE_STRDUP 97 | 98 | /* Define to 1 if you have the header file. */ 99 | #undef HAVE_STRINGS_H 100 | 101 | /* Define to 1 if you have the header file. */ 102 | #undef HAVE_STRING_H 103 | 104 | /* Define to 1 if you have the `strncasecmp' function. */ 105 | #undef HAVE_STRNCASECMP 106 | 107 | /* Define to 1 if you have the `strstr' function. */ 108 | #undef HAVE_STRSTR 109 | 110 | /* Define to 1 if you have the header file, and it defines `DIR'. 111 | */ 112 | #undef HAVE_SYS_DIR_H 113 | 114 | /* Define to 1 if you have the header file, and it defines `DIR'. 115 | */ 116 | #undef HAVE_SYS_NDIR_H 117 | 118 | /* Define to 1 if you have the header file. */ 119 | #undef HAVE_SYS_PARAM_H 120 | 121 | /* Define to 1 if you have the header file. */ 122 | #undef HAVE_SYS_STAT_H 123 | 124 | /* Define to 1 if you have the header file. */ 125 | #undef HAVE_SYS_TIME_H 126 | 127 | /* Define to 1 if you have the header file. */ 128 | #undef HAVE_SYS_TYPES_H 129 | 130 | /* Define if taskstats support enabled. */ 131 | #undef HAVE_TASKSTATS 132 | 133 | /* Define to 1 if you have the header file. */ 134 | #undef HAVE_UNISTD_H 135 | 136 | /* Define if vserver support enabled. */ 137 | #undef HAVE_VSERVER 138 | 139 | /* Define to 1 if the system has the type `_Bool'. */ 140 | #undef HAVE__BOOL 141 | 142 | /* Define to 1 if `lstat' dereferences a symlink specified with a trailing 143 | slash. */ 144 | #undef LSTAT_FOLLOWS_SLASHED_SYMLINK 145 | 146 | /* Name of package */ 147 | #undef PACKAGE 148 | 149 | /* Define to the address where bug reports for this package should be sent. */ 150 | #undef PACKAGE_BUGREPORT 151 | 152 | /* Define to the full name of this package. */ 153 | #undef PACKAGE_NAME 154 | 155 | /* Define to the full name and version of this package. */ 156 | #undef PACKAGE_STRING 157 | 158 | /* Define to the one symbol short name of this package. */ 159 | #undef PACKAGE_TARNAME 160 | 161 | /* Define to the home page for this package. */ 162 | #undef PACKAGE_URL 163 | 164 | /* Define to the version of this package. */ 165 | #undef PACKAGE_VERSION 166 | 167 | /* Path of proc filesystem */ 168 | #undef PROCDIR 169 | 170 | /* Define as the return type of signal handlers (`int' or `void'). */ 171 | #undef RETSIGTYPE 172 | 173 | /* Define to 1 if you have the ANSI C header files. */ 174 | #undef STDC_HEADERS 175 | 176 | /* Enable extensions on AIX 3, Interix. */ 177 | #ifndef _ALL_SOURCE 178 | # undef _ALL_SOURCE 179 | #endif 180 | /* Enable GNU extensions on systems that have them. */ 181 | #ifndef _GNU_SOURCE 182 | # undef _GNU_SOURCE 183 | #endif 184 | /* Enable threading extensions on Solaris. */ 185 | #ifndef _POSIX_PTHREAD_SEMANTICS 186 | # undef _POSIX_PTHREAD_SEMANTICS 187 | #endif 188 | /* Enable extensions on HP NonStop. */ 189 | #ifndef _TANDEM_SOURCE 190 | # undef _TANDEM_SOURCE 191 | #endif 192 | /* Enable general extensions on Solaris. */ 193 | #ifndef __EXTENSIONS__ 194 | # undef __EXTENSIONS__ 195 | #endif 196 | 197 | 198 | /* Version number of package */ 199 | #undef VERSION 200 | 201 | /* Define to 1 if on MINIX. */ 202 | #undef _MINIX 203 | 204 | /* Define to 2 if the system does not provide POSIX.1 features except with 205 | this defined. */ 206 | #undef _POSIX_1_SOURCE 207 | 208 | /* Define to 1 if you need to in order for `stat' and other things to work. */ 209 | #undef _POSIX_SOURCE 210 | 211 | /* Define to empty if `const' does not conform to ANSI C. */ 212 | #undef const 213 | 214 | /* Define to `int' if doesn't define. */ 215 | #undef gid_t 216 | 217 | /* Define to `int' if does not define. */ 218 | #undef pid_t 219 | 220 | /* Define to `int' if doesn't define. */ 221 | #undef uid_t 222 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/dragonflybsd/Platform.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - dragonflybsd/Platform.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 "Platform.h" 10 | #include "Meter.h" 11 | #include "CPUMeter.h" 12 | #include "MemoryMeter.h" 13 | #include "SwapMeter.h" 14 | #include "TasksMeter.h" 15 | #include "LoadAverageMeter.h" 16 | #include "UptimeMeter.h" 17 | #include "ClockMeter.h" 18 | #include "HostnameMeter.h" 19 | #include "DragonFlyBSDProcess.h" 20 | #include "DragonFlyBSDProcessList.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | /*{ 31 | #include "Action.h" 32 | #include "BatteryMeter.h" 33 | #include "SignalsPanel.h" 34 | 35 | extern ProcessFieldData Process_fields[]; 36 | 37 | }*/ 38 | 39 | #ifndef CLAMP 40 | #define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x))) 41 | #endif 42 | 43 | ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; 44 | 45 | int Platform_numberOfFields = LAST_PROCESSFIELD; 46 | 47 | const SignalItem Platform_signals[] = { 48 | { .name = " 0 Cancel", .number = 0 }, 49 | { .name = " 1 SIGHUP", .number = 1 }, 50 | { .name = " 2 SIGINT", .number = 2 }, 51 | { .name = " 3 SIGQUIT", .number = 3 }, 52 | { .name = " 4 SIGILL", .number = 4 }, 53 | { .name = " 5 SIGTRAP", .number = 5 }, 54 | { .name = " 6 SIGABRT", .number = 6 }, 55 | { .name = " 7 SIGEMT", .number = 7 }, 56 | { .name = " 8 SIGFPE", .number = 8 }, 57 | { .name = " 9 SIGKILL", .number = 9 }, 58 | { .name = "10 SIGBUS", .number = 10 }, 59 | { .name = "11 SIGSEGV", .number = 11 }, 60 | { .name = "12 SIGSYS", .number = 12 }, 61 | { .name = "13 SIGPIPE", .number = 13 }, 62 | { .name = "14 SIGALRM", .number = 14 }, 63 | { .name = "15 SIGTERM", .number = 15 }, 64 | { .name = "16 SIGURG", .number = 16 }, 65 | { .name = "17 SIGSTOP", .number = 17 }, 66 | { .name = "18 SIGTSTP", .number = 18 }, 67 | { .name = "19 SIGCONT", .number = 19 }, 68 | { .name = "20 SIGCHLD", .number = 20 }, 69 | { .name = "21 SIGTTIN", .number = 21 }, 70 | { .name = "22 SIGTTOU", .number = 22 }, 71 | { .name = "23 SIGIO", .number = 23 }, 72 | { .name = "24 SIGXCPU", .number = 24 }, 73 | { .name = "25 SIGXFSZ", .number = 25 }, 74 | { .name = "26 SIGVTALRM", .number = 26 }, 75 | { .name = "27 SIGPROF", .number = 27 }, 76 | { .name = "28 SIGWINCH", .number = 28 }, 77 | { .name = "29 SIGINFO", .number = 29 }, 78 | { .name = "30 SIGUSR1", .number = 30 }, 79 | { .name = "31 SIGUSR2", .number = 31 }, 80 | { .name = "32 SIGTHR", .number = 32 }, 81 | { .name = "33 SIGLIBRT", .number = 33 }, 82 | }; 83 | 84 | const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem); 85 | 86 | void Platform_setBindings(Htop_Action* keys) { 87 | (void) keys; 88 | } 89 | 90 | MeterClass* Platform_meterTypes[] = { 91 | &CPUMeter_class, 92 | &ClockMeter_class, 93 | &LoadAverageMeter_class, 94 | &LoadMeter_class, 95 | &MemoryMeter_class, 96 | &SwapMeter_class, 97 | &TasksMeter_class, 98 | &UptimeMeter_class, 99 | &BatteryMeter_class, 100 | &HostnameMeter_class, 101 | &AllCPUsMeter_class, 102 | &AllCPUs2Meter_class, 103 | &LeftCPUsMeter_class, 104 | &RightCPUsMeter_class, 105 | &LeftCPUs2Meter_class, 106 | &RightCPUs2Meter_class, 107 | &BlankMeter_class, 108 | NULL 109 | }; 110 | 111 | int Platform_getUptime() { 112 | struct timeval bootTime, currTime; 113 | int mib[2] = { CTL_KERN, KERN_BOOTTIME }; 114 | size_t size = sizeof(bootTime); 115 | 116 | int err = sysctl(mib, 2, &bootTime, &size, NULL, 0); 117 | if (err) { 118 | return -1; 119 | } 120 | gettimeofday(&currTime, NULL); 121 | 122 | return (int) difftime(currTime.tv_sec, bootTime.tv_sec); 123 | } 124 | 125 | void Platform_getLoadAverage(double* one, double* five, double* fifteen) { 126 | struct loadavg loadAverage; 127 | int mib[2] = { CTL_VM, VM_LOADAVG }; 128 | size_t size = sizeof(loadAverage); 129 | 130 | int err = sysctl(mib, 2, &loadAverage, &size, NULL, 0); 131 | if (err) { 132 | *one = 0; 133 | *five = 0; 134 | *fifteen = 0; 135 | return; 136 | } 137 | *one = (double) loadAverage.ldavg[0] / loadAverage.fscale; 138 | *five = (double) loadAverage.ldavg[1] / loadAverage.fscale; 139 | *fifteen = (double) loadAverage.ldavg[2] / loadAverage.fscale; 140 | } 141 | 142 | int Platform_getMaxPid() { 143 | int maxPid; 144 | size_t size = sizeof(maxPid); 145 | int err = sysctlbyname("kern.pid_max", &maxPid, &size, NULL, 0); 146 | if (err) { 147 | return 999999; 148 | } 149 | return maxPid; 150 | } 151 | 152 | double Platform_setCPUValues(Meter* this, int cpu) { 153 | DragonFlyBSDProcessList* fpl = (DragonFlyBSDProcessList*) this->pl; 154 | int cpus = this->pl->cpuCount; 155 | CPUData* cpuData; 156 | 157 | if (cpus == 1) { 158 | // single CPU box has everything in fpl->cpus[0] 159 | cpuData = &(fpl->cpus[0]); 160 | } else { 161 | cpuData = &(fpl->cpus[cpu]); 162 | } 163 | 164 | double percent; 165 | double* v = this->values; 166 | 167 | v[CPU_METER_NICE] = cpuData->nicePercent; 168 | v[CPU_METER_NORMAL] = cpuData->userPercent; 169 | if (this->pl->settings->detailedCPUTime) { 170 | v[CPU_METER_KERNEL] = cpuData->systemPercent; 171 | v[CPU_METER_IRQ] = cpuData->irqPercent; 172 | Meter_setItems(this, 4); 173 | percent = v[0]+v[1]+v[2]+v[3]; 174 | } else { 175 | v[2] = cpuData->systemAllPercent; 176 | Meter_setItems(this, 3); 177 | percent = v[0]+v[1]+v[2]; 178 | } 179 | 180 | percent = CLAMP(percent, 0.0, 100.0); 181 | if (isnan(percent)) percent = 0.0; 182 | return percent; 183 | } 184 | 185 | void Platform_setMemoryValues(Meter* this) { 186 | // TODO 187 | ProcessList* pl = (ProcessList*) this->pl; 188 | 189 | this->total = pl->totalMem; 190 | this->values[0] = pl->usedMem; 191 | this->values[1] = pl->buffersMem; 192 | this->values[2] = pl->cachedMem; 193 | } 194 | 195 | void Platform_setSwapValues(Meter* this) { 196 | ProcessList* pl = (ProcessList*) this->pl; 197 | this->total = pl->totalSwap; 198 | this->values[0] = pl->usedSwap; 199 | } 200 | 201 | void Platform_setTasksValues(Meter* this) { 202 | // TODO 203 | (void)this; // prevent unused warning 204 | } 205 | 206 | char* Platform_getProcessEnv(pid_t pid) { 207 | // TODO 208 | (void)pid; // prevent unused warning 209 | return NULL; 210 | } 211 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/Header.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - Header.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 "Header.h" 9 | 10 | #include "CRT.h" 11 | #include "StringUtils.h" 12 | #include "Platform.h" 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | /*{ 20 | #include "Meter.h" 21 | #include "Settings.h" 22 | #include "Vector.h" 23 | 24 | typedef struct Header_ { 25 | Vector** columns; 26 | Settings* settings; 27 | struct ProcessList_* pl; 28 | int nrColumns; 29 | int pad; 30 | int height; 31 | } Header; 32 | 33 | }*/ 34 | 35 | #ifndef MAX 36 | #define MAX(a,b) ((a)>(b)?(a):(b)) 37 | #endif 38 | 39 | #ifndef Header_forEachColumn 40 | #define Header_forEachColumn(this_, i_) for (int (i_)=0; (i_) < (this_)->nrColumns; ++(i_)) 41 | #endif 42 | 43 | Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns) { 44 | Header* this = xCalloc(1, sizeof(Header)); 45 | this->columns = xCalloc(nrColumns, sizeof(Vector*)); 46 | this->settings = settings; 47 | this->pl = pl; 48 | this->nrColumns = nrColumns; 49 | Header_forEachColumn(this, i) { 50 | this->columns[i] = Vector_new(Class(Meter), true, DEFAULT_SIZE); 51 | } 52 | return this; 53 | } 54 | 55 | void Header_delete(Header* this) { 56 | Header_forEachColumn(this, i) { 57 | Vector_delete(this->columns[i]); 58 | } 59 | free(this->columns); 60 | free(this); 61 | } 62 | 63 | void Header_populateFromSettings(Header* this) { 64 | Header_forEachColumn(this, col) { 65 | MeterColumnSettings* colSettings = &this->settings->columns[col]; 66 | for (int i = 0; i < colSettings->len; i++) { 67 | Header_addMeterByName(this, colSettings->names[i], col); 68 | if (colSettings->modes[i] != 0) { 69 | Header_setMode(this, i, colSettings->modes[i], col); 70 | } 71 | } 72 | } 73 | Header_calculateHeight(this); 74 | } 75 | 76 | void Header_writeBackToSettings(const Header* this) { 77 | Header_forEachColumn(this, col) { 78 | MeterColumnSettings* colSettings = &this->settings->columns[col]; 79 | 80 | String_freeArray(colSettings->names); 81 | free(colSettings->modes); 82 | 83 | Vector* vec = this->columns[col]; 84 | int len = Vector_size(vec); 85 | 86 | colSettings->names = xCalloc(len+1, sizeof(char*)); 87 | colSettings->modes = xCalloc(len, sizeof(int)); 88 | colSettings->len = len; 89 | 90 | for (int i = 0; i < len; i++) { 91 | Meter* meter = (Meter*) Vector_get(vec, i); 92 | char* name = xCalloc(64, sizeof(char)); 93 | if (meter->param) { 94 | xSnprintf(name, 63, "%s(%d)", As_Meter(meter)->name, meter->param); 95 | } else { 96 | xSnprintf(name, 63, "%s", As_Meter(meter)->name); 97 | } 98 | colSettings->names[i] = name; 99 | colSettings->modes[i] = meter->mode; 100 | } 101 | } 102 | } 103 | 104 | MeterModeId Header_addMeterByName(Header* this, char* name, int column) { 105 | Vector* meters = this->columns[column]; 106 | 107 | char* paren = strchr(name, '('); 108 | int param = 0; 109 | if (paren) { 110 | int ok = sscanf(paren, "(%10d)", ¶m); 111 | if (!ok) param = 0; 112 | *paren = '\0'; 113 | } 114 | MeterModeId mode = TEXT_METERMODE; 115 | for (MeterClass** type = Platform_meterTypes; *type; type++) { 116 | if (String_eq(name, (*type)->name)) { 117 | Meter* meter = Meter_new(this->pl, param, *type); 118 | Vector_add(meters, meter); 119 | mode = meter->mode; 120 | break; 121 | } 122 | } 123 | return mode; 124 | } 125 | 126 | void Header_setMode(Header* this, int i, MeterModeId mode, int column) { 127 | Vector* meters = this->columns[column]; 128 | 129 | if (i >= Vector_size(meters)) 130 | return; 131 | Meter* meter = (Meter*) Vector_get(meters, i); 132 | Meter_setMode(meter, mode); 133 | } 134 | 135 | Meter* Header_addMeterByClass(Header* this, MeterClass* type, int param, int column) { 136 | Vector* meters = this->columns[column]; 137 | 138 | Meter* meter = Meter_new(this->pl, param, type); 139 | Vector_add(meters, meter); 140 | return meter; 141 | } 142 | 143 | int Header_size(Header* this, int column) { 144 | Vector* meters = this->columns[column]; 145 | return Vector_size(meters); 146 | } 147 | 148 | char* Header_readMeterName(Header* this, int i, int column) { 149 | Vector* meters = this->columns[column]; 150 | Meter* meter = (Meter*) Vector_get(meters, i); 151 | 152 | int nameLen = strlen(Meter_name(meter)); 153 | int len = nameLen + 100; 154 | char* name = xMalloc(len); 155 | strncpy(name, Meter_name(meter), nameLen); 156 | name[nameLen] = '\0'; 157 | if (meter->param) 158 | xSnprintf(name + nameLen, len - nameLen, "(%d)", meter->param); 159 | 160 | return name; 161 | } 162 | 163 | MeterModeId Header_readMeterMode(Header* this, int i, int column) { 164 | Vector* meters = this->columns[column]; 165 | 166 | Meter* meter = (Meter*) Vector_get(meters, i); 167 | return meter->mode; 168 | } 169 | 170 | void Header_reinit(Header* this) { 171 | Header_forEachColumn(this, col) { 172 | for (int i = 0; i < Vector_size(this->columns[col]); i++) { 173 | Meter* meter = (Meter*) Vector_get(this->columns[col], i); 174 | if (Meter_initFn(meter)) 175 | Meter_init(meter); 176 | } 177 | } 178 | } 179 | 180 | void Header_draw(const Header* this) { 181 | int height = this->height; 182 | int pad = this->pad; 183 | attrset(CRT_colors[RESET_COLOR]); 184 | for (int y = 0; y < height; y++) { 185 | mvhline(y, 0, ' ', COLS); 186 | } 187 | int width = COLS / this->nrColumns - (pad * this->nrColumns - 1) - 1; 188 | int x = pad; 189 | 190 | Header_forEachColumn(this, col) { 191 | Vector* meters = this->columns[col]; 192 | for (int y = (pad / 2), i = 0; i < Vector_size(meters); i++) { 193 | Meter* meter = (Meter*) Vector_get(meters, i); 194 | meter->draw(meter, x, y, width); 195 | y += meter->h; 196 | } 197 | x += width + pad; 198 | } 199 | } 200 | 201 | int Header_calculateHeight(Header* this) { 202 | int pad = this->settings->headerMargin ? 2 : 0; 203 | int maxHeight = pad; 204 | 205 | Header_forEachColumn(this, col) { 206 | Vector* meters = this->columns[col]; 207 | int height = pad; 208 | for (int i = 0; i < Vector_size(meters); i++) { 209 | Meter* meter = (Meter*) Vector_get(meters, i); 210 | height += meter->h; 211 | } 212 | maxHeight = MAX(maxHeight, height); 213 | } 214 | this->height = maxHeight; 215 | this->pad = pad; 216 | return maxHeight; 217 | } 218 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/IncSet.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - IncSet.c 3 | (C) 2005-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 "IncSet.h" 9 | #include "StringUtils.h" 10 | #include "Panel.h" 11 | #include "ListItem.h" 12 | #include "CRT.h" 13 | #include 14 | #include 15 | 16 | /*{ 17 | 18 | #include "FunctionBar.h" 19 | #include "Panel.h" 20 | #include 21 | 22 | #define INCMODE_MAX 40 23 | 24 | typedef enum { 25 | INC_SEARCH = 0, 26 | INC_FILTER = 1 27 | } IncType; 28 | 29 | #define IncSet_filter(inc_) (inc_->filtering ? inc_->modes[INC_FILTER].buffer : NULL) 30 | 31 | typedef struct IncMode_ { 32 | char buffer[INCMODE_MAX+1]; 33 | int index; 34 | FunctionBar* bar; 35 | bool isFilter; 36 | } IncMode; 37 | 38 | typedef struct IncSet_ { 39 | IncMode modes[2]; 40 | IncMode* active; 41 | FunctionBar* defaultBar; 42 | bool filtering; 43 | bool found; 44 | } IncSet; 45 | 46 | typedef const char* (*IncMode_GetPanelValue)(Panel*, int); 47 | 48 | }*/ 49 | 50 | static void IncMode_reset(IncMode* mode) { 51 | mode->index = 0; 52 | mode->buffer[0] = 0; 53 | } 54 | 55 | static const char* const searchFunctions[] = {"Next ", "Cancel ", " Search: ", NULL}; 56 | static const char* const searchKeys[] = {"F3", "Esc", " "}; 57 | static int searchEvents[] = {KEY_F(3), 27, ERR}; 58 | 59 | static inline void IncMode_initSearch(IncMode* search) { 60 | memset(search, 0, sizeof(IncMode)); 61 | search->bar = FunctionBar_new(searchFunctions, searchKeys, searchEvents); 62 | search->isFilter = false; 63 | } 64 | 65 | static const char* const filterFunctions[] = {"Done ", "Clear ", " Filter: ", NULL}; 66 | static const char* const filterKeys[] = {"Enter", "Esc", " "}; 67 | static int filterEvents[] = {13, 27, ERR}; 68 | 69 | static inline void IncMode_initFilter(IncMode* filter) { 70 | memset(filter, 0, sizeof(IncMode)); 71 | filter->bar = FunctionBar_new(filterFunctions, filterKeys, filterEvents); 72 | filter->isFilter = true; 73 | } 74 | 75 | static inline void IncMode_done(IncMode* mode) { 76 | FunctionBar_delete(mode->bar); 77 | } 78 | 79 | IncSet* IncSet_new(FunctionBar* bar) { 80 | IncSet* this = xCalloc(1, sizeof(IncSet)); 81 | IncMode_initSearch(&(this->modes[INC_SEARCH])); 82 | IncMode_initFilter(&(this->modes[INC_FILTER])); 83 | this->active = NULL; 84 | this->filtering = false; 85 | this->defaultBar = bar; 86 | return this; 87 | } 88 | 89 | void IncSet_delete(IncSet* this) { 90 | IncMode_done(&(this->modes[0])); 91 | IncMode_done(&(this->modes[1])); 92 | free(this); 93 | } 94 | 95 | static void updateWeakPanel(IncSet* this, Panel* panel, Vector* lines) { 96 | Object* selected = Panel_getSelected(panel); 97 | Panel_prune(panel); 98 | if (this->filtering) { 99 | int n = 0; 100 | const char* incFilter = this->modes[INC_FILTER].buffer; 101 | for (int i = 0; i < Vector_size(lines); i++) { 102 | ListItem* line = (ListItem*)Vector_get(lines, i); 103 | if (String_contains_i(line->value, incFilter)) { 104 | Panel_add(panel, (Object*)line); 105 | if (selected == (Object*)line) Panel_setSelected(panel, n); 106 | n++; 107 | } 108 | } 109 | } else { 110 | for (int i = 0; i < Vector_size(lines); i++) { 111 | Object* line = Vector_get(lines, i); 112 | Panel_add(panel, line); 113 | if (selected == line) Panel_setSelected(panel, i); 114 | } 115 | } 116 | } 117 | 118 | static bool search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelValue) { 119 | int size = Panel_size(panel); 120 | bool found = false; 121 | for (int i = 0; i < size; i++) { 122 | if (String_contains_i(getPanelValue(panel, i), mode->buffer)) { 123 | Panel_setSelected(panel, i); 124 | found = true; 125 | break; 126 | } 127 | } 128 | if (found) 129 | FunctionBar_draw(mode->bar, mode->buffer); 130 | else 131 | FunctionBar_drawAttr(mode->bar, mode->buffer, CRT_colors[FAILED_SEARCH]); 132 | return found; 133 | } 134 | 135 | bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines) { 136 | if (ch == ERR) 137 | return true; 138 | IncMode* mode = this->active; 139 | int size = Panel_size(panel); 140 | bool filterChanged = false; 141 | bool doSearch = true; 142 | if (ch == KEY_F(3)) { 143 | if (size == 0) return true; 144 | int here = Panel_getSelectedIndex(panel); 145 | int i = here; 146 | for(;;) { 147 | i++; 148 | if (i == size) i = 0; 149 | if (i == here) break; 150 | if (String_contains_i(getPanelValue(panel, i), mode->buffer)) { 151 | Panel_setSelected(panel, i); 152 | break; 153 | } 154 | } 155 | doSearch = false; 156 | } else if (ch < 255 && isprint((char)ch)) { 157 | if (mode->index < INCMODE_MAX) { 158 | mode->buffer[mode->index] = ch; 159 | mode->index++; 160 | mode->buffer[mode->index] = 0; 161 | if (mode->isFilter) { 162 | filterChanged = true; 163 | if (mode->index == 1) this->filtering = true; 164 | } 165 | } 166 | } else if ((ch == KEY_BACKSPACE || ch == 127)) { 167 | if (mode->index > 0) { 168 | mode->index--; 169 | mode->buffer[mode->index] = 0; 170 | if (mode->isFilter) { 171 | filterChanged = true; 172 | if (mode->index == 0) { 173 | this->filtering = false; 174 | IncMode_reset(mode); 175 | } 176 | } 177 | } else { 178 | doSearch = false; 179 | } 180 | } else if (ch == KEY_RESIZE) { 181 | Panel_resize(panel, COLS, LINES-panel->y-1); 182 | } else { 183 | if (mode->isFilter) { 184 | filterChanged = true; 185 | if (ch == 27) { 186 | this->filtering = false; 187 | IncMode_reset(mode); 188 | } 189 | } else { 190 | IncMode_reset(mode); 191 | } 192 | this->active = NULL; 193 | Panel_setDefaultBar(panel); 194 | FunctionBar_draw(this->defaultBar, NULL); 195 | doSearch = false; 196 | } 197 | if (doSearch) { 198 | this->found = search(mode, panel, getPanelValue); 199 | } 200 | if (filterChanged && lines) { 201 | updateWeakPanel(this, panel, lines); 202 | } 203 | return filterChanged; 204 | } 205 | 206 | const char* IncSet_getListItemValue(Panel* panel, int i) { 207 | ListItem* l = (ListItem*) Panel_get(panel, i); 208 | if (l) 209 | return l->value; 210 | return ""; 211 | } 212 | 213 | void IncSet_activate(IncSet* this, IncType type, Panel* panel) { 214 | this->active = &(this->modes[type]); 215 | FunctionBar_draw(this->active->bar, this->active->buffer); 216 | panel->currentBar = this->active->bar; 217 | } 218 | 219 | void IncSet_drawBar(IncSet* this) { 220 | if (this->active) { 221 | FunctionBar_draw(this->active->bar, this->active->buffer); 222 | } else { 223 | FunctionBar_draw(this->defaultBar, NULL); 224 | } 225 | } 226 | 227 | int IncSet_synthesizeEvent(IncSet* this, int x) { 228 | if (this->active) { 229 | return FunctionBar_synthesizeEvent(this->active->bar, x); 230 | } else { 231 | return FunctionBar_synthesizeEvent(this->defaultBar, x); 232 | } 233 | } 234 | -------------------------------------------------------------------------------- /htop/htop-2.1.1/freebsd/FreeBSDProcess.c: -------------------------------------------------------------------------------- 1 | /* 2 | htop - FreeBSDProcess.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 "ProcessList.h" 10 | #include "FreeBSDProcess.h" 11 | #include "Platform.h" 12 | #include "CRT.h" 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | /*{ 20 | 21 | typedef enum FreeBSDProcessFields { 22 | // Add platform-specific fields here, with ids >= 100 23 | JID = 100, 24 | JAIL = 101, 25 | LAST_PROCESSFIELD = 102, 26 | } FreeBSDProcessField; 27 | 28 | 29 | typedef struct FreeBSDProcess_ { 30 | Process super; 31 | int kernel; 32 | int jid; 33 | char* jname; 34 | } FreeBSDProcess; 35 | 36 | 37 | #ifndef Process_isKernelThread 38 | #define Process_isKernelThread(_process) (_process->kernel == 1) 39 | #endif 40 | 41 | #ifndef Process_isUserlandThread 42 | #define Process_isUserlandThread(_process) (_process->pid != _process->tgid) 43 | #endif 44 | 45 | }*/ 46 | 47 | ProcessClass FreeBSDProcess_class = { 48 | .super = { 49 | .extends = Class(Process), 50 | .display = Process_display, 51 | .delete = Process_delete, 52 | .compare = FreeBSDProcess_compare 53 | }, 54 | .writeField = (Process_WriteField) FreeBSDProcess_writeField, 55 | }; 56 | 57 | ProcessFieldData Process_fields[] = { 58 | [0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, }, 59 | [PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, }, 60 | [COMM] = { .name = "Command", .title = "Command ", .description = "Command line", .flags = 0, }, 61 | [STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging)", .flags = 0, }, 62 | [PPID] = { .name = "PPID", .title = " PPID ", .description = "Parent process ID", .flags = 0, }, 63 | [PGRP] = { .name = "PGRP", .title = " PGRP ", .description = "Process group ID", .flags = 0, }, 64 | [SESSION] = { .name = "SESSION", .title = " SID ", .description = "Process's session ID", .flags = 0, }, 65 | [TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", .flags = 0, }, 66 | [TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, }, 67 | [MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, }, 68 | [MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, }, 69 | [PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, }, 70 | [NICE] = { .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", .flags = 0, }, 71 | [STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", .flags = 0, }, 72 | 73 | [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, }, 74 | [M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, }, 75 | [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, }, 76 | [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, }, 77 | [PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, }, 78 | [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, }, 79 | [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, }, 80 | [TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, }, 81 | [NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, }, 82 | [TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, }, 83 | [JID] = { .name = "JID", .title = " JID ", .description = "Jail prison ID", .flags = 0, }, 84 | [JAIL] = { .name = "JAIL", .title = "JAIL ", .description = "Jail prison name", .flags = 0, }, 85 | [LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, }, 86 | }; 87 | 88 | ProcessPidColumn Process_pidColumns[] = { 89 | { .id = JID, .label = "JID" }, 90 | { .id = PID, .label = "PID" }, 91 | { .id = PPID, .label = "PPID" }, 92 | { .id = TPGID, .label = "TPGID" }, 93 | { .id = TGID, .label = "TGID" }, 94 | { .id = PGRP, .label = "PGRP" }, 95 | { .id = SESSION, .label = "SID" }, 96 | { .id = 0, .label = NULL }, 97 | }; 98 | 99 | FreeBSDProcess* FreeBSDProcess_new(Settings* settings) { 100 | FreeBSDProcess* this = xCalloc(1, sizeof(FreeBSDProcess)); 101 | Object_setClass(this, Class(FreeBSDProcess)); 102 | Process_init(&this->super, settings); 103 | return this; 104 | } 105 | 106 | void Process_delete(Object* cast) { 107 | FreeBSDProcess* this = (FreeBSDProcess*) cast; 108 | Process_done((Process*)cast); 109 | free(this->jname); 110 | free(this); 111 | } 112 | 113 | void FreeBSDProcess_writeField(Process* this, RichString* str, ProcessField field) { 114 | FreeBSDProcess* fp = (FreeBSDProcess*) this; 115 | char buffer[256]; buffer[255] = '\0'; 116 | int attr = CRT_colors[DEFAULT_COLOR]; 117 | int n = sizeof(buffer) - 1; 118 | switch ((int) field) { 119 | // add FreeBSD-specific fields here 120 | case JID: xSnprintf(buffer, n, Process_pidFormat, fp->jid); break; 121 | case JAIL:{ 122 | xSnprintf(buffer, n, "%-11s ", fp->jname); break; 123 | if (buffer[11] != '\0') { 124 | buffer[11] = ' '; 125 | buffer[12] = '\0'; 126 | } 127 | break; 128 | } 129 | default: 130 | Process_writeField(this, str, field); 131 | return; 132 | } 133 | RichString_append(str, attr, buffer); 134 | } 135 | 136 | long FreeBSDProcess_compare(const void* v1, const void* v2) { 137 | FreeBSDProcess *p1, *p2; 138 | Settings *settings = ((Process*)v1)->settings; 139 | if (settings->direction == 1) { 140 | p1 = (FreeBSDProcess*)v1; 141 | p2 = (FreeBSDProcess*)v2; 142 | } else { 143 | p2 = (FreeBSDProcess*)v1; 144 | p1 = (FreeBSDProcess*)v2; 145 | } 146 | switch ((int) settings->sortKey) { 147 | // add FreeBSD-specific fields here 148 | case JID: 149 | return (p1->jid - p2->jid); 150 | case JAIL: 151 | return strcmp(p1->jname ? p1->jname : "", p2->jname ? p2->jname : ""); 152 | default: 153 | return Process_compare(v1, v2); 154 | } 155 | } 156 | 157 | bool Process_isThread(Process* this) { 158 | FreeBSDProcess* fp = (FreeBSDProcess*) this; 159 | 160 | if (fp->kernel == 1 ) 161 | return 1; 162 | else 163 | return (Process_isUserlandThread(this)); 164 | } 165 | --------------------------------------------------------------------------------