Skip to content

Commit

Permalink
Minor whitespace and small logic flow improvements on review
Browse files Browse the repository at this point in the history
Quality improvements from BenBE as part of review for #1234.
  • Loading branch information
natoscott committed May 8, 2023
1 parent 72235d8 commit 290ddba
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 42 deletions.
16 changes: 11 additions & 5 deletions darwin/DarwinMachine.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
htop - DarwinMachine.c
(C) 2014 Hisham H. Muhammad
(C) 2023 htop dev team
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
Expand Down Expand Up @@ -33,12 +34,17 @@ static void DarwinMachine_getHostInfo(host_basic_info_data_t* p) {
}

static void DarwinMachine_freeCPULoadInfo(processor_cpu_load_info_t* p) {
if (NULL != p && NULL != *p) {
if (0 != munmap(*p, vm_page_size)) {
CRT_fatalError("Unable to free old CPU load information");
}
*p = NULL;
if (!p)
return;

if (!*p)
return;

if (0 != munmap(*p, vm_page_size)) {
CRT_fatalError("Unable to free old CPU load information");
}

*p = NULL;
}

static unsigned DarwinMachine_allocateCPULoadInfo(processor_cpu_load_info_t* p) {
Expand Down
2 changes: 1 addition & 1 deletion linux/LinuxMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ static void LinuxMachine_scanCPUTime(LinuxMachine* this) {
// The rest will remain at zero.
unsigned int adjCpuId;
if (i == 0) {
(void) sscanf(buffer, "cpu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice);
(void) sscanf(buffer, "cpu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice);
adjCpuId = 0;
} else {
unsigned int cpuid;
Expand Down
1 change: 1 addition & 0 deletions netbsd/NetBSDMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ void Machine_scan(Machine* super) {

bool Machine_isCPUonline(const Machine* host, unsigned int id) {
assert(id < host->existingCPUs);
(void)host; (void)id;

// TODO: Support detecting online / offline CPUs.
return true;
Expand Down
2 changes: 1 addition & 1 deletion openbsd/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ int Platform_getMaxPid(void) {
double Platform_setCPUValues(Meter* this, unsigned int cpu) {
const Machine* host = this->host;
const OpenBSDMachine* ohost = (const OpenBSDMachine*) host;
const CPUData* cpuData = &(ohost->cpuData[cpu]);
const CPUData* cpuData = &ohost->cpuData[cpu];
double total;
double totalPercent;
double* v = this->values;
Expand Down
4 changes: 2 additions & 2 deletions solaris/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,13 @@ void Platform_setSwapValues(Meter* this) {
void Platform_setZfsArcValues(Meter* this) {
const SolarisMachine* shost = (SolarisMachine*) this->host;

ZfsArcMeter_readStats(this, &(shost->zfs));
ZfsArcMeter_readStats(this, &shost->zfs);
}

void Platform_setZfsCompressedArcValues(Meter* this) {
const SolarisMachine* shost = (SolarisMachine*) this->host;

ZfsCompressedArcMeter_readStats(this, &(shost->zfs));
ZfsCompressedArcMeter_readStats(this, &shost->zfs);
}

static int Platform_buildenv(void* accum, struct ps_prochandle* Phandle, uintptr_t addr, const char* str) {
Expand Down
69 changes: 36 additions & 33 deletions solaris/SolarisMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,48 +241,51 @@ static void SolarisMachine_scanMemoryInfo(SolarisMachine* this) {
}

static void SolarisMachine_scanZfsArcstats(SolarisMachine* this) {
kstat_named_t *cur_kstat = NULL;
kstat_t *arcstats = NULL;
int ksrphyserr = -1;
kstat_named_t *cur_kstat;
kstat_t *arcstats;
int ksrphyserr;

if (this->kd != NULL) {
arcstats = kstat_lookup_wrapper(this->kd, "zfs", 0, "arcstats");
}
if (arcstats != NULL) {
ksrphyserr = kstat_read(this->kd, arcstats, NULL);
}
if (ksrphyserr != -1) {
cur_kstat = kstat_data_lookup_wrapper( arcstats, "size" );
this->zfs.size = cur_kstat->value.ui64 / 1024;
this->zfs.enabled = this->zfs.size > 0 ? 1 : 0;
if (this->kd == NULL)
return;

cur_kstat = kstat_data_lookup_wrapper( arcstats, "c_max" );
this->zfs.max = cur_kstat->value.ui64 / 1024;
arcstats = kstat_lookup_wrapper(this->kd, "zfs", 0, "arcstats");
if (arcstats == NULL)
return;

cur_kstat = kstat_data_lookup_wrapper( arcstats, "mfu_size" );
this->zfs.MFU = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;
ksrphyserr = kstat_read(this->kd, arcstats, NULL);
if (ksrphyserr == -1)
return;

cur_kstat = kstat_data_lookup_wrapper( arcstats, "mru_size" );
this->zfs.MRU = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;
cur_kstat = kstat_data_lookup_wrapper( arcstats, "size" );
this->zfs.size = cur_kstat->value.ui64 / 1024;
this->zfs.enabled = this->zfs.size > 0 ? 1 : 0;

cur_kstat = kstat_data_lookup_wrapper( arcstats, "anon_size" );
this->zfs.anon = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;
cur_kstat = kstat_data_lookup_wrapper( arcstats, "c_max" );
this->zfs.max = cur_kstat->value.ui64 / 1024;

cur_kstat = kstat_data_lookup_wrapper( arcstats, "hdr_size" );
this->zfs.header = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;
cur_kstat = kstat_data_lookup_wrapper( arcstats, "mfu_size" );
this->zfs.MFU = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;

cur_kstat = kstat_data_lookup_wrapper( arcstats, "other_size" );
this->zfs.other = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;
cur_kstat = kstat_data_lookup_wrapper( arcstats, "mru_size" );
this->zfs.MRU = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;

if ((cur_kstat = kstat_data_lookup_wrapper( arcstats, "compressed_size" )) != NULL) {
this->zfs.compressed = cur_kstat->value.ui64 / 1024;
this->zfs.isCompressed = 1;
cur_kstat = kstat_data_lookup_wrapper( arcstats, "anon_size" );
this->zfs.anon = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;

cur_kstat = kstat_data_lookup_wrapper( arcstats, "uncompressed_size" );
this->zfs.uncompressed = cur_kstat->value.ui64 / 1024;
} else {
this->zfs.isCompressed = 0;
}
cur_kstat = kstat_data_lookup_wrapper( arcstats, "hdr_size" );
this->zfs.header = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;

cur_kstat = kstat_data_lookup_wrapper( arcstats, "other_size" );
this->zfs.other = cur_kstat != NULL ? cur_kstat->value.ui64 / 1024 : 0;

if ((cur_kstat = kstat_data_lookup_wrapper( arcstats, "compressed_size" )) != NULL) {
this->zfs.compressed = cur_kstat->value.ui64 / 1024;
this->zfs.isCompressed = 1;

cur_kstat = kstat_data_lookup_wrapper( arcstats, "uncompressed_size" );
this->zfs.uncompressed = cur_kstat->value.ui64 / 1024;
} else {
this->zfs.isCompressed = 0;
}
}

Expand Down

0 comments on commit 290ddba

Please sign in to comment.