diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:00:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:00:29 +0000 |
commit | 52e25213825024b8bb446eb26b03bedc9d5c2103 (patch) | |
tree | da70bf44b2423f6f8e9a070c063fed79d190b489 /solaris | |
parent | Initial commit. (diff) | |
download | htop-upstream.tar.xz htop-upstream.zip |
Adding upstream version 3.2.2.upstream/3.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'solaris')
-rw-r--r-- | solaris/Platform.c | 331 | ||||
-rw-r--r-- | solaris/Platform.h | 159 | ||||
-rw-r--r-- | solaris/ProcessField.h | 24 | ||||
-rw-r--r-- | solaris/SolarisProcess.c | 137 | ||||
-rw-r--r-- | solaris/SolarisProcess.h | 49 | ||||
-rw-r--r-- | solaris/SolarisProcessList.c | 560 | ||||
-rw-r--r-- | solaris/SolarisProcessList.h | 65 |
7 files changed, 1325 insertions, 0 deletions
diff --git a/solaris/Platform.c b/solaris/Platform.c new file mode 100644 index 0000000..96f3526 --- /dev/null +++ b/solaris/Platform.c @@ -0,0 +1,331 @@ +/* +htop - solaris/Platform.c +(C) 2014 Hisham H. Muhammad +(C) 2015 David C. Hunt +(C) 2017,2018 Guy M. Broome +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include "solaris/Platform.h" + +#include <kstat.h> +#include <math.h> +#include <string.h> +#include <time.h> +#include <utmpx.h> +#include <sys/loadavg.h> +#include <sys/resource.h> +#include <sys/types.h> +#include <sys/time.h> +#include <sys/var.h> + +#include "Macros.h" +#include "Meter.h" +#include "CPUMeter.h" +#include "MemoryMeter.h" +#include "MemorySwapMeter.h" +#include "SwapMeter.h" +#include "TasksMeter.h" +#include "LoadAverageMeter.h" +#include "ClockMeter.h" +#include "DateMeter.h" +#include "DateTimeMeter.h" +#include "HostnameMeter.h" +#include "SysArchMeter.h" +#include "UptimeMeter.h" +#include "zfs/ZfsArcMeter.h" +#include "zfs/ZfsCompressedArcMeter.h" +#include "SolarisProcess.h" +#include "SolarisProcessList.h" + + +const ScreenDefaults Platform_defaultScreens[] = { + { + .name = "Default", + .columns = "PID LWPID USER PRIORITY NICE M_VIRT M_RESIDENT STATE PERCENT_CPU PERCENT_MEM TIME Command", + .sortKey = "PERCENT_CPU", + }, +}; + +const unsigned int Platform_numberOfDefaultScreens = ARRAYSIZE(Platform_defaultScreens); + +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 = ARRAYSIZE(Platform_signals); + +const MeterClass* const Platform_meterTypes[] = { + &CPUMeter_class, + &ClockMeter_class, + &DateMeter_class, + &DateTimeMeter_class, + &LoadAverageMeter_class, + &LoadMeter_class, + &MemoryMeter_class, + &SwapMeter_class, + &MemorySwapMeter_class, + &TasksMeter_class, + &BatteryMeter_class, + &HostnameMeter_class, + &SysArchMeter_class, + &UptimeMeter_class, + &AllCPUsMeter_class, + &AllCPUs2Meter_class, + &AllCPUs4Meter_class, + &AllCPUs8Meter_class, + &LeftCPUsMeter_class, + &RightCPUsMeter_class, + &LeftCPUs2Meter_class, + &RightCPUs2Meter_class, + &LeftCPUs4Meter_class, + &RightCPUs4Meter_class, + &LeftCPUs8Meter_class, + &RightCPUs8Meter_class, + &ZfsArcMeter_class, + &ZfsCompressedArcMeter_class, + &BlankMeter_class, + NULL +}; + +bool Platform_init(void) { + /* no platform-specific setup needed */ + return true; +} + +void Platform_done(void) { + /* no platform-specific cleanup needed */ +} + +void Platform_setBindings(Htop_Action* keys) { + /* no platform-specific key bindings */ + (void) keys; +} + +int Platform_getUptime(void) { + int boot_time = 0; + int curr_time = time(NULL); + struct utmpx* ent; + + while (( ent = getutxent() )) { + if ( String_eq("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) { + double plat_loadavg[3]; + if (getloadavg( plat_loadavg, 3 ) < 0) { + *one = NAN; + *five = NAN; + *fifteen = NAN; + return; + } + *one = plat_loadavg[LOADAVG_1MIN]; + *five = plat_loadavg[LOADAVG_5MIN]; + *fifteen = plat_loadavg[LOADAVG_15MIN]; +} + +int Platform_getMaxPid(void) { + int vproc = 32778; // Reasonable Solaris default + + kstat_ctl_t* kc = kstat_open(); + if (kc != NULL) { + kstat_t* kshandle = kstat_lookup_wrapper(kc, "unix", 0, "var"); + if (kshandle != NULL) { + kstat_read(kc, kshandle, NULL); + + kvar_t* ksvar = kshandle->ks_data; + if (ksvar && ksvar->v_proc > 0) { + vproc = ksvar->v_proc; + } + } + kstat_close(kc); + } + + return vproc; +} + +double Platform_setCPUValues(Meter* this, unsigned int cpu) { + const SolarisProcessList* spl = (const SolarisProcessList*) this->pl; + unsigned int cpus = this->pl->existingCPUs; + const CPUData* cpuData = NULL; + + if (cpus == 1) { + // single CPU box has everything in spl->cpus[0] + cpuData = &(spl->cpus[0]); + } else { + cpuData = &(spl->cpus[cpu]); + } + + if (!cpuData->online) { + this->curItems = 0; + return NAN; + } + + 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; + this->curItems = 4; + percent = v[0] + v[1] + v[2] + v[3]; + } else { + v[2] = cpuData->systemAllPercent; + this->curItems = 3; + percent = v[0] + v[1] + v[2]; + } + + percent = isnan(percent) ? 0.0 : CLAMP(percent, 0.0, 100.0); + + v[CPU_METER_FREQUENCY] = cpuData->frequency; + v[CPU_METER_TEMPERATURE] = NAN; + + return percent; +} + +void Platform_setMemoryValues(Meter* this) { + const ProcessList* pl = this->pl; + this->total = pl->totalMem; + this->values[MEMORY_METER_USED] = pl->usedMem; + this->values[MEMORY_METER_BUFFERS] = pl->buffersMem; + // this->values[MEMORY_METER_SHARED] = "shared memory, like tmpfs and shm" + this->values[MEMORY_METER_CACHE] = pl->cachedMem; + // this->values[MEMORY_METER_AVAILABLE] = "available memory" +} + +void Platform_setSwapValues(Meter* this) { + const ProcessList* pl = this->pl; + this->total = pl->totalSwap; + this->values[SWAP_METER_USED] = pl->usedSwap; + this->values[SWAP_METER_CACHE] = NAN; +} + +void Platform_setZfsArcValues(Meter* this) { + const SolarisProcessList* spl = (const SolarisProcessList*) this->pl; + + ZfsArcMeter_readStats(this, &(spl->zfs)); +} + +void Platform_setZfsCompressedArcValues(Meter* this) { + const SolarisProcessList* spl = (const SolarisProcessList*) this->pl; + + ZfsCompressedArcMeter_readStats(this, &(spl->zfs)); +} + +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); + + while ((thissz + 2) > (accump->capacity - accump->size)) { + if (accump->capacity > (SIZE_MAX / 2)) + return 1; + + accump->capacity *= 2; + accump->env = xRealloc(accump->env, accump->capacity); + } + + strlcpy( accump->env + accump->size, str, accump->capacity - accump->size); + strncpy( accump->env + accump->size + thissz + 1, "\n", 2); + + 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 NULL; + } + + 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 xRealloc(envBuilder.env, envBuilder.size + 1); +} + +FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) { + (void)pid; + return NULL; +} + +bool Platform_getDiskIO(DiskIOData* data) { + // TODO + (void)data; + return false; +} + +bool Platform_getNetworkIO(NetworkIOData* data) { + // TODO + (void)data; + return false; +} + +void Platform_getBattery(double* percent, ACPresence* isOnAC) { + *percent = NAN; + *isOnAC = AC_ERROR; +} diff --git a/solaris/Platform.h b/solaris/Platform.h new file mode 100644 index 0000000..14431e3 --- /dev/null +++ b/solaris/Platform.h @@ -0,0 +1,159 @@ +#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 GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include "config.h" // IWYU pragma: keep + +#include <kstat.h> + +/* On OmniOS /usr/include/sys/regset.h redefines ERR to 13 - \r, breaking the Enter key. + * Since ncruses macros use the ERR macro, we can not use another name. + */ +#undef ERR +#include <libproc.h> +#undef ERR +#define ERR (-1) + +#include <signal.h> +#include <stdbool.h> + +#include <sys/mkdev.h> +#include <sys/proc.h> +#include <sys/types.h> + +#include "Action.h" +#include "BatteryMeter.h" +#include "DiskIOMeter.h" +#include "Hashtable.h" +#include "NetworkIOMeter.h" +#include "ProcessLocksScreen.h" +#include "SignalsPanel.h" +#include "CommandLine.h" +#include "generic/gettime.h" +#include "generic/hostname.h" +#include "generic/uname.h" + + +#define kill(pid, signal) kill(pid / 1024, signal) + +typedef struct var kvar_t; + +typedef struct envAccum_ { + size_t capacity; + size_t size; + size_t bytes; + char* env; +} envAccum; + +extern const ScreenDefaults Platform_defaultScreens[]; + +extern const unsigned int Platform_numberOfDefaultScreens; + +extern const SignalItem Platform_signals[]; + +extern const unsigned int Platform_numberOfSignals; + +extern const MeterClass* const Platform_meterTypes[]; + +bool Platform_init(void); + +void Platform_done(void); + +void Platform_setBindings(Htop_Action* keys); + +int Platform_getUptime(void); + +void Platform_getLoadAverage(double* one, double* five, double* fifteen); + +int Platform_getMaxPid(void); + +double Platform_setCPUValues(Meter* this, unsigned int cpu); + +void Platform_setMemoryValues(Meter* this); + +void Platform_setSwapValues(Meter* this); + +void Platform_setZfsArcValues(Meter* this); + +void Platform_setZfsCompressedArcValues(Meter* this); + +char* Platform_getProcessEnv(pid_t pid); + +FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid); + +bool Platform_getDiskIO(DiskIOData* data); + +bool Platform_getNetworkIO(NetworkIOData* data); + +void Platform_getBattery(double* percent, ACPresence* isOnAC); + +static inline void Platform_getHostname(char* buffer, size_t size) { + Generic_hostname(buffer, size); +} + +static inline void Platform_getRelease(char** string) { + *string = Generic_uname(); +} + +#define PLATFORM_LONG_OPTIONS + +static inline void Platform_longOptionsUsage(ATTR_UNUSED const char* name) { } + +static inline CommandLineStatus Platform_getLongOption(ATTR_UNUSED int opt, ATTR_UNUSED int argc, ATTR_UNUSED char** argv) { + return STATUS_ERROR_EXIT; +} + +static inline void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) { + Generic_gettime_realtime(tv, msec); +} + +static inline void Platform_gettime_monotonic(uint64_t* msec) { + Generic_gettime_monotonic(msec); +} + +static inline void* kstat_data_lookup_wrapper(kstat_t* ksp, const char* name) { +IGNORE_WCASTQUAL_BEGIN + return kstat_data_lookup(ksp, (char*)name); +IGNORE_WCASTQUAL_END +} + +static inline kstat_t* kstat_lookup_wrapper(kstat_ctl_t* kc, const char* ks_module, int ks_instance, const char* ks_name) { +IGNORE_WCASTQUAL_BEGIN + return kstat_lookup(kc, (char*)ks_module, ks_instance, (char*)ks_name); +IGNORE_WCASTQUAL_END +} + +static inline Hashtable* Platform_dynamicMeters(void) { + return NULL; +} + +static inline void Platform_dynamicMetersDone(ATTR_UNUSED Hashtable* table) { } + +static inline void Platform_dynamicMeterInit(ATTR_UNUSED Meter* meter) { } + +static inline void Platform_dynamicMeterUpdateValues(ATTR_UNUSED Meter* meter) { } + +static inline void Platform_dynamicMeterDisplay(ATTR_UNUSED const Meter* meter, ATTR_UNUSED RichString* out) { } + +static inline Hashtable* Platform_dynamicColumns(void) { + return NULL; +} + +static inline void Platform_dynamicColumnsDone(ATTR_UNUSED Hashtable* table) { } + +static inline const char* Platform_dynamicColumnInit(ATTR_UNUSED unsigned int key) { + return NULL; +} + +static inline bool Platform_dynamicColumnWriteField(ATTR_UNUSED const Process* proc, ATTR_UNUSED RichString* str, ATTR_UNUSED unsigned int key) { + return false; +} + +#endif diff --git a/solaris/ProcessField.h b/solaris/ProcessField.h new file mode 100644 index 0000000..65dbcdc --- /dev/null +++ b/solaris/ProcessField.h @@ -0,0 +1,24 @@ +#ifndef HEADER_SolarisProcessField +#define HEADER_SolarisProcessField +/* +htop - solaris/ProcessField.h +(C) 2020 htop dev team +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + + +#define PLATFORM_PROCESS_FIELDS \ + ZONEID = 100, \ + ZONE = 101, \ + PROJID = 102, \ + TASKID = 103, \ + POOLID = 104, \ + CONTID = 105, \ + LWPID = 106, \ + \ + DUMMY_BUMP_FIELD = CWD, \ + // End of list + + +#endif /* HEADER_SolarisProcessField */ diff --git a/solaris/SolarisProcess.c b/solaris/SolarisProcess.c new file mode 100644 index 0000000..840757e --- /dev/null +++ b/solaris/SolarisProcess.c @@ -0,0 +1,137 @@ +/* +htop - SolarisProcess.c +(C) 2015 Hisham H. Muhammad +(C) 2017,2018 Guy M. Broome +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include "solaris/SolarisProcess.h" + +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/syscall.h> + +#include "Process.h" +#include "ProcessList.h" +#include "CRT.h" + +#include "solaris/Platform.h" + + +const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = { + [0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, }, + [PID] = { .name = "PID", .title = "PID", .description = "Process/thread ID", .flags = 0, .pidColumn = true, }, + [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, .pidColumn = true, }, + [PGRP] = { .name = "PGRP", .title = "PGRP", .description = "Process group ID", .flags = 0, .pidColumn = true, }, + [SESSION] = { .name = "SESSION", .title = "SID", .description = "Process's session ID", .flags = 0, .pidColumn = true, }, + [TTY] = { .name = "TTY", .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, .pidColumn = true, }, + //[MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, .defaultSortDesc = true, }, + //[MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, .defaultSortDesc = true, }, + [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, }, + [ELAPSED] = { .name = "ELAPSED", .title = "ELAPSED ", .description = "Time since the process was started", .flags = 0, }, + [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, }, + [M_VIRT] = { .name = "M_VIRT", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, .defaultSortDesc = true, }, + [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, .defaultSortDesc = true, }, + [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, .defaultSortDesc = true, .autoWidth = true, }, + [PERCENT_NORM_CPU] = { .name = "PERCENT_NORM_CPU", .title = "NCPU%", .description = "Normalized percentage of the CPU time the process used in the last sampling (normalized by cpu count)", .flags = 0, .defaultSortDesc = true, .autoWidth = true, }, + [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, .defaultSortDesc = true, }, + [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, .defaultSortDesc = true, }, + [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, .pidColumn = true, }, + [PROC_COMM] = { .name = "COMM", .title = "COMM ", .description = "comm string of the process", .flags = 0, }, + [PROC_EXE] = { .name = "EXE", .title = "EXE ", .description = "Basename of exe of the process", .flags = 0, }, + [CWD] = { .name = "CWD", .title = "CWD ", .description = "The current working directory of the process", .flags = PROCESS_FLAG_CWD, }, + [ZONEID] = { .name = "ZONEID", .title = "ZONEID", .description = "Zone ID", .flags = 0, .pidColumn = true, }, + [ZONE] = { .name = "ZONE", .title = "ZONE ", .description = "Zone name", .flags = 0, }, + [PROJID] = { .name = "PROJID", .title = "PRJID", .description = "Project ID", .flags = 0, .pidColumn = true, }, + [TASKID] = { .name = "TASKID", .title = "TSKID", .description = "Task ID", .flags = 0, .pidColumn = true, }, + [POOLID] = { .name = "POOLID", .title = "POLID", .description = "Pool ID", .flags = 0, .pidColumn = true, }, + [CONTID] = { .name = "CONTID", .title = "CNTID", .description = "Contract ID", .flags = 0, .pidColumn = true, }, + [LWPID] = { .name = "LWPID", .title = "LWPID", .description = "LWP ID", .flags = 0, .pidColumn = true, }, +}; + +Process* SolarisProcess_new(const Settings* settings) { + SolarisProcess* this = xCalloc(1, sizeof(SolarisProcess)); + Object_setClass(this, Class(SolarisProcess)); + Process_init(&this->super, settings); + return &this->super; +} + +void Process_delete(Object* cast) { + SolarisProcess* sp = (SolarisProcess*) cast; + Process_done((Process*)cast); + free(sp->zname); + free(sp); +} + +static void SolarisProcess_writeField(const Process* this, RichString* str, ProcessField field) { + const SolarisProcess* sp = (const SolarisProcess*) this; + char buffer[256]; buffer[255] = '\0'; + int attr = CRT_colors[DEFAULT_COLOR]; + int n = sizeof(buffer) - 1; + switch (field) { + // add Solaris-specific fields here + case ZONEID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, sp->zoneid); break; + case PROJID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, sp->projid); break; + case TASKID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, sp->taskid); break; + case POOLID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, sp->poolid); break; + case CONTID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, sp->contid); break; + case ZONE: Process_printLeftAlignedField(str, attr, sp->zname ? sp->zname : "global", ZONENAME_MAX/4); return; + case PID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, sp->realpid); break; + case PPID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, sp->realppid); break; + case TGID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, sp->realtgid); break; + case LWPID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, sp->lwpid); break; + default: + Process_writeField(this, str, field); + return; + } + RichString_appendWide(str, attr, buffer); +} + +static int SolarisProcess_compareByKey(const Process* v1, const Process* v2, ProcessField key) { + const SolarisProcess* p1 = (const SolarisProcess*)v1; + const SolarisProcess* p2 = (const SolarisProcess*)v2; + + switch (key) { + case ZONEID: + return SPACESHIP_NUMBER(p1->zoneid, p2->zoneid); + case PROJID: + return SPACESHIP_NUMBER(p1->projid, p2->projid); + case TASKID: + return SPACESHIP_NUMBER(p1->taskid, p2->taskid); + case POOLID: + return SPACESHIP_NUMBER(p1->poolid, p2->poolid); + case CONTID: + return SPACESHIP_NUMBER(p1->contid, p2->contid); + case ZONE: + return strcmp(p1->zname ? p1->zname : "global", p2->zname ? p2->zname : "global"); + case PID: + return SPACESHIP_NUMBER(p1->realpid, p2->realpid); + case PPID: + return SPACESHIP_NUMBER(p1->realppid, p2->realppid); + case LWPID: + return SPACESHIP_NUMBER(p1->lwpid, p2->lwpid); + default: + return Process_compareByKey_Base(v1, v2, key); + } +} + +const ProcessClass SolarisProcess_class = { + .super = { + .extends = Class(Process), + .display = Process_display, + .delete = Process_delete, + .compare = Process_compare + }, + .writeField = SolarisProcess_writeField, + .compareByKey = SolarisProcess_compareByKey +}; diff --git a/solaris/SolarisProcess.h b/solaris/SolarisProcess.h new file mode 100644 index 0000000..13a2bc1 --- /dev/null +++ b/solaris/SolarisProcess.h @@ -0,0 +1,49 @@ +#ifndef HEADER_SolarisProcess +#define HEADER_SolarisProcess +/* +htop - SolarisProcess.h +(C) 2015 Hisham H. Muhammad +(C) 2017,2018 Guy M. Broome +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include "config.h" // IWYU pragma: keep + +#include <zone.h> +#include <sys/proc.h> + +/* On OmniOS /usr/include/sys/regset.h redefines ERR to 13 - \r, breaking the Enter key. + * Since ncruses macros use the ERR macro, we can not use another name. + */ +#undef ERR +#include <libproc.h> +#undef ERR +#define ERR (-1) + +#include "Settings.h" + + +typedef struct SolarisProcess_ { + Process super; + zoneid_t zoneid; + char* zname; + taskid_t taskid; + projid_t projid; + poolid_t poolid; + ctid_t contid; + pid_t realpid; + pid_t realppid; + pid_t realtgid; + pid_t lwpid; +} SolarisProcess; + +extern const ProcessClass SolarisProcess_class; + +extern const ProcessFieldData Process_fields[LAST_PROCESSFIELD]; + +Process* SolarisProcess_new(const Settings* settings); + +void Process_delete(Object* cast); + +#endif diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c new file mode 100644 index 0000000..905cfbd --- /dev/null +++ b/solaris/SolarisProcessList.c @@ -0,0 +1,560 @@ +/* +htop - SolarisProcessList.c +(C) 2014 Hisham H. Muhammad +(C) 2017,2018 Guy M. Broome +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + + +#include "solaris/SolarisProcessList.h" + +#include <unistd.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/user.h> +#include <limits.h> +#include <string.h> +#include <procfs.h> +#include <errno.h> +#include <pwd.h> +#include <math.h> +#include <time.h> + +#include "CRT.h" +#include "solaris/Platform.h" +#include "solaris/SolarisProcess.h" + + +#define GZONE "global " +#define UZONE "unknown " + +static int pageSize; +static int pageSizeKB; + +static char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) { + char* zname; + + if ( sproc->zoneid == 0 ) { + zname = xStrdup(GZONE); + } else if ( kd == NULL ) { + zname = xStrdup(UZONE); + } else { + kstat_t* ks = kstat_lookup_wrapper( kd, "zones", sproc->zoneid, NULL ); + zname = xStrdup(ks == NULL ? UZONE : ks->ks_name); + } + + return zname; +} + +static void SolarisProcessList_updateCPUcount(ProcessList* super) { + SolarisProcessList* spl = (SolarisProcessList*) super; + long int s; + bool change = false; + + s = sysconf(_SC_NPROCESSORS_CONF); + if (s < 1) + CRT_fatalError("Cannot get existing CPU count by sysconf(_SC_NPROCESSORS_CONF)"); + + if (s != super->existingCPUs) { + if (s == 1) { + spl->cpus = xRealloc(spl->cpus, sizeof(CPUData)); + spl->cpus[0].online = true; + } else { + spl->cpus = xReallocArray(spl->cpus, s + 1, sizeof(CPUData)); + spl->cpus[0].online = true; /* average is always "online" */ + for (int i = 1; i < s + 1; i++) { + spl->cpus[i].online = false; + } + } + + change = true; + super->existingCPUs = s; + } + + s = sysconf(_SC_NPROCESSORS_ONLN); + if (s < 1) + CRT_fatalError("Cannot get active CPU count by sysconf(_SC_NPROCESSORS_ONLN)"); + + if (s != super->activeCPUs) { + change = true; + super->activeCPUs = s; + } + + if (change) { + kstat_close(spl->kd); + spl->kd = kstat_open(); + if (!spl->kd) + CRT_fatalError("Cannot open kstat handle"); + } +} + +ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* dynamicMeters, Hashtable* dynamicColumns, Hashtable* pidMatchList, uid_t userId) { + SolarisProcessList* spl = xCalloc(1, sizeof(SolarisProcessList)); + ProcessList* pl = (ProcessList*) spl; + ProcessList_init(pl, Class(SolarisProcess), usersTable, dynamicMeters, dynamicColumns, pidMatchList, userId); + + spl->kd = kstat_open(); + if (!spl->kd) + CRT_fatalError("Cannot open kstat handle"); + + pageSize = sysconf(_SC_PAGESIZE); + if (pageSize == -1) + CRT_fatalError("Cannot get pagesize by sysconf(_SC_PAGESIZE)"); + pageSizeKB = pageSize / 1024; + + SolarisProcessList_updateCPUcount(pl); + + return pl; +} + +static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) { + const SolarisProcessList* spl = (SolarisProcessList*) pl; + unsigned int activeCPUs = pl->activeCPUs; + unsigned int existingCPUs = pl->existingCPUs; + kstat_t* cpuinfo = NULL; + kstat_named_t* idletime = NULL; + kstat_named_t* intrtime = NULL; + kstat_named_t* krnltime = NULL; + kstat_named_t* usertime = NULL; + kstat_named_t* cpu_freq = NULL; + double idlebuf = 0; + double intrbuf = 0; + double krnlbuf = 0; + double userbuf = 0; + int arrskip = 0; + + assert(existingCPUs > 0); + assert(spl->kd); + + if (existingCPUs > 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 (unsigned int i = 0; i < existingCPUs; i++) { + CPUData* cpuData = &(spl->cpus[i + arrskip]); + + if ((cpuinfo = kstat_lookup_wrapper(spl->kd, "cpu", i, "sys")) != NULL) { + cpuData->online = true; + if (kstat_read(spl->kd, cpuinfo, NULL) != -1) { + idletime = kstat_data_lookup_wrapper(cpuinfo, "cpu_nsec_idle"); + intrtime = kstat_data_lookup_wrapper(cpuinfo, "cpu_nsec_intr"); + krnltime = kstat_data_lookup_wrapper(cpuinfo, "cpu_nsec_kernel"); + usertime = kstat_data_lookup_wrapper(cpuinfo, "cpu_nsec_user"); + } + } else { + cpuData->online = false; + continue; + } + + assert( (idletime != NULL) && (intrtime != NULL) + && (krnltime != NULL) && (usertime != NULL) ); + + if (pl->settings->showCPUFrequency) { + if ((cpuinfo = kstat_lookup_wrapper(spl->kd, "cpu_info", i, NULL)) != NULL) { + if (kstat_read(spl->kd, cpuinfo, NULL) != -1) { + cpu_freq = kstat_data_lookup_wrapper(cpuinfo, "current_clock_Hz"); + } + } + + assert( cpu_freq != NULL ); + } + + uint64_t 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; + // Add frequency in MHz + cpuData->frequency = pl->settings->showCPUFrequency ? (double)cpu_freq->value.ui64 / 1E6 : NAN; + // Accumulate the current percentages into buffers for later average calculation + if (existingCPUs > 1) { + userbuf += cpuData->userPercent; + krnlbuf += cpuData->systemPercent; + intrbuf += cpuData->irqPercent; + idlebuf += cpuData->idlePercent; + } + } + + if (existingCPUs > 1) { + CPUData* cpuData = &(spl->cpus[0]); + cpuData->userPercent = userbuf / activeCPUs; + cpuData->nicePercent = (double)0.0; // Not implemented on Solaris + cpuData->systemPercent = krnlbuf / activeCPUs; + cpuData->irqPercent = intrbuf / activeCPUs; + cpuData->systemAllPercent = cpuData->systemPercent + cpuData->irqPercent; + cpuData->idlePercent = idlebuf / activeCPUs; + } +} + +static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { + SolarisProcessList* spl = (SolarisProcessList*) pl; + static kstat_t *meminfo = NULL; + int ksrphyserr = -1; + kstat_named_t *totalmem_pgs = NULL; + kstat_named_t *freemem_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 == NULL) { + // Look up the kstat chain just once, it never changes + meminfo = kstat_lookup_wrapper(spl->kd, "unix", 0, "system_pages"); + } + if (meminfo != NULL) { + ksrphyserr = kstat_read(spl->kd, meminfo, NULL); + } + if (ksrphyserr != -1) { + totalmem_pgs = kstat_data_lookup_wrapper(meminfo, "physmem"); + freemem_pgs = kstat_data_lookup_wrapper(meminfo, "freemem"); + pages = kstat_data_lookup_wrapper(meminfo, "pagestotal"); + + pl->totalMem = totalmem_pgs->value.ui64 * pageSizeKB; + if (pl->totalMem > freemem_pgs->value.ui64 * pageSizeKB) { + pl->usedMem = pl->totalMem - freemem_pgs->value.ui64 * pageSizeKB; + } else { + pl->usedMem = 0; // This can happen in non-global zone (in theory) + } + // 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) * pageSizeKB; + } else { + // Fall back to basic sysconf if kstat isn't working + pl->totalMem = sysconf(_SC_PHYS_PAGES) * pageSize; + pl->buffersMem = 0; + pl->cachedMem = 0; + pl->usedMem = pl->totalMem - (sysconf(_SC_AVPHYS_PAGES) * pageSize); + } + + // 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 * pageSizeKB; + pl->usedSwap = pl->totalSwap - (totalfree * pageSizeKB); +} + +static inline void SolarisProcessList_scanZfsArcstats(ProcessList* pl) { + SolarisProcessList* spl = (SolarisProcessList*) pl; + kstat_t *arcstats = NULL; + int ksrphyserr = -1; + kstat_named_t *cur_kstat = NULL; + + if (spl->kd != NULL) { + arcstats = kstat_lookup_wrapper(spl->kd, "zfs", 0, "arcstats"); + } + if (arcstats != NULL) { + ksrphyserr = kstat_read(spl->kd, arcstats, NULL); + } + if (ksrphyserr != -1) { + cur_kstat = kstat_data_lookup_wrapper( arcstats, "size" ); + spl->zfs.size = cur_kstat->value.ui64 / 1024; + spl->zfs.enabled = spl->zfs.size > 0 ? 1 : 0; + + cur_kstat = kstat_data_lookup_wrapper( arcstats, "c_max" ); + spl->zfs.max = cur_kstat->value.ui64 / 1024; + + cur_kstat = kstat_data_lookup_wrapper( arcstats, "mfu_size" ); + spl->zfs.MFU = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0; + + cur_kstat = kstat_data_lookup_wrapper( arcstats, "mru_size" ); + spl->zfs.MRU = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0; + + cur_kstat = kstat_data_lookup_wrapper( arcstats, "anon_size" ); + spl->zfs.anon = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0; + + cur_kstat = kstat_data_lookup_wrapper( arcstats, "hdr_size" ); + spl->zfs.header = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0; + + cur_kstat = kstat_data_lookup_wrapper( arcstats, "other_size" ); + spl->zfs.other = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0; + + if ((cur_kstat = kstat_data_lookup_wrapper( arcstats, "compressed_size" )) != NULL) { + spl->zfs.compressed = cur_kstat->value.ui64 / 1024; + spl->zfs.isCompressed = 1; + + cur_kstat = kstat_data_lookup_wrapper( arcstats, "uncompressed_size" ); + spl->zfs.uncompressed = cur_kstat->value.ui64 / 1024; + } else { + spl->zfs.isCompressed = 0; + } + } +} + +void ProcessList_delete(ProcessList* pl) { + SolarisProcessList* spl = (SolarisProcessList*) pl; + ProcessList_done(pl); + free(spl->cpus); + if (spl->kd) { + kstat_close(spl->kd); + } + free(spl); +} + +static void SolarisProcessList_updateExe(pid_t pid, Process* proc) { + char path[32]; + xSnprintf(path, sizeof(path), "/proc/%d/path/a.out", pid); + + char target[PATH_MAX]; + ssize_t ret = readlink(path, target, sizeof(target) - 1); + if (ret <= 0) + return; + + target[ret] = '\0'; + Process_updateExe(proc, target); +} + +static void SolarisProcessList_updateCwd(pid_t pid, Process* proc) { + char path[32]; + xSnprintf(path, sizeof(path), "/proc/%d/cwd", pid); + + char target[PATH_MAX]; + ssize_t ret = readlink(path, target, sizeof(target) - 1); + if (ret <= 0) + return; + + target[ret] = '\0'; + free_and_xStrdup(&proc->procCwd, target); +} + +/* Taken from: https://docs.oracle.com/cd/E19253-01/817-6223/6mlkidlom/index.html#tbl-sched-state */ +static inline ProcessState SolarisProcessList_getProcessState(char state) { + switch (state) { + case 'S': return SLEEPING; + case 'R': return RUNNABLE; + case 'O': return RUNNING; + case 'Z': return ZOMBIE; + case 'T': return STOPPED; + case 'I': return IDLE; + default: return UNKNOWN; + } +} + +/* 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. + */ + +static int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo, void* listptr) { + 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, SolarisProcess_new); + SolarisProcess* sproc = (SolarisProcess*) proc; + + // 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 - NZERO; + proc->processor = _lwpsinfo->pr_onpro; + proc->state = SolarisProcessList_getProcessState(_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->pgrp = _psinfo->pr_pgid; + proc->nlwp = _psinfo->pr_nlwp; + proc->session = _psinfo->pr_sid; + + proc->tty_nr = _psinfo->pr_ttydev; + const char* name = (_psinfo->pr_ttydev != PRNODEV) ? ttyname(_psinfo->pr_ttydev) : NULL; + if (!name) { + free(proc->tty_name); + proc->tty_name = NULL; + } else { + free_and_xStrdup(&proc->tty_name, name); + } + + proc->m_resident = _psinfo->pr_rssize; // KB + proc->m_virt = _psinfo->pr_size; // KB + + if (proc->st_uid != _psinfo->pr_euid) { + proc->st_uid = _psinfo->pr_euid; + proc->user = UsersTable_getRef(pl->usersTable, proc->st_uid); + } + + if (!preExisting) { + sproc->realpid = _psinfo->pr_pid; + sproc->lwpid = lwpid_real; + sproc->zoneid = _psinfo->pr_zoneid; + sproc->zname = SolarisProcessList_readZoneName(spl->kd, sproc); + SolarisProcessList_updateExe(_psinfo->pr_pid, proc); + + Process_updateComm(proc, _psinfo->pr_fname); + Process_updateCmdline(proc, _psinfo->pr_psargs, 0, 0); + + if (proc->settings->ss->flags & PROCESS_FLAG_CWD) { + SolarisProcessList_updateCwd(_psinfo->pr_pid, proc); + } + } + + // 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; + sproc->realtgid = _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; + Process_updateCPUFieldWidths(proc->percent_cpu); + + proc->time = _psinfo->pr_time.tv_sec * 100 + _psinfo->pr_time.tv_nsec / 10000000; + if (!preExisting) { // Tasks done only for NEW processes + proc->isUserlandThread = false; + proc->starttime_ctime = _psinfo->pr_start.tv_sec; + } + + // Update proc and thread counts based on settings + if (proc->isKernelThread && !pl->settings->hideKernelThreads) { + pl->kernelThreads += proc->nlwp; + pl->totalTasks += proc->nlwp + 1; + if (proc->state == RUNNING) { + pl->runningTasks++; + } + } else if (!proc->isKernelThread) { + if (proc->state == RUNNING) { + pl->runningTasks++; + } + if (pl->settings->hideUserlandThreads) { + pl->totalTasks++; + } else { + pl->userlandThreads += proc->nlwp; + pl->totalTasks += proc->nlwp + 1; + } + } + proc->show = !(pl->settings->hideKernelThreads && proc->isKernelThread); + } 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; + Process_updateCPUFieldWidths(proc->percent_cpu); + + proc->time = _lwpsinfo->pr_time.tv_sec * 100 + _lwpsinfo->pr_time.tv_nsec / 10000000; + if (!preExisting) { // Tasks done only for NEW LWPs + proc->isUserlandThread = true; + proc->ppid = _psinfo->pr_pid * 1024; + proc->tgid = _psinfo->pr_pid * 1024; + sproc->realppid = _psinfo->pr_pid; + sproc->realtgid = _psinfo->pr_pid; + proc->starttime_ctime = _lwpsinfo->pr_start.tv_sec; + } + + // Top-level process only gets this for the representative LWP + if (proc->isKernelThread && !pl->settings->hideKernelThreads) { + proc->show = true; + } + if (!proc->isKernelThread && !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)) { + proc->isKernelThread = true; + } else { + proc->isKernelThread = false; + } + + Process_fillStarttimeBuffer(proc); + ProcessList_add(pl, proc); + } + + proc->updated = true; + + // End common code pass 2 + + return 0; +} + +void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { + SolarisProcessList_updateCPUcount(super); + SolarisProcessList_scanCPUTime(super); + SolarisProcessList_scanMemoryInfo(super); + SolarisProcessList_scanZfsArcstats(super); + + // in pause mode only gather global data for meters (CPU/memory/...) + if (pauseProcessUpdate) { + return; + } + + super->kernelThreads = 1; + proc_walk(&SolarisProcessList_walkproc, super, PR_WALK_LWP); +} + +bool ProcessList_isCPUonline(const ProcessList* super, unsigned int id) { + assert(id < super->existingCPUs); + + const SolarisProcessList* spl = (const SolarisProcessList*) super; + + return (super->existingCPUs == 1) ? true : spl->cpus[id + 1].online; +} diff --git a/solaris/SolarisProcessList.h b/solaris/SolarisProcessList.h new file mode 100644 index 0000000..91fd4f4 --- /dev/null +++ b/solaris/SolarisProcessList.h @@ -0,0 +1,65 @@ +#ifndef HEADER_SolarisProcessList +#define HEADER_SolarisProcessList +/* +htop - SolarisProcessList.h +(C) 2014 Hisham H. Muhammad +(C) 2017,2018 Guy M. Broome +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include "config.h" // IWYU pragma: keep + +#include <kstat.h> +#include <stdbool.h> +#include <stdint.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> + +#include "Hashtable.h" +#include "ProcessList.h" +#include "UsersTable.h" + +#include "solaris/SolarisProcess.h" + +#include "zfs/ZfsArcStats.h" + + +#define ZONE_ERRMSGLEN 1024 +extern char zone_errmsg[ZONE_ERRMSGLEN]; + +typedef struct CPUData_ { + double userPercent; + double nicePercent; + double systemPercent; + double irqPercent; + double idlePercent; + double systemAllPercent; + double frequency; + uint64_t luser; + uint64_t lkrnl; + uint64_t lintr; + uint64_t lidle; + bool online; +} CPUData; + +typedef struct SolarisProcessList_ { + ProcessList super; + kstat_ctl_t* kd; + CPUData* cpus; + ZfsArcStats zfs; +} SolarisProcessList; + +ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* dynamicMeters, Hashtable* dynamicColumns, Hashtable* pidMatchList, uid_t userId); + +void ProcessList_delete(ProcessList* pl); + +void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate); + +bool ProcessList_isCPUonline(const ProcessList* super, unsigned int id); + +#endif |