diff options
Diffstat (limited to 'unsupported')
-rw-r--r-- | unsupported/Platform.c | 165 | ||||
-rw-r--r-- | unsupported/Platform.h | 124 | ||||
-rw-r--r-- | unsupported/ProcessField.h | 15 | ||||
-rw-r--r-- | unsupported/UnsupportedMachine.c | 56 | ||||
-rw-r--r-- | unsupported/UnsupportedMachine.h | 17 | ||||
-rw-r--r-- | unsupported/UnsupportedProcess.c | 112 | ||||
-rw-r--r-- | unsupported/UnsupportedProcess.h | 28 | ||||
-rw-r--r-- | unsupported/UnsupportedProcessTable.c | 90 | ||||
-rw-r--r-- | unsupported/UnsupportedProcessTable.h | 17 |
9 files changed, 624 insertions, 0 deletions
diff --git a/unsupported/Platform.c b/unsupported/Platform.c new file mode 100644 index 0000000..dbfddd9 --- /dev/null +++ b/unsupported/Platform.c @@ -0,0 +1,165 @@ +/* +htop - unsupported/Platform.c +(C) 2014 Hisham H. Muhammad +(C) 2015 David C. Hunt +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include "config.h" // IWYU pragma: keep + +#include "unsupported/Platform.h" + +#include <math.h> + +#include "CPUMeter.h" +#include "ClockMeter.h" +#include "DateMeter.h" +#include "DateTimeMeter.h" +#include "FileDescriptorMeter.h" +#include "HostnameMeter.h" +#include "LoadAverageMeter.h" +#include "Macros.h" +#include "MemoryMeter.h" +#include "MemorySwapMeter.h" +#include "SwapMeter.h" +#include "SysArchMeter.h" +#include "TasksMeter.h" +#include "UptimeMeter.h" + + +const ScreenDefaults Platform_defaultScreens[] = { + { + .name = "Main", + .columns = "PID 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 }, +}; + +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, + &FileDescriptorMeter_class, + &BlankMeter_class, + NULL +}; + +static const char Platform_unsupported[] = "unsupported"; + +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) { + return 0; +} + +void Platform_getLoadAverage(double* one, double* five, double* fifteen) { + *one = 0; + *five = 0; + *fifteen = 0; +} + +pid_t Platform_getMaxPid(void) { + return INT_MAX; +} + +double Platform_setCPUValues(Meter* this, unsigned int cpu) { + (void) cpu; + + double* v = this->values; + v[CPU_METER_FREQUENCY] = NAN; + v[CPU_METER_TEMPERATURE] = NAN; + + this->curItems = 1; + + return 0.0; +} + +void Platform_setMemoryValues(Meter* this) { + (void) this; +} + +void Platform_setSwapValues(Meter* this) { + (void) this; +} + +char* Platform_getProcessEnv(pid_t pid) { + (void) pid; + return NULL; +} + +FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) { + (void)pid; + return NULL; +} + +void Platform_getFileDescriptors(double* used, double* max) { + *used = 1337; + *max = 4711; +} + +bool Platform_getDiskIO(DiskIOData* data) { + (void)data; + return false; +} + +bool Platform_getNetworkIO(NetworkIOData* data) { + (void)data; + return false; +} + +void Platform_getBattery(double* percent, ACPresence* isOnAC) { + *percent = NAN; + *isOnAC = AC_ERROR; +} + +void Platform_getHostname(char* buffer, size_t size) { + String_safeStrncpy(buffer, Platform_unsupported, size); +} + +void Platform_getRelease(char** string) { + *string = xStrdup(Platform_unsupported); +} diff --git a/unsupported/Platform.h b/unsupported/Platform.h new file mode 100644 index 0000000..c4cd06a --- /dev/null +++ b/unsupported/Platform.h @@ -0,0 +1,124 @@ +#ifndef HEADER_Platform +#define HEADER_Platform +/* +htop - unsupported/Platform.h +(C) 2014 Hisham H. Muhammad +(C) 2015 David C. Hunt +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include <stdbool.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 "unsupported/UnsupportedProcess.h" + + +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); + +pid_t Platform_getMaxPid(void); + +double Platform_setCPUValues(Meter* this, unsigned int cpu); + +void Platform_setMemoryValues(Meter* this); + +void Platform_setSwapValues(Meter* this); + +char* Platform_getProcessEnv(pid_t pid); + +FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid); + +void Platform_getFileDescriptors(double* used, double* max); + +bool Platform_getDiskIO(DiskIOData* data); + +bool Platform_getNetworkIO(NetworkIOData* data); + +void Platform_getBattery(double* percent, ACPresence* isOnAC); + +void Platform_getHostname(char* buffer, size_t size); + +void Platform_getRelease(char** string); + +#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 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_dynamicColumnName(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; +} + +static inline Hashtable* Platform_dynamicScreens(void) { + return NULL; +} + +static inline void Platform_defaultDynamicScreens(ATTR_UNUSED Settings* settings) { } + +static inline void Platform_addDynamicScreen(ATTR_UNUSED ScreenSettings* ss) { } + +static inline void Platform_addDynamicScreenAvailableColumns(ATTR_UNUSED Panel* availableColumns, ATTR_UNUSED const char* screen) { } + +static inline void Platform_dynamicScreensDone(ATTR_UNUSED Hashtable* screens) { } + +#endif diff --git a/unsupported/ProcessField.h b/unsupported/ProcessField.h new file mode 100644 index 0000000..0c908ea --- /dev/null +++ b/unsupported/ProcessField.h @@ -0,0 +1,15 @@ +#ifndef HEADER_UnsupportedProcessField +#define HEADER_UnsupportedProcessField +/* +htop - unsupported/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 \ + // End of list + + +#endif /* HEADER_UnsupportedProcessField */ diff --git a/unsupported/UnsupportedMachine.c b/unsupported/UnsupportedMachine.c new file mode 100644 index 0000000..a6635ac --- /dev/null +++ b/unsupported/UnsupportedMachine.c @@ -0,0 +1,56 @@ +/* +htop - UnsupportedMachine.c +(C) 2014 Hisham H. Muhammad +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include "UnsupportedMachine.h" + +#include <stdlib.h> +#include <string.h> + +#include "Machine.h" + + +Machine* Machine_new(UsersTable* usersTable, uid_t userId) { + UnsupportedMachine* this = xCalloc(1, sizeof(UnsupportedMachine)); + Machine* super = &this->super; + + Machine_init(super, usersTable, userId); + + super->existingCPUs = 1; + super->activeCPUs = 1; + + return super; +} + +void Machine_delete(Machine* super) { + UnsupportedMachine* this = (UnsupportedMachine*) super; + Machine_done(super); + free(this); +} + +bool Machine_isCPUonline(const Machine* host, unsigned int id) { + assert(id < host->existingCPUs); + + (void) host; (void) id; + + return true; +} + +void Machine_scan(Machine* super) { + super->existingCPUs = 1; + super->activeCPUs = 1; + + super->totalMem = 0; + super->usedMem = 0; + super->buffersMem = 0; + super->cachedMem = 0; + super->sharedMem = 0; + super->availableMem = 0; + + super->totalSwap = 0; + super->usedSwap = 0; + super->cachedSwap = 0; +} diff --git a/unsupported/UnsupportedMachine.h b/unsupported/UnsupportedMachine.h new file mode 100644 index 0000000..4ec760f --- /dev/null +++ b/unsupported/UnsupportedMachine.h @@ -0,0 +1,17 @@ +#ifndef HEADER_UnsupportedMachine +#define HEADER_UnsupportedMachine +/* +htop - UnsupportedMachine.h +(C) 2014 Hisham H. Muhammad +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include "Machine.h" + + +typedef struct UnsupportedMachine_ { + Machine super; +} UnsupportedMachine; + +#endif diff --git a/unsupported/UnsupportedProcess.c b/unsupported/UnsupportedProcess.c new file mode 100644 index 0000000..3d6d883 --- /dev/null +++ b/unsupported/UnsupportedProcess.c @@ -0,0 +1,112 @@ +/* +htop - UnsupportedProcess.c +(C) 2015 Hisham H. Muhammad +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include "config.h" // IWYU pragma: keep + +#include "unsupported/UnsupportedProcess.h" + +#include <stdlib.h> + +#include "CRT.h" +#include "Process.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, D disk, Z zombie, T traced, W paging)", .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, }, +}; + +Process* UnsupportedProcess_new(const Machine* host) { + Process* this = xCalloc(1, sizeof(UnsupportedProcess)); + Object_setClass(this, Class(UnsupportedProcess)); + Process_init(this, host); + return this; +} + +void Process_delete(Object* cast) { + Process* super = (Process*) cast; + Process_done(super); + // free platform-specific fields here + free(cast); +} + +static void UnsupportedProcess_rowWriteField(const Row* super, RichString* str, ProcessField field) { + const UnsupportedProcess* up = (const UnsupportedProcess*) super; + + bool coloring = super->host->settings->highlightMegabytes; + char buffer[256]; buffer[255] = '\0'; + int attr = CRT_colors[DEFAULT_COLOR]; + size_t n = sizeof(buffer) - 1; + + (void) coloring; + (void) n; + + switch (field) { + /* Add platform specific fields */ + default: + Process_writeField(&up->super, str, field); + return; + } + + RichString_appendWide(str, attr, buffer); +} + +static int UnsupportedProcess_compareByKey(const Process* v1, const Process* v2, ProcessField key) { + const UnsupportedProcess* p1 = (const UnsupportedProcess*)v1; + const UnsupportedProcess* p2 = (const UnsupportedProcess*)v2; + + (void) p1; + (void) p2; + + switch (key) { + /* Add platform specific fields */ + default: + return Process_compareByKey_Base(v1, v2, key); + } +} + +const ProcessClass UnsupportedProcess_class = { + .super = { + .super = { + .extends = Class(Process), + .display = Row_display, + .delete = Process_delete, + .compare = Process_compare + }, + .isHighlighted = Process_rowIsHighlighted, + .isVisible = Process_rowIsVisible, + .matchesFilter = Process_rowMatchesFilter, + .compareByParent = Process_compareByParent, + .sortKeyString = Process_rowGetSortKey, + .writeField = UnsupportedProcess_rowWriteField + }, + .compareByKey = UnsupportedProcess_compareByKey +}; diff --git a/unsupported/UnsupportedProcess.h b/unsupported/UnsupportedProcess.h new file mode 100644 index 0000000..21956dd --- /dev/null +++ b/unsupported/UnsupportedProcess.h @@ -0,0 +1,28 @@ +#ifndef HEADER_UnsupportedProcess +#define HEADER_UnsupportedProcess +/* +htop - UnsupportedProcess.h +(C) 2015 Hisham H. Muhammad +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include "Machine.h" + + +typedef struct UnsupportedProcess_ { + Process super; + + /* Add platform specific fields */ +} UnsupportedProcess; + + +extern const ProcessFieldData Process_fields[LAST_PROCESSFIELD]; + +Process* UnsupportedProcess_new(const Machine* host); + +void Process_delete(Object* cast); + +extern const ProcessClass UnsupportedProcess_class; + +#endif diff --git a/unsupported/UnsupportedProcessTable.c b/unsupported/UnsupportedProcessTable.c new file mode 100644 index 0000000..db43f1e --- /dev/null +++ b/unsupported/UnsupportedProcessTable.c @@ -0,0 +1,90 @@ +/* +htop - UnsupportedProcessTable.c +(C) 2014 Hisham H. Muhammad +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include "config.h" // IWYU pragma: keep + +#include "UnsupportedProcessTable.h" + +#include <stdlib.h> +#include <string.h> + +#include "ProcessTable.h" +#include "UnsupportedProcess.h" + + +ProcessTable* ProcessTable_new(Machine* host, Hashtable* pidMatchList) { + UnsupportedProcessTable* this = xCalloc(1, sizeof(UnsupportedProcessTable)); + Object_setClass(this, Class(ProcessTable)); + + ProcessTable* super = &this->super; + ProcessTable_init(super, Class(Process), host, pidMatchList); + + return this; +} + +void ProcessTable_delete(Object* cast) { + UnsupportedProcessTable* this = (UnsupportedProcessTable*) cast; + ProcessTable_done(&this->super); + free(this); +} + +void ProcessTable_goThroughEntries(ProcessTable* super) { + bool preExisting = true; + Process* proc; + + proc = ProcessTable_getProcess(super, 1, &preExisting, UnsupportedProcess_new); + + /* Empty values */ + proc->time = proc->time + 10; + Process_setPid(proc, 1); + Process_setParent(proc, 1); + Process_setThreadGroup(proc, 0); + + Process_updateComm(proc, "commof16char"); + Process_updateCmdline(proc, "<unsupported architecture>", 0, 0); + Process_updateExe(proc, "/path/to/executable"); + + const Settings* settings = proc->host->settings; + if (settings->ss->flags & PROCESS_FLAG_CWD) { + free_and_xStrdup(&proc->procCwd, "/current/working/directory"); + } + + proc->super.updated = true; + + proc->state = RUNNING; + proc->isKernelThread = false; + proc->isUserlandThread = false; + proc->super.show = true; /* Reflected in settings-> "hideXXX" really */ + proc->pgrp = 0; + proc->session = 0; + proc->tty_nr = 0; + proc->tty_name = NULL; + proc->tpgid = 0; + proc->processor = 0; + + proc->percent_cpu = 2.5; + proc->percent_mem = 2.5; + Process_updateCPUFieldWidths(proc->percent_cpu); + + proc->st_uid = 0; + proc->user = "nobody"; /* Update whenever proc->st_uid is changed */ + + proc->priority = 0; + proc->nice = 0; + proc->nlwp = 1; + proc->starttime_ctime = 1433116800; // Jun 01, 2015 + Process_fillStarttimeBuffer(proc); + + proc->m_virt = 100; + proc->m_resident = 100; + + proc->minflt = 20; + proc->majflt = 20; + + if (!preExisting) + ProcessTable_add(super, proc); +} diff --git a/unsupported/UnsupportedProcessTable.h b/unsupported/UnsupportedProcessTable.h new file mode 100644 index 0000000..1de8087 --- /dev/null +++ b/unsupported/UnsupportedProcessTable.h @@ -0,0 +1,17 @@ +#ifndef HEADER_UnsupportedProcessTable +#define HEADER_UnsupportedProcessTable +/* +htop - UnsupportedProcessTable.h +(C) 2014 Hisham H. Muhammad +Released under the GNU GPLv2+, see the COPYING file +in the source distribution for its full text. +*/ + +#include "ProcessTable.h" + + +typedef struct UnsupportedProcessTable_ { + ProcessTable super; +} UnsupportedProcessTable; + +#endif |