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

@ -170,7 +170,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
doSearch = false;
}
} else if (ch == KEY_RESIZE) {
Panel_resize(panel, COLS, LINES-panel->y-1);
Panel_resize(panel, COLS, LINES - panel->y - 1);
} else {
if (mode->isFilter) {
filterChanged = true;

View File

@ -287,7 +287,7 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
for (int i = 0; i < 32; i++)
if (indent & (1U << i))
maxIndent = i+1;
maxIndent = i + 1;
for (int i = 0; i < maxIndent - 1; i++) {
int written, ret;
if (indent & (1 << i))

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;
}
@ -76,7 +86,7 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
unsigned cpu_count;
// TODO Improving the accuracy of the load counts woule help a lot.
if (0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t *)p, &info_size)) {
if (0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t*)p, &info_size)) {
CRT_fatalError("Unable to retrieve CPU info\n");
}
@ -86,8 +96,9 @@ 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) {
@ -145,11 +156,11 @@ void ProcessList_delete(ProcessList* this) {
}
void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
DarwinProcessList *dpl = (DarwinProcessList *)super;
DarwinProcessList* dpl = (DarwinProcessList*)super;
bool preExisting = true;
struct kinfo_proc *ps;
struct kinfo_proc* ps;
size_t count;
DarwinProcess *proc;
DarwinProcess* proc;
/* Update the global data (CPU times and VM stats) */
ProcessList_freeCPULoadInfo(&dpl->prev_load);
@ -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;
@ -186,7 +198,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
ps = ProcessList_getKInfoProcs(&count);
for (size_t i = 0; i < count; ++i) {
proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, DarwinProcess_new);
proc = (DarwinProcess*)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, DarwinProcess_new);
DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], preExisting);
DarwinProcess_setFromLibprocPidinfo(proc, dpl);
@ -194,7 +206,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
// Disabled for High Sierra due to bug in macOS High Sierra
bool isScanThreadSupported = ! ( CompareKernelVersion(17, 0, 0) >= 0 && CompareKernelVersion(17, 5, 0) < 0);
if (isScanThreadSupported){
if (isScanThreadSupported) {
DarwinProcess_scanThreads(proc);
}

View File

@ -211,11 +211,11 @@ double Platform_setCPUValues(Meter* mtr, int cpu) {
}
mtr->values[CPU_METER_NICE]
= ((double)curr->cpu_ticks[CPU_STATE_NICE] - (double)prev->cpu_ticks[CPU_STATE_NICE])* 100.0 / total;
= ((double)curr->cpu_ticks[CPU_STATE_NICE] - (double)prev->cpu_ticks[CPU_STATE_NICE]) * 100.0 / total;
mtr->values[CPU_METER_NORMAL]
= ((double)curr->cpu_ticks[CPU_STATE_USER] - (double)prev->cpu_ticks[CPU_STATE_USER])* 100.0 / total;
= ((double)curr->cpu_ticks[CPU_STATE_USER] - (double)prev->cpu_ticks[CPU_STATE_USER]) * 100.0 / total;
mtr->values[CPU_METER_KERNEL]
= ((double)curr->cpu_ticks[CPU_STATE_SYSTEM] - (double)prev->cpu_ticks[CPU_STATE_SYSTEM])* 100.0 / total;
= ((double)curr->cpu_ticks[CPU_STATE_SYSTEM] - (double)prev->cpu_ticks[CPU_STATE_SYSTEM]) * 100.0 / total;
mtr->curItems = 3;

View File

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

View File

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

View File

@ -419,20 +419,20 @@ 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: "))
process->io_rchar = strtoull(line+7, NULL, 10);
else if (String_startsWith(line+1, "ead_bytes: ")) {
process->io_read_bytes = strtoull(line+12, NULL, 10);
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: ")) {
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);
process->io_rate_read_time = now;
}
break;
case 'w':
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: ")) {
process->io_write_bytes = strtoull(line+13, NULL, 10);
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: ")) {
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);
process->io_rate_write_time = now;
@ -446,8 +446,8 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna
}
break;
case 'c':
if (String_startsWith(line+1, "ancelled_write_bytes: ")) {
process->io_cancelled_write_bytes = strtoull(line+23, NULL, 10);
if (String_startsWith(line + 1, "ancelled_write_bytes: ")) {
process->io_cancelled_write_bytes = strtoull(line + 23, NULL, 10);
}
}
}
@ -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

@ -24,7 +24,7 @@ static const int PressureStallMeter_attributes[] = {
};
static void PressureStallMeter_updateValues(Meter* this, char* buffer, int len) {
const char *file;
const char* file;
if (strstr(Meter_name(this), "CPU")) {
file = "cpu";
} else if (strstr(Meter_name(this), "IO")) {

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;
}
@ -281,7 +281,7 @@ char* Platform_getProcessEnv(pid_t pid) {
if (size + 2 < capacity)
env = xRealloc(env, capacity + 2);
env[size] = 0;
env[size+1] = 0;
env[size + 1] = 0;
}
(void) kvm_close(kt);

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

@ -31,7 +31,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
return;
bool preExisting = true;
Process *proc;
Process* proc;
proc = ProcessList_getProcess(super, 1, &preExisting, UnsupportedProcess_new);

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);