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]); this->delay = atoi(option[1]);
} else if (String_eq(option[0], "color_scheme")) { } else if (String_eq(option[0], "color_scheme")) {
this->colorScheme = atoi(option[1]); 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")) { } else if (String_eq(option[0], "enable_mouse")) {
this->enableMouse = atoi(option[1]); this->enableMouse = atoi(option[1]);
} else if (String_eq(option[0], "left_meters")) { } else if (String_eq(option[0], "left_meters")) {

View File

@ -35,7 +35,9 @@ void GetKernelVersion(struct kern *k) {
char str[256] = {0}; char str[256] = {0};
size_t size = sizeof(str); size_t size = sizeof(str);
int ret = sysctlbyname("kern.osrelease", str, &size, NULL, 0); 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_)); 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) { int CompareKernelVersion(short int major, short int minor, short int component) {
struct kern k; struct kern k;
GetKernelVersion(&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[0] != major) {
if ( k.version[2] != component) return k.version[2] - component; 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; return 0;
} }
@ -86,9 +96,10 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
void ProcessList_getVMStats(vm_statistics_t p) { void ProcessList_getVMStats(vm_statistics_t p) {
mach_msg_type_number_t info_size = HOST_VM_INFO_COUNT; 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"); CRT_fatalError("Unable to retrieve VM statistics\n");
} }
}
struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) { struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) {
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 }; 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); openzfs_sysctl_updateArcStats(&dpl->zfs);
// in pause mode only gather global data for meters (CPU/memory/...) // in pause mode only gather global data for meters (CPU/memory/...)
if (pauseProcessUpdate) if (pauseProcessUpdate) {
return; return;
}
/* Get the time difference */ /* Get the time difference */
dpl->global_diff = 0; dpl->global_diff = 0;

View File

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

View File

@ -379,6 +379,7 @@ long LinuxProcess_compare(const void* v1, const void* v2) {
default: default:
return Process_compare(v1, v2); return Process_compare(v1, v2);
} }
test_diff: test_diff:
return (diff > 0) ? 1 : (diff < 0 ? -1 : 0); 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) { while ((line = strsep(&buf, "\n")) != NULL) {
switch (line[0]) { switch (line[0]) {
case 'r': 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); 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_read_bytes = strtoull(line + 12, NULL, 10);
process->io_rate_read_bps = process->io_rate_read_bps =
((double)(process->io_read_bytes - last_read))/(((double)(now - process->io_rate_read_time))/1000); ((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; break;
case 'w': 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); 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_write_bytes = strtoull(line + 13, NULL, 10);
process->io_rate_write_bps = process->io_rate_write_bps =
((double)(process->io_write_bytes - last_write))/(((double)(now - process->io_rate_write_time))/1000); ((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; continue;
// Exception handler. // Exception handler.
errorReadingProcess: {
errorReadingProcess:
{
if (preExisting) { if (preExisting) {
ProcessList_remove(pl, proc); ProcessList_remove(pl, proc);
} else { } else {

View File

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

View File

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

View File

@ -34,7 +34,9 @@ void openzfs_sysctl_init(ZfsArcStats *stats) {
len = sizeof(arcSize); len = sizeof(arcSize);
if (sysctlbyname("kstat.zfs.misc.arcstats.size", &arcSize, &len, NULL, 0) == 0 && arcSize != 0) { if (sysctlbyname("kstat.zfs.misc.arcstats.size", &arcSize, &len, NULL, 0) == 0 && arcSize != 0) {
stats->enabled = 1; 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.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); 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.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.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); 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) { if (sysctlnametomib("kstat.zfs.misc.arcstats.compressed_size", MIB_kstat_zfs_misc_arcstats_compressed_size, &len) == 0) {
stats->isCompressed = 1; stats->isCompressed = 1;
sysctlnametomib("kstat.zfs.misc.arcstats.uncompressed_size", MIB_kstat_zfs_misc_arcstats_uncompressed_size, &len); sysctlnametomib("kstat.zfs.misc.arcstats.uncompressed_size", MIB_kstat_zfs_misc_arcstats_uncompressed_size, &len);