mirror of https://github.com/xzeldon/htop.git
Standardize indentation.
This commit is contained in:
parent
907f8298a0
commit
f70649a178
|
@ -7,7 +7,7 @@
|
|||
#include <IOKit/ps/IOPSKeys.h>
|
||||
|
||||
void Battery_getData(double* level, ACPresence* isOnAC) {
|
||||
CFTypeRef power_sources = IOPSCopyPowerSourcesInfo();
|
||||
CFTypeRef power_sources = IOPSCopyPowerSourcesInfo();
|
||||
|
||||
*level = -1;
|
||||
*isOnAC = AC_ERROR;
|
||||
|
@ -22,50 +22,50 @@ void Battery_getData(double* level, ACPresence* isOnAC) {
|
|||
int len;
|
||||
|
||||
if(NULL == list) {
|
||||
CFRelease(power_sources);
|
||||
CFRelease(power_sources);
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
len = CFArrayGetCount(list);
|
||||
|
||||
/* Get the battery */
|
||||
for(int i = 0; i < len && battery == NULL; ++i) {
|
||||
CFDictionaryRef candidate = IOPSGetPowerSourceDescription(power_sources,
|
||||
CFArrayGetValueAtIndex(list, i)); /* GET rule */
|
||||
CFStringRef type;
|
||||
CFDictionaryRef candidate = IOPSGetPowerSourceDescription(power_sources,
|
||||
CFArrayGetValueAtIndex(list, i)); /* GET rule */
|
||||
CFStringRef type;
|
||||
|
||||
if(NULL != candidate) {
|
||||
type = (CFStringRef) CFDictionaryGetValue(candidate,
|
||||
CFSTR(kIOPSTransportTypeKey)); /* GET rule */
|
||||
if(NULL != candidate) {
|
||||
type = (CFStringRef) CFDictionaryGetValue(candidate,
|
||||
CFSTR(kIOPSTransportTypeKey)); /* GET rule */
|
||||
|
||||
if(kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) {
|
||||
CFRetain(candidate);
|
||||
battery = candidate;
|
||||
}
|
||||
}
|
||||
if(kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) {
|
||||
CFRetain(candidate);
|
||||
battery = candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(NULL != battery) {
|
||||
/* Determine the AC state */
|
||||
CFStringRef power_state = CFDictionaryGetValue(battery, CFSTR(kIOPSPowerSourceStateKey));
|
||||
/* Determine the AC state */
|
||||
CFStringRef power_state = CFDictionaryGetValue(battery, CFSTR(kIOPSPowerSourceStateKey));
|
||||
|
||||
*isOnAC = (kCFCompareEqualTo == CFStringCompare(power_state, CFSTR(kIOPSACPowerValue), 0))
|
||||
? AC_PRESENT
|
||||
: AC_ABSENT;
|
||||
*isOnAC = (kCFCompareEqualTo == CFStringCompare(power_state, CFSTR(kIOPSACPowerValue), 0))
|
||||
? AC_PRESENT
|
||||
: AC_ABSENT;
|
||||
|
||||
/* Get the percentage remaining */
|
||||
double current;
|
||||
double max;
|
||||
/* Get the percentage remaining */
|
||||
double current;
|
||||
double max;
|
||||
|
||||
CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSCurrentCapacityKey)),
|
||||
kCFNumberDoubleType, ¤t);
|
||||
CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSMaxCapacityKey)),
|
||||
kCFNumberDoubleType, &max);
|
||||
CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSCurrentCapacityKey)),
|
||||
kCFNumberDoubleType, ¤t);
|
||||
CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSMaxCapacityKey)),
|
||||
kCFNumberDoubleType, &max);
|
||||
|
||||
*level = (current * 100.0) / max;
|
||||
*level = (current * 100.0) / max;
|
||||
|
||||
CFRelease(battery);
|
||||
CFRelease(battery);
|
||||
}
|
||||
|
||||
CFRelease(list);
|
||||
|
|
|
@ -12,24 +12,24 @@ in the source distribution for its full text.
|
|||
#include <execinfo.h>
|
||||
|
||||
void CRT_handleSIGSEGV(int sgn) {
|
||||
(void) sgn;
|
||||
CRT_done();
|
||||
#ifdef __APPLE__
|
||||
fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at http://hisham.hm/htop\n");
|
||||
#ifdef HAVE_EXECINFO_H
|
||||
size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *));
|
||||
fprintf(stderr, "\n Please include in your report the following backtrace: \n");
|
||||
backtrace_symbols_fd(backtraceArray, size, 2);
|
||||
fprintf(stderr, "\nAdditionally, in order to make the above backtrace useful,");
|
||||
fprintf(stderr, "\nplease also run the following command to generate a disassembly of your binary:");
|
||||
fprintf(stderr, "\n\n otool -tvV `which htop` > ~/htop.otool");
|
||||
fprintf(stderr, "\n\nand then attach the file ~/htop.otool to your bug report.");
|
||||
fprintf(stderr, "\n\nThank you for helping to improve htop!\n\n");
|
||||
#endif
|
||||
#else
|
||||
fprintf(stderr, "\nUnfortunately, you seem to be using an unsupported platform!");
|
||||
fprintf(stderr, "\nPlease contact your platform package mantainer!\n\n");
|
||||
#endif
|
||||
abort();
|
||||
(void) sgn;
|
||||
CRT_done();
|
||||
#ifdef __APPLE__
|
||||
fprintf(stderr, "\n\nhtop " VERSION " aborting. Please report bug at http://hisham.hm/htop\n");
|
||||
#ifdef HAVE_EXECINFO_H
|
||||
size_t size = backtrace(backtraceArray, sizeof(backtraceArray) / sizeof(void *));
|
||||
fprintf(stderr, "\n Please include in your report the following backtrace: \n");
|
||||
backtrace_symbols_fd(backtraceArray, size, 2);
|
||||
fprintf(stderr, "\nAdditionally, in order to make the above backtrace useful,");
|
||||
fprintf(stderr, "\nplease also run the following command to generate a disassembly of your binary:");
|
||||
fprintf(stderr, "\n\n otool -tvV `which htop` > ~/htop.otool");
|
||||
fprintf(stderr, "\n\nand then attach the file ~/htop.otool to your bug report.");
|
||||
fprintf(stderr, "\n\nThank you for helping to improve htop!\n\n");
|
||||
#endif
|
||||
#else
|
||||
fprintf(stderr, "\nUnfortunately, you seem to be using an unsupported platform!");
|
||||
fprintf(stderr, "\nPlease contact your platform package mantainer!\n\n");
|
||||
#endif
|
||||
abort();
|
||||
}
|
||||
|
||||
|
|
|
@ -62,11 +62,11 @@ bool Process_isThread(Process* this) {
|
|||
}
|
||||
|
||||
void DarwinProcess_setStartTime(Process *proc, struct extern_proc *ep, time_t now) {
|
||||
struct tm date;
|
||||
struct tm date;
|
||||
|
||||
proc->starttime_ctime = ep->p_starttime.tv_sec;
|
||||
(void) localtime_r(&proc->starttime_ctime, &date);
|
||||
strftime(proc->starttime_show, 7, ((proc->starttime_ctime > now - 86400) ? "%R " : "%b%d "), &date);
|
||||
proc->starttime_ctime = ep->p_starttime.tv_sec;
|
||||
(void) localtime_r(&proc->starttime_ctime, &date);
|
||||
strftime(proc->starttime_show, 7, ((proc->starttime_ctime > now - 86400) ? "%R " : "%b%d "), &date);
|
||||
}
|
||||
|
||||
char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int show_args ) {
|
||||
|
@ -253,92 +253,92 @@ ERROR_A:
|
|||
}
|
||||
|
||||
void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, time_t now, bool exists) {
|
||||
struct extern_proc *ep = &ps->kp_proc;
|
||||
struct extern_proc *ep = &ps->kp_proc;
|
||||
|
||||
/* UNSET HERE :
|
||||
*
|
||||
* processor
|
||||
* user (set at ProcessList level)
|
||||
* nlwp
|
||||
* percent_cpu
|
||||
* percent_mem
|
||||
* m_size
|
||||
* m_resident
|
||||
* minflt
|
||||
* majflt
|
||||
*/
|
||||
/* UNSET HERE :
|
||||
*
|
||||
* processor
|
||||
* user (set at ProcessList level)
|
||||
* nlwp
|
||||
* percent_cpu
|
||||
* percent_mem
|
||||
* m_size
|
||||
* m_resident
|
||||
* minflt
|
||||
* majflt
|
||||
*/
|
||||
|
||||
/* First, the "immutable" parts */
|
||||
if(!exists) {
|
||||
/* Set the PID/PGID/etc. */
|
||||
proc->pid = ep->p_pid;
|
||||
proc->ppid = ps->kp_eproc.e_ppid;
|
||||
proc->pgrp = ps->kp_eproc.e_pgid;
|
||||
proc->session = 0; /* TODO Get the session id */
|
||||
proc->tgid = ps->kp_eproc.e_tpgid;
|
||||
proc->st_uid = ps->kp_eproc.e_ucred.cr_uid;
|
||||
/* e_tdev = (major << 24) | (minor & 0xffffff) */
|
||||
/* e_tdev == -1 for "no device" */
|
||||
proc->tty_nr = ps->kp_eproc.e_tdev & 0xff; /* TODO tty_nr is unsigned */
|
||||
/* First, the "immutable" parts */
|
||||
if(!exists) {
|
||||
/* Set the PID/PGID/etc. */
|
||||
proc->pid = ep->p_pid;
|
||||
proc->ppid = ps->kp_eproc.e_ppid;
|
||||
proc->pgrp = ps->kp_eproc.e_pgid;
|
||||
proc->session = 0; /* TODO Get the session id */
|
||||
proc->tgid = ps->kp_eproc.e_tpgid;
|
||||
proc->st_uid = ps->kp_eproc.e_ucred.cr_uid;
|
||||
/* e_tdev = (major << 24) | (minor & 0xffffff) */
|
||||
/* e_tdev == -1 for "no device" */
|
||||
proc->tty_nr = ps->kp_eproc.e_tdev & 0xff; /* TODO tty_nr is unsigned */
|
||||
|
||||
DarwinProcess_setStartTime(proc, ep, now);
|
||||
DarwinProcess_setStartTime(proc, ep, now);
|
||||
|
||||
/* The command is from the old Mac htop */
|
||||
char *slash;
|
||||
/* The command is from the old Mac htop */
|
||||
char *slash;
|
||||
|
||||
proc->comm = DarwinProcess_getCmdLine(ps, false);
|
||||
slash = strrchr(proc->comm, '/');
|
||||
proc->basenameOffset = (NULL != slash) ? (slash - proc->comm) : 0;
|
||||
}
|
||||
proc->comm = DarwinProcess_getCmdLine(ps, false);
|
||||
slash = strrchr(proc->comm, '/');
|
||||
proc->basenameOffset = (NULL != slash) ? (slash - proc->comm) : 0;
|
||||
}
|
||||
|
||||
/* Mutable information */
|
||||
proc->nice = ep->p_nice;
|
||||
proc->priority = ep->p_priority;
|
||||
/* Mutable information */
|
||||
proc->nice = ep->p_nice;
|
||||
proc->priority = ep->p_priority;
|
||||
|
||||
/* Set the state */
|
||||
switch(ep->p_stat) {
|
||||
case SIDL: proc->state = 'I'; break;
|
||||
case SRUN: proc->state = 'R'; break;
|
||||
case SSLEEP: proc->state = 'S'; break;
|
||||
case SSTOP: proc->state = 'T'; break;
|
||||
case SZOMB: proc->state = 'Z'; break;
|
||||
default: proc->state = '?'; break;
|
||||
}
|
||||
/* Set the state */
|
||||
switch(ep->p_stat) {
|
||||
case SIDL: proc->state = 'I'; break;
|
||||
case SRUN: proc->state = 'R'; break;
|
||||
case SSLEEP: proc->state = 'S'; break;
|
||||
case SSTOP: proc->state = 'T'; break;
|
||||
case SZOMB: proc->state = 'Z'; break;
|
||||
default: proc->state = '?'; break;
|
||||
}
|
||||
|
||||
/* Make sure the updated flag is set */
|
||||
proc->updated = true;
|
||||
/* Make sure the updated flag is set */
|
||||
proc->updated = true;
|
||||
}
|
||||
|
||||
void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList *dpl) {
|
||||
struct proc_taskinfo pti;
|
||||
struct proc_taskinfo pti;
|
||||
|
||||
if(sizeof(pti) == proc_pidinfo(proc->super.pid, PROC_PIDTASKINFO, 0, &pti, sizeof(pti))) {
|
||||
if(0 != proc->utime || 0 != proc->stime) {
|
||||
uint64_t diff = (pti.pti_total_system - proc->stime)
|
||||
+ (pti.pti_total_user - proc->utime);
|
||||
if(sizeof(pti) == proc_pidinfo(proc->super.pid, PROC_PIDTASKINFO, 0, &pti, sizeof(pti))) {
|
||||
if(0 != proc->utime || 0 != proc->stime) {
|
||||
uint64_t diff = (pti.pti_total_system - proc->stime)
|
||||
+ (pti.pti_total_user - proc->utime);
|
||||
|
||||
proc->super.percent_cpu = (double)diff * (double)dpl->super.cpuCount
|
||||
/ ((double)dpl->global_diff * 100000.0);
|
||||
proc->super.percent_cpu = (double)diff * (double)dpl->super.cpuCount
|
||||
/ ((double)dpl->global_diff * 100000.0);
|
||||
|
||||
// fprintf(stderr, "%f %llu %llu %llu %llu %llu\n", proc->super.percent_cpu,
|
||||
// proc->stime, proc->utime, pti.pti_total_system, pti.pti_total_user, dpl->global_diff);
|
||||
// exit(7);
|
||||
}
|
||||
// fprintf(stderr, "%f %llu %llu %llu %llu %llu\n", proc->super.percent_cpu,
|
||||
// proc->stime, proc->utime, pti.pti_total_system, pti.pti_total_user, dpl->global_diff);
|
||||
// exit(7);
|
||||
}
|
||||
|
||||
proc->super.time = (pti.pti_total_system + pti.pti_total_user) / 10000000;
|
||||
proc->super.nlwp = pti.pti_threadnum;
|
||||
proc->super.m_size = pti.pti_virtual_size / 1024;
|
||||
proc->super.m_resident = pti.pti_resident_size / 1024;
|
||||
proc->super.majflt = pti.pti_faults;
|
||||
proc->super.percent_mem = (double)pti.pti_resident_size * 100.0
|
||||
/ (double)dpl->host_info.max_mem;
|
||||
proc->super.time = (pti.pti_total_system + pti.pti_total_user) / 10000000;
|
||||
proc->super.nlwp = pti.pti_threadnum;
|
||||
proc->super.m_size = pti.pti_virtual_size / 1024;
|
||||
proc->super.m_resident = pti.pti_resident_size / 1024;
|
||||
proc->super.majflt = pti.pti_faults;
|
||||
proc->super.percent_mem = (double)pti.pti_resident_size * 100.0
|
||||
/ (double)dpl->host_info.max_mem;
|
||||
|
||||
proc->stime = pti.pti_total_system;
|
||||
proc->utime = pti.pti_total_user;
|
||||
proc->stime = pti.pti_total_system;
|
||||
proc->utime = pti.pti_total_user;
|
||||
|
||||
dpl->super.kernelThreads += 0; /*pti.pti_threads_system;*/
|
||||
dpl->super.userlandThreads += pti.pti_threadnum; /*pti.pti_threads_user;*/
|
||||
dpl->super.totalTasks += pti.pti_threadnum;
|
||||
dpl->super.runningTasks += pti.pti_numrunning;
|
||||
}
|
||||
dpl->super.kernelThreads += 0; /*pti.pti_threads_system;*/
|
||||
dpl->super.userlandThreads += pti.pti_threadnum; /*pti.pti_threads_user;*/
|
||||
dpl->super.totalTasks += pti.pti_threadnum;
|
||||
dpl->super.runningTasks += pti.pti_numrunning;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,17 +85,17 @@ char* Process_pidFormat = "%7u ";
|
|||
char* Process_tpgidFormat = "%7u ";
|
||||
|
||||
int Platform_getUptime() {
|
||||
struct timeval bootTime, currTime;
|
||||
int mib[2] = { CTL_KERN, KERN_BOOTTIME };
|
||||
size_t size = sizeof(bootTime);
|
||||
struct timeval bootTime, currTime;
|
||||
int mib[2] = { CTL_KERN, KERN_BOOTTIME };
|
||||
size_t size = sizeof(bootTime);
|
||||
|
||||
int err = sysctl(mib, 2, &bootTime, &size, NULL, 0);
|
||||
if (err) {
|
||||
return -1;
|
||||
}
|
||||
gettimeofday(&currTime, NULL);
|
||||
int err = sysctl(mib, 2, &bootTime, &size, NULL, 0);
|
||||
if (err) {
|
||||
return -1;
|
||||
}
|
||||
gettimeofday(&currTime, NULL);
|
||||
|
||||
return (int) difftime(currTime.tv_sec, bootTime.tv_sec);
|
||||
return (int) difftime(currTime.tv_sec, bootTime.tv_sec);
|
||||
}
|
||||
|
||||
void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
|
||||
|
@ -142,46 +142,45 @@ void Process_setupColumnWidths() {
|
|||
}
|
||||
|
||||
double Platform_setCPUValues(Meter* mtr, int cpu) {
|
||||
/* All just from CPUMeter.c */
|
||||
static const int CPU_METER_NICE = 0;
|
||||
static const int CPU_METER_NORMAL = 1;
|
||||
static const int CPU_METER_KERNEL = 2;
|
||||
/* All just from CPUMeter.c */
|
||||
static const int CPU_METER_NICE = 0;
|
||||
static const int CPU_METER_NORMAL = 1;
|
||||
static const int CPU_METER_KERNEL = 2;
|
||||
|
||||
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];
|
||||
double total = 0;
|
||||
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];
|
||||
double total = 0;
|
||||
|
||||
/* Take the sums */
|
||||
for(size_t i = 0; i < CPU_STATE_MAX; ++i) {
|
||||
total += (double)curr->cpu_ticks[i] - (double)prev->cpu_ticks[i];
|
||||
}
|
||||
/* Take the sums */
|
||||
for(size_t i = 0; i < CPU_STATE_MAX; ++i) {
|
||||
total += (double)curr->cpu_ticks[i] - (double)prev->cpu_ticks[i];
|
||||
}
|
||||
|
||||
mtr->values[CPU_METER_NICE]
|
||||
= ((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;
|
||||
mtr->values[CPU_METER_KERNEL]
|
||||
= ((double)curr->cpu_ticks[CPU_STATE_SYSTEM] - (double)prev->cpu_ticks[CPU_STATE_SYSTEM])* 100.0 / total;
|
||||
mtr->values[CPU_METER_NICE]
|
||||
= ((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;
|
||||
mtr->values[CPU_METER_KERNEL]
|
||||
= ((double)curr->cpu_ticks[CPU_STATE_SYSTEM] - (double)prev->cpu_ticks[CPU_STATE_SYSTEM])* 100.0 / total;
|
||||
|
||||
Meter_setItems(mtr, 3);
|
||||
Meter_setItems(mtr, 3);
|
||||
|
||||
/* Convert to percent and return */
|
||||
total = mtr->values[CPU_METER_NICE] + mtr->values[CPU_METER_NORMAL] + mtr->values[CPU_METER_KERNEL];
|
||||
/* Convert to percent and return */
|
||||
total = mtr->values[CPU_METER_NICE] + mtr->values[CPU_METER_NORMAL] + mtr->values[CPU_METER_KERNEL];
|
||||
|
||||
return MIN(100.0, MAX(0.0, total));
|
||||
return MIN(100.0, MAX(0.0, total));
|
||||
}
|
||||
|
||||
void Platform_setMemoryValues(Meter* mtr) {
|
||||
DarwinProcessList *dpl = (DarwinProcessList *)mtr->pl;
|
||||
vm_statistics64_t vm = &dpl->vm_stats;
|
||||
double page_K = (double)vm_page_size / (double)1024;
|
||||
|
||||
mtr->total = dpl->host_info.max_mem / 1024;
|
||||
mtr->values[0] = (double)(vm->active_count + vm->wire_count) * page_K;
|
||||
mtr->values[1] = (double)vm->purgeable_count * page_K;
|
||||
mtr->values[2] = (double)vm->inactive_count * page_K;
|
||||
DarwinProcessList *dpl = (DarwinProcessList *)mtr->pl;
|
||||
vm_statistics64_t vm = &dpl->vm_stats;
|
||||
double page_K = (double)vm_page_size / (double)1024;
|
||||
|
||||
mtr->total = dpl->host_info.max_mem / 1024;
|
||||
mtr->values[0] = (double)(vm->active_count + vm->wire_count) * page_K;
|
||||
mtr->values[1] = (double)vm->purgeable_count * page_K;
|
||||
mtr->values[2] = (double)vm->inactive_count * page_K;
|
||||
}
|
||||
|
||||
void Platform_setSwapValues(Meter* this) {
|
||||
|
|
Loading…
Reference in New Issue