Hold only a const version of the ProcessList in Meters

This commit is contained in:
Christian Göttsche 2020-10-21 21:25:50 +02:00 committed by cgzones
parent f757810f48
commit 72103e9613
13 changed files with 43 additions and 43 deletions

View File

@ -31,7 +31,7 @@ const MeterClass Meter_class = {
}
};
Meter* Meter_new(struct ProcessList_* pl, int param, const MeterClass* type) {
Meter* Meter_new(const struct ProcessList_* pl, int param, const MeterClass* type) {
Meter* this = xCalloc(1, sizeof(Meter));
Object_setClass(this, type);
this->h = 1;

View File

@ -74,7 +74,7 @@ struct Meter_ {
int param;
GraphData* drawData;
int h;
ProcessList* pl;
const ProcessList* pl;
char curItems;
double* values;
double total;
@ -98,7 +98,7 @@ typedef enum {
extern const MeterClass Meter_class;
Meter* Meter_new(ProcessList* pl, int param, const MeterClass* type);
Meter* Meter_new(const ProcessList* pl, int param, const MeterClass* type);
int Meter_humanUnit(char* buffer, unsigned long int value, int size);

View File

@ -24,7 +24,7 @@ static const int TasksMeter_attributes[] = {
};
static void TasksMeter_updateValues(Meter* this, char* buffer, int len) {
ProcessList* pl = this->pl;
const ProcessList* pl = this->pl;
this->values[0] = pl->kernelThreads;
this->values[1] = pl->userlandThreads;
this->values[2] = pl->totalTasks - pl->kernelThreads - pl->userlandThreads;
@ -32,7 +32,7 @@ static void TasksMeter_updateValues(Meter* this, char* buffer, int len) {
if (pl->totalTasks > this->total) {
this->total = pl->totalTasks;
}
if (this->pl->settings->hideKernelThreads) {
if (pl->settings->hideKernelThreads) {
this->values[0] = 0;
}
xSnprintf(buffer, len, "%d/%d", (int) this->values[3], (int) this->total);

View File

@ -176,8 +176,8 @@ ProcessPidColumn Process_pidColumns[] = {
};
static double Platform_setCPUAverageValues(Meter* mtr) {
DarwinProcessList *dpl = (DarwinProcessList *)mtr->pl;
int cpus = dpl->super.cpuCount;
const ProcessList *dpl = mtr->pl;
int cpus = dpl->cpuCount;
double sumNice = 0.0;
double sumNormal = 0.0;
double sumKernel = 0.0;
@ -200,9 +200,9 @@ double Platform_setCPUValues(Meter* mtr, int cpu) {
return Platform_setCPUAverageValues(mtr);
}
DarwinProcessList *dpl = (DarwinProcessList *)mtr->pl;
processor_cpu_load_info_t prev = &dpl->prev_load[cpu-1];
processor_cpu_load_info_t curr = &dpl->curr_load[cpu-1];
const DarwinProcessList *dpl = (const DarwinProcessList *)mtr->pl;
const processor_cpu_load_info_t prev = &dpl->prev_load[cpu-1];
const processor_cpu_load_info_t curr = &dpl->curr_load[cpu-1];
double total = 0;
/* Take the sums */
@ -228,8 +228,8 @@ double Platform_setCPUValues(Meter* mtr, int cpu) {
}
void Platform_setMemoryValues(Meter* mtr) {
DarwinProcessList *dpl = (DarwinProcessList *)mtr->pl;
vm_statistics_t vm = &dpl->vm_stats;
const DarwinProcessList *dpl = (const DarwinProcessList *)mtr->pl;
const struct vm_statistics* vm = &dpl->vm_stats;
double page_K = (double)vm_page_size / (double)1024;
mtr->total = dpl->host_info.max_mem / 1024;
@ -249,13 +249,13 @@ void Platform_setSwapValues(Meter* mtr) {
}
void Platform_setZfsArcValues(Meter* this) {
DarwinProcessList* dpl = (DarwinProcessList*) this->pl;
const DarwinProcessList* dpl = (const DarwinProcessList*) this->pl;
ZfsArcMeter_readStats(this, &(dpl->zfs));
}
void Platform_setZfsCompressedArcValues(Meter* this) {
DarwinProcessList* dpl = (DarwinProcessList*) this->pl;
const DarwinProcessList* dpl = (const DarwinProcessList*) this->pl;
ZfsCompressedArcMeter_readStats(this, &(dpl->zfs));
}

View File

@ -149,9 +149,9 @@ int Platform_getMaxPid() {
}
double Platform_setCPUValues(Meter* this, int cpu) {
DragonFlyBSDProcessList* fpl = (DragonFlyBSDProcessList*) this->pl;
const DragonFlyBSDProcessList* fpl = (const DragonFlyBSDProcessList*) this->pl;
int cpus = this->pl->cpuCount;
CPUData* cpuData;
const CPUData* cpuData;
if (cpus == 1) {
// single CPU box has everything in fpl->cpus[0]
@ -186,7 +186,7 @@ double Platform_setCPUValues(Meter* this, int cpu) {
void Platform_setMemoryValues(Meter* this) {
// TODO
ProcessList* pl = (ProcessList*) this->pl;
const ProcessList* pl = this->pl;
this->total = pl->totalMem;
this->values[0] = pl->usedMem;
@ -195,7 +195,7 @@ void Platform_setMemoryValues(Meter* this) {
}
void Platform_setSwapValues(Meter* this) {
ProcessList* pl = (ProcessList*) this->pl;
const ProcessList* pl = this->pl;
this->total = pl->totalSwap;
this->values[0] = pl->usedSwap;
}

View File

@ -157,9 +157,9 @@ int Platform_getMaxPid() {
}
double Platform_setCPUValues(Meter* this, int cpu) {
FreeBSDProcessList* fpl = (FreeBSDProcessList*) this->pl;
const FreeBSDProcessList* fpl = (const FreeBSDProcessList*) this->pl;
int cpus = this->pl->cpuCount;
CPUData* cpuData;
const CPUData* cpuData;
if (cpus == 1) {
// single CPU box has everything in fpl->cpus[0]
@ -194,7 +194,7 @@ double Platform_setCPUValues(Meter* this, int cpu) {
void Platform_setMemoryValues(Meter* this) {
// TODO
ProcessList* pl = (ProcessList*) this->pl;
const ProcessList* pl = this->pl;
this->total = pl->totalMem;
this->values[0] = pl->usedMem;
@ -203,19 +203,19 @@ void Platform_setMemoryValues(Meter* this) {
}
void Platform_setSwapValues(Meter* this) {
ProcessList* pl = (ProcessList*) this->pl;
const ProcessList* pl = this->pl;
this->total = pl->totalSwap;
this->values[0] = pl->usedSwap;
}
void Platform_setZfsArcValues(Meter* this) {
FreeBSDProcessList* fpl = (FreeBSDProcessList*) this->pl;
const FreeBSDProcessList* fpl = (const FreeBSDProcessList*) this->pl;
ZfsArcMeter_readStats(this, &(fpl->zfs));
}
void Platform_setZfsCompressedArcValues(Meter* this) {
FreeBSDProcessList* fpl = (FreeBSDProcessList*) this->pl;
const FreeBSDProcessList* fpl = (const FreeBSDProcessList*) this->pl;
ZfsCompressedArcMeter_readStats(this, &(fpl->zfs));
}

View File

@ -189,8 +189,8 @@ int Platform_getMaxPid() {
}
double Platform_setCPUValues(Meter* this, int cpu) {
LinuxProcessList* pl = (LinuxProcessList*) this->pl;
CPUData* cpuData = &(pl->cpus[cpu]);
const LinuxProcessList* pl = (const LinuxProcessList*) this->pl;
const CPUData* cpuData = &(pl->cpus[cpu]);
double total = (double) ( cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod);
double percent;
double* v = this->values;
@ -224,8 +224,8 @@ double Platform_setCPUValues(Meter* this, int cpu) {
}
void Platform_setMemoryValues(Meter* this) {
ProcessList* pl = this->pl;
LinuxProcessList* lpl = (LinuxProcessList*) this->pl;
const ProcessList* pl = this->pl;
const LinuxProcessList* lpl = (const LinuxProcessList*) pl;
long int usedMem = pl->usedMem;
long int buffersMem = pl->buffersMem;
@ -243,19 +243,19 @@ void Platform_setMemoryValues(Meter* this) {
}
void Platform_setSwapValues(Meter* this) {
ProcessList* pl = (ProcessList*) this->pl;
const ProcessList* pl = this->pl;
this->total = pl->totalSwap;
this->values[0] = pl->usedSwap;
}
void Platform_setZfsArcValues(Meter* this) {
LinuxProcessList* lpl = (LinuxProcessList*) this->pl;
const LinuxProcessList* lpl = (const LinuxProcessList*) this->pl;
ZfsArcMeter_readStats(this, &(lpl->zfs));
}
void Platform_setZfsCompressedArcValues(Meter* this) {
LinuxProcessList* lpl = (LinuxProcessList*) this->pl;
const LinuxProcessList* lpl = (const LinuxProcessList*) this->pl;
ZfsCompressedArcMeter_readStats(this, &(lpl->zfs));
}

View File

@ -189,7 +189,7 @@ double Platform_setCPUValues(Meter* this, int cpu) {
}
void Platform_setMemoryValues(Meter* this) {
ProcessList* pl = (ProcessList*) this->pl;
const ProcessList* pl = this->pl;
long int usedMem = pl->usedMem;
long int buffersMem = pl->buffersMem;
long int cachedMem = pl->cachedMem;
@ -207,7 +207,7 @@ void Platform_setMemoryValues(Meter* this) {
* Taken almost directly from OpenBSD's top(1)
*/
void Platform_setSwapValues(Meter* this) {
ProcessList* pl = (ProcessList*) this->pl;
const ProcessList* pl = this->pl;
struct swapent *swdev;
unsigned long long int total, used;
int nswap, rnswap, i;

View File

@ -167,9 +167,9 @@ int Platform_getMaxPid() {
}
double Platform_setCPUValues(Meter* this, int cpu) {
SolarisProcessList* spl = (SolarisProcessList*) this->pl;
const SolarisProcessList* spl = (const SolarisProcessList*) this->pl;
int cpus = this->pl->cpuCount;
CPUData* cpuData = NULL;
const CPUData* cpuData = NULL;
if (cpus == 1) {
// single CPU box has everything in spl->cpus[0]
@ -203,7 +203,7 @@ double Platform_setCPUValues(Meter* this, int cpu) {
}
void Platform_setMemoryValues(Meter* this) {
ProcessList* pl = (ProcessList*) this->pl;
const ProcessList* pl = this->pl;
this->total = pl->totalMem;
this->values[0] = pl->usedMem;
this->values[1] = pl->buffersMem;
@ -211,19 +211,19 @@ void Platform_setMemoryValues(Meter* this) {
}
void Platform_setSwapValues(Meter* this) {
ProcessList* pl = (ProcessList*) this->pl;
const ProcessList* pl = this->pl;
this->total = pl->totalSwap;
this->values[0] = pl->usedSwap;
}
void Platform_setZfsArcValues(Meter* this) {
SolarisProcessList* spl = (SolarisProcessList*) this->pl;
const SolarisProcessList* spl = (const SolarisProcessList*) this->pl;
ZfsArcMeter_readStats(this, &(spl->zfs));
}
void Platform_setZfsCompressedArcValues(Meter* this) {
SolarisProcessList* spl = (SolarisProcessList*) this->pl;
const SolarisProcessList* spl = (const SolarisProcessList*) this->pl;
ZfsCompressedArcMeter_readStats(this, &(spl->zfs));
}

View File

@ -18,7 +18,7 @@ static const int ZfsArcMeter_attributes[] = {
ZFS_MFU, ZFS_MRU, ZFS_ANON, ZFS_HEADER, ZFS_OTHER
};
void ZfsArcMeter_readStats(Meter* this, ZfsArcStats* stats) {
void ZfsArcMeter_readStats(Meter* this, const ZfsArcStats* stats) {
this->total = stats->max;
this->values[0] = stats->MFU;
this->values[1] = stats->MRU;

View File

@ -11,7 +11,7 @@ in the source distribution for its full text.
#include "Meter.h"
void ZfsArcMeter_readStats(Meter* this, ZfsArcStats* stats);
void ZfsArcMeter_readStats(Meter* this, const ZfsArcStats* stats);
extern const MeterClass ZfsArcMeter_class;

View File

@ -21,7 +21,7 @@ static const int ZfsCompressedArcMeter_attributes[] = {
ZFS_COMPRESSED
};
void ZfsCompressedArcMeter_readStats(Meter* this, ZfsArcStats* stats) {
void ZfsCompressedArcMeter_readStats(Meter* this, const ZfsArcStats* stats) {
if ( stats->isCompressed ) {
this->total = stats->uncompressed;
this->values[0] = stats->compressed;

View File

@ -11,7 +11,7 @@ in the source distribution for its full text.
#include "Meter.h"
void ZfsCompressedArcMeter_readStats(Meter* this, ZfsArcStats* stats);
void ZfsCompressedArcMeter_readStats(Meter* this, const ZfsArcStats* stats);
extern const MeterClass ZfsCompressedArcMeter_class;