From adbfe3c3f171af332322d61f2a4912f36b57edda Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 16 Mar 2015 03:13:42 -0300 Subject: [PATCH] Get FreeBSD tree to compile again with latest changes. --- ColumnsPanel.c | 4 +- MainPanel.h | 45 ++++++++++++ Makefile.am | 7 +- ProcessList.c | 10 +++ ProcessList.h | 10 +++ Settings.c | 2 +- freebsd/Battery.c | 15 ++++ freebsd/Battery.h | 15 ++++ freebsd/FreeBSDProcess.c | 134 +++++++++++++++++++++++++++++++++++ freebsd/FreeBSDProcess.h | 40 +++++++++++ freebsd/FreeBSDProcessList.c | 18 +++-- freebsd/FreeBSDProcessList.h | 10 ++- freebsd/Platform.c | 23 +++++- freebsd/Platform.h | 14 +++- linux/LinuxProcess.c | 2 +- linux/LinuxProcessList.c | 10 --- 16 files changed, 333 insertions(+), 26 deletions(-) create mode 100644 MainPanel.h create mode 100644 freebsd/Battery.c create mode 100644 freebsd/Battery.h create mode 100644 freebsd/FreeBSDProcess.c create mode 100644 freebsd/FreeBSDProcess.h diff --git a/ColumnsPanel.c b/ColumnsPanel.c index 02b3d386..45b4de00 100644 --- a/ColumnsPanel.c +++ b/ColumnsPanel.c @@ -129,7 +129,9 @@ ColumnsPanel* ColumnsPanel_new(Settings* settings) { ProcessField* fields = this->settings->fields; for (; *fields; fields++) { - Panel_add(super, (Object*) ListItem_new(Process_fields[*fields].name, *fields)); + if (Process_fields[*fields].name) { + Panel_add(super, (Object*) ListItem_new(Process_fields[*fields].name, *fields)); + } } return this; } diff --git a/MainPanel.h b/MainPanel.h new file mode 100644 index 00000000..830890e5 --- /dev/null +++ b/MainPanel.h @@ -0,0 +1,45 @@ +/* Do not edit this file. It was automatically generated. */ + +#ifndef HEADER_MainPanel +#define HEADER_MainPanel +/* +htop - ColumnsPanel.h +(C) 2004-2015 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "Panel.h" +#include "Action.h" +#include "Settings.h" + +typedef struct MainPanel_ { + Panel super; + State* state; + FunctionBar* fuBar; + Htop_Action *keys; + pid_t pidSearch; +} MainPanel; + +typedef bool(*MainPanel_ForeachProcessFn)(Process*, size_t); + + +void MainPanel_updateTreeFunctions(FunctionBar* fuBar, bool mode); + +void MainPanel_pidSearch(MainPanel* this, int ch); + +int MainPanel_selectedPid(MainPanel* this); + +const char* MainPanel_getValue(MainPanel* this, int i); + +bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, int arg, bool* wasAnyTagged); + +extern PanelClass MainPanel_class; + +MainPanel* MainPanel_new(FunctionBar* fuBar); + +void MainPanel_setState(MainPanel* this, State* state); + +void MainPanel_delete(Object* object); + +#endif diff --git a/Makefile.am b/Makefile.am index bdf7b05a..3b3ba432 100644 --- a/Makefile.am +++ b/Makefile.am @@ -12,7 +12,7 @@ applications_DATA = htop.desktop pixmapdir = $(datadir)/pixmaps pixmap_DATA = htop.png -htop_CFLAGS = -pedantic -Wall $(wextra_flag) -std=c99 -rdynamic -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(my_htop_platform)" +htop_CFLAGS = -pedantic -Wall $(wextra_flag) -std=c99 -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(my_htop_platform)" AM_CPPFLAGS = -DNDEBUG myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \ @@ -34,6 +34,7 @@ UptimeMeter.h TraceScreen.h UsersTable.h Vector.h Process.h AffinityPanel.h \ HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h if HTOP_LINUX +htop_CFLAGS += -rdynamic myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \ linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c @@ -43,10 +44,10 @@ endif if HTOP_FREEBSD myhtopplatsources = freebsd/Platform.c freebsd/FreeBSDProcessList.c \ -freebsd/FreeBSDCRT.c +freebsd/FreeBSDProcess.c freebsd/FreeBSDCRT.c freebsd/Battery.c myhtopplatheaders = freebsd/Platform.h freebsd/FreeBSDProcessList.h \ -freebsd/FreeBSDCRT.h +freebsd/FreeBSDProcess.h freebsd/FreeBSDCRT.h freebsd/Battery.h endif if HTOP_UNSUPPORTED diff --git a/ProcessList.c b/ProcessList.c index 1b36ac54..953c0e30 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -49,6 +49,16 @@ typedef struct ProcessList_ { bool topologyOk; #endif + unsigned long long int totalMem; + unsigned long long int usedMem; + unsigned long long int freeMem; + unsigned long long int sharedMem; + unsigned long long int buffersMem; + unsigned long long int cachedMem; + unsigned long long int totalSwap; + unsigned long long int usedSwap; + unsigned long long int freeSwap; + int cpuCount; } ProcessList; diff --git a/ProcessList.h b/ProcessList.h index e4c266c6..ba6f337d 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -43,6 +43,16 @@ typedef struct ProcessList_ { bool topologyOk; #endif + unsigned long long int totalMem; + unsigned long long int usedMem; + unsigned long long int freeMem; + unsigned long long int sharedMem; + unsigned long long int buffersMem; + unsigned long long int cachedMem; + unsigned long long int totalSwap; + unsigned long long int usedSwap; + unsigned long long int freeSwap; + int cpuCount; } ProcessList; diff --git a/Settings.c b/Settings.c index 2b1fde96..41d8738a 100644 --- a/Settings.c +++ b/Settings.c @@ -139,7 +139,7 @@ static void readFields(ProcessField* fields, int* flags, const char* line) { for (j = 0, i = 0; i < Platform_numberOfFields && ids[i]; i++) { // This "+1" is for compatibility with the older enum format. int id = atoi(ids[i]) + 1; - if (id > 0 && id < Platform_numberOfFields) { + if (id > 0 && Process_fields[id].name && id < Platform_numberOfFields) { fields[j] = id; *flags |= Process_fields[id].flags; j++; diff --git a/freebsd/Battery.c b/freebsd/Battery.c new file mode 100644 index 00000000..ab63aa10 --- /dev/null +++ b/freebsd/Battery.c @@ -0,0 +1,15 @@ +/* +htop - freebsd/Battery.c +(C) 2015 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "BatteryMeter.h" + +void Battery_getData(double* level, ACPresence* isOnAC) { + // TODO + *level = -1; + *isOnAC = AC_ERROR; +} + diff --git a/freebsd/Battery.h b/freebsd/Battery.h new file mode 100644 index 00000000..2b4a9a87 --- /dev/null +++ b/freebsd/Battery.h @@ -0,0 +1,15 @@ +/* Do not edit this file. It was automatically generated. */ + +#ifndef HEADER_Battery +#define HEADER_Battery +/* +htop - freebsd/Battery.h +(C) 2015 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +void Battery_getData(double* level, ACPresence* isOnAC); + + +#endif diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c new file mode 100644 index 00000000..614a6b8e --- /dev/null +++ b/freebsd/FreeBSDProcess.c @@ -0,0 +1,134 @@ +/* +htop - FreeBSDProcess.c +(C) 2015 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "Process.h" +#include "ProcessList.h" +#include "FreeBSDProcess.h" +#include "Platform.h" +#include "CRT.h" + +#include +#include +#include + +/*{ + +typedef enum FreeBSDProcessFields { + // Add platform-specific fields here, with ids >= 100 + LAST_PROCESSFIELD = 100, +} FreeBSDProcessField; + +typedef struct FreeBSDProcess_ { + Process super; +} FreeBSDProcess; + +}*/ + +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, D disk, Z zombie, T traced, W paging)", .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 = " SESN ", .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, }, + + [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, }, + [LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, }, +}; + +char* Process_pidFormat = "%7u "; +char* Process_tpgidFormat = "%7u "; + +void Process_setupColumnWidths() { + int maxPid = Platform_getMaxPid(); + if (maxPid == -1) return; + if (maxPid > 99999) { + Process_fields[PID].title = " PID "; + Process_fields[PPID].title = " PPID "; + Process_fields[TPGID].title = " TPGID "; + Process_fields[TGID].title = " TGID "; + Process_fields[PGRP].title = " PGRP "; + Process_fields[SESSION].title = " SESN "; + Process_pidFormat = "%7u "; + Process_tpgidFormat = "%7d "; + } else { + Process_fields[PID].title = " PID "; + Process_fields[PPID].title = " PPID "; + Process_fields[TPGID].title = "TPGID "; + Process_fields[TGID].title = " TGID "; + Process_fields[PGRP].title = " PGRP "; + Process_fields[SESSION].title = " SESN "; + Process_pidFormat = "%5u "; + Process_tpgidFormat = "%5d "; + } +} + +FreeBSDProcess* FreeBSDProcess_new(Settings* settings) { + FreeBSDProcess* this = calloc(sizeof(FreeBSDProcess), 1); + Object_setClass(this, Class(Process)); + Process_init(&this->super, settings); + return this; +} + +void Process_delete(Object* cast) { + FreeBSDProcess* this = (FreeBSDProcess*) cast; + Process_done((Process*)cast); + free(this); +} + +void Process_writeField(Process* this, RichString* str, ProcessField field) { + //FreeBSDProcess* fp = (FreeBSDProcess*) this; + char buffer[256]; buffer[255] = '\0'; + int attr = CRT_colors[DEFAULT_COLOR]; + //int n = sizeof(buffer) - 1; + switch (field) { + // add FreeBSD-specific fields here + default: + Process_writeDefaultField(this, str, field); + return; + } + RichString_append(str, attr, buffer); +} + +long Process_compare(const void* v1, const void* v2) { + FreeBSDProcess *p1, *p2; + Settings *settings = ((Process*)v1)->settings; + if (settings->direction == 1) { + p1 = (FreeBSDProcess*)v1; + p2 = (FreeBSDProcess*)v2; + } else { + p2 = (FreeBSDProcess*)v1; + p1 = (FreeBSDProcess*)v2; + } + switch (settings->sortKey) { + // add FreeBSD-specific fields here + default: + return Process_defaultCompare(v1, v2); + } +} + +bool Process_isThread(Process* this) { + (void) this; + // TODO + return false; +} diff --git a/freebsd/FreeBSDProcess.h b/freebsd/FreeBSDProcess.h new file mode 100644 index 00000000..42a1fcb1 --- /dev/null +++ b/freebsd/FreeBSDProcess.h @@ -0,0 +1,40 @@ +/* Do not edit this file. It was automatically generated. */ + +#ifndef HEADER_FreeBSDProcess +#define HEADER_FreeBSDProcess +/* +htop - FreeBSDProcess.h +(C) 2015 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + + +typedef enum FreeBSDProcessFields { + // Add platform-specific fields here, with ids >= 100 + LAST_PROCESSFIELD = 100, +} FreeBSDProcessField; + +typedef struct FreeBSDProcess_ { + Process super; +} FreeBSDProcess; + + +extern ProcessFieldData Process_fields[]; + +extern char* Process_pidFormat; +extern char* Process_tpgidFormat; + +void Process_setupColumnWidths(); + +FreeBSDProcess* FreeBSDProcess_new(Settings* settings); + +void Process_delete(Object* cast); + +void Process_writeField(Process* this, RichString* str, ProcessField field); + +long Process_compare(const void* v1, const void* v2); + +bool Process_isThread(Process* this); + +#endif diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index ac985005..24ab833e 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -18,9 +18,17 @@ in the source distribution for its full text. #include +typedef struct CPUData_ { + unsigned long long int totalTime; + unsigned long long int totalPeriod; +} CPUData; + typedef struct FreeBSDProcessList_ { ProcessList super; kvm_t* kd; + + CPUData* cpus; + } FreeBSDProcessList; }*/ @@ -31,21 +39,21 @@ static int MIB_hw_physmem[2]; static int pageSizeKb; -ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList) { +ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) { FreeBSDProcessList* fpl = calloc(1, sizeof(FreeBSDProcessList)); ProcessList* pl = (ProcessList*) fpl; - ProcessList_init(pl, usersTable, pidWhiteList); + ProcessList_init(pl, usersTable, pidWhiteList, userId); int cpus = 1; size_t sizeof_cpus = sizeof(cpus); int err = sysctlbyname("hw.ncpu", &cpus, &sizeof_cpus, NULL, 0); if (err) cpus = 1; pl->cpuCount = MAX(cpus, 1); - pl->cpus = realloc(pl->cpus, cpus * sizeof(CPUData)); + fpl->cpus = realloc(fpl->cpus, cpus * sizeof(CPUData)); for (int i = 0; i < cpus; i++) { - pl->cpus[i].totalTime = 1; - pl->cpus[i].totalPeriod = 1; + fpl->cpus[i].totalTime = 1; + fpl->cpus[i].totalPeriod = 1; } size_t len; diff --git a/freebsd/FreeBSDProcessList.h b/freebsd/FreeBSDProcessList.h index 11a5dde7..5127175b 100644 --- a/freebsd/FreeBSDProcessList.h +++ b/freebsd/FreeBSDProcessList.h @@ -12,13 +12,21 @@ in the source distribution for its full text. #include +typedef struct CPUData_ { + unsigned long long int totalTime; + unsigned long long int totalPeriod; +} CPUData; + typedef struct FreeBSDProcessList_ { ProcessList super; kvm_t* kd; + + CPUData* cpus; + } FreeBSDProcessList; -ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList); +ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId); void ProcessList_delete(ProcessList* this); diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 72f6e425..0254fe40 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -15,6 +15,7 @@ in the source distribution for its full text. #include "UptimeMeter.h" #include "ClockMeter.h" #include "HostnameMeter.h" +#include "FreeBSDProcess.h" #include #include @@ -26,8 +27,15 @@ in the source distribution for its full text. /*{ #include "Action.h" #include "BatteryMeter.h" + +extern ProcessFieldData Process_fields[]; + }*/ +ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; + +int Platform_numberOfFields = LAST_PROCESSFIELD; + void Platform_setBindings(Htop_Action* keys) { (void) keys; } @@ -94,9 +102,18 @@ int Platform_getMaxPid() { return maxPid; } -void Platform_getBatteryLevel(double* level, ACPresence* isOnAC) { +double Platform_setCPUValues(Meter* this, int cpu) { // TODO - *level = -1; - *isOnAC = AC_ERROR; } +void Platform_setMemoryValues(Meter* this) { + // TODO +} + +void Platform_setSwapValues(Meter* this) { + // TODO +} + +void Platform_setTasksValues(Meter* this) { + // TODO +} diff --git a/freebsd/Platform.h b/freebsd/Platform.h index eb2a8017..3758f57d 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -12,6 +12,13 @@ in the source distribution for its full text. #include "Action.h" #include "BatteryMeter.h" +extern ProcessFieldData Process_fields[]; + + +extern ProcessField Platform_defaultFields[]; + +extern int Platform_numberOfFields; + void Platform_setBindings(Htop_Action* keys); extern MeterClass* Platform_meterTypes[]; @@ -22,7 +29,12 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen); int Platform_getMaxPid(); -void Platform_getBatteryLevel(double* level, ACPresence* isOnAC); +double Platform_setCPUValues(Meter* this, int cpu); +void Platform_setMemoryValues(Meter* this); + +void Platform_setSwapValues(Meter* this); + +void Platform_setTasksValues(Meter* this); #endif diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 8ed0ebc6..60f27739 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -83,7 +83,7 @@ typedef enum LinuxProcessFields { OOM = 114, #endif IO_PRIORITY = 115, - LAST_PROCESSFIELD + LAST_PROCESSFIELD = 116, } LinuxProcessField; #include "IOPriority.h" diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index a4268632..9d01ce60 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -69,16 +69,6 @@ typedef struct LinuxProcessList_ { CPUData* cpus; - unsigned long long int totalMem; - unsigned long long int usedMem; - unsigned long long int freeMem; - unsigned long long int sharedMem; - unsigned long long int buffersMem; - unsigned long long int cachedMem; - unsigned long long int totalSwap; - unsigned long long int usedSwap; - unsigned long long int freeSwap; - } LinuxProcessList; #ifndef PROCDIR