mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-15 13:34:35 +03:00
Compare commits
39 Commits
3.0.0beta3
...
3.0.0beta4
Author | SHA1 | Date | |
---|---|---|---|
5c6d7cca3e | |||
6fe06fb7e5 | |||
657836a2ae | |||
63e1417b8c | |||
9b4bdfcb3e | |||
7a71f9cf32 | |||
c91b0938d5 | |||
4f934c977d | |||
d1696b5d5d | |||
beb47cbb12 | |||
677cac9fab | |||
6790e004cd | |||
8677162836 | |||
475798e8ab | |||
7689c5c3b7 | |||
c2ab3ac422 | |||
61bb649e0a | |||
b8ec1c0337 | |||
499af738e7 | |||
416ef48a62 | |||
b9e0da9200 | |||
509303323f | |||
421a31d6f1 | |||
d4c4c02b97 | |||
1ef20d1f14 | |||
1ab5afa1fe | |||
00d1fb019a | |||
dd175b6881 | |||
7ad9701a12 | |||
881fe9631a | |||
0de77c7075 | |||
0f71db9d82 | |||
da4010783e | |||
3f7622a302 | |||
df5d81a881 | |||
6c2b3b546d | |||
f48f5a10ca | |||
1aa23925c9 | |||
2e1f56d934 |
24
Action.c
24
Action.c
@ -155,6 +155,21 @@ static bool expandCollapse(Panel* panel) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool collapseIntoParent(Panel* panel) {
|
||||
Process* p = (Process*) Panel_getSelected(panel);
|
||||
if (!p) return false;
|
||||
pid_t ppid = Process_getParentPid(p);
|
||||
for (int i = 0; i < Panel_size(panel); i++) {
|
||||
Process* q = (Process*) Panel_get(panel, i);
|
||||
if (q->pid == ppid) {
|
||||
q->showChildren = false;
|
||||
Panel_setSelected(panel, i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey) {
|
||||
ScreenSettings* ss = settings->ss;
|
||||
ss->sortKey = sortKey;
|
||||
@ -264,6 +279,14 @@ static Htop_Reaction actionExpandOrCollapse(State* st) {
|
||||
return changed ? HTOP_RECALCULATE : HTOP_OK;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionCollapseIntoParent(State* st) {
|
||||
if (!st->settings->ss->treeView) {
|
||||
return HTOP_OK;
|
||||
}
|
||||
bool changed = collapseIntoParent(st->panel);
|
||||
return changed ? HTOP_RECALCULATE : HTOP_OK;
|
||||
}
|
||||
|
||||
static Htop_Reaction actionExpandCollapseOrSortColumn(State* st) {
|
||||
return st->settings->ss->treeView ? actionExpandOrCollapse(st) : actionSetSortColumn(st);
|
||||
}
|
||||
@ -570,6 +593,7 @@ void Action_setBindings(Htop_Action* keys) {
|
||||
keys['+'] = actionExpandOrCollapse;
|
||||
keys['='] = actionExpandOrCollapse;
|
||||
keys['-'] = actionExpandOrCollapse;
|
||||
keys['\177'] = actionCollapseIntoParent;
|
||||
keys['u'] = actionFilterByUser;
|
||||
keys['F'] = Action_follow;
|
||||
keys['S'] = actionSetup;
|
||||
|
136
Makefile.am
136
Makefile.am
@ -12,8 +12,8 @@ applications_DATA = htop.desktop
|
||||
pixmapdir = $(datadir)/pixmaps
|
||||
pixmap_DATA = htop.png
|
||||
|
||||
htop_CFLAGS = -pedantic -Wall $(wextra_flag) -std=c99 -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(top_srcdir)/$(my_htop_platform)"
|
||||
htop_LDFLAGS =
|
||||
AM_CFLAGS = -pedantic -Wall $(wextra_flag) -std=c99 -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(top_srcdir)/$(my_htop_platform)"
|
||||
AM_LDFLAGS =
|
||||
AM_CPPFLAGS = -DNDEBUG
|
||||
|
||||
myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \
|
||||
@ -36,66 +36,164 @@ TasksMeter.h UptimeMeter.h TraceScreen.h UsersTable.h Vector.h Process.h \
|
||||
AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h \
|
||||
EnvScreen.h InfoScreen.h XAlloc.h
|
||||
|
||||
all_platform_headers =
|
||||
|
||||
# Linux
|
||||
# -----
|
||||
|
||||
linux_platform_headers = \
|
||||
linux/Platform.h \
|
||||
linux/IOPriorityPanel.h \
|
||||
linux/IOPriority.h \
|
||||
linux/LinuxProcess.h \
|
||||
linux/LinuxProcessList.h \
|
||||
linux/LinuxCRT.h \
|
||||
linux/Battery.h \
|
||||
linux/PerfCounter.h
|
||||
|
||||
all_platform_headers += $(linux_platform_headers)
|
||||
|
||||
if HTOP_LINUX
|
||||
htop_CFLAGS += -rdynamic
|
||||
AM_CFLAGS += -rdynamic
|
||||
myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \
|
||||
linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c \
|
||||
linux/PerfCounter.c
|
||||
|
||||
myhtopplatheaders = linux/Platform.h linux/IOPriorityPanel.h linux/IOPriority.h \
|
||||
linux/LinuxProcess.h linux/LinuxProcessList.h linux/LinuxCRT.h linux/Battery.h \
|
||||
linux/PerfCounter.h
|
||||
myhtopplatheaders = $(linux_platform_headers)
|
||||
endif
|
||||
|
||||
# FreeBSD
|
||||
# -------
|
||||
|
||||
freebsd_platform_headers = \
|
||||
freebsd/Platform.h \
|
||||
freebsd/FreeBSDProcessList.h \
|
||||
freebsd/FreeBSDProcess.h \
|
||||
freebsd/FreeBSDCRT.h \
|
||||
freebsd/Battery.h
|
||||
|
||||
all_platform_headers += $(freebsd_platform_headers)
|
||||
|
||||
if HTOP_FREEBSD
|
||||
myhtopplatsources = freebsd/Platform.c freebsd/FreeBSDProcessList.c \
|
||||
freebsd/FreeBSDProcess.c freebsd/FreeBSDCRT.c freebsd/Battery.c
|
||||
|
||||
myhtopplatheaders = freebsd/Platform.h freebsd/FreeBSDProcessList.h \
|
||||
freebsd/FreeBSDProcess.h freebsd/FreeBSDCRT.h freebsd/Battery.h
|
||||
myhtopplatheaders = $(freebsd_platform_headers)
|
||||
endif
|
||||
|
||||
# DragonFlyBSD
|
||||
# ------------
|
||||
|
||||
dragonflybsd_platform_headers = \
|
||||
dragonflybsd/Platform.h \
|
||||
dragonflybsd/DragonFlyBSDProcessList.h \
|
||||
dragonflybsd/DragonFlyBSDProcess.h \
|
||||
dragonflybsd/DragonFlyBSDCRT.h \
|
||||
dragonflybsd/Battery.h
|
||||
|
||||
all_platform_headers += $(dragonflybsd_platform_headers)
|
||||
|
||||
if HTOP_DRAGONFLYBSD
|
||||
htop_LDFLAGS += -lkvm -lkinfo -lexecinfo
|
||||
AM_LDFLAGS += -lkvm -lkinfo -lexecinfo
|
||||
myhtopplatsources = dragonflybsd/Platform.c dragonflybsd/DragonFlyBSDProcessList.c \
|
||||
dragonflybsd/DragonFlyBSDProcess.c dragonflybsd/DragonFlyBSDCRT.c dragonflybsd/Battery.c
|
||||
|
||||
myhtopplatheaders = dragonflybsd/Platform.h dragonflybsd/DragonFlyBSDProcessList.h \
|
||||
dragonflybsd/DragonFlyBSDProcess.h dragonflybsd/DragonFlyBSDCRT.h dragonflybsd/Battery.h
|
||||
myhtopplatheaders = $(dragonflybsd_platform_headers)
|
||||
endif
|
||||
|
||||
# OpenBSD
|
||||
# -------
|
||||
|
||||
openbsd_platform_headers = \
|
||||
openbsd/Platform.h \
|
||||
openbsd/OpenBSDProcessList.h \
|
||||
openbsd/OpenBSDProcess.h \
|
||||
openbsd/OpenBSDCRT.h \
|
||||
openbsd/Battery.h
|
||||
|
||||
all_platform_headers += $(openbsd_platform_headers)
|
||||
|
||||
if HTOP_OPENBSD
|
||||
myhtopplatsources = openbsd/Platform.c openbsd/OpenBSDProcessList.c \
|
||||
openbsd/OpenBSDProcess.c openbsd/OpenBSDCRT.c openbsd/Battery.c
|
||||
|
||||
myhtopplatheaders = openbsd/Platform.h openbsd/OpenBSDProcessList.h \
|
||||
openbsd/OpenBSDProcess.h openbsd/OpenBSDCRT.h openbsd/Battery.h
|
||||
myhtopplatheaders = $(openbsd_platform_headers)
|
||||
endif
|
||||
|
||||
# Darwin
|
||||
# ------
|
||||
|
||||
darwin_platform_headers = \
|
||||
darwin/Platform.h \
|
||||
darwin/DarwinProcess.h \
|
||||
darwin/DarwinProcessList.h \
|
||||
darwin/DarwinCRT.h \
|
||||
darwin/Battery.h
|
||||
|
||||
all_platform_headers += $(darwin_platform_headers)
|
||||
|
||||
if HTOP_DARWIN
|
||||
htop_LDFLAGS += -framework IOKit -framework CoreFoundation
|
||||
AM_LDFLAGS += -framework IOKit -framework CoreFoundation
|
||||
myhtopplatsources = darwin/Platform.c darwin/DarwinProcess.c \
|
||||
darwin/DarwinProcessList.c darwin/DarwinCRT.c darwin/Battery.c
|
||||
|
||||
myhtopplatheaders = darwin/Platform.h darwin/DarwinProcess.h \
|
||||
darwin/DarwinProcessList.h darwin/DarwinCRT.h darwin/Battery.h
|
||||
myhtopplatheaders = $(darwin_platform_headers)
|
||||
endif
|
||||
|
||||
# Solaris
|
||||
# -------
|
||||
|
||||
solaris_platform_headers = \
|
||||
solaris/Platform.h \
|
||||
solaris/SolarisProcess.h \
|
||||
solaris/SolarisProcessList.h \
|
||||
solaris/SolarisCRT.h \
|
||||
solaris/Battery.h
|
||||
|
||||
all_platform_headers += $(solaris_platform_headers)
|
||||
|
||||
if HTOP_SOLARIS
|
||||
myhtopplatsources = solaris/Platform.c \
|
||||
solaris/SolarisProcess.c solaris/SolarisProcessList.c \
|
||||
solaris/SolarisCRT.c solaris/Battery.c
|
||||
|
||||
myhtopplatheaders = $(solaris_platform_headers)
|
||||
endif
|
||||
|
||||
# Unsupported
|
||||
# -----------
|
||||
|
||||
unsupported_platform_headers = \
|
||||
unsupported/Platform.h \
|
||||
unsupported/UnsupportedProcess.h \
|
||||
unsupported/UnsupportedProcessList.h \
|
||||
unsupported/UnsupportedCRT.h \
|
||||
unsupported/Battery.h
|
||||
|
||||
all_platform_headers += $(unsupported_platform_headers)
|
||||
|
||||
if HTOP_UNSUPPORTED
|
||||
myhtopplatsources = unsupported/Platform.c \
|
||||
unsupported/UnsupportedProcess.c unsupported/UnsupportedProcessList.c \
|
||||
unsupported/UnsupportedCRT.c unsupported/Battery.c
|
||||
|
||||
myhtopplatheaders = unsupported/Platform.h \
|
||||
unsupported/UnsupportedProcess.h unsupported/UnsupportedProcessList.h \
|
||||
unsupported/UnsupportedCRT.h unsupported/Battery.h
|
||||
myhtopplatheaders = $(unsupported_platform_headers)
|
||||
endif
|
||||
|
||||
# ----
|
||||
|
||||
SUFFIXES = .h
|
||||
|
||||
BUILT_SOURCES = $(myhtopheaders) $(myhtopplatheaders)
|
||||
htop_SOURCES = $(myhtopheaders) $(myhtopplatheaders) $(myhtopsources) $(myhtopplatsources) config.h
|
||||
|
||||
.PHONY: htop-headers clean-htop-headers
|
||||
|
||||
htop-headers: $(myhtopheaders) $(all_platform_headers)
|
||||
|
||||
clean-htop-headers:
|
||||
-rm -f $(myhtopheaders) $(all_platform_headers)
|
||||
|
||||
target:
|
||||
echo $(htop_SOURCES)
|
||||
|
||||
|
@ -76,16 +76,35 @@ void OpenFilesScreen_draw(InfoScreen* this) {
|
||||
}
|
||||
|
||||
static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
||||
char command[1025];
|
||||
xSnprintf(command, 1024, "lsof -P -p %d -F 2> /dev/null", pid);
|
||||
FILE* fd = popen(command, "r");
|
||||
char buffer[1025];
|
||||
xSnprintf(buffer, 1024, "%d", pid);
|
||||
OpenFiles_ProcessData* pdata = xCalloc(1, sizeof(OpenFiles_ProcessData));
|
||||
OpenFiles_FileData* fdata = NULL;
|
||||
OpenFiles_Data* item = &(pdata->data);
|
||||
if (!fd) {
|
||||
pdata->error = 127;
|
||||
int fdpair[2];
|
||||
if (pipe(fdpair) == -1) {
|
||||
pdata->error = 1;
|
||||
return pdata;
|
||||
}
|
||||
pid_t child = fork();
|
||||
if (child == -1) {
|
||||
pdata->error = 1;
|
||||
return pdata;
|
||||
}
|
||||
if (child == 0) {
|
||||
close(fdpair[0]);
|
||||
dup2(fdpair[1], STDOUT_FILENO);
|
||||
close(fdpair[1]);
|
||||
int fdnull = open("/dev/null", O_WRONLY);
|
||||
if (fdnull < 0)
|
||||
exit(1);
|
||||
dup2(fdnull, STDERR_FILENO);
|
||||
close(fdnull);
|
||||
execlp("lsof", "lsof", "-P", "-p", buffer, "-F", NULL);
|
||||
exit(127);
|
||||
}
|
||||
close(fdpair[1]);
|
||||
FILE* fd = fdopen(fdpair[0], "r");
|
||||
for (;;) {
|
||||
char* line = String_readLine(fd);
|
||||
if (!line) {
|
||||
@ -105,7 +124,15 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
|
||||
item->data[cmd] = xStrdup(line + 1);
|
||||
free(line);
|
||||
}
|
||||
pdata->error = pclose(fd);
|
||||
int wstatus;
|
||||
if (waitpid(child, &wstatus, 0) == -1) {
|
||||
pdata->error = 1;
|
||||
return pdata;
|
||||
}
|
||||
if (!WIFEXITED(wstatus))
|
||||
pdata->error = 1;
|
||||
else
|
||||
pdata->error = WEXITSTATUS(wstatus);
|
||||
return pdata;
|
||||
}
|
||||
|
||||
|
@ -179,6 +179,8 @@ typedef struct ProcessClass_ {
|
||||
|
||||
#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
|
||||
|
||||
#define Process_getParentPid(process_) (process_->tgid == process_->pid ? process_->ppid : process_->tgid)
|
||||
|
||||
#define Process_isChildOf(process_, pid_) (process_->tgid == pid_ || (process_->tgid == process_->pid && process_->ppid == pid_))
|
||||
|
||||
#define Process_sortState(state) ((state) == 'I' ? 0x100 : (state))
|
||||
|
@ -157,6 +157,8 @@ typedef struct ProcessClass_ {
|
||||
|
||||
#define As_Process(this_) ((ProcessClass*)((this_)->super.klass))
|
||||
|
||||
#define Process_getParentPid(process_) (process_->tgid == process_->pid ? process_->ppid : process_->tgid)
|
||||
|
||||
#define Process_isChildOf(process_, pid_) (process_->tgid == pid_ || (process_->tgid == process_->pid && process_->ppid == pid_))
|
||||
|
||||
#define Process_sortState(state) ((state) == 'I' ? 0x100 : (state))
|
||||
|
@ -229,7 +229,7 @@ void ProcessList_sort(ProcessList* this) {
|
||||
ProcessList_buildTree(this, process->pid, 0, 0, direction, false);
|
||||
break;
|
||||
}
|
||||
pid_t ppid = process->tgid == process->pid ? process->ppid : process->tgid;
|
||||
pid_t ppid = Process_getParentPid(process);
|
||||
// Bisect the process vector to find parent
|
||||
int l = 0, r = size;
|
||||
// If PID corresponds with PPID (e.g. "kernel_task" (PID:0, PPID:0)
|
||||
|
19
Settings.c
19
Settings.c
@ -23,6 +23,12 @@ in the source distribution for its full text.
|
||||
#include "Process.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
const char* name;
|
||||
const char* columns;
|
||||
const char* sortKey;
|
||||
} ScreenDefaults;
|
||||
|
||||
typedef struct {
|
||||
int len;
|
||||
char** names;
|
||||
@ -266,14 +272,11 @@ ScreenSettings* Settings_newScreen(Settings* this, const char* name, const char*
|
||||
}
|
||||
|
||||
static void Settings_defaultScreens(Settings* this) {
|
||||
Settings_newScreen(this, "Default", "PID USER PRIORITY NICE M_SIZE M_RESIDENT M_SHARE STATE PERCENT_CPU PERCENT_MEM TIME Command");
|
||||
this->screens[0]->sortKey = toFieldIndex("PERCENT_CPU");
|
||||
Settings_newScreen(this, "I/O", "PID USER IO_PRIORITY IO_RATE IO_READ_RATE IO_WRITE_RATE PERCENT_SWAP_DELAY PERCENT_IO_DELAY Command");
|
||||
this->screens[1]->sortKey = toFieldIndex("IO_RATE");
|
||||
Settings_newScreen(this, "Perf Counters", "PID USER PERCENT_CPU PROCESSOR MCYCLE MINSTR IPC PERCENT_MISS PERCENT_BMISS Command");
|
||||
this->screens[2]->sortKey = toFieldIndex("MCYCLE");
|
||||
Settings_newScreen(this, "L1 Data Cache", "PID USER PERCENT_CPU L1DREADS L1DRMISSES L1DWRITES L1DWMISSES Command");
|
||||
this->screens[3]->sortKey = toFieldIndex("L1DREADS");
|
||||
for (unsigned int i = 0; i < Platform_numberOfDefaultScreens; i++) {
|
||||
ScreenDefaults* defaults = &Platform_defaultScreens[i];
|
||||
Settings_newScreen(this, defaults->name, defaults->columns);
|
||||
this->screens[0]->sortKey = toFieldIndex(defaults->sortKey);
|
||||
}
|
||||
}
|
||||
|
||||
static bool Settings_read(Settings* this, const char* fileName) {
|
||||
|
@ -14,6 +14,12 @@ in the source distribution for its full text.
|
||||
#include "Process.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
const char* name;
|
||||
const char* columns;
|
||||
const char* sortKey;
|
||||
} ScreenDefaults;
|
||||
|
||||
typedef struct {
|
||||
int len;
|
||||
char** names;
|
||||
|
@ -41,10 +41,10 @@ Panel* SignalsPanel_new() {
|
||||
}
|
||||
#if (defined(SIGRTMIN) && defined(SIGRTMAX))
|
||||
if (SIGRTMAX - SIGRTMIN <= 100) {
|
||||
static char buf[15];
|
||||
static char buf[16];
|
||||
for (int sig = SIGRTMIN; sig <= SIGRTMAX; i++, sig++) {
|
||||
int n = sig - SIGRTMIN;
|
||||
xSnprintf(buf, 15, "%2d SIGRTMIN%-+3d", sig, n);
|
||||
xSnprintf(buf, 16, "%2d SIGRTMIN%-+3d", sig, n);
|
||||
if (n == 0) {
|
||||
buf[11] = '\0';
|
||||
}
|
||||
|
@ -27,11 +27,11 @@ in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
char* String_cat(const char* s1, const char* s2) {
|
||||
int l1 = strlen(s1);
|
||||
int l2 = strlen(s2);
|
||||
size_t l1 = strlen(s1);
|
||||
size_t l2 = strlen(s2);
|
||||
char* out = xMalloc(l1 + l2 + 1);
|
||||
strncpy(out, s1, l1);
|
||||
strncpy(out+l1, s2, l2+1);
|
||||
strncpy(out + l1, s2, l2 + 1);
|
||||
return out;
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ char* String_trim(const char* in) {
|
||||
while (in[0] == ' ' || in[0] == '\t' || in[0] == '\n') {
|
||||
in++;
|
||||
}
|
||||
int len = strlen(in);
|
||||
size_t len = strlen(in);
|
||||
while (len > 0 && (in[len-1] == ' ' || in[len-1] == '\t' || in[len-1] == '\n')) {
|
||||
len--;
|
||||
}
|
||||
@ -80,7 +80,7 @@ char** String_split(const char* s, char sep, int* n) {
|
||||
s += size + 1;
|
||||
}
|
||||
if (s[0] != '\0') {
|
||||
int size = strlen(s);
|
||||
size_t size = strlen(s);
|
||||
char* token = xMalloc(size + 1);
|
||||
strncpy(token, s, size + 1);
|
||||
out[ctr] = token;
|
||||
|
@ -101,7 +101,7 @@ bool TraceScreen_forkTracer(TraceScreen* this) {
|
||||
int ok = fcntl(this->fdpair[1], F_SETFL, O_NONBLOCK);
|
||||
if (ok != -1) {
|
||||
xSnprintf(buffer, sizeof(buffer), "%d", this->super.process->pid);
|
||||
execlp("strace", "strace", "-p", buffer, NULL);
|
||||
execlp("strace", "strace", "-s", "512", "-p", buffer, NULL);
|
||||
}
|
||||
const char* message = "Could not execute 'strace'. Please make sure it is available in your $PATH.";
|
||||
ssize_t written = write(this->fdpair[1], message, strlen(message));
|
||||
|
12
configure.ac
12
configure.ac
@ -2,7 +2,7 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ(2.65)
|
||||
AC_INIT([htop],[3.0.0beta3],[hisham@gobolinux.org])
|
||||
AC_INIT([htop],[3.0.0beta4],[hisham@gobolinux.org])
|
||||
|
||||
SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH:-$(date +%s)}"
|
||||
year=$(date -u -d "@$SOURCE_DATE_EPOCH" "+%Y" 2>/dev/null || date -u -r "$SOURCE_DATE_EPOCH" "+%Y" 2>/dev/null || date -u "+%Y")
|
||||
@ -43,6 +43,9 @@ dragonfly*)
|
||||
darwin*)
|
||||
my_htop_platform=darwin
|
||||
;;
|
||||
solaris*)
|
||||
my_htop_platform=solaris
|
||||
;;
|
||||
*)
|
||||
my_htop_platform=unsupported
|
||||
;;
|
||||
@ -238,6 +241,12 @@ if test "$my_htop_platform" = "openbsd"; then
|
||||
AC_CHECK_LIB([kvm], [kvm_open], [], [missing_libraries="$missing_libraries libkvm"])
|
||||
fi
|
||||
|
||||
if test "$my_htop_platform" = "solaris"; then
|
||||
AC_CHECK_LIB([kstat], [kstat_open], [], [missing_libraries="$missing_libraries libkstat"])
|
||||
AC_CHECK_LIB([proc], [Pgrab_error], [], [missing_libraries="$missing_libraries libproc"])
|
||||
AC_CHECK_LIB([malloc], [free], [], [missing_libraries="$missing_libraries libmalloc"])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(linux_affinity, [AS_HELP_STRING([--enable-linux-affinity], [enable Linux sched_setaffinity and sched_getaffinity for affinity support, disables hwloc])], ,enable_linux_affinity="yes")
|
||||
if test "x$enable_linux_affinity" = xyes -a "x$cross_compiling" = xno; then
|
||||
AC_MSG_CHECKING([for usable sched_setaffinity])
|
||||
@ -348,6 +357,7 @@ AM_CONDITIONAL([HTOP_FREEBSD], [test "$my_htop_platform" = freebsd])
|
||||
AM_CONDITIONAL([HTOP_DRAGONFLYBSD], [test "$my_htop_platform" = dragonflybsd])
|
||||
AM_CONDITIONAL([HTOP_OPENBSD], [test "$my_htop_platform" = openbsd])
|
||||
AM_CONDITIONAL([HTOP_DARWIN], [test "$my_htop_platform" = darwin])
|
||||
AM_CONDITIONAL([HTOP_SOLARIS], [test "$my_htop_platform" = solaris])
|
||||
AM_CONDITIONAL([HTOP_UNSUPPORTED], [test "$my_htop_platform" = unsupported])
|
||||
AC_SUBST(my_htop_platform)
|
||||
AC_CONFIG_FILES([Makefile htop.1])
|
||||
|
@ -18,6 +18,8 @@ in the source distribution for its full text.
|
||||
#include <sys/mman.h>
|
||||
#include <utmpx.h>
|
||||
#include <err.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/*{
|
||||
#include "ProcessList.h"
|
||||
@ -38,19 +40,51 @@ typedef struct DarwinProcessList_ {
|
||||
|
||||
}*/
|
||||
|
||||
typedef struct kern {
|
||||
short int version[3];
|
||||
} kern_;
|
||||
|
||||
static void getKernelVersion(struct kern *k) {
|
||||
static short int version_[3] = {0};
|
||||
if (!version_[0]) {
|
||||
// just in case it fails someday
|
||||
version_[0] = version_[1] = version_[2] = -1;
|
||||
char str[256] = {0};
|
||||
size_t size = sizeof(str);
|
||||
int ret = sysctlbyname("kern.osrelease", str, &size, NULL, 0);
|
||||
if (ret == 0) sscanf(str, "%hd.%hd.%hd", &version_[0], &version_[1], &version_[2]);
|
||||
}
|
||||
memcpy(k->version, version_, sizeof(version_));
|
||||
}
|
||||
|
||||
static int compareKernelVersion(short int major, short int minor, short int component) {
|
||||
/*
|
||||
compare the given os version with the one installed returns:
|
||||
0 if equals the installed version
|
||||
positive value if less than the installed version
|
||||
negative value if more than the installed version
|
||||
*/
|
||||
struct kern k;
|
||||
getKernelVersion(&k);
|
||||
if ( k.version[0] != major) return k.version[0] - major;
|
||||
if ( k.version[1] != minor) return k.version[1] - minor;
|
||||
if ( k.version[2] != component) return k.version[2] - component;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ProcessList_getHostInfo(host_basic_info_data_t *p) {
|
||||
mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT;
|
||||
|
||||
if(0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) {
|
||||
CRT_fatalError("Unable to retrieve host info\n");
|
||||
if (0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) {
|
||||
CRT_fatalError("Unable to retrieve host info\n");
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) {
|
||||
if(NULL != p && NULL != *p) {
|
||||
if(0 != munmap(*p, vm_page_size)) {
|
||||
CRT_fatalError("Unable to free old CPU load information\n");
|
||||
}
|
||||
if (NULL != p && NULL != *p) {
|
||||
if (0 != munmap(*p, vm_page_size)) {
|
||||
CRT_fatalError("Unable to free old CPU load information\n");
|
||||
}
|
||||
}
|
||||
|
||||
*p = NULL;
|
||||
@ -61,7 +95,7 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
|
||||
unsigned cpu_count;
|
||||
|
||||
// TODO Improving the accuracy of the load counts woule help a lot.
|
||||
if(0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t *)p, &info_size)) {
|
||||
if (0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t *)p, &info_size)) {
|
||||
CRT_fatalError("Unable to retrieve CPU info\n");
|
||||
}
|
||||
|
||||
@ -69,10 +103,10 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
|
||||
}
|
||||
|
||||
void ProcessList_getVMStats(vm_statistics_t p) {
|
||||
mach_msg_type_number_t info_size = HOST_VM_INFO_COUNT;
|
||||
mach_msg_type_number_t info_size = HOST_VM_INFO_COUNT;
|
||||
|
||||
if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)p, &info_size) != 0)
|
||||
CRT_fatalError("Unable to retrieve VM statistics\n");
|
||||
if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)p, &info_size) != 0)
|
||||
CRT_fatalError("Unable to retrieve VM statistics\n");
|
||||
}
|
||||
|
||||
struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) {
|
||||
@ -127,61 +161,65 @@ void ProcessList_delete(ProcessList* this) {
|
||||
}
|
||||
|
||||
void ProcessList_goThroughEntries(ProcessList* super) {
|
||||
DarwinProcessList *dpl = (DarwinProcessList *)super;
|
||||
bool preExisting = true;
|
||||
struct kinfo_proc *ps;
|
||||
size_t count;
|
||||
DarwinProcess *proc;
|
||||
struct timeval tv;
|
||||
DarwinProcessList *dpl = (DarwinProcessList *)super;
|
||||
bool preExisting = true;
|
||||
struct kinfo_proc *ps;
|
||||
size_t count;
|
||||
DarwinProcess *proc;
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday(&tv, NULL); /* Start processing time */
|
||||
gettimeofday(&tv, NULL); /* Start processing time */
|
||||
|
||||
/* Update the global data (CPU times and VM stats) */
|
||||
ProcessList_freeCPULoadInfo(&dpl->prev_load);
|
||||
dpl->prev_load = dpl->curr_load;
|
||||
ProcessList_allocateCPULoadInfo(&dpl->curr_load);
|
||||
ProcessList_getVMStats(&dpl->vm_stats);
|
||||
/* Update the global data (CPU times and VM stats) */
|
||||
ProcessList_freeCPULoadInfo(&dpl->prev_load);
|
||||
dpl->prev_load = dpl->curr_load;
|
||||
ProcessList_allocateCPULoadInfo(&dpl->curr_load);
|
||||
ProcessList_getVMStats(&dpl->vm_stats);
|
||||
|
||||
/* Get the time difference */
|
||||
dpl->global_diff = 0;
|
||||
for(int i = 0; i < dpl->super.cpuCount; ++i) {
|
||||
for(size_t j = 0; j < CPU_STATE_MAX; ++j) {
|
||||
dpl->global_diff += dpl->curr_load[i].cpu_ticks[j] - dpl->prev_load[i].cpu_ticks[j];
|
||||
}
|
||||
}
|
||||
/* Get the time difference */
|
||||
dpl->global_diff = 0;
|
||||
for(int i = 0; i < dpl->super.cpuCount; ++i) {
|
||||
for(size_t j = 0; j < CPU_STATE_MAX; ++j) {
|
||||
dpl->global_diff += dpl->curr_load[i].cpu_ticks[j] - dpl->prev_load[i].cpu_ticks[j];
|
||||
}
|
||||
}
|
||||
|
||||
/* Clear the thread counts */
|
||||
super->kernelThreads = 0;
|
||||
super->userlandThreads = 0;
|
||||
super->totalTasks = 0;
|
||||
super->runningTasks = 0;
|
||||
/* Clear the thread counts */
|
||||
super->kernelThreads = 0;
|
||||
super->userlandThreads = 0;
|
||||
super->totalTasks = 0;
|
||||
super->runningTasks = 0;
|
||||
|
||||
/* We use kinfo_procs for initial data since :
|
||||
*
|
||||
* 1) They always succeed.
|
||||
* 2) The contain the basic information.
|
||||
*
|
||||
* We attempt to fill-in additional information with libproc.
|
||||
*/
|
||||
ps = ProcessList_getKInfoProcs(&count);
|
||||
/* We use kinfo_procs for initial data since :
|
||||
*
|
||||
* 1) They always succeed.
|
||||
* 2) The contain the basic information.
|
||||
*
|
||||
* We attempt to fill-in additional information with libproc.
|
||||
*/
|
||||
ps = ProcessList_getKInfoProcs(&count);
|
||||
|
||||
for(size_t i = 0; i < count; ++i) {
|
||||
proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, (Process_New)DarwinProcess_new);
|
||||
for(size_t i = 0; i < count; ++i) {
|
||||
proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, (Process_New)DarwinProcess_new);
|
||||
|
||||
DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], tv.tv_sec, preExisting);
|
||||
DarwinProcess_setFromLibprocPidinfo(proc, dpl);
|
||||
|
||||
// Disabled due to bug in macOS High Sierra
|
||||
// DarwinProcess_scanThreads(proc);
|
||||
DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], tv.tv_sec, preExisting);
|
||||
DarwinProcess_setFromLibprocPidinfo(proc, dpl);
|
||||
|
||||
super->totalTasks += 1;
|
||||
// Disabled for High Sierra due to bug in macOS High Sierra
|
||||
bool isScanThreadSupported = ! ( compareKernelVersion(17, 0, 0) >= 0 && compareKernelVersion(17, 5, 0) < 0);
|
||||
|
||||
if(!preExisting) {
|
||||
proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid);
|
||||
if (isScanThreadSupported){
|
||||
DarwinProcess_scanThreads(proc);
|
||||
}
|
||||
|
||||
ProcessList_add(super, &proc->super);
|
||||
}
|
||||
}
|
||||
super->totalTasks += 1;
|
||||
|
||||
free(ps);
|
||||
if (!preExisting) {
|
||||
proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid);
|
||||
|
||||
ProcessList_add(super, &proc->super);
|
||||
}
|
||||
}
|
||||
|
||||
free(ps);
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ typedef struct DarwinProcessList_ {
|
||||
} DarwinProcessList;
|
||||
|
||||
|
||||
|
||||
void ProcessList_getHostInfo(host_basic_info_data_t *p);
|
||||
|
||||
void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p);
|
||||
|
@ -36,7 +36,15 @@ typedef enum DarwinProcessFields {
|
||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||
#endif
|
||||
|
||||
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
||||
ScreenDefaults Platform_defaultScreens[] = {
|
||||
{
|
||||
.name = "Default",
|
||||
.columns = "PID USER PRIORITY NICE M_SIZE M_RESIDENT STATE PERCENT_CPU PERCENT_MEM TIME Command",
|
||||
.sortKey = "PERCENT_CPU",
|
||||
},
|
||||
};
|
||||
|
||||
const unsigned int Platform_numberOfDefaultScreens = sizeof(Platform_defaultScreens)/sizeof(ScreenDefaults);
|
||||
|
||||
const SignalItem Platform_signals[] = {
|
||||
{ .name = " 0 Cancel", .number = 0 },
|
||||
|
@ -20,11 +20,14 @@ typedef enum DarwinProcessFields {
|
||||
LAST_PROCESSFIELD = 100,
|
||||
} DarwinProcessField;
|
||||
|
||||
|
||||
#ifndef CLAMP
|
||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||
#endif
|
||||
|
||||
extern ProcessField Platform_defaultFields[];
|
||||
extern ScreenDefaults Platform_defaultScreens[];
|
||||
|
||||
extern const unsigned int Platform_numberOfDefaultScreens;
|
||||
|
||||
extern const SignalItem Platform_signals[];
|
||||
|
||||
|
@ -40,7 +40,15 @@ extern ProcessFieldData Process_fields[];
|
||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||
#endif
|
||||
|
||||
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
||||
ScreenDefaults Platform_defaultScreens[] = {
|
||||
{
|
||||
.name = "Default",
|
||||
.columns = "PID USER PRIORITY NICE M_SIZE M_RESIDENT STATE PERCENT_CPU PERCENT_MEM TIME Command",
|
||||
.sortKey = "PERCENT_CPU",
|
||||
},
|
||||
};
|
||||
|
||||
const unsigned int Platform_numberOfDefaultScreens = sizeof(Platform_defaultScreens)/sizeof(ScreenDefaults);
|
||||
|
||||
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
||||
|
||||
|
@ -21,7 +21,9 @@ extern ProcessFieldData Process_fields[];
|
||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||
#endif
|
||||
|
||||
extern ProcessField Platform_defaultFields[];
|
||||
extern ScreenDefaults Platform_defaultScreens[];
|
||||
|
||||
extern const unsigned int Platform_numberOfDefaultScreens;
|
||||
|
||||
extern int Platform_numberOfFields;
|
||||
|
||||
|
@ -39,6 +39,16 @@ extern ProcessFieldData Process_fields[];
|
||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||
#endif
|
||||
|
||||
ScreenDefaults Platform_defaultScreens[] = {
|
||||
{
|
||||
.name = "Default",
|
||||
.columns = "PID USER PRIORITY NICE M_SIZE M_RESIDENT STATE PERCENT_CPU PERCENT_MEM TIME Command",
|
||||
.sortKey = "PERCENT_CPU",
|
||||
},
|
||||
};
|
||||
|
||||
const unsigned int Platform_numberOfDefaultScreens = sizeof(Platform_defaultScreens)/sizeof(ScreenDefaults);
|
||||
|
||||
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
||||
|
||||
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
||||
|
@ -20,6 +20,10 @@ extern ProcessFieldData Process_fields[];
|
||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||
#endif
|
||||
|
||||
extern ScreenDefaults Platform_defaultScreens[];
|
||||
|
||||
extern const unsigned int Platform_numberOfDefaultScreens;
|
||||
|
||||
extern ProcessField Platform_defaultFields[];
|
||||
|
||||
extern int Platform_numberOfFields;
|
||||
|
11
htop.c
11
htop.c
@ -42,6 +42,7 @@ static void printHelpFlag() {
|
||||
"-d --delay=DELAY Set the delay between updates, in tenths of seconds\n"
|
||||
"-h --help Print this help screen\n"
|
||||
"-s --sort-key=COLUMN Sort by COLUMN (try --sort-key=help for a list)\n"
|
||||
"-t --tree Show the tree view by default\n"
|
||||
"-u --user=USERNAME Show only processes of a given user\n"
|
||||
"-p --pid=PID,[,PID,PID...] Show only the given PIDs\n"
|
||||
"-v --version Print version info\n"
|
||||
@ -61,6 +62,7 @@ typedef struct CommandLineSettings_ {
|
||||
int sortKey;
|
||||
int delay;
|
||||
bool useColors;
|
||||
bool treeView;
|
||||
} CommandLineSettings;
|
||||
|
||||
static CommandLineSettings parseArguments(int argc, char** argv) {
|
||||
@ -71,6 +73,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
|
||||
.sortKey = 0,
|
||||
.delay = -1,
|
||||
.useColors = true,
|
||||
.treeView = false,
|
||||
};
|
||||
|
||||
static struct option long_opts[] =
|
||||
@ -82,6 +85,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
|
||||
{"user", required_argument, 0, 'u'},
|
||||
{"no-color", no_argument, 0, 'C'},
|
||||
{"no-colour",no_argument, 0, 'C'},
|
||||
{"tree", no_argument, 0, 't'},
|
||||
{"pid", required_argument, 0, 'p'},
|
||||
{"io", no_argument, 0, 'i'},
|
||||
{0,0,0,0}
|
||||
@ -89,7 +93,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
|
||||
|
||||
int opt, opti=0;
|
||||
/* Parse arguments */
|
||||
while ((opt = getopt_long(argc, argv, "hvCs:d:u:p:i", long_opts, &opti))) {
|
||||
while ((opt = getopt_long(argc, argv, "hvCst::d:u:p:i", long_opts, &opti))) {
|
||||
if (opt == EOF) break;
|
||||
switch (opt) {
|
||||
case 'h':
|
||||
@ -127,6 +131,9 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
|
||||
case 'C':
|
||||
flags.useColors = false;
|
||||
break;
|
||||
case 't':
|
||||
flags.treeView = true;
|
||||
break;
|
||||
case 'p': {
|
||||
char* argCopy = xStrdup(optarg);
|
||||
char* saveptr;
|
||||
@ -197,6 +204,8 @@ int main(int argc, char** argv) {
|
||||
settings->delay = flags.delay;
|
||||
if (!flags.useColors)
|
||||
settings->colorScheme = COLORSCHEME_MONOCHROME;
|
||||
if (flags.treeView)
|
||||
settings->screens[0]->treeView = true;
|
||||
|
||||
CRT_init(settings->delay, settings->colorScheme);
|
||||
|
||||
|
@ -117,6 +117,7 @@ typedef enum LinuxProcessFields {
|
||||
|
||||
typedef struct LinuxProcess_ {
|
||||
Process super;
|
||||
bool isKernelThread;
|
||||
IOPriority ioPriority;
|
||||
unsigned long int cminflt;
|
||||
unsigned long int cmajflt;
|
||||
@ -185,7 +186,7 @@ typedef struct LinuxProcess_ {
|
||||
} LinuxProcess;
|
||||
|
||||
#ifndef Process_isKernelThread
|
||||
#define Process_isKernelThread(_process) (_process->pgrp == 0)
|
||||
#define Process_isKernelThread(_process) (((LinuxProcess*)(_process))->isKernelThread)
|
||||
#endif
|
||||
|
||||
#ifndef Process_isUserlandThread
|
||||
|
@ -109,6 +109,7 @@ typedef enum LinuxProcessFields {
|
||||
|
||||
typedef struct LinuxProcess_ {
|
||||
Process super;
|
||||
bool isKernelThread;
|
||||
IOPriority ioPriority;
|
||||
unsigned long int cminflt;
|
||||
unsigned long int cmajflt;
|
||||
@ -177,7 +178,7 @@ typedef struct LinuxProcess_ {
|
||||
} LinuxProcess;
|
||||
|
||||
#ifndef Process_isKernelThread
|
||||
#define Process_isKernelThread(_process) (_process->pgrp == 0)
|
||||
#define Process_isKernelThread(_process) (((LinuxProcess*)(_process))->isKernelThread)
|
||||
#endif
|
||||
|
||||
#ifndef Process_isUserlandThread
|
||||
|
@ -748,9 +748,6 @@ static void setCommand(Process* process, const char* command, int len) {
|
||||
}
|
||||
|
||||
static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirname, const char* name) {
|
||||
if (Process_isKernelThread(process))
|
||||
return true;
|
||||
|
||||
char filename[MAX_NAME+1];
|
||||
xSnprintf(filename, MAX_NAME, "%s/%s/cmdline", dirname, name);
|
||||
int fd = open(filename, O_RDONLY);
|
||||
@ -762,7 +759,10 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna
|
||||
close(fd);
|
||||
int tokenEnd = 0;
|
||||
int lastChar = 0;
|
||||
if (amtRead <= 0) {
|
||||
if (amtRead == 0) {
|
||||
((LinuxProcess*)process)->isKernelThread = true;
|
||||
return true;
|
||||
} else if (amtRead < 0) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < amtRead; i++) {
|
||||
|
@ -36,16 +36,13 @@ in the source distribution for its full text.
|
||||
#include "BatteryMeter.h"
|
||||
#include "LinuxProcess.h"
|
||||
#include "SignalsPanel.h"
|
||||
#include "Settings.h"
|
||||
}*/
|
||||
|
||||
#ifndef CLAMP
|
||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||
#endif
|
||||
|
||||
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
||||
|
||||
//static ProcessField defaultIoFields[] = { PID, IO_PRIORITY, USER, IO_READ_RATE, IO_WRITE_RATE, IO_RATE, COMM, 0 };
|
||||
|
||||
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
||||
|
||||
const SignalItem Platform_signals[] = {
|
||||
@ -85,6 +82,31 @@ const SignalItem Platform_signals[] = {
|
||||
{ .name = "31 SIGSYS", .number = 31 },
|
||||
};
|
||||
|
||||
ScreenDefaults Platform_defaultScreens[] = {
|
||||
{
|
||||
.name = "Default",
|
||||
.columns = "PID USER PRIORITY NICE M_SIZE M_RESIDENT M_SHARE STATE PERCENT_CPU PERCENT_MEM TIME Command",
|
||||
.sortKey = "PERCENT_CPU",
|
||||
},
|
||||
{
|
||||
.name = "I/O",
|
||||
.columns = "PID USER IO_PRIORITY IO_RATE IO_READ_RATE IO_WRITE_RATE PERCENT_SWAP_DELAY PERCENT_IO_DELAY Command",
|
||||
.sortKey = "IO_RATE",
|
||||
},
|
||||
{
|
||||
.name = "Perf Counters",
|
||||
.columns = "PID USER PERCENT_CPU PROCESSOR MCYCLE MINSTR IPC PERCENT_MISS PERCENT_BMISS Command",
|
||||
.sortKey = "MCYCLE",
|
||||
},
|
||||
{
|
||||
.name = "L1 Data Cache",
|
||||
.columns = "PID USER PERCENT_CPU L1DREADS L1DRMISSES L1DWRITES L1DWMISSES Command",
|
||||
.sortKey = "LD1READS",
|
||||
},
|
||||
};
|
||||
|
||||
const unsigned int Platform_numberOfDefaultScreens = sizeof(Platform_defaultScreens)/sizeof(ScreenDefaults);
|
||||
|
||||
const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
||||
|
||||
static Htop_Reaction Platform_actionSetIOPriority(State* st) {
|
||||
|
@ -14,17 +14,20 @@ in the source distribution for its full text.
|
||||
#include "BatteryMeter.h"
|
||||
#include "LinuxProcess.h"
|
||||
#include "SignalsPanel.h"
|
||||
#include "Settings.h"
|
||||
|
||||
#ifndef CLAMP
|
||||
#define CLAMP(x,low,high) (((x)>(high))?(high):(((x)<(low))?(low):(x)))
|
||||
#endif
|
||||
|
||||
extern ProcessField Platform_defaultFields[];
|
||||
|
||||
extern int Platform_numberOfFields;
|
||||
|
||||
extern const SignalItem Platform_signals[];
|
||||
|
||||
extern ScreenDefaults Platform_defaultScreens[];
|
||||
|
||||
extern const unsigned int Platform_numberOfDefaultScreens;
|
||||
|
||||
extern const unsigned int Platform_numberOfSignals;
|
||||
|
||||
void Platform_setBindings(Htop_Action* keys);
|
||||
|
@ -7,10 +7,65 @@ in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "BatteryMeter.h"
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/sensors.h>
|
||||
#include <errno.h>
|
||||
|
||||
void Battery_getData(double* level, ACPresence* isOnAC) {
|
||||
// TODO
|
||||
*level = -1;
|
||||
*isOnAC = AC_ERROR;
|
||||
static bool findDevice(const char* name, int* mib, struct sensordev* snsrdev, size_t* sdlen) {
|
||||
for (int devn = 0;; devn++) {
|
||||
mib[2] = devn;
|
||||
if (sysctl(mib, 3, snsrdev, sdlen, NULL, 0) == -1) {
|
||||
if (errno == ENXIO)
|
||||
continue;
|
||||
if (errno == ENOENT)
|
||||
return false;
|
||||
}
|
||||
if (strcmp(name, snsrdev->xname) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Battery_getData(double* level, ACPresence* isOnAC) {
|
||||
static int mib[] = {CTL_HW, HW_SENSORS, 0, 0, 0};
|
||||
struct sensor s;
|
||||
size_t slen = sizeof(struct sensor);
|
||||
struct sensordev snsrdev;
|
||||
size_t sdlen = sizeof(struct sensordev);
|
||||
|
||||
bool found = findDevice("acpibat0", mib, &snsrdev, &sdlen);
|
||||
|
||||
*level = -1;
|
||||
if (found) {
|
||||
/* last full capacity */
|
||||
mib[3] = 7;
|
||||
mib[4] = 0;
|
||||
double last_full_capacity = 0;
|
||||
if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) {
|
||||
last_full_capacity = s.value;
|
||||
}
|
||||
if (last_full_capacity > 0) {
|
||||
/* remaining capacity */
|
||||
mib[3] = 7;
|
||||
mib[4] = 3;
|
||||
if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) {
|
||||
double charge = s.value;
|
||||
*level = 100*(charge / last_full_capacity);
|
||||
if (charge >= last_full_capacity) {
|
||||
*level = 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
found = findDevice("acpiac0", mib, &snsrdev, &sdlen);
|
||||
|
||||
*isOnAC = AC_ERROR;
|
||||
if (found) {
|
||||
mib[3] = 9;
|
||||
mib[4] = 0;
|
||||
if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) {
|
||||
*isOnAC = s.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,5 +12,4 @@ in the source distribution for its full text.
|
||||
|
||||
void Battery_getData(double* level, ACPresence* isOnAC);
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -92,7 +92,15 @@ static int percentages(int cnt, int64_t *out, int64_t *new, int64_t *old, int64_
|
||||
return (total_change);
|
||||
}
|
||||
|
||||
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
||||
ScreenDefaults Platform_defaultScreens[] = {
|
||||
{
|
||||
.name = "Default",
|
||||
.columns = "PID USER PRIORITY NICE M_SIZE M_RESIDENT STATE PERCENT_CPU PERCENT_MEM TIME Command",
|
||||
.sortKey = "PERCENT_CPU",
|
||||
},
|
||||
};
|
||||
|
||||
const unsigned int Platform_numberOfDefaultScreens = sizeof(Platform_defaultScreens)/sizeof(ScreenDefaults);
|
||||
|
||||
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
||||
|
||||
|
@ -32,7 +32,9 @@ extern ProcessFieldData Process_fields[];
|
||||
* The routine assumes modulo arithmetic. This function is especially
|
||||
* useful on BSD machines for calculating cpu state percentages.
|
||||
*/
|
||||
extern ProcessField Platform_defaultFields[];
|
||||
extern ScreenDefaults Platform_defaultScreens[];
|
||||
|
||||
extern const unsigned int Platform_numberOfDefaultScreens;
|
||||
|
||||
extern int Platform_numberOfFields;
|
||||
|
||||
|
8
solaris/Battery.c
Normal file
8
solaris/Battery.c
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
#include "BatteryMeter.h"
|
||||
|
||||
void Battery_getData(double* level, ACPresence* isOnAC) {
|
||||
*level = -1;
|
||||
*isOnAC = AC_ERROR;
|
||||
}
|
||||
|
9
solaris/Battery.h
Normal file
9
solaris/Battery.h
Normal file
@ -0,0 +1,9 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_Battery
|
||||
#define HEADER_Battery
|
||||
|
||||
void Battery_getData(double* level, ACPresence* isOnAC);
|
||||
|
||||
|
||||
#endif
|
265
solaris/Platform.c
Normal file
265
solaris/Platform.c
Normal file
@ -0,0 +1,265 @@
|
||||
/*
|
||||
htop - solaris/Platform.c
|
||||
(C) 2014 Hisham H. Muhammad
|
||||
(C) 2015 David C. Hunt
|
||||
(C) 2017,2018 Guy M. Broome
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "Platform.h"
|
||||
#include "Meter.h"
|
||||
#include "CPUMeter.h"
|
||||
#include "MemoryMeter.h"
|
||||
#include "SwapMeter.h"
|
||||
#include "TasksMeter.h"
|
||||
#include "LoadAverageMeter.h"
|
||||
#include "ClockMeter.h"
|
||||
#include "HostnameMeter.h"
|
||||
#include "UptimeMeter.h"
|
||||
#include "SolarisProcess.h"
|
||||
#include "SolarisProcessList.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <utmpx.h>
|
||||
#include <sys/loadavg.h>
|
||||
#include <string.h>
|
||||
#include <kstat.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <sys/var.h>
|
||||
|
||||
/*{
|
||||
#include "Action.h"
|
||||
#include "BatteryMeter.h"
|
||||
#include "SignalsPanel.h"
|
||||
#include <signal.h>
|
||||
#include <sys/mkdev.h>
|
||||
#include <sys/proc.h>
|
||||
#include <libproc.h>
|
||||
|
||||
#define kill(pid, signal) kill(pid / 1024, signal)
|
||||
|
||||
extern ProcessFieldData Process_fields[];
|
||||
typedef struct var kvar_t;
|
||||
|
||||
typedef struct envAccum_ {
|
||||
size_t capacity;
|
||||
size_t size;
|
||||
size_t bytes;
|
||||
char *env;
|
||||
} envAccum;
|
||||
|
||||
}*/
|
||||
|
||||
double plat_loadavg[3] = {0};
|
||||
|
||||
const SignalItem Platform_signals[] = {
|
||||
{ .name = " 0 Cancel", .number = 0 },
|
||||
{ .name = " 1 SIGHUP", .number = 1 },
|
||||
{ .name = " 2 SIGINT", .number = 2 },
|
||||
{ .name = " 3 SIGQUIT", .number = 3 },
|
||||
{ .name = " 4 SIGILL", .number = 4 },
|
||||
{ .name = " 5 SIGTRAP", .number = 5 },
|
||||
{ .name = " 6 SIGABRT/IOT", .number = 6 },
|
||||
{ .name = " 7 SIGEMT", .number = 7 },
|
||||
{ .name = " 8 SIGFPE", .number = 8 },
|
||||
{ .name = " 9 SIGKILL", .number = 9 },
|
||||
{ .name = "10 SIGBUS", .number = 10 },
|
||||
{ .name = "11 SIGSEGV", .number = 11 },
|
||||
{ .name = "12 SIGSYS", .number = 12 },
|
||||
{ .name = "13 SIGPIPE", .number = 13 },
|
||||
{ .name = "14 SIGALRM", .number = 14 },
|
||||
{ .name = "15 SIGTERM", .number = 15 },
|
||||
{ .name = "16 SIGUSR1", .number = 16 },
|
||||
{ .name = "17 SIGUSR2", .number = 17 },
|
||||
{ .name = "18 SIGCHLD/CLD", .number = 18 },
|
||||
{ .name = "19 SIGPWR", .number = 19 },
|
||||
{ .name = "20 SIGWINCH", .number = 20 },
|
||||
{ .name = "21 SIGURG", .number = 21 },
|
||||
{ .name = "22 SIGPOLL/IO", .number = 22 },
|
||||
{ .name = "23 SIGSTOP", .number = 23 },
|
||||
{ .name = "24 SIGTSTP", .number = 24 },
|
||||
{ .name = "25 SIGCONT", .number = 25 },
|
||||
{ .name = "26 SIGTTIN", .number = 26 },
|
||||
{ .name = "27 SIGTTOU", .number = 27 },
|
||||
{ .name = "28 SIGVTALRM", .number = 28 },
|
||||
{ .name = "29 SIGPROF", .number = 29 },
|
||||
{ .name = "30 SIGXCPU", .number = 30 },
|
||||
{ .name = "31 SIGXFSZ", .number = 31 },
|
||||
{ .name = "32 SIGWAITING", .number = 32 },
|
||||
{ .name = "33 SIGLWP", .number = 33 },
|
||||
{ .name = "34 SIGFREEZE", .number = 34 },
|
||||
{ .name = "35 SIGTHAW", .number = 35 },
|
||||
{ .name = "36 SIGCANCEL", .number = 36 },
|
||||
{ .name = "37 SIGLOST", .number = 37 },
|
||||
{ .name = "38 SIGXRES", .number = 38 },
|
||||
{ .name = "39 SIGJVM1", .number = 39 },
|
||||
{ .name = "40 SIGJVM2", .number = 40 },
|
||||
{ .name = "41 SIGINFO", .number = 41 },
|
||||
};
|
||||
|
||||
const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
||||
|
||||
ScreenDefaults Platform_defaultScreens[] = {
|
||||
{
|
||||
.name = "Default",
|
||||
.columns = "PID LWPID USER PRIORITY NICE M_SIZE M_RESIDENT STATE PERCENT_CPU PERCENT_MEM TIME Command",
|
||||
.sortKey = "PERCENT_CPU",
|
||||
},
|
||||
};
|
||||
|
||||
const unsigned int Platform_numberOfDefaultScreens = sizeof(Platform_defaultScreens)/sizeof(ScreenDefaults);
|
||||
|
||||
MeterClass* Platform_meterTypes[] = {
|
||||
&CPUMeter_class,
|
||||
&ClockMeter_class,
|
||||
&LoadAverageMeter_class,
|
||||
&LoadMeter_class,
|
||||
&MemoryMeter_class,
|
||||
&SwapMeter_class,
|
||||
&TasksMeter_class,
|
||||
&BatteryMeter_class,
|
||||
&HostnameMeter_class,
|
||||
&UptimeMeter_class,
|
||||
&AllCPUsMeter_class,
|
||||
&AllCPUs2Meter_class,
|
||||
&LeftCPUsMeter_class,
|
||||
&RightCPUsMeter_class,
|
||||
&LeftCPUs2Meter_class,
|
||||
&RightCPUs2Meter_class,
|
||||
&BlankMeter_class,
|
||||
NULL
|
||||
};
|
||||
|
||||
void Platform_setBindings(Htop_Action* keys) {
|
||||
(void) keys;
|
||||
}
|
||||
|
||||
int Platform_numberOfFields = LAST_PROCESSFIELD;
|
||||
|
||||
extern char Process_pidFormat[20];
|
||||
|
||||
int Platform_getUptime() {
|
||||
int boot_time = 0;
|
||||
int curr_time = time(NULL);
|
||||
struct utmpx * ent;
|
||||
|
||||
while (( ent = getutxent() )) {
|
||||
if ( !strcmp("system boot", ent->ut_line )) {
|
||||
boot_time = ent->ut_tv.tv_sec;
|
||||
}
|
||||
}
|
||||
|
||||
endutxent();
|
||||
|
||||
return (curr_time-boot_time);
|
||||
}
|
||||
|
||||
void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
|
||||
getloadavg( plat_loadavg, 3 );
|
||||
*one = plat_loadavg[LOADAVG_1MIN];
|
||||
*five = plat_loadavg[LOADAVG_5MIN];
|
||||
*fifteen = plat_loadavg[LOADAVG_15MIN];
|
||||
}
|
||||
|
||||
int Platform_getMaxPid() {
|
||||
kstat_ctl_t *kc = NULL;
|
||||
kstat_t *kshandle = NULL;
|
||||
kvar_t *ksvar = NULL;
|
||||
int vproc = 32778; // Reasonable Solaris default
|
||||
kc = kstat_open();
|
||||
if (kc != NULL) { kshandle = kstat_lookup(kc,"unix",0,"var"); }
|
||||
if (kshandle != NULL) { kstat_read(kc,kshandle,NULL); }
|
||||
ksvar = kshandle->ks_data;
|
||||
if (ksvar->v_proc > 0 ) {
|
||||
vproc = ksvar->v_proc;
|
||||
}
|
||||
if (kc != NULL) { kstat_close(kc); }
|
||||
return vproc;
|
||||
}
|
||||
|
||||
double Platform_setCPUValues(Meter* this, int cpu) {
|
||||
SolarisProcessList* spl = (SolarisProcessList*) this->pl;
|
||||
int cpus = this->pl->cpuCount;
|
||||
CPUData* cpuData = NULL;
|
||||
|
||||
if (cpus == 1) {
|
||||
// single CPU box has everything in spl->cpus[0]
|
||||
cpuData = &(spl->cpus[0]);
|
||||
} else {
|
||||
cpuData = &(spl->cpus[cpu]);
|
||||
}
|
||||
|
||||
double percent;
|
||||
double* v = this->values;
|
||||
|
||||
v[CPU_METER_NICE] = cpuData->nicePercent;
|
||||
v[CPU_METER_NORMAL] = cpuData->userPercent;
|
||||
if (this->pl->settings->detailedCPUTime) {
|
||||
v[CPU_METER_KERNEL] = cpuData->systemPercent;
|
||||
v[CPU_METER_IRQ] = cpuData->irqPercent;
|
||||
Meter_setItems(this, 4);
|
||||
percent = v[0]+v[1]+v[2]+v[3];
|
||||
} else {
|
||||
v[2] = cpuData->systemAllPercent;
|
||||
Meter_setItems(this, 3);
|
||||
percent = v[0]+v[1]+v[2];
|
||||
}
|
||||
|
||||
percent = CLAMP(percent, 0.0, 100.0);
|
||||
if (isnan(percent)) percent = 0.0;
|
||||
return percent;
|
||||
}
|
||||
|
||||
void Platform_setMemoryValues(Meter* this) {
|
||||
ProcessList* pl = (ProcessList*) this->pl;
|
||||
this->total = pl->totalMem;
|
||||
this->values[0] = pl->usedMem;
|
||||
this->values[1] = pl->buffersMem;
|
||||
this->values[2] = pl->cachedMem;
|
||||
}
|
||||
|
||||
void Platform_setSwapValues(Meter* this) {
|
||||
ProcessList* pl = (ProcessList*) this->pl;
|
||||
this->total = pl->totalSwap;
|
||||
this->values[0] = pl->usedSwap;
|
||||
}
|
||||
|
||||
static int Platform_buildenv(void *accum, struct ps_prochandle *Phandle, uintptr_t addr, const char *str) {
|
||||
envAccum *accump = accum;
|
||||
(void) Phandle;
|
||||
(void) addr;
|
||||
size_t thissz = strlen(str);
|
||||
if ((thissz + 2) > (accump->capacity - accump->size))
|
||||
accump->env = xRealloc(accump->env, accump->capacity *= 2);
|
||||
if ((thissz + 2) > (accump->capacity - accump->size))
|
||||
return 1;
|
||||
strlcpy( accump->env + accump->size, str, (accump->capacity - accump->size));
|
||||
strncpy( accump->env + accump->size + thissz + 1, "\n", 1);
|
||||
accump->size = accump->size + thissz + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* Platform_getProcessEnv(pid_t pid) {
|
||||
envAccum envBuilder;
|
||||
pid_t realpid = pid / 1024;
|
||||
int graberr;
|
||||
struct ps_prochandle *Phandle;
|
||||
|
||||
if ((Phandle = Pgrab(realpid,PGRAB_RDONLY,&graberr)) == NULL)
|
||||
return "Unable to read process environment.";
|
||||
|
||||
envBuilder.capacity = 4096;
|
||||
envBuilder.size = 0;
|
||||
envBuilder.env = xMalloc(envBuilder.capacity);
|
||||
|
||||
(void) Penv_iter(Phandle,Platform_buildenv,&envBuilder);
|
||||
|
||||
Prelease(Phandle, 0);
|
||||
|
||||
strncpy( envBuilder.env + envBuilder.size, "\0", 1);
|
||||
return envBuilder.env;
|
||||
}
|
67
solaris/Platform.h
Normal file
67
solaris/Platform.h
Normal file
@ -0,0 +1,67 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_Platform
|
||||
#define HEADER_Platform
|
||||
/*
|
||||
htop - solaris/Platform.h
|
||||
(C) 2014 Hisham H. Muhammad
|
||||
(C) 2015 David C. Hunt
|
||||
(C) 2017,2018 Guy M. Broome
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "Action.h"
|
||||
#include "BatteryMeter.h"
|
||||
#include "SignalsPanel.h"
|
||||
#include <signal.h>
|
||||
#include <sys/mkdev.h>
|
||||
#include <sys/proc.h>
|
||||
#include <libproc.h>
|
||||
|
||||
#define kill(pid, signal) kill(pid / 1024, signal)
|
||||
|
||||
extern ProcessFieldData Process_fields[];
|
||||
typedef struct var kvar_t;
|
||||
|
||||
typedef struct envAccum_ {
|
||||
size_t capacity;
|
||||
size_t size;
|
||||
size_t bytes;
|
||||
char *env;
|
||||
} envAccum;
|
||||
|
||||
|
||||
extern double plat_loadavg[3];
|
||||
|
||||
extern const SignalItem Platform_signals[];
|
||||
|
||||
extern const unsigned int Platform_numberOfSignals;
|
||||
|
||||
extern ScreenDefaults Platform_defaultScreens[];
|
||||
|
||||
extern const unsigned int Platform_numberOfDefaultScreens;
|
||||
|
||||
extern MeterClass* Platform_meterTypes[];
|
||||
|
||||
void Platform_setBindings(Htop_Action* keys);
|
||||
|
||||
extern int Platform_numberOfFields;
|
||||
|
||||
extern char Process_pidFormat[20];
|
||||
|
||||
int Platform_getUptime();
|
||||
|
||||
void Platform_getLoadAverage(double* one, double* five, double* fifteen);
|
||||
|
||||
int Platform_getMaxPid();
|
||||
|
||||
double Platform_setCPUValues(Meter* this, int cpu);
|
||||
|
||||
void Platform_setMemoryValues(Meter* this);
|
||||
|
||||
void Platform_setSwapValues(Meter* this);
|
||||
|
||||
char* Platform_getProcessEnv(pid_t pid);
|
||||
|
||||
#endif
|
32
solaris/SolarisCRT.c
Normal file
32
solaris/SolarisCRT.c
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
htop - SolarisCRT.c
|
||||
(C) 2014 Hisham H. Muhammad
|
||||
(C) 2018 Guy M. Broome
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "CRT.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef HAVE_EXECINFO_H
|
||||
#include <execinfo.h>
|
||||
#endif
|
||||
|
||||
void CRT_handleSIGSEGV(int sgn) {
|
||||
(void) sgn;
|
||||
CRT_done();
|
||||
fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at http://hisham.hm/htop\n");
|
||||
#ifdef HAVE_EXECINFO_H
|
||||
size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *));
|
||||
fprintf(stderr, "\n Please include in your report the following backtrace: \n");
|
||||
backtrace_symbols_fd(backtraceArray, size, 2);
|
||||
fprintf(stderr, "\nAdditionally, in order to make the above backtrace useful,");
|
||||
fprintf(stderr, "\nplease also run the following command to generate a disassembly of your binary:");
|
||||
fprintf(stderr, "\n\n objdump -d `which htop` > ~/htop.objdump");
|
||||
fprintf(stderr, "\n\nand then attach the file ~/htop.objdump to your bug report.");
|
||||
fprintf(stderr, "\n\nThank you for helping to improve htop!\n\n");
|
||||
#endif
|
||||
abort();
|
||||
}
|
18
solaris/SolarisCRT.h
Normal file
18
solaris/SolarisCRT.h
Normal file
@ -0,0 +1,18 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_SolarisCRT
|
||||
#define HEADER_SolarisCRT
|
||||
/*
|
||||
htop - SolarisCRT.h
|
||||
(C) 2014 Hisham H. Muhammad
|
||||
(C) 2018 Guy M. Broome
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_EXECINFO_H
|
||||
#endif
|
||||
|
||||
void CRT_handleSIGSEGV(int sgn);
|
||||
|
||||
#endif
|
214
solaris/SolarisProcess.c
Normal file
214
solaris/SolarisProcess.c
Normal file
@ -0,0 +1,214 @@
|
||||
/*
|
||||
htop - SolarisProcess.c
|
||||
(C) 2015 Hisham H. Muhammad
|
||||
(C) 2017,2018 Guy M. Broome
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "Process.h"
|
||||
#include "ProcessList.h"
|
||||
#include "SolarisProcess.h"
|
||||
#include "Platform.h"
|
||||
#include "CRT.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
/*{
|
||||
#include "Settings.h"
|
||||
#include <zone.h>
|
||||
#include <sys/proc.h>
|
||||
#include <libproc.h>
|
||||
|
||||
typedef enum SolarisProcessFields {
|
||||
// Add platform-specific fields here, with ids >= 100
|
||||
ZONEID = 100,
|
||||
ZONE = 101,
|
||||
PROJID = 102,
|
||||
TASKID = 103,
|
||||
POOLID = 104,
|
||||
CONTID = 105,
|
||||
LWPID = 106,
|
||||
LAST_PROCESSFIELD = 107,
|
||||
} SolarisProcessField;
|
||||
|
||||
|
||||
typedef struct SolarisProcess_ {
|
||||
Process super;
|
||||
int kernel;
|
||||
zoneid_t zoneid;
|
||||
char* zname;
|
||||
taskid_t taskid;
|
||||
projid_t projid;
|
||||
poolid_t poolid;
|
||||
ctid_t contid;
|
||||
bool is_lwp;
|
||||
pid_t realpid;
|
||||
pid_t realppid;
|
||||
pid_t lwpid;
|
||||
} SolarisProcess;
|
||||
|
||||
|
||||
#ifndef Process_isKernelThread
|
||||
#define Process_isKernelThread(_process) (_process->kernel == 1)
|
||||
#endif
|
||||
|
||||
#ifndef Process_isUserlandThread
|
||||
#define Process_isUserlandThread(_process) (_process->pid != _process->tgid)
|
||||
#endif
|
||||
|
||||
}*/
|
||||
|
||||
ProcessClass SolarisProcess_class = {
|
||||
.super = {
|
||||
.extends = Class(Process),
|
||||
.display = Process_display,
|
||||
.delete = Process_delete,
|
||||
.compare = SolarisProcess_compare
|
||||
},
|
||||
.writeField = (Process_WriteField) SolarisProcess_writeField,
|
||||
};
|
||||
|
||||
ProcessFieldData Process_fields[] = {
|
||||
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
|
||||
[PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, },
|
||||
[COMM] = { .name = "Command", .title = "Command ", .description = "Command line", .flags = 0, },
|
||||
[STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping, R running, O onproc, Z zombie, T stopped, W waiting)", .flags = 0, },
|
||||
[PPID] = { .name = "PPID", .title = " PPID ", .description = "Parent process ID", .flags = 0, },
|
||||
[PGRP] = { .name = "PGRP", .title = " PGRP ", .description = "Process group ID", .flags = 0, },
|
||||
[SESSION] = { .name = "SESSION", .title = " SID ", .description = "Process's session ID", .flags = 0, },
|
||||
[TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", .flags = 0, },
|
||||
[TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, },
|
||||
[MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, },
|
||||
[MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, },
|
||||
[PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, },
|
||||
[NICE] = { .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", .flags = 0, },
|
||||
[STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", .flags = 0, },
|
||||
[PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, },
|
||||
[M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, },
|
||||
[M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, },
|
||||
[ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, },
|
||||
[PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, },
|
||||
[PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, },
|
||||
[USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
|
||||
[TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, },
|
||||
[NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, },
|
||||
[TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, },
|
||||
[ZONEID] = { .name = "ZONEID", .title = " ZONEID ", .description = "Zone ID", .flags = 0, },
|
||||
[ZONE] = { .name = "ZONE", .title = "ZONE ", .description = "Zone name", .flags = 0, },
|
||||
[PROJID] = { .name = "PROJID", .title = " PRJID ", .description = "Project ID", .flags = 0, },
|
||||
[TASKID] = { .name = "TASKID", .title = " TSKID ", .description = "Task ID", .flags = 0, },
|
||||
[POOLID] = { .name = "POOLID", .title = " POLID ", .description = "Pool ID", .flags = 0, },
|
||||
[CONTID] = { .name = "CONTID", .title = " CNTID ", .description = "Contract ID", .flags = 0, },
|
||||
[LWPID] = { .name = "LWPID", .title = " LWPID ", .description = "LWP ID", .flags = 0, },
|
||||
[LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
||||
};
|
||||
|
||||
ProcessPidColumn Process_pidColumns[] = {
|
||||
{ .id = ZONEID, .label = "ZONEID" },
|
||||
{ .id = TASKID, .label = "TSKID" },
|
||||
{ .id = PROJID, .label = "PRJID" },
|
||||
{ .id = POOLID, .label = "POLID" },
|
||||
{ .id = CONTID, .label = "CNTID" },
|
||||
{ .id = PID, .label = "PID" },
|
||||
{ .id = PPID, .label = "PPID" },
|
||||
{ .id = LWPID, .label = "LWPID" },
|
||||
{ .id = TPGID, .label = "TPGID" },
|
||||
{ .id = TGID, .label = "TGID" },
|
||||
{ .id = PGRP, .label = "PGRP" },
|
||||
{ .id = SESSION, .label = "SID" },
|
||||
{ .id = 0, .label = NULL },
|
||||
};
|
||||
|
||||
SolarisProcess* SolarisProcess_new(Settings* settings) {
|
||||
SolarisProcess* this = xCalloc(1, sizeof(SolarisProcess));
|
||||
Object_setClass(this, Class(SolarisProcess));
|
||||
Process_init(&this->super, settings);
|
||||
return this;
|
||||
}
|
||||
|
||||
void Process_delete(Object* cast) {
|
||||
SolarisProcess* sp = (SolarisProcess*) cast;
|
||||
Process_done((Process*)cast);
|
||||
free(sp->zname);
|
||||
free(sp);
|
||||
}
|
||||
|
||||
void SolarisProcess_writeField(Process* this, RichString* str, ProcessField field) {
|
||||
SolarisProcess* sp = (SolarisProcess*) this;
|
||||
char buffer[256]; buffer[255] = '\0';
|
||||
int attr = CRT_colors[DEFAULT_COLOR];
|
||||
int n = sizeof(buffer) - 1;
|
||||
switch ((int) field) {
|
||||
// add Solaris-specific fields here
|
||||
case ZONEID: xSnprintf(buffer, n, Process_pidFormat, sp->zoneid); break;
|
||||
case PROJID: xSnprintf(buffer, n, Process_pidFormat, sp->projid); break;
|
||||
case TASKID: xSnprintf(buffer, n, Process_pidFormat, sp->taskid); break;
|
||||
case POOLID: xSnprintf(buffer, n, Process_pidFormat, sp->poolid); break;
|
||||
case CONTID: xSnprintf(buffer, n, Process_pidFormat, sp->contid); break;
|
||||
case ZONE:{
|
||||
xSnprintf(buffer, n, "%-*s ", ZONENAME_MAX/4, sp->zname); break;
|
||||
if (buffer[ZONENAME_MAX/4] != '\0') {
|
||||
buffer[ZONENAME_MAX/4] = ' ';
|
||||
buffer[(ZONENAME_MAX/4)+1] = '\0';
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PID: xSnprintf(buffer, n, Process_pidFormat, sp->realpid); break;
|
||||
case PPID: xSnprintf(buffer, n, Process_pidFormat, sp->realppid); break;
|
||||
case LWPID: xSnprintf(buffer, n, Process_pidFormat, sp->lwpid); break;
|
||||
default:
|
||||
Process_writeField(this, str, field);
|
||||
return;
|
||||
}
|
||||
RichString_append(str, attr, buffer);
|
||||
}
|
||||
|
||||
long SolarisProcess_compare(const void* v1, const void* v2) {
|
||||
SolarisProcess *p1, *p2;
|
||||
Settings* settings = ((Process*)v1)->settings;
|
||||
if (settings->direction == 1) {
|
||||
p1 = (SolarisProcess*)v1;
|
||||
p2 = (SolarisProcess*)v2;
|
||||
} else {
|
||||
p2 = (SolarisProcess*)v1;
|
||||
p1 = (SolarisProcess*)v2;
|
||||
}
|
||||
switch ((int) settings->sortKey) {
|
||||
case ZONEID:
|
||||
return (p1->zoneid - p2->zoneid);
|
||||
case PROJID:
|
||||
return (p1->projid - p2->projid);
|
||||
case TASKID:
|
||||
return (p1->taskid - p2->taskid);
|
||||
case POOLID:
|
||||
return (p1->poolid - p2->poolid);
|
||||
case CONTID:
|
||||
return (p1->contid - p2->contid);
|
||||
case ZONE:
|
||||
return strcmp(p1->zname ? p1->zname : "global", p2->zname ? p2->zname : "global");
|
||||
case PID:
|
||||
return (p1->realpid - p2->realpid);
|
||||
case PPID:
|
||||
return (p1->realppid - p2->realppid);
|
||||
case LWPID:
|
||||
return (p1->lwpid - p2->lwpid);
|
||||
default:
|
||||
return Process_compare(v1, v2);
|
||||
}
|
||||
}
|
||||
|
||||
bool Process_isThread(Process* this) {
|
||||
SolarisProcess* fp = (SolarisProcess*) this;
|
||||
|
||||
if (fp->kernel == 1 ) {
|
||||
return 1;
|
||||
} else if (fp->is_lwp) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
72
solaris/SolarisProcess.h
Normal file
72
solaris/SolarisProcess.h
Normal file
@ -0,0 +1,72 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_SolarisProcess
|
||||
#define HEADER_SolarisProcess
|
||||
/*
|
||||
htop - SolarisProcess.h
|
||||
(C) 2015 Hisham H. Muhammad
|
||||
(C) 2017,2018 Guy M. Broome
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "Settings.h"
|
||||
#include <zone.h>
|
||||
#include <sys/proc.h>
|
||||
#include <libproc.h>
|
||||
|
||||
typedef enum SolarisProcessFields {
|
||||
// Add platform-specific fields here, with ids >= 100
|
||||
ZONEID = 100,
|
||||
ZONE = 101,
|
||||
PROJID = 102,
|
||||
TASKID = 103,
|
||||
POOLID = 104,
|
||||
CONTID = 105,
|
||||
LWPID = 106,
|
||||
LAST_PROCESSFIELD = 107,
|
||||
} SolarisProcessField;
|
||||
|
||||
|
||||
typedef struct SolarisProcess_ {
|
||||
Process super;
|
||||
int kernel;
|
||||
zoneid_t zoneid;
|
||||
char* zname;
|
||||
taskid_t taskid;
|
||||
projid_t projid;
|
||||
poolid_t poolid;
|
||||
ctid_t contid;
|
||||
bool is_lwp;
|
||||
pid_t realpid;
|
||||
pid_t realppid;
|
||||
pid_t lwpid;
|
||||
} SolarisProcess;
|
||||
|
||||
|
||||
#ifndef Process_isKernelThread
|
||||
#define Process_isKernelThread(_process) (_process->kernel == 1)
|
||||
#endif
|
||||
|
||||
#ifndef Process_isUserlandThread
|
||||
#define Process_isUserlandThread(_process) (_process->pid != _process->tgid)
|
||||
#endif
|
||||
|
||||
|
||||
extern ProcessClass SolarisProcess_class;
|
||||
|
||||
extern ProcessFieldData Process_fields[];
|
||||
|
||||
extern ProcessPidColumn Process_pidColumns[];
|
||||
|
||||
SolarisProcess* SolarisProcess_new(Settings* settings);
|
||||
|
||||
void Process_delete(Object* cast);
|
||||
|
||||
void SolarisProcess_writeField(Process* this, RichString* str, ProcessField field);
|
||||
|
||||
long SolarisProcess_compare(const void* v1, const void* v2);
|
||||
|
||||
bool Process_isThread(Process* this);
|
||||
|
||||
#endif
|
373
solaris/SolarisProcessList.c
Normal file
373
solaris/SolarisProcessList.c
Normal file
@ -0,0 +1,373 @@
|
||||
/*
|
||||
htop - SolarisProcessList.c
|
||||
(C) 2014 Hisham H. Muhammad
|
||||
(C) 2017,2018 Guy M. Broome
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#include "ProcessList.h"
|
||||
#include "SolarisProcess.h"
|
||||
#include "SolarisProcessList.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/user.h>
|
||||
#include <err.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <procfs.h>
|
||||
#include <errno.h>
|
||||
#include <pwd.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
|
||||
#define MAXCMDLINE 255
|
||||
|
||||
/*{
|
||||
|
||||
#include <kstat.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/sysconf.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <sys/swap.h>
|
||||
|
||||
#define ZONE_ERRMSGLEN 1024
|
||||
char zone_errmsg[ZONE_ERRMSGLEN];
|
||||
|
||||
typedef struct CPUData_ {
|
||||
double userPercent;
|
||||
double nicePercent;
|
||||
double systemPercent;
|
||||
double irqPercent;
|
||||
double idlePercent;
|
||||
double systemAllPercent;
|
||||
uint64_t luser;
|
||||
uint64_t lkrnl;
|
||||
uint64_t lintr;
|
||||
uint64_t lidle;
|
||||
} CPUData;
|
||||
|
||||
typedef struct SolarisProcessList_ {
|
||||
ProcessList super;
|
||||
kstat_ctl_t* kd;
|
||||
CPUData* cpus;
|
||||
} SolarisProcessList;
|
||||
|
||||
}*/
|
||||
|
||||
char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) {
|
||||
char* zname;
|
||||
if ( sproc->zoneid == 0 ) {
|
||||
zname = xStrdup("global ");
|
||||
} else if ( kd == NULL ) {
|
||||
zname = xStrdup("unknown ");
|
||||
} else {
|
||||
kstat_t* ks = kstat_lookup( kd, "zones", sproc->zoneid, NULL );
|
||||
zname = xStrdup(ks->ks_name);
|
||||
}
|
||||
return zname;
|
||||
}
|
||||
|
||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
|
||||
SolarisProcessList* spl = xCalloc(1, sizeof(SolarisProcessList));
|
||||
ProcessList* pl = (ProcessList*) spl;
|
||||
ProcessList_init(pl, Class(SolarisProcess), usersTable, pidWhiteList, userId);
|
||||
|
||||
spl->kd = kstat_open();
|
||||
|
||||
pl->cpuCount = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
|
||||
if (pl->cpuCount == 1 ) {
|
||||
spl->cpus = xRealloc(spl->cpus, sizeof(CPUData));
|
||||
} else {
|
||||
spl->cpus = xRealloc(spl->cpus, (pl->cpuCount + 1) * sizeof(CPUData));
|
||||
}
|
||||
|
||||
return pl;
|
||||
}
|
||||
|
||||
static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) {
|
||||
const SolarisProcessList* spl = (SolarisProcessList*) pl;
|
||||
int cpus = pl->cpuCount;
|
||||
kstat_t *cpuinfo = NULL;
|
||||
int kchain = 0;
|
||||
kstat_named_t *idletime = NULL;
|
||||
kstat_named_t *intrtime = NULL;
|
||||
kstat_named_t *krnltime = NULL;
|
||||
kstat_named_t *usertime = NULL;
|
||||
double idlebuf = 0;
|
||||
double intrbuf = 0;
|
||||
double krnlbuf = 0;
|
||||
double userbuf = 0;
|
||||
uint64_t totaltime = 0;
|
||||
int arrskip = 0;
|
||||
|
||||
assert(cpus > 0);
|
||||
|
||||
if (cpus > 1) {
|
||||
// Store values for the stats loop one extra element up in the array
|
||||
// to leave room for the average to be calculated afterwards
|
||||
arrskip++;
|
||||
}
|
||||
|
||||
// Calculate per-CPU statistics first
|
||||
for (int i = 0; i < cpus; i++) {
|
||||
if (spl->kd != NULL) { cpuinfo = kstat_lookup(spl->kd,"cpu",i,"sys"); }
|
||||
if (cpuinfo != NULL) { kchain = kstat_read(spl->kd,cpuinfo,NULL); }
|
||||
if (kchain != -1 ) {
|
||||
idletime = kstat_data_lookup(cpuinfo,"cpu_nsec_idle");
|
||||
intrtime = kstat_data_lookup(cpuinfo,"cpu_nsec_intr");
|
||||
krnltime = kstat_data_lookup(cpuinfo,"cpu_nsec_kernel");
|
||||
usertime = kstat_data_lookup(cpuinfo,"cpu_nsec_user");
|
||||
}
|
||||
|
||||
assert( (idletime != NULL) && (intrtime != NULL)
|
||||
&& (krnltime != NULL) && (usertime != NULL) );
|
||||
|
||||
CPUData* cpuData = &(spl->cpus[i+arrskip]);
|
||||
totaltime = (idletime->value.ui64 - cpuData->lidle)
|
||||
+ (intrtime->value.ui64 - cpuData->lintr)
|
||||
+ (krnltime->value.ui64 - cpuData->lkrnl)
|
||||
+ (usertime->value.ui64 - cpuData->luser);
|
||||
// Calculate percentages of deltas since last reading
|
||||
cpuData->userPercent = ((usertime->value.ui64 - cpuData->luser) / (double)totaltime) * 100.0;
|
||||
cpuData->nicePercent = (double)0.0; // Not implemented on Solaris
|
||||
cpuData->systemPercent = ((krnltime->value.ui64 - cpuData->lkrnl) / (double)totaltime) * 100.0;
|
||||
cpuData->irqPercent = ((intrtime->value.ui64 - cpuData->lintr) / (double)totaltime) * 100.0;
|
||||
cpuData->systemAllPercent = cpuData->systemPercent + cpuData->irqPercent;
|
||||
cpuData->idlePercent = ((idletime->value.ui64 - cpuData->lidle) / (double)totaltime) * 100.0;
|
||||
// Store current values to use for the next round of deltas
|
||||
cpuData->luser = usertime->value.ui64;
|
||||
cpuData->lkrnl = krnltime->value.ui64;
|
||||
cpuData->lintr = intrtime->value.ui64;
|
||||
cpuData->lidle = idletime->value.ui64;
|
||||
// Accumulate the current percentages into buffers for later average calculation
|
||||
if (cpus > 1) {
|
||||
userbuf += cpuData->userPercent;
|
||||
krnlbuf += cpuData->systemPercent;
|
||||
intrbuf += cpuData->irqPercent;
|
||||
idlebuf += cpuData->idlePercent;
|
||||
}
|
||||
}
|
||||
|
||||
if (cpus > 1) {
|
||||
CPUData* cpuData = &(spl->cpus[0]);
|
||||
cpuData->userPercent = userbuf / cpus;
|
||||
cpuData->nicePercent = (double)0.0; // Not implemented on Solaris
|
||||
cpuData->systemPercent = krnlbuf / cpus;
|
||||
cpuData->irqPercent = intrbuf / cpus;
|
||||
cpuData->systemAllPercent = cpuData->systemPercent + cpuData->irqPercent;
|
||||
cpuData->idlePercent = idlebuf / cpus;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) {
|
||||
SolarisProcessList* spl = (SolarisProcessList*) pl;
|
||||
kstat_t *meminfo = NULL;
|
||||
int ksrphyserr = -1;
|
||||
kstat_named_t *totalmem_pgs = NULL;
|
||||
kstat_named_t *lockedmem_pgs = NULL;
|
||||
kstat_named_t *pages = NULL;
|
||||
struct swaptable *sl = NULL;
|
||||
struct swapent *swapdev = NULL;
|
||||
uint64_t totalswap = 0;
|
||||
uint64_t totalfree = 0;
|
||||
int nswap = 0;
|
||||
char *spath = NULL;
|
||||
char *spathbase = NULL;
|
||||
|
||||
// Part 1 - physical memory
|
||||
if (spl->kd != NULL) { meminfo = kstat_lookup(spl->kd,"unix",0,"system_pages"); }
|
||||
if (meminfo != NULL) { ksrphyserr = kstat_read(spl->kd,meminfo,NULL); }
|
||||
if (ksrphyserr != -1) {
|
||||
totalmem_pgs = kstat_data_lookup( meminfo, "physmem" );
|
||||
lockedmem_pgs = kstat_data_lookup( meminfo, "pageslocked" );
|
||||
pages = kstat_data_lookup( meminfo, "pagestotal" );
|
||||
|
||||
pl->totalMem = totalmem_pgs->value.ui64 * PAGE_SIZE_KB;
|
||||
pl->usedMem = lockedmem_pgs->value.ui64 * PAGE_SIZE_KB;
|
||||
// Not sure how to implement this on Solaris - suggestions welcome!
|
||||
pl->cachedMem = 0;
|
||||
// Not really "buffers" but the best Solaris analogue that I can find to
|
||||
// "memory in use but not by programs or the kernel itself"
|
||||
pl->buffersMem = (totalmem_pgs->value.ui64 - pages->value.ui64) * PAGE_SIZE_KB;
|
||||
} else {
|
||||
// Fall back to basic sysconf if kstat isn't working
|
||||
pl->totalMem = sysconf(_SC_PHYS_PAGES) * PAGE_SIZE;
|
||||
pl->buffersMem = 0;
|
||||
pl->cachedMem = 0;
|
||||
pl->usedMem = pl->totalMem - (sysconf(_SC_AVPHYS_PAGES) * PAGE_SIZE);
|
||||
}
|
||||
|
||||
// Part 2 - swap
|
||||
nswap = swapctl(SC_GETNSWP, NULL);
|
||||
if (nswap > 0) { sl = xMalloc((nswap * sizeof(swapent_t)) + sizeof(int)); }
|
||||
if (sl != NULL) { spathbase = xMalloc( nswap * MAXPATHLEN ); }
|
||||
if (spathbase != NULL) {
|
||||
spath = spathbase;
|
||||
swapdev = sl->swt_ent;
|
||||
for (int i = 0; i < nswap; i++, swapdev++) {
|
||||
swapdev->ste_path = spath;
|
||||
spath += MAXPATHLEN;
|
||||
}
|
||||
sl->swt_n = nswap;
|
||||
}
|
||||
nswap = swapctl(SC_LIST, sl);
|
||||
if (nswap > 0) {
|
||||
swapdev = sl->swt_ent;
|
||||
for (int i = 0; i < nswap; i++, swapdev++) {
|
||||
totalswap += swapdev->ste_pages;
|
||||
totalfree += swapdev->ste_free;
|
||||
}
|
||||
}
|
||||
free(spathbase);
|
||||
free(sl);
|
||||
pl->totalSwap = totalswap * PAGE_SIZE_KB;
|
||||
pl->usedSwap = pl->totalSwap - (totalfree * PAGE_SIZE_KB);
|
||||
}
|
||||
|
||||
void ProcessList_delete(ProcessList* pl) {
|
||||
SolarisProcessList* spl = (SolarisProcessList*) pl;
|
||||
ProcessList_done(pl);
|
||||
free(spl->cpus);
|
||||
if (spl->kd) kstat_close(spl->kd);
|
||||
free(spl);
|
||||
}
|
||||
|
||||
/* NOTE: the following is a callback function of type proc_walk_f
|
||||
* and MUST conform to the appropriate definition in order
|
||||
* to work. See libproc(3LIB) on a Solaris or Illumos
|
||||
* system for more info.
|
||||
*/
|
||||
|
||||
int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void *listptr) {
|
||||
struct timeval tv;
|
||||
struct tm date;
|
||||
bool preExisting;
|
||||
pid_t getpid;
|
||||
|
||||
// Setup process list
|
||||
ProcessList *pl = (ProcessList*) listptr;
|
||||
SolarisProcessList *spl = (SolarisProcessList*) listptr;
|
||||
|
||||
id_t lwpid_real = _lwpsinfo->pr_lwpid;
|
||||
if (lwpid_real > 1023) return 0;
|
||||
pid_t lwpid = (_psinfo->pr_pid * 1024) + lwpid_real;
|
||||
bool onMasterLWP = (_lwpsinfo->pr_lwpid == _psinfo->pr_lwp.pr_lwpid);
|
||||
if (onMasterLWP) {
|
||||
getpid = _psinfo->pr_pid * 1024;
|
||||
} else {
|
||||
getpid = lwpid;
|
||||
}
|
||||
Process *proc = ProcessList_getProcess(pl, getpid, &preExisting, (Process_New) SolarisProcess_new);
|
||||
SolarisProcess *sproc = (SolarisProcess*) proc;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
// Common code pass 1
|
||||
proc->show = false;
|
||||
sproc->taskid = _psinfo->pr_taskid;
|
||||
sproc->projid = _psinfo->pr_projid;
|
||||
sproc->poolid = _psinfo->pr_poolid;
|
||||
sproc->contid = _psinfo->pr_contract;
|
||||
proc->priority = _lwpsinfo->pr_pri;
|
||||
proc->nice = _lwpsinfo->pr_nice;
|
||||
proc->processor = _lwpsinfo->pr_onpro;
|
||||
proc->state = _lwpsinfo->pr_sname;
|
||||
// NOTE: This 'percentage' is a 16-bit BINARY FRACTIONS where 1.0 = 0x8000
|
||||
// Source: https://docs.oracle.com/cd/E19253-01/816-5174/proc-4/index.html
|
||||
// (accessed on 18 November 2017)
|
||||
proc->percent_mem = ((uint16_t)_psinfo->pr_pctmem/(double)32768)*(double)100.0;
|
||||
proc->st_uid = _psinfo->pr_euid;
|
||||
proc->pgrp = _psinfo->pr_pgid;
|
||||
proc->nlwp = _psinfo->pr_nlwp;
|
||||
proc->tty_nr = _psinfo->pr_ttydev;
|
||||
proc->m_resident = _psinfo->pr_rssize/PAGE_SIZE_KB;
|
||||
proc->m_size = _psinfo->pr_size/PAGE_SIZE_KB;
|
||||
|
||||
if (!preExisting) {
|
||||
sproc->realpid = _psinfo->pr_pid;
|
||||
sproc->lwpid = lwpid_real;
|
||||
sproc->zoneid = _psinfo->pr_zoneid;
|
||||
sproc->zname = SolarisProcessList_readZoneName(spl->kd,sproc);
|
||||
proc->user = UsersTable_getRef(pl->usersTable, proc->st_uid);
|
||||
proc->comm = xStrdup(_psinfo->pr_fname);
|
||||
proc->commLen = strnlen(_psinfo->pr_fname,PRFNSZ);
|
||||
}
|
||||
|
||||
// End common code pass 1
|
||||
|
||||
if (onMasterLWP) { // Are we on the representative LWP?
|
||||
proc->ppid = (_psinfo->pr_ppid * 1024);
|
||||
proc->tgid = (_psinfo->pr_ppid * 1024);
|
||||
sproc->realppid = _psinfo->pr_ppid;
|
||||
// See note above (in common section) about this BINARY FRACTION
|
||||
proc->percent_cpu = ((uint16_t)_psinfo->pr_pctcpu/(double)32768)*(double)100.0;
|
||||
proc->time = _psinfo->pr_time.tv_sec;
|
||||
if(!preExisting) { // Tasks done only for NEW processes
|
||||
sproc->is_lwp = false;
|
||||
proc->starttime_ctime = _psinfo->pr_start.tv_sec;
|
||||
}
|
||||
|
||||
// Update proc and thread counts based on settings
|
||||
if (sproc->kernel && !pl->settings->hideKernelThreads) {
|
||||
pl->kernelThreads += proc->nlwp;
|
||||
pl->totalTasks += proc->nlwp+1;
|
||||
if (proc->state == 'O') pl->runningTasks++;
|
||||
} else if (!sproc->kernel) {
|
||||
if (proc->state == 'O') pl->runningTasks++;
|
||||
if (pl->settings->hideUserlandThreads) {
|
||||
pl->totalTasks++;
|
||||
} else {
|
||||
pl->userlandThreads += proc->nlwp;
|
||||
pl->totalTasks += proc->nlwp+1;
|
||||
}
|
||||
}
|
||||
proc->show = !(pl->settings->hideKernelThreads && sproc->kernel);
|
||||
} else { // We are not in the master LWP, so jump to the LWP handling code
|
||||
proc->percent_cpu = ((uint16_t)_lwpsinfo->pr_pctcpu/(double)32768)*(double)100.0;
|
||||
proc->time = _lwpsinfo->pr_time.tv_sec;
|
||||
if (!preExisting) { // Tasks done only for NEW LWPs
|
||||
sproc->is_lwp = true;
|
||||
proc->basenameOffset = -1;
|
||||
proc->ppid = _psinfo->pr_pid * 1024;
|
||||
proc->tgid = _psinfo->pr_pid * 1024;
|
||||
sproc->realppid = _psinfo->pr_pid;
|
||||
proc->starttime_ctime = _lwpsinfo->pr_start.tv_sec;
|
||||
}
|
||||
|
||||
// Top-level process only gets this for the representative LWP
|
||||
if (sproc->kernel && !pl->settings->hideKernelThreads) proc->show = true;
|
||||
if (!sproc->kernel && !pl->settings->hideUserlandThreads) proc->show = true;
|
||||
} // Top-level LWP or subordinate LWP
|
||||
|
||||
// Common code pass 2
|
||||
|
||||
if (!preExisting) {
|
||||
if ((sproc->realppid <= 0) && !(sproc->realpid <= 1)) {
|
||||
sproc->kernel = true;
|
||||
} else {
|
||||
sproc->kernel = false;
|
||||
}
|
||||
(void) localtime_r((time_t*) &proc->starttime_ctime, &date);
|
||||
strftime(proc->starttime_show, 7, ((proc->starttime_ctime > tv.tv_sec - 86400) ? "%R " : "%b%d "), &date);
|
||||
ProcessList_add(pl, proc);
|
||||
}
|
||||
proc->updated = true;
|
||||
|
||||
// End common code pass 2
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ProcessList_goThroughEntries(ProcessList* this) {
|
||||
SolarisProcessList_scanCPUTime(this);
|
||||
SolarisProcessList_scanMemoryInfo(this);
|
||||
this->kernelThreads = 1;
|
||||
proc_walk(&SolarisProcessList_walkproc, this, PR_WALK_LWP);
|
||||
}
|
||||
|
64
solaris/SolarisProcessList.h
Normal file
64
solaris/SolarisProcessList.h
Normal file
@ -0,0 +1,64 @@
|
||||
/* Do not edit this file. It was automatically generated. */
|
||||
|
||||
#ifndef HEADER_SolarisProcessList
|
||||
#define HEADER_SolarisProcessList
|
||||
/*
|
||||
htop - SolarisProcessList.h
|
||||
(C) 2014 Hisham H. Muhammad
|
||||
(C) 2017,2018 Guy M. Broome
|
||||
Released under the GNU GPL, see the COPYING file
|
||||
in the source distribution for its full text.
|
||||
*/
|
||||
|
||||
#define MAXCMDLINE 255
|
||||
|
||||
|
||||
#include <kstat.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/sysconf.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <sys/swap.h>
|
||||
|
||||
#define ZONE_ERRMSGLEN 1024
|
||||
char zone_errmsg[ZONE_ERRMSGLEN];
|
||||
|
||||
typedef struct CPUData_ {
|
||||
double userPercent;
|
||||
double nicePercent;
|
||||
double systemPercent;
|
||||
double irqPercent;
|
||||
double idlePercent;
|
||||
double systemAllPercent;
|
||||
uint64_t luser;
|
||||
uint64_t lkrnl;
|
||||
uint64_t lintr;
|
||||
uint64_t lidle;
|
||||
} CPUData;
|
||||
|
||||
typedef struct SolarisProcessList_ {
|
||||
ProcessList super;
|
||||
kstat_ctl_t* kd;
|
||||
CPUData* cpus;
|
||||
} SolarisProcessList;
|
||||
|
||||
|
||||
char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc);
|
||||
|
||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
|
||||
|
||||
void ProcessList_delete(ProcessList* pl);
|
||||
|
||||
/* NOTE: the following is a callback function of type proc_walk_f
|
||||
* and MUST conform to the appropriate definition in order
|
||||
* to work. See libproc(3LIB) on a Solaris or Illumos
|
||||
* system for more info.
|
||||
*/
|
||||
|
||||
int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void *listptr);
|
||||
|
||||
void ProcessList_goThroughEntries(ProcessList* this);
|
||||
|
||||
|
||||
#endif
|
@ -29,7 +29,15 @@ const SignalItem Platform_signals[] = {
|
||||
|
||||
const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
|
||||
|
||||
ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
|
||||
ScreenDefaults Platform_defaultScreens[] = {
|
||||
{
|
||||
.name = "Default",
|
||||
.columns = "PID LWPID USER PRIORITY NICE M_SIZE M_RESIDENT STATE PERCENT_CPU PERCENT_MEM TIME Command",
|
||||
.sortKey = "PERCENT_CPU",
|
||||
},
|
||||
};
|
||||
|
||||
const unsigned int Platform_numberOfDefaultScreens = sizeof(Platform_defaultScreens)/sizeof(ScreenDefaults);
|
||||
|
||||
ProcessFieldData Process_fields[] = {
|
||||
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
|
||||
|
@ -19,7 +19,9 @@ extern const SignalItem Platform_signals[];
|
||||
|
||||
extern const unsigned int Platform_numberOfSignals;
|
||||
|
||||
extern ProcessField Platform_defaultFields[];
|
||||
extern ScreenDefaults Platform_defaultScreens[];
|
||||
|
||||
extern const unsigned int Platform_numberOfDefaultScreens;
|
||||
|
||||
extern ProcessFieldData Process_fields[];
|
||||
|
||||
|
Reference in New Issue
Block a user