Skip to content

Commit

Permalink
Merge branch 'hishamhm-pull-1012'
Browse files Browse the repository at this point in the history
  • Loading branch information
natoscott committed Aug 20, 2020
2 parents fed14a5 + b55f932 commit 31391b2
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 8 deletions.
93 changes: 85 additions & 8 deletions CPUMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ static void AllCPUsMeter_getRange(Meter* this, int* start, int* count) {
}
}

static int MapClassnameToColumncount(Meter* this){
if (strchr(Meter_name(this), '4'))
return 4;
else if (strchr(Meter_name(this), '2'))
return 2;
else
return 1;
}

static void AllCPUsMeter_init(Meter* this) {
int cpus = this->pl->cpuCount;
if (!this->drawData)
Expand All @@ -176,10 +185,8 @@ static void AllCPUsMeter_init(Meter* this) {
if (this->mode == 0)
this->mode = BAR_METERMODE;
int h = Meter_modes[this->mode]->h;
if (strchr(Meter_name(this), '2'))
this->h = h * ((count+1) / 2);
else
this->h = h * count;
int ncol = MapClassnameToColumncount(this);
this->h = h * ((count + ncol - 1)/ ncol);
}

static void AllCPUsMeter_done(Meter* this) {
Expand All @@ -199,10 +206,8 @@ static void AllCPUsMeter_updateMode(Meter* this, int mode) {
for (int i = 0; i < count; i++) {
Meter_setMode(meters[i], mode);
}
if (strchr(Meter_name(this), '2'))
this->h = h * ((count+1) / 2);
else
this->h = h * count;
int ncol = MapClassnameToColumncount(this);
this->h = h * ((count + ncol - 1)/ ncol);
}

static void DualColCPUsMeter_draw(Meter* this, int x, int y, int w) {
Expand Down Expand Up @@ -233,6 +238,22 @@ static void SingleColCPUsMeter_draw(Meter* this, int x, int y, int w) {
}
}

static void MultiColCPUsMeter_draw(Meter* this, int x, int y, int w){
Meter** meters = (Meter**) this->drawData;
int start, count;
AllCPUsMeter_getRange(this, &start, &count);
int ncol = MapClassnameToColumncount(this);
int colwidth = (w-ncol)/ncol + 1;
int diff = (w - (colwidth * ncol));
int nrows = (count + ncol - 1) / ncol;
for (int i = 0; i < count; i++){
int d = (i/nrows) > diff ? diff : (i / nrows) ; // dynamic spacer
int xpos = x + ((i / nrows) * colwidth) + d;
int ypos = y + ((i % nrows) * meters[0]->h);
meters[i]->draw(meters[i], xpos, ypos, colwidth);
}
}

MeterClass CPUMeter_class = {
.super = {
.extends = Class(Meter),
Expand Down Expand Up @@ -364,3 +385,59 @@ MeterClass RightCPUs2Meter_class = {
.done = AllCPUsMeter_done
};

MeterClass AllCPUs4Meter_class = {
.super = {
.extends = Class(Meter),
.delete = Meter_delete,
.display = CPUMeter_display
},
.defaultMode = CUSTOM_METERMODE,
.total = 100.0,
.attributes = CPUMeter_attributes,
.name = "AllCPUs4",
.uiName = "CPUs (1&2&3&4/4)",
.description = "CPUs (1&2&3&4/4): all CPUs in 4 shorter columns",
.caption = "CPU",
.draw = MultiColCPUsMeter_draw,
.init = AllCPUsMeter_init,
.updateMode = AllCPUsMeter_updateMode,
.done = AllCPUsMeter_done
};

MeterClass LeftCPUs4Meter_class = {
.super = {
.extends = Class(Meter),
.delete = Meter_delete,
.display = CPUMeter_display
},
.defaultMode = CUSTOM_METERMODE,
.total = 100.0,
.attributes = CPUMeter_attributes,
.name = "LeftCPUs4",
.uiName = "CPUs (1-4/8)",
.description = "CPUs (1-4/8): first half in 4 shorter columns",
.caption = "CPU",
.draw = MultiColCPUsMeter_draw,
.init = AllCPUsMeter_init,
.updateMode = AllCPUsMeter_updateMode,
.done = AllCPUsMeter_done
};

MeterClass RightCPUs4Meter_class = {
.super = {
.extends = Class(Meter),
.delete = Meter_delete,
.display = CPUMeter_display
},
.defaultMode = CUSTOM_METERMODE,
.total = 100.0,
.attributes = CPUMeter_attributes,
.name = "RightCPUs4",
.uiName = "CPUs (5-8/8)",
.description = "CPUs (5-8/8): second half in 4 shorter columns",
.caption = "CPU",
.draw = MultiColCPUsMeter_draw,
.init = AllCPUsMeter_init,
.updateMode = AllCPUsMeter_updateMode,
.done = AllCPUsMeter_done
};
5 changes: 5 additions & 0 deletions CPUMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@ extern MeterClass LeftCPUs2Meter_class;

extern MeterClass RightCPUs2Meter_class;

extern MeterClass AllCPUs4Meter_class;

extern MeterClass LeftCPUs4Meter_class;

extern MeterClass RightCPUs4Meter_class;

#endif
3 changes: 3 additions & 0 deletions linux/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,13 @@ MeterClass* Platform_meterTypes[] = {
&HostnameMeter_class,
&AllCPUsMeter_class,
&AllCPUs2Meter_class,
&AllCPUs4Meter_class,
&LeftCPUsMeter_class,
&RightCPUsMeter_class,
&LeftCPUs2Meter_class,
&RightCPUs2Meter_class,
&LeftCPUs4Meter_class,
&RightCPUs4Meter_class,
&BlankMeter_class,
&PressureStallCPUSomeMeter_class,
&PressureStallIOSomeMeter_class,
Expand Down

0 comments on commit 31391b2

Please sign in to comment.