* Option for counting CPUs from zero

(thanks to Sean Noonan)
* Meters update in every screen (no longer halting while on Setup, etc.)
This commit is contained in:
Hisham Muhammad 2011-03-22 20:37:08 +00:00
parent b561956637
commit a9c0ea3753
21 changed files with 147 additions and 68 deletions

View File

@ -3,6 +3,7 @@
#include "Panel.h" #include "Panel.h"
#include "CheckItem.h" #include "CheckItem.h"
#include "ProcessList.h"
#include "debug.h" #include "debug.h"
#include <assert.h> #include <assert.h>
@ -25,14 +26,14 @@ static HandlerResult AffinityPanel_eventHandler(Panel* this, int ch) {
return result; return result;
} }
Panel* AffinityPanel_new(int processorCount, unsigned long mask) { Panel* AffinityPanel_new(ProcessList* pl, unsigned long mask) {
Panel* this = Panel_new(1, 1, 1, 1, CHECKITEM_CLASS, true, ListItem_compare); Panel* this = Panel_new(1, 1, 1, 1, CHECKITEM_CLASS, true, ListItem_compare);
this->eventHandler = AffinityPanel_eventHandler; this->eventHandler = AffinityPanel_eventHandler;
Panel_setHeader(this, "Use CPUs:"); Panel_setHeader(this, "Use CPUs:");
for (int i = 0; i < processorCount; i++) { for (int i = 0; i < pl->cpuCount; i++) {
char number[10]; char number[10];
snprintf(number, 9, "%d", i+1); snprintf(number, 9, "%d", ProcessList_cpuId(pl, i) + 1);
Panel_add(this, (Object*) CheckItem_new(String_copy(number), NULL, mask & (1 << i))); Panel_add(this, (Object*) CheckItem_new(String_copy(number), NULL, mask & (1 << i)));
} }
return this; return this;

View File

@ -6,11 +6,12 @@
#include "Panel.h" #include "Panel.h"
#include "CheckItem.h" #include "CheckItem.h"
#include "ProcessList.h"
#include "debug.h" #include "debug.h"
#include <assert.h> #include <assert.h>
Panel* AffinityPanel_new(int processorCount, unsigned long mask); Panel* AffinityPanel_new(ProcessList* pl, unsigned long mask);
unsigned long AffinityPanel_getAffinity(Panel* this); unsigned long AffinityPanel_getAffinity(Panel* this);

View File

@ -33,7 +33,7 @@ static void CPUMeter_init(Meter* this) {
int cpu = this->param; int cpu = this->param;
if (this->pl->cpuCount > 1) { if (this->pl->cpuCount > 1) {
char caption[10]; char caption[10];
sprintf(caption, "%-3d", cpu); sprintf(caption, "%-3d ", ProcessList_cpuId(this->pl, cpu));
Meter_setCaption(this, caption); Meter_setCaption(this, caption);
} }
if (this->param == 0) if (this->param == 0)
@ -124,8 +124,8 @@ static void CPUMeter_display(Object* cast, RichString* out) {
static void AllCPUsMeter_init(Meter* this) { static void AllCPUsMeter_init(Meter* this) {
int cpus = this->pl->cpuCount; int cpus = this->pl->cpuCount;
this->drawBuffer = malloc(sizeof(Meter*) * cpus); this->drawData = malloc(sizeof(Meter*) * cpus);
Meter** meters = (Meter**) this->drawBuffer; Meter** meters = (Meter**) this->drawData;
for (int i = 0; i < cpus; i++) for (int i = 0; i < cpus; i++)
meters[i] = Meter_new(this->pl, i+1, &CPUMeter); meters[i] = Meter_new(this->pl, i+1, &CPUMeter);
this->h = cpus; this->h = cpus;
@ -134,7 +134,7 @@ static void AllCPUsMeter_init(Meter* this) {
static void AllCPUsMeter_done(Meter* this) { static void AllCPUsMeter_done(Meter* this) {
int cpus = this->pl->cpuCount; int cpus = this->pl->cpuCount;
Meter** meters = (Meter**) this->drawBuffer; Meter** meters = (Meter**) this->drawData;
for (int i = 0; i < cpus; i++) for (int i = 0; i < cpus; i++)
Meter_delete((Object*)meters[i]); Meter_delete((Object*)meters[i]);
} }
@ -148,7 +148,7 @@ static void AllCPUsMeter_setMode(Meter* this, int mode) {
static void AllCPUsMeter_draw(Meter* this, int x, int y, int w) { static void AllCPUsMeter_draw(Meter* this, int x, int y, int w) {
int cpus = this->pl->cpuCount; int cpus = this->pl->cpuCount;
Meter** meters = (Meter**) this->drawBuffer; Meter** meters = (Meter**) this->drawData;
for (int i = 0; i < cpus; i++) { for (int i = 0; i < cpus; i++) {
Meter_setMode(meters[i], this->mode); Meter_setMode(meters[i], this->mode);
meters[i]->draw(meters[i], x, y, w); meters[i]->draw(meters[i], x, y, w);

View File

@ -1,4 +1,10 @@
What's new in version 0.9.1
* Option for counting CPUs from zero
(thanks to Sean Noonan)
* Meters update in every screen (no longer halting while on Setup, etc.)
What's new in version 0.9 What's new in version 0.9
* Add support for "steal"/guest CPU time measurement * Add support for "steal"/guest CPU time measurement

View File

@ -90,7 +90,7 @@ void* DebugMemory_realloc(void* ptr, int size, char* file, int line, char* str)
return data; return data;
} }
void* DebugMemory_strdup(char* str, char* file, int line) { void* DebugMemory_strdup(const char* str, char* file, int line) {
assert(str); assert(str);
char* data = strdup(str); char* data = strdup(str);
DebugMemory_registerAllocation(data, file, line); DebugMemory_registerAllocation(data, file, line);
@ -102,7 +102,7 @@ void* DebugMemory_strdup(char* str, char* file, int line) {
} }
void DebugMemory_free(void* data, char* file, int line) { void DebugMemory_free(void* data, char* file, int line) {
assert(data); if (!data) return;
DebugMemory_registerDeallocation(data, file, line); DebugMemory_registerDeallocation(data, file, line);
if (singleton->file) { if (singleton->file) {
if (singleton->totals) fprintf(singleton->file, "%d\t", singleton->size); if (singleton->totals) fprintf(singleton->file, "%d\t", singleton->size);

View File

@ -48,7 +48,7 @@ void* DebugMemory_calloc(int a, int b, char* file, int line);
void* DebugMemory_realloc(void* ptr, int size, char* file, int line, char* str); void* DebugMemory_realloc(void* ptr, int size, char* file, int line, char* str);
void* DebugMemory_strdup(char* str, char* file, int line); void* DebugMemory_strdup(const char* str, char* file, int line);
void DebugMemory_free(void* data, char* file, int line); void DebugMemory_free(void* data, char* file, int line);

View File

@ -47,6 +47,7 @@ static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
this->settings->changed = true; this->settings->changed = true;
Header* header = this->settings->header; Header* header = this->settings->header;
Header_calculateHeight(header); Header_calculateHeight(header);
Header_reinit(header);
Header_draw(header); Header_draw(header);
ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2); ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2);
} }
@ -74,5 +75,6 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight large numbers in memory counters"), &(settings->pl->highlightMegabytes), false)); Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight large numbers in memory counters"), &(settings->pl->highlightMegabytes), false));
Panel_add(super, (Object*) CheckItem_new(String_copy("Leave a margin around header"), &(settings->header->margin), false)); Panel_add(super, (Object*) CheckItem_new(String_copy("Leave a margin around header"), &(settings->header->margin), false));
Panel_add(super, (Object*) CheckItem_new(String_copy("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->pl->detailedCPUTime), false)); Panel_add(super, (Object*) CheckItem_new(String_copy("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->pl->detailedCPUTime), false));
Panel_add(super, (Object*) CheckItem_new(String_copy("Count CPUs from 0 instead of 1"), &(settings->pl->countCPUsFromZero), false));
return this; return this;
} }

View File

@ -95,11 +95,11 @@ void FunctionBar_setLabel(FunctionBar* this, int event, const char* text) {
} }
} }
void FunctionBar_draw(FunctionBar* this, char* buffer) { void FunctionBar_draw(const FunctionBar* this, char* buffer) {
FunctionBar_drawAttr(this, buffer, CRT_colors[FUNCTION_BAR]); FunctionBar_drawAttr(this, buffer, CRT_colors[FUNCTION_BAR]);
} }
void FunctionBar_drawAttr(FunctionBar* this, char* buffer, int attr) { void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr) {
attrset(CRT_colors[FUNCTION_BAR]); attrset(CRT_colors[FUNCTION_BAR]);
mvhline(LINES-1, 0, ' ', COLS); mvhline(LINES-1, 0, ' ', COLS);
int x = 0; int x = 0;
@ -118,7 +118,7 @@ void FunctionBar_drawAttr(FunctionBar* this, char* buffer, int attr) {
attrset(CRT_colors[RESET_COLOR]); attrset(CRT_colors[RESET_COLOR]);
} }
int FunctionBar_synthesizeEvent(FunctionBar* this, int pos) { int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos) {
int x = 0; int x = 0;
for (int i = 0; i < this->size; i++) { for (int i = 0; i < this->size; i++) {
x += strlen(this->keys[i]); x += strlen(this->keys[i]);

View File

@ -43,10 +43,10 @@ void FunctionBar_delete(Object* cast);
void FunctionBar_setLabel(FunctionBar* this, int event, const char* text); void FunctionBar_setLabel(FunctionBar* this, int event, const char* text);
void FunctionBar_draw(FunctionBar* this, char* buffer); void FunctionBar_draw(const FunctionBar* this, char* buffer);
void FunctionBar_drawAttr(FunctionBar* this, char* buffer, int attr); void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr);
int FunctionBar_synthesizeEvent(FunctionBar* this, int pos); int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos);
#endif #endif

View File

@ -10,6 +10,7 @@ in the source distribution for its full text.
#include "debug.h" #include "debug.h"
#include <assert.h> #include <assert.h>
#include <time.h>
/*{ /*{
@ -34,7 +35,7 @@ typedef struct Header_ {
#endif #endif
Header* Header_new(ProcessList* pl) { Header* Header_new(ProcessList* pl) {
Header* this = malloc(sizeof(Header)); Header* this = calloc(sizeof(Header), 1);
this->leftMeters = Vector_new(METER_CLASS, true, DEFAULT_SIZE, NULL); this->leftMeters = Vector_new(METER_CLASS, true, DEFAULT_SIZE, NULL);
this->rightMeters = Vector_new(METER_CLASS, true, DEFAULT_SIZE, NULL); this->rightMeters = Vector_new(METER_CLASS, true, DEFAULT_SIZE, NULL);
this->margin = true; this->margin = true;
@ -132,7 +133,18 @@ void Header_defaultMeters(Header* this) {
Vector_add(this->rightMeters, Meter_new(this->pl, 0, &UptimeMeter)); Vector_add(this->rightMeters, Meter_new(this->pl, 0, &UptimeMeter));
} }
void Header_draw(Header* this) { void Header_reinit(Header* this) {
for (int i = 0; i < Vector_size(this->leftMeters); i++) {
Meter* meter = (Meter*) Vector_get(this->leftMeters, i);
meter->type->init(meter);
}
for (int i = 0; i < Vector_size(this->rightMeters); i++) {
Meter* meter = (Meter*) Vector_get(this->rightMeters, i);
meter->type->init(meter);
}
}
void Header_draw(const Header* this) {
int height = this->height; int height = this->height;
int pad = this->pad; int pad = this->pad;

View File

@ -13,6 +13,7 @@ in the source distribution for its full text.
#include "debug.h" #include "debug.h"
#include <assert.h> #include <assert.h>
#include <time.h>
typedef enum HeaderSide_ { typedef enum HeaderSide_ {
@ -52,7 +53,9 @@ MeterModeId Header_readMeterMode(Header* this, int i, HeaderSide side);
void Header_defaultMeters(Header* this); void Header_defaultMeters(Header* this);
void Header_draw(Header* this); void Header_reinit(Header* this);
void Header_draw(const Header* this);
int Header_calculateHeight(Header* this); int Header_calculateHeight(Header* this);

59
Meter.c
View File

@ -23,6 +23,7 @@ in the source distribution for its full text.
#include <assert.h> #include <assert.h>
#ifndef USE_FUNKY_MODES #ifndef USE_FUNKY_MODES
#include <time.h>
#define USE_FUNKY_MODES 1 #define USE_FUNKY_MODES 1
#endif #endif
@ -69,13 +70,20 @@ struct Meter_ {
int mode; int mode;
int param; int param;
Meter_Draw draw; Meter_Draw draw;
void* drawBuffer; void* drawData;
int h; int h;
ProcessList* pl; ProcessList* pl;
double* values; double* values;
double total; double total;
}; };
#ifdef USE_FUNKY_MODES
typedef struct GraphData_ {
time_t time;
double values[METER_BUFFER_LEN];
} GraphData;
#endif
typedef enum { typedef enum {
CUSTOM_METERMODE = 0, CUSTOM_METERMODE = 0,
BAR_METERMODE, BAR_METERMODE,
@ -152,8 +160,8 @@ void Meter_delete(Object* cast) {
if (this->type->done) { if (this->type->done) {
this->type->done(this); this->type->done(this);
} }
if (this->drawBuffer) if (this->drawData)
free(this->drawBuffer); free(this->drawData);
free(this->caption); free(this->caption);
free(this->values); free(this->values);
free(this); free(this);
@ -186,9 +194,9 @@ void Meter_setMode(Meter* this, int modeIndex) {
this->type->setMode(this, modeIndex); this->type->setMode(this, modeIndex);
} else { } else {
assert(modeIndex >= 1); assert(modeIndex >= 1);
if (this->drawBuffer) if (this->drawData)
free(this->drawBuffer); free(this->drawData);
this->drawBuffer = NULL; this->drawData = NULL;
MeterMode* mode = Meter_modes[modeIndex]; MeterMode* mode = Meter_modes[modeIndex];
this->draw = mode->draw; this->draw = mode->draw;
@ -328,23 +336,30 @@ static const char* GraphMeterMode_characters = "^`'-.,_~'`-.,_~'`-.,_";
static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
if (!this->drawBuffer) this->drawBuffer = calloc(sizeof(double), METER_BUFFER_LEN); if (!this->drawData) this->drawData = calloc(sizeof(GraphData), 1);
double* drawBuffer = (double*) this->drawBuffer; GraphData* data = (GraphData*) this->drawData;
const int nValues = METER_BUFFER_LEN;
time_t now = time(NULL);
if (now > data->time) {
data->time = now;
for (int i = 0; i < METER_BUFFER_LEN - 1; i++) for (int i = 0; i < nValues - 1; i++)
drawBuffer[i] = drawBuffer[i+1]; data->values[i] = data->values[i+1];
MeterType* type = this->type; MeterType* type = this->type;
char buffer[METER_BUFFER_LEN]; char buffer[nValues];
type->setValues(this, buffer, METER_BUFFER_LEN - 1); type->setValues(this, buffer, nValues - 1);
double value = 0.0; double value = 0.0;
for (int i = 0; i < type->items; i++) for (int i = 0; i < type->items; i++)
value += this->values[i]; value += this->values[i];
value /= this->total; value /= this->total;
drawBuffer[METER_BUFFER_LEN - 1] = value; data->values[nValues - 1] = value;
for (int i = METER_BUFFER_LEN - w, k = 0; i < METER_BUFFER_LEN; i++, k++) { }
value = drawBuffer[i];
for (int i = nValues - w, k = 0; i < nValues; i++, k++) {
double value = data->values[i];
DrawDot( CRT_colors[DEFAULT_COLOR], y, ' ' ); DrawDot( CRT_colors[DEFAULT_COLOR], y, ' ' );
DrawDot( CRT_colors[DEFAULT_COLOR], y+1, ' ' ); DrawDot( CRT_colors[DEFAULT_COLOR], y+1, ' ' );
DrawDot( CRT_colors[DEFAULT_COLOR], y+2, ' ' ); DrawDot( CRT_colors[DEFAULT_COLOR], y+2, ' ' );

10
Meter.h
View File

@ -26,6 +26,7 @@ in the source distribution for its full text.
#include <assert.h> #include <assert.h>
#ifndef USE_FUNKY_MODES #ifndef USE_FUNKY_MODES
#include <time.h>
#define USE_FUNKY_MODES 1 #define USE_FUNKY_MODES 1
#endif #endif
@ -71,13 +72,20 @@ struct Meter_ {
int mode; int mode;
int param; int param;
Meter_Draw draw; Meter_Draw draw;
void* drawBuffer; void* drawData;
int h; int h;
ProcessList* pl; ProcessList* pl;
double* values; double* values;
double total; double total;
}; };
#ifdef USE_FUNKY_MODES
typedef struct GraphData_ {
time_t time;
double values[METER_BUFFER_LEN];
} GraphData;
#endif
typedef enum { typedef enum {
CUSTOM_METERMODE = 0, CUSTOM_METERMODE = 0,
BAR_METERMODE, BAR_METERMODE,

View File

@ -332,7 +332,7 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel
case TTY_NR: snprintf(buffer, n, "%5u ", this->tty_nr); break; case TTY_NR: snprintf(buffer, n, "%5u ", this->tty_nr); break;
case TGID: snprintf(buffer, n, "%5u ", this->tgid); break; case TGID: snprintf(buffer, n, "%5u ", this->tgid); break;
case TPGID: snprintf(buffer, n, "%5d ", this->tpgid); break; case TPGID: snprintf(buffer, n, "%5d ", this->tpgid); break;
case PROCESSOR: snprintf(buffer, n, "%3d ", this->processor+1); break; case PROCESSOR: snprintf(buffer, n, "%3d ", ProcessList_cpuId(this->pl, this->processor)); break;
case NLWP: snprintf(buffer, n, "%4ld ", this->nlwp); break; case NLWP: snprintf(buffer, n, "%4ld ", this->nlwp); break;
case COMM: { case COMM: {
if (this->pl->highlightThreads && Process_isThread(this)) { if (this->pl->highlightThreads && Process_isThread(this)) {
@ -471,7 +471,7 @@ static void Process_display(Object* cast, RichString* out) {
RichString_setAttr(out, CRT_colors[PROCESS_SHADOW]); RichString_setAttr(out, CRT_colors[PROCESS_SHADOW]);
if (this->tag == true) if (this->tag == true)
RichString_setAttr(out, CRT_colors[PROCESS_TAG]); RichString_setAttr(out, CRT_colors[PROCESS_TAG]);
assert(out->len > 0); assert(out->chlen > 0);
} }
void Process_delete(Object* cast) { void Process_delete(Object* cast) {

View File

@ -54,6 +54,9 @@ in the source distribution for its full text.
#define MAX_READ 2048 #define MAX_READ 2048
#endif #endif
#ifndef ProcessList_cpuId
#define ProcessList_cpuId(pl, cpu) ((pl)->countCPUsFromZero ? (cpu)-1 : (cpu))
#endif
}*/ }*/
/*{ /*{
@ -124,6 +127,7 @@ typedef struct ProcessList_ {
bool highlightMegabytes; bool highlightMegabytes;
bool highlightThreads; bool highlightThreads;
bool detailedCPUTime; bool detailedCPUTime;
bool countCPUsFromZero;
} ProcessList; } ProcessList;
}*/ }*/
@ -132,7 +136,7 @@ static ProcessField defaultHeaders[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RE
ProcessList* ProcessList_new(UsersTable* usersTable) { ProcessList* ProcessList_new(UsersTable* usersTable) {
ProcessList* this; ProcessList* this;
this = malloc(sizeof(ProcessList)); this = calloc(sizeof(ProcessList), 1);
this->processes = Vector_new(PROCESS_CLASS, true, DEFAULT_SIZE, Process_compare); this->processes = Vector_new(PROCESS_CLASS, true, DEFAULT_SIZE, Process_compare);
this->processTable = Hashtable_new(70, false); this->processTable = Hashtable_new(70, false);
assert(Hashtable_count(this->processTable) == Vector_count(this->processes)); assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
@ -177,6 +181,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable) {
this->highlightBaseName = false; this->highlightBaseName = false;
this->highlightMegabytes = false; this->highlightMegabytes = false;
this->detailedCPUTime = false; this->detailedCPUTime = false;
this->countCPUsFromZero = false;
return this; return this;
} }

View File

@ -56,6 +56,9 @@ in the source distribution for its full text.
#define MAX_READ 2048 #define MAX_READ 2048
#endif #endif
#ifndef ProcessList_cpuId
#define ProcessList_cpuId(pl, cpu) ((pl)->countCPUsFromZero ? (cpu)-1 : (cpu))
#endif
typedef struct CPUData_ { typedef struct CPUData_ {
@ -124,6 +127,7 @@ typedef struct ProcessList_ {
bool highlightMegabytes; bool highlightMegabytes;
bool highlightThreads; bool highlightThreads;
bool detailedCPUTime; bool detailedCPUTime;
bool countCPUsFromZero;
} ProcessList; } ProcessList;

View File

@ -9,10 +9,12 @@ in the source distribution for its full text.
#include "Panel.h" #include "Panel.h"
#include "Object.h" #include "Object.h"
#include "Vector.h" #include "Vector.h"
#include "Header.h"
#include "FunctionBar.h" #include "FunctionBar.h"
#include "debug.h" #include "debug.h"
#include <assert.h> #include <assert.h>
#include <time.h>
#include <stdbool.h> #include <stdbool.h>
@ -32,13 +34,15 @@ typedef struct ScreenManager_ {
Vector* items; Vector* items;
Vector* fuBars; Vector* fuBars;
int itemCount; int itemCount;
FunctionBar* fuBar; const FunctionBar* fuBar;
const Header* header;
time_t lastScan;
bool owner; bool owner;
} ScreenManager; } ScreenManager;
}*/ }*/
ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, bool owner) { ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, bool owner) {
ScreenManager* this; ScreenManager* this;
this = malloc(sizeof(ScreenManager)); this = malloc(sizeof(ScreenManager));
this->x1 = x1; this->x1 = x1;
@ -50,6 +54,7 @@ ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation ori
this->items = Vector_new(PANEL_CLASS, owner, DEFAULT_SIZE, NULL); this->items = Vector_new(PANEL_CLASS, owner, DEFAULT_SIZE, NULL);
this->fuBars = Vector_new(FUNCTIONBAR_CLASS, true, DEFAULT_SIZE, NULL); this->fuBars = Vector_new(FUNCTIONBAR_CLASS, true, DEFAULT_SIZE, NULL);
this->itemCount = 0; this->itemCount = 0;
this->header = header;
this->owner = owner; this->owner = owner;
return this; return this;
} }
@ -119,14 +124,24 @@ void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) {
void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
bool quit = false; bool quit = false;
int focus = 0; int focus = 0;
Panel* panelFocus = (Panel*) Vector_get(this->items, focus); Panel* panelFocus = (Panel*) Vector_get(this->items, focus);
if (this->fuBar) if (this->fuBar)
FunctionBar_draw(this->fuBar, NULL); FunctionBar_draw(this->fuBar, NULL);
this->lastScan = 0;
int ch = 0; int ch = 0;
while (!quit) { while (!quit) {
int items = this->itemCount; int items = this->itemCount;
if (this->header) {
time_t now = time(NULL);
if (now > this->lastScan) {
ProcessList_scan(this->header->pl);
this->lastScan = now;
}
Header_draw(this->header);
}
for (int i = 0; i < items; i++) { for (int i = 0; i < items; i++) {
Panel* panel = (Panel*) Vector_get(this->items, i); Panel* panel = (Panel*) Vector_get(this->items, i);
Panel_draw(panel, i == focus); Panel_draw(panel, i == focus);

View File

@ -12,10 +12,12 @@ in the source distribution for its full text.
#include "Panel.h" #include "Panel.h"
#include "Object.h" #include "Object.h"
#include "Vector.h" #include "Vector.h"
#include "Header.h"
#include "FunctionBar.h" #include "FunctionBar.h"
#include "debug.h" #include "debug.h"
#include <assert.h> #include <assert.h>
#include <time.h>
#include <stdbool.h> #include <stdbool.h>
@ -34,12 +36,14 @@ typedef struct ScreenManager_ {
Vector* items; Vector* items;
Vector* fuBars; Vector* fuBars;
int itemCount; int itemCount;
FunctionBar* fuBar; const FunctionBar* fuBar;
const Header* header;
time_t lastScan;
bool owner; bool owner;
} ScreenManager; } ScreenManager;
ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, bool owner); ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, bool owner);
void ScreenManager_delete(ScreenManager* this); void ScreenManager_delete(ScreenManager* this);

View File

@ -113,6 +113,8 @@ static bool Settings_read(Settings* this, char* fileName) {
this->pl->detailedCPUTime = atoi(option[1]); this->pl->detailedCPUTime = atoi(option[1]);
} else if (String_eq(option[0], "detailed_cpu_time")) { } else if (String_eq(option[0], "detailed_cpu_time")) {
this->pl->detailedCPUTime = atoi(option[1]); this->pl->detailedCPUTime = atoi(option[1]);
} else if (String_eq(option[0], "cpu_count_from_zero")) {
this->pl->countCPUsFromZero = atoi(option[1]);
} else if (String_eq(option[0], "delay")) { } else if (String_eq(option[0], "delay")) {
this->delay = atoi(option[1]); this->delay = atoi(option[1]);
} else if (String_eq(option[0], "color_scheme")) { } else if (String_eq(option[0], "color_scheme")) {
@ -172,6 +174,7 @@ bool Settings_write(Settings* this) {
fprintf(fd, "tree_view=%d\n", (int) this->pl->treeView); fprintf(fd, "tree_view=%d\n", (int) this->pl->treeView);
fprintf(fd, "header_margin=%d\n", (int) this->header->margin); fprintf(fd, "header_margin=%d\n", (int) this->header->margin);
fprintf(fd, "detailed_cpu_time=%d\n", (int) this->pl->detailedCPUTime); fprintf(fd, "detailed_cpu_time=%d\n", (int) this->pl->detailedCPUTime);
fprintf(fd, "cpu_count_from_zero=%d\n", (int) this->pl->countCPUsFromZero);
fprintf(fd, "color_scheme=%d\n", (int) this->colorScheme); fprintf(fd, "color_scheme=%d\n", (int) this->colorScheme);
fprintf(fd, "delay=%d\n", (int) this->delay); fprintf(fd, "delay=%d\n", (int) this->delay);
fprintf(fd, "left_meters="); fprintf(fd, "left_meters=");

22
htop.c
View File

@ -164,8 +164,8 @@ static void showHelp(ProcessList* pl) {
static const char* CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; static const char* CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
static void Setup_run(Settings* settings, int headerHeight) { static void Setup_run(Settings* settings, const Header* header) {
ScreenManager* scr = ScreenManager_new(0, headerHeight, 0, -1, HORIZONTAL, true); ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, true);
CategoriesPanel* panelCategories = CategoriesPanel_new(settings, scr); CategoriesPanel* panelCategories = CategoriesPanel_new(settings, scr);
ScreenManager_add(scr, (Panel*) panelCategories, FunctionBar_new(CategoriesFunctions, NULL, NULL), 16); ScreenManager_add(scr, (Panel*) panelCategories, FunctionBar_new(CategoriesFunctions, NULL, NULL), 16);
CategoriesPanel_makeMetersPage(panelCategories); CategoriesPanel_makeMetersPage(panelCategories);
@ -201,12 +201,12 @@ static HandlerResult pickWithEnter(Panel* panel, int ch) {
return IGNORED; return IGNORED;
} }
static Object* pickFromVector(Panel* panel, Panel* list, int x, int y, const char** keyLabels, FunctionBar* prevBar) { static Object* pickFromVector(Panel* panel, Panel* list, int x, int y, const char** keyLabels, FunctionBar* prevBar, Header* header) {
const char* fuKeys[] = {"Enter", "Esc", NULL}; const char* fuKeys[] = {"Enter", "Esc", NULL};
int fuEvents[] = {13, 27}; int fuEvents[] = {13, 27};
if (!list->eventHandler) if (!list->eventHandler)
Panel_setEventHandler(list, pickWithEnter); Panel_setEventHandler(list, pickWithEnter);
ScreenManager* scr = ScreenManager_new(0, y, 0, -1, HORIZONTAL, false); ScreenManager* scr = ScreenManager_new(0, y, 0, -1, HORIZONTAL, header, false);
ScreenManager_add(scr, list, FunctionBar_new(keyLabels, fuKeys, fuEvents), x - 1); ScreenManager_add(scr, list, FunctionBar_new(keyLabels, fuKeys, fuEvents), x - 1);
ScreenManager_add(scr, panel, NULL, -1); ScreenManager_add(scr, panel, NULL, -1);
Panel* panelFocus; Panel* panelFocus;
@ -376,7 +376,7 @@ int main(int argc, char** argv) {
double oldTime = 0.0; double oldTime = 0.0;
bool recalculate; bool recalculate;
int ch = 0; int ch = ERR;
int closeTimeout = 0; int closeTimeout = 0;
while (!quit) { while (!quit) {
@ -606,7 +606,7 @@ int main(int argc, char** argv) {
case 'C': case 'C':
case KEY_F(2): case KEY_F(2):
{ {
Setup_run(settings, headerHeight); Setup_run(settings, header);
// TODO: shouldn't need this, colors should be dynamic // TODO: shouldn't need this, colors should be dynamic
ProcessList_printHeader(pl, Panel_getHeader(panel)); ProcessList_printHeader(pl, Panel_getHeader(panel));
headerHeight = Header_calculateHeight(header); headerHeight = Header_calculateHeight(header);
@ -630,7 +630,7 @@ int main(int argc, char** argv) {
ListItem* allUsers = ListItem_new("All users", -1); ListItem* allUsers = ListItem_new("All users", -1);
Panel_insert(usersPanel, 0, (Object*) allUsers); Panel_insert(usersPanel, 0, (Object*) allUsers);
const char* fuFunctions[] = {"Show ", "Cancel ", NULL}; const char* fuFunctions[] = {"Show ", "Cancel ", NULL};
ListItem* picked = (ListItem*) pickFromVector(panel, usersPanel, 20, headerHeight, fuFunctions, defaultBar); ListItem* picked = (ListItem*) pickFromVector(panel, usersPanel, 20, headerHeight, fuFunctions, defaultBar, header);
if (picked) { if (picked) {
if (picked == allUsers) { if (picked == allUsers) {
userOnly = false; userOnly = false;
@ -659,7 +659,7 @@ int main(int argc, char** argv) {
} }
SignalsPanel_reset((SignalsPanel*) killPanel); SignalsPanel_reset((SignalsPanel*) killPanel);
const char* fuFunctions[] = {"Send ", "Cancel ", NULL}; const char* fuFunctions[] = {"Send ", "Cancel ", NULL};
Signal* sgn = (Signal*) pickFromVector(panel, killPanel, 15, headerHeight, fuFunctions, defaultBar); Signal* sgn = (Signal*) pickFromVector(panel, killPanel, 15, headerHeight, fuFunctions, defaultBar, header);
if (sgn) { if (sgn) {
if (sgn->number != 0) { if (sgn->number != 0) {
Panel_setHeader(panel, "Sending..."); Panel_setHeader(panel, "Sending...");
@ -692,10 +692,10 @@ int main(int argc, char** argv) {
unsigned long curr = Process_getAffinity((Process*) Panel_getSelected(panel)); unsigned long curr = Process_getAffinity((Process*) Panel_getSelected(panel));
Panel* affinityPanel = AffinityPanel_new(pl->cpuCount, curr); Panel* affinityPanel = AffinityPanel_new(pl, curr);
const char* fuFunctions[] = {"Set ", "Cancel ", NULL}; const char* fuFunctions[] = {"Set ", "Cancel ", NULL};
void* set = pickFromVector(panel, affinityPanel, 15, headerHeight, fuFunctions, defaultBar); void* set = pickFromVector(panel, affinityPanel, 15, headerHeight, fuFunctions, defaultBar, header);
if (set) { if (set) {
unsigned long new = AffinityPanel_getAffinity(affinityPanel); unsigned long new = AffinityPanel_getAffinity(affinityPanel);
bool anyTagged = false; bool anyTagged = false;
@ -742,7 +742,7 @@ int main(int argc, char** argv) {
Panel_setSelected(sortPanel, i); Panel_setSelected(sortPanel, i);
free(name); free(name);
} }
ListItem* field = (ListItem*) pickFromVector(panel, sortPanel, 15, headerHeight, fuFunctions, defaultBar); ListItem* field = (ListItem*) pickFromVector(panel, sortPanel, 15, headerHeight, fuFunctions, defaultBar, header);
if (field) { if (field) {
settings->changed = true; settings->changed = true;
setSortKey(pl, field->key, panel, settings); setSortKey(pl, field->key, panel, settings);

10
m4/ltversion.m4 vendored
View File

@ -9,15 +9,15 @@
# Generated from ltversion.in. # Generated from ltversion.in.
# serial 3017 ltversion.m4 # serial 3012 ltversion.m4
# This file is part of GNU Libtool # This file is part of GNU Libtool
m4_define([LT_PACKAGE_VERSION], [2.2.6b]) m4_define([LT_PACKAGE_VERSION], [2.2.6])
m4_define([LT_PACKAGE_REVISION], [1.3017]) m4_define([LT_PACKAGE_REVISION], [1.3012])
AC_DEFUN([LTVERSION_VERSION], AC_DEFUN([LTVERSION_VERSION],
[macro_version='2.2.6b' [macro_version='2.2.6'
macro_revision='1.3017' macro_revision='1.3012'
_LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?])
_LT_DECL(, macro_revision, 0) _LT_DECL(, macro_revision, 0)
]) ])