diff --git a/Settings.c b/Settings.c index acf4f581..817fbc15 100644 --- a/Settings.c +++ b/Settings.c @@ -23,6 +23,12 @@ in the source distribution for its full text. #include "Process.h" #include +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) { diff --git a/Settings.h b/Settings.h index 80ec9560..22729aa9 100644 --- a/Settings.h +++ b/Settings.h @@ -14,6 +14,12 @@ in the source distribution for its full text. #include "Process.h" #include +typedef struct { + const char* name; + const char* columns; + const char* sortKey; +} ScreenDefaults; + typedef struct { int len; char** names; diff --git a/darwin/Platform.c b/darwin/Platform.c index ef7c3653..16c89585 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -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 }, diff --git a/darwin/Platform.h b/darwin/Platform.h index d5446a88..77e74b56 100644 --- a/darwin/Platform.h +++ b/darwin/Platform.h @@ -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[]; diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 370943d7..716c99e7 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -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; diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h index c2684f34..0ab526ae 100644 --- a/dragonflybsd/Platform.h +++ b/dragonflybsd/Platform.h @@ -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; diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 5dd6ca41..eb7164a7 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -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; diff --git a/freebsd/Platform.h b/freebsd/Platform.h index 1735e7e3..c5cd50b4 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -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; diff --git a/linux/Platform.c b/linux/Platform.c index dfe4dd64..7efc7e47 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -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) { diff --git a/linux/Platform.h b/linux/Platform.h index b0456e5b..f17e2b3e 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -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); diff --git a/openbsd/Battery.h b/openbsd/Battery.h index b1a4982e..0f05af3a 100644 --- a/openbsd/Battery.h +++ b/openbsd/Battery.h @@ -12,5 +12,4 @@ in the source distribution for its full text. void Battery_getData(double* level, ACPresence* isOnAC); - #endif diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 01b6c478..a49bf60b 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -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; diff --git a/openbsd/Platform.h b/openbsd/Platform.h index e0da7b9f..34974048 100644 --- a/openbsd/Platform.h +++ b/openbsd/Platform.h @@ -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; diff --git a/solaris/Platform.c b/solaris/Platform.c index a29fcb47..e54d732b 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -103,7 +103,15 @@ const SignalItem Platform_signals[] = { const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem); -ProcessField Platform_defaultFields[] = { PID, LWPID, 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); MeterClass* Platform_meterTypes[] = { &CPUMeter_class, diff --git a/solaris/Platform.h b/solaris/Platform.h index f961b913..f3943876 100644 --- a/solaris/Platform.h +++ b/solaris/Platform.h @@ -38,7 +38,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 MeterClass* Platform_meterTypes[]; diff --git a/unsupported/Platform.c b/unsupported/Platform.c index ba844191..f487c497 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -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, }, diff --git a/unsupported/Platform.h b/unsupported/Platform.h index 14f3d1a6..0e94abd7 100644 --- a/unsupported/Platform.h +++ b/unsupported/Platform.h @@ -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[];