Whitespace and indentation issues

This commit is contained in:
Benny Baumann 2020-10-31 22:14:27 +01:00
parent 9a16b1079e
commit b23f8235e2
24 changed files with 347 additions and 288 deletions

View File

@ -182,7 +182,8 @@ static bool Settings_read(Settings* this, const char* fileName, int initialCpuCo
this->delay = atoi(option[1]);
} else if (String_eq(option[0], "color_scheme")) {
this->colorScheme = atoi(option[1]);
if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) this->colorScheme = 0;
if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME)
this->colorScheme = 0;
} else if (String_eq(option[0], "enable_mouse")) {
this->enableMouse = atoi(option[1]);
} else if (String_eq(option[0], "left_meters")) {

View File

@ -35,7 +35,9 @@ void GetKernelVersion(struct kern *k) {
char str[256] = {0};
size_t size = sizeof(str);
int ret = sysctlbyname("kern.osrelease", str, &size, NULL, 0);
if (ret == 0) sscanf(str, "%hd.%hd.%hd", &version_[0], &version_[1], &version_[2]);
if (ret == 0) {
sscanf(str, "%hd.%hd.%hd", &version_[0], &version_[1], &version_[2]);
}
}
memcpy(k->version, version_, sizeof(version_));
}
@ -48,9 +50,17 @@ negative value if more than the installed version
int CompareKernelVersion(short int major, short int minor, short int component) {
struct kern k;
GetKernelVersion(&k);
if ( k.version[0] != major) return k.version[0] - major;
if ( k.version[1] != minor) return k.version[1] - minor;
if ( k.version[2] != component) return k.version[2] - component;
if (k.version[0] != major) {
return k.version[0] - major;
}
if (k.version[1] != minor) {
return k.version[1] - minor;
}
if (k.version[2] != component) {
return k.version[2] - component;
}
return 0;
}
@ -86,9 +96,10 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
void ProcessList_getVMStats(vm_statistics_t p) {
mach_msg_type_number_t info_size = HOST_VM_INFO_COUNT;
if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)p, &info_size) != 0)
if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)p, &info_size) != 0) {
CRT_fatalError("Unable to retrieve VM statistics\n");
}
}
struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) {
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 };
@ -159,8 +170,9 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
openzfs_sysctl_updateArcStats(&dpl->zfs);
// in pause mode only gather global data for meters (CPU/memory/...)
if (pauseProcessUpdate)
if (pauseProcessUpdate) {
return;
}
/* Get the time difference */
dpl->global_diff = 0;

View File

@ -345,6 +345,7 @@ retry:
curpos = nextpos;
}
free(jls);
}

View File

@ -379,6 +379,7 @@ long LinuxProcess_compare(const void* v1, const void* v2) {
default:
return Process_compare(v1, v2);
}
test_diff:
return (diff > 0) ? 1 : (diff < 0 ? -1 : 0);
}

View File

@ -419,9 +419,9 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna
while ((line = strsep(&buf, "\n")) != NULL) {
switch (line[0]) {
case 'r':
if (line[1] == 'c' && String_startsWith(line+2, "har: "))
if (line[1] == 'c' && String_startsWith(line + 2, "har: ")) {
process->io_rchar = strtoull(line + 7, NULL, 10);
else if (String_startsWith(line+1, "ead_bytes: ")) {
} else if (String_startsWith(line + 1, "ead_bytes: ")) {
process->io_read_bytes = strtoull(line + 12, NULL, 10);
process->io_rate_read_bps =
((double)(process->io_read_bytes - last_read))/(((double)(now - process->io_rate_read_time))/1000);
@ -429,9 +429,9 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna
}
break;
case 'w':
if (line[1] == 'c' && String_startsWith(line+2, "har: "))
if (line[1] == 'c' && String_startsWith(line + 2, "har: ")) {
process->io_wchar = strtoull(line + 7, NULL, 10);
else if (String_startsWith(line+1, "rite_bytes: ")) {
} else if (String_startsWith(line + 1, "rite_bytes: ")) {
process->io_write_bytes = strtoull(line + 13, NULL, 10);
process->io_rate_write_bps =
((double)(process->io_write_bytes - last_write))/(((double)(now - process->io_rate_write_time))/1000);
@ -1087,7 +1087,9 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char*
continue;
// Exception handler.
errorReadingProcess: {
errorReadingProcess:
{
if (preExisting) {
ProcessList_remove(pl, proc);
} else {

View File

@ -32,127 +32,152 @@ ProcessFieldData Process_fields[] = {
.name = "",
.title = NULL,
.description = NULL,
.flags = 0, },
.flags = 0,
},
[PID] = {
.name = "PID",
.title = " PID ",
.description = "Process/thread ID",
.flags = 0, },
.flags = 0,
},
[COMM] = {
.name = "Command",
.title = "Command ",
.description = "Command line",
.flags = 0, },
.flags = 0,
},
[STATE] = {
.name = "STATE",
.title = "S ",
.description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging)",
.flags = 0, },
.flags = 0,
},
[PPID] = {
.name = "PPID",
.title = " PPID ",
.description = "Parent process ID",
.flags = 0, },
.flags = 0,
},
[PGRP] = {
.name = "PGRP",
.title = " PGRP ",
.description = "Process group ID",
.flags = 0, },
.flags = 0,
},
[SESSION] = {
.name = "SESSION",
.title = " SESN ",
.description = "Process's session ID",
.flags = 0, },
.flags = 0,
},
[TTY_NR] = {
.name = "TTY_NR",
.title = " TTY ",
.description = "Controlling terminal",
.flags = 0, },
.flags = 0,
},
[TPGID] = {
.name = "TPGID",
.title = " TPGID ",
.description = "Process ID of the fg process group of the controlling terminal",
.flags = 0, },
.flags = 0,
},
[MINFLT] = {
.name = "MINFLT",
.title = " MINFLT ",
.description = "Number of minor faults which have not required loading a memory page from disk",
.flags = 0, },
.flags = 0,
},
[MAJFLT] = {
.name = "MAJFLT",
.title = " MAJFLT ",
.description = "Number of major faults which have required loading a memory page from disk",
.flags = 0, },
.flags = 0,
},
[PRIORITY] = {
.name = "PRIORITY",
.title = "PRI ",
.description = "Kernel's internal priority for the process",
.flags = 0, },
.flags = 0,
},
[NICE] = {
.name = "NICE",
.title = " NI ",
.description = "Nice value (the higher the value, the more it lets other processes take priority)",
.flags = 0, },
.flags = 0,
},
[STARTTIME] = {
.name = "STARTTIME",
.title = "START ",
.description = "Time the process was started",
.flags = 0, },
.flags = 0,
},
[PROCESSOR] = {
.name = "PROCESSOR",
.title = "CPU ",
.description = "Id of the CPU the process last executed on",
.flags = 0, },
.flags = 0,
},
[M_SIZE] = {
.name = "M_SIZE",
.title = " VIRT ",
.description = "Total program size in virtual memory",
.flags = 0, },
.flags = 0,
},
[M_RESIDENT] = {
.name = "M_RESIDENT",
.title = " RES ",
.description = "Resident set size, size of the text and data sections, plus stack usage",
.flags = 0, },
.flags = 0,
},
[ST_UID] = {
.name = "ST_UID",
.title = " UID ",
.description = "User ID of the process owner",
.flags = 0, },
.flags = 0,
},
[PERCENT_CPU] = {
.name = "PERCENT_CPU",
.title = "CPU% ",
.description = "Percentage of the CPU time the process used in the last sampling",
.flags = 0, },
.flags = 0,
},
[PERCENT_MEM] = {
.name = "PERCENT_MEM",
.title = "MEM% ",
.description = "Percentage of the memory the process is using, based on resident memory size",
.flags = 0, },
.flags = 0,
},
[USER] = {
.name = "USER",
.title = "USER ",
.description = "Username of the process owner (or user ID if name cannot be determined)",
.flags = 0, },
.flags = 0,
},
[TIME] = {
.name = "TIME",
.title = " TIME+ ",
.description = "Total time the process has spent in user and system time",
.flags = 0, },
.flags = 0,
},
[NLWP] = {
.name = "NLWP",
.title = "NLWP ",
.description = "Number of threads in the process",
.flags = 0, },
.flags = 0,
},
[TGID] = {
.name = "TGID",
.title = " TGID ",
.description = "Thread group ID (i.e. process ID)",
.flags = 0, },
.flags = 0,
},
[LAST_PROCESSFIELD] = {
.name = "*** report bug! ***",
.title = NULL,
.description = NULL,
.flags = 0, },
.flags = 0,
},
};
ProcessPidColumn Process_pidColumns[] = {

View File

@ -254,7 +254,7 @@ char* Platform_getProcessEnv(pid_t pid) {
return NULL;
if ((kproc = kvm_getprocs(kt, KERN_PROC_PID, pid,
sizeof(struct kinfo_proc), &count)) == NULL) {\
sizeof(struct kinfo_proc), &count)) == NULL) {
(void) kvm_close(kt);
return NULL;
}

View File

@ -30,6 +30,7 @@ in the source distribution for its full text.
char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) {
char* zname;
if ( sproc->zoneid == 0 ) {
zname = xStrdup(GZONE);
} else if ( kd == NULL ) {
@ -38,6 +39,7 @@ char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) {
kstat_t* ks = kstat_lookup( kd, "zones", sproc->zoneid, NULL );
zname = xStrdup(ks == NULL ? UZONE : ks->ks_name);
}
return zname;
}
@ -85,8 +87,12 @@ static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) {
// Calculate per-CPU statistics first
for (int i = 0; i < cpus; i++) {
if (spl->kd != NULL) { cpuinfo = kstat_lookup(spl->kd,"cpu",i,"sys"); }
if (cpuinfo != NULL) { kchain = kstat_read(spl->kd,cpuinfo,NULL); }
if (spl->kd != NULL) {
cpuinfo = kstat_lookup(spl->kd, "cpu", i, "sys");
}
if (cpuinfo != NULL) {
kchain = kstat_read(spl->kd, cpuinfo, NULL);
}
if (kchain != -1 ) {
idletime = kstat_data_lookup(cpuinfo,"cpu_nsec_idle");
intrtime = kstat_data_lookup(cpuinfo,"cpu_nsec_intr");
@ -180,8 +186,12 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) {
// Part 2 - swap
nswap = swapctl(SC_GETNSWP, NULL);
if (nswap > 0) { sl = xMalloc((nswap * sizeof(swapent_t)) + sizeof(int)); }
if (sl != NULL) { spathbase = xMalloc( nswap * MAXPATHLEN ); }
if (nswap > 0) {
sl = xMalloc((nswap * sizeof(swapent_t)) + sizeof(int));
}
if (sl != NULL) {
spathbase = xMalloc( nswap * MAXPATHLEN );
}
if (spathbase != NULL) {
spath = spathbase;
swapdev = sl->swt_ent;
@ -211,8 +221,12 @@ static inline void SolarisProcessList_scanZfsArcstats(ProcessList* pl) {
int ksrphyserr = -1;
kstat_named_t *cur_kstat = NULL;
if (spl->kd != NULL) { arcstats = kstat_lookup(spl->kd, "zfs", 0, "arcstats"); }
if (arcstats != NULL) { ksrphyserr = kstat_read(spl->kd, arcstats, NULL); }
if (spl->kd != NULL) {
arcstats = kstat_lookup(spl->kd, "zfs", 0, "arcstats");
}
if (arcstats != NULL) {
ksrphyserr = kstat_read(spl->kd, arcstats, NULL);
}
if (ksrphyserr != -1) {
cur_kstat = kstat_data_lookup( arcstats, "size" );
spl->zfs.size = cur_kstat->value.ui64 / 1024;

View File

@ -34,7 +34,9 @@ void openzfs_sysctl_init(ZfsArcStats *stats) {
len = sizeof(arcSize);
if (sysctlbyname("kstat.zfs.misc.arcstats.size", &arcSize, &len, NULL, 0) == 0 && arcSize != 0) {
stats->enabled = 1;
len = 5; sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len);
len = 5;
sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len);
sysctlnametomib("kstat.zfs.misc.arcstats.c_max", MIB_kstat_zfs_misc_arcstats_c_max, &len);
sysctlnametomib("kstat.zfs.misc.arcstats.mfu_size", MIB_kstat_zfs_misc_arcstats_mfu_size, &len);
@ -42,6 +44,7 @@ void openzfs_sysctl_init(ZfsArcStats *stats) {
sysctlnametomib("kstat.zfs.misc.arcstats.anon_size", MIB_kstat_zfs_misc_arcstats_anon_size, &len);
sysctlnametomib("kstat.zfs.misc.arcstats.hdr_size", MIB_kstat_zfs_misc_arcstats_hdr_size, &len);
sysctlnametomib("kstat.zfs.misc.arcstats.other_size", MIB_kstat_zfs_misc_arcstats_other_size, &len);
if (sysctlnametomib("kstat.zfs.misc.arcstats.compressed_size", MIB_kstat_zfs_misc_arcstats_compressed_size, &len) == 0) {
stats->isCompressed = 1;
sysctlnametomib("kstat.zfs.misc.arcstats.uncompressed_size", MIB_kstat_zfs_misc_arcstats_uncompressed_size, &len);