mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-14 21:14:35 +03:00
Resolve merge conflicts, merge #298 "Macro cleanup" from @BenBE
This commit is contained in:
@ -13,7 +13,7 @@ void Battery_getData(double* level, ACPresence* isOnAC) {
|
||||
*level = NAN;
|
||||
*isOnAC = AC_ERROR;
|
||||
|
||||
if(NULL == power_sources) {
|
||||
if (NULL == power_sources) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ void Battery_getData(double* level, ACPresence* isOnAC) {
|
||||
CFDictionaryRef battery = NULL;
|
||||
int len;
|
||||
|
||||
if(NULL == list) {
|
||||
if (NULL == list) {
|
||||
CFRelease(power_sources);
|
||||
|
||||
return;
|
||||
@ -30,38 +30,38 @@ void Battery_getData(double* level, ACPresence* isOnAC) {
|
||||
len = CFArrayGetCount(list);
|
||||
|
||||
/* Get the battery */
|
||||
for(int i = 0; i < len && battery == NULL; ++i) {
|
||||
for (int i = 0; i < len && battery == NULL; ++i) {
|
||||
CFDictionaryRef candidate = IOPSGetPowerSourceDescription(power_sources,
|
||||
CFArrayGetValueAtIndex(list, i)); /* GET rule */
|
||||
CFArrayGetValueAtIndex(list, i)); /* GET rule */
|
||||
CFStringRef type;
|
||||
|
||||
if(NULL != candidate) {
|
||||
if (NULL != candidate) {
|
||||
type = (CFStringRef) CFDictionaryGetValue(candidate,
|
||||
CFSTR(kIOPSTransportTypeKey)); /* GET rule */
|
||||
CFSTR(kIOPSTransportTypeKey)); /* GET rule */
|
||||
|
||||
if(kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) {
|
||||
if (kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) {
|
||||
CFRetain(candidate);
|
||||
battery = candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(NULL != battery) {
|
||||
if (NULL != battery) {
|
||||
/* Determine the AC state */
|
||||
CFStringRef power_state = CFDictionaryGetValue(battery, CFSTR(kIOPSPowerSourceStateKey));
|
||||
|
||||
*isOnAC = (kCFCompareEqualTo == CFStringCompare(power_state, CFSTR(kIOPSACPowerValue), 0))
|
||||
? AC_PRESENT
|
||||
: AC_ABSENT;
|
||||
? AC_PRESENT
|
||||
: AC_ABSENT;
|
||||
|
||||
/* Get the percentage remaining */
|
||||
double current;
|
||||
double max;
|
||||
|
||||
CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSCurrentCapacityKey)),
|
||||
kCFNumberDoubleType, ¤t);
|
||||
kCFNumberDoubleType, ¤t);
|
||||
CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSMaxCapacityKey)),
|
||||
kCFNumberDoubleType, &max);
|
||||
kCFNumberDoubleType, &max);
|
||||
|
||||
*level = (current * 100.0) / max;
|
||||
|
||||
|
@ -52,7 +52,7 @@ bool Process_isThread(const Process* this) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) {
|
||||
char* DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) {
|
||||
/* This function is from the old Mac version of htop. Originally from ps? */
|
||||
int mib[3], argmax, nargs, c = 0;
|
||||
size_t size;
|
||||
@ -68,7 +68,7 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) {
|
||||
}
|
||||
|
||||
/* Allocate space for the arguments. */
|
||||
procargs = ( char * ) xMalloc( argmax );
|
||||
procargs = (char*)xMalloc(argmax);
|
||||
if ( procargs == NULL ) {
|
||||
goto ERROR_A;
|
||||
}
|
||||
@ -158,12 +158,12 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) {
|
||||
/* Convert previous '\0'. */
|
||||
*np = ' ';
|
||||
}
|
||||
/* Note location of current '\0'. */
|
||||
np = cp;
|
||||
if (*basenameOffset == 0) {
|
||||
*basenameOffset = cp - sp;
|
||||
}
|
||||
}
|
||||
/* Note location of current '\0'. */
|
||||
np = cp;
|
||||
if (*basenameOffset == 0) {
|
||||
*basenameOffset = cp - sp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -195,8 +195,8 @@ ERROR_A:
|
||||
return retval;
|
||||
}
|
||||
|
||||
void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool exists) {
|
||||
struct extern_proc *ep = &ps->kp_proc;
|
||||
void DarwinProcess_setFromKInfoProc(Process* proc, struct kinfo_proc* ps, bool exists) {
|
||||
struct extern_proc* ep = &ps->kp_proc;
|
||||
|
||||
/* UNSET HERE :
|
||||
*
|
||||
@ -212,7 +212,7 @@ void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool e
|
||||
*/
|
||||
|
||||
/* First, the "immutable" parts */
|
||||
if(!exists) {
|
||||
if (!exists) {
|
||||
/* Set the PID/PGID/etc. */
|
||||
proc->pid = ep->p_pid;
|
||||
proc->ppid = ps->kp_eproc.e_ppid;
|
||||
@ -241,16 +241,16 @@ void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool e
|
||||
proc->updated = true;
|
||||
}
|
||||
|
||||
void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList *dpl) {
|
||||
void DarwinProcess_setFromLibprocPidinfo(DarwinProcess* proc, DarwinProcessList* dpl) {
|
||||
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) {
|
||||
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);
|
||||
+ (pti.pti_total_user - proc->utime);
|
||||
|
||||
proc->super.percent_cpu = (double)diff * (double)dpl->super.cpuCount
|
||||
/ ((double)dpl->global_diff * 100000.0);
|
||||
/ ((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);
|
||||
@ -263,7 +263,7 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList
|
||||
proc->super.m_resident = pti.pti_resident_size / CRT_pageSize;
|
||||
proc->super.majflt = pti.pti_faults;
|
||||
proc->super.percent_mem = (double)pti.pti_resident_size * 100.0
|
||||
/ (double)dpl->host_info.max_mem;
|
||||
/ (double)dpl->host_info.max_mem;
|
||||
|
||||
proc->stime = pti.pti_total_system;
|
||||
proc->utime = pti.pti_total_user;
|
||||
@ -280,7 +280,7 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList
|
||||
* Based on: http://stackoverflow.com/questions/6788274/ios-mac-cpu-usage-for-thread
|
||||
* and https://github.com/max-horvath/htop-osx/blob/e86692e869e30b0bc7264b3675d2a4014866ef46/ProcessList.c
|
||||
*/
|
||||
void DarwinProcess_scanThreads(DarwinProcess *dp) {
|
||||
void DarwinProcess_scanThreads(DarwinProcess* dp) {
|
||||
Process* proc = (Process*) dp;
|
||||
kern_return_t ret;
|
||||
|
||||
|
@ -28,17 +28,17 @@ void Process_delete(Object* cast);
|
||||
|
||||
bool Process_isThread(const Process* this);
|
||||
|
||||
char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset);
|
||||
char* DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset);
|
||||
|
||||
void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool exists);
|
||||
void DarwinProcess_setFromKInfoProc(Process* proc, struct kinfo_proc* ps, bool exists);
|
||||
|
||||
void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList *dpl);
|
||||
void DarwinProcess_setFromLibprocPidinfo(DarwinProcess* proc, DarwinProcessList* dpl);
|
||||
|
||||
/*
|
||||
* Scan threads for process state information.
|
||||
* Based on: http://stackoverflow.com/questions/6788274/ios-mac-cpu-usage-for-thread
|
||||
* and https://github.com/max-horvath/htop-osx/blob/e86692e869e30b0bc7264b3675d2a4014866ef46/ProcessList.c
|
||||
*/
|
||||
void DarwinProcess_scanThreads(DarwinProcess *dp);
|
||||
void DarwinProcess_scanThreads(DarwinProcess* dp);
|
||||
|
||||
#endif
|
||||
|
@ -24,10 +24,10 @@ in the source distribution for its full text.
|
||||
#include <stdbool.h>
|
||||
|
||||
struct kern {
|
||||
short int version[3];
|
||||
short int version[3];
|
||||
};
|
||||
|
||||
void GetKernelVersion(struct kern *k) {
|
||||
void GetKernelVersion(struct kern* k) {
|
||||
static short int version_[3] = {0};
|
||||
if (!version_[0]) {
|
||||
// just in case it fails someday
|
||||
@ -35,9 +35,11 @@ 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]);
|
||||
}
|
||||
memcpy(k->version, version_, sizeof(version_));
|
||||
if (ret == 0) {
|
||||
sscanf(str, "%hd.%hd.%hd", &version_[0], &version_[1], &version_[2]);
|
||||
}
|
||||
}
|
||||
memcpy(k->version, version_, sizeof(version_));
|
||||
}
|
||||
|
||||
/* compare the given os version with the one installed returns:
|
||||
@ -46,68 +48,80 @@ positive value if less than the installed version
|
||||
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;
|
||||
return 0;
|
||||
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;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ProcessList_getHostInfo(host_basic_info_data_t *p) {
|
||||
void ProcessList_getHostInfo(host_basic_info_data_t* p) {
|
||||
mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT;
|
||||
|
||||
if(0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) {
|
||||
CRT_fatalError("Unable to retrieve host info\n");
|
||||
if (0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) {
|
||||
CRT_fatalError("Unable to retrieve host info\n");
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessList_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\n");
|
||||
}
|
||||
*p = NULL;
|
||||
void ProcessList_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\n");
|
||||
}
|
||||
*p = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
|
||||
unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t* p) {
|
||||
mach_msg_type_number_t info_size = sizeof(processor_cpu_load_info_t);
|
||||
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)) {
|
||||
CRT_fatalError("Unable to retrieve CPU info\n");
|
||||
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");
|
||||
}
|
||||
|
||||
return cpu_count;
|
||||
}
|
||||
|
||||
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)
|
||||
CRT_fatalError("Unable to retrieve VM statistics\n");
|
||||
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) {
|
||||
struct kinfo_proc* ProcessList_getKInfoProcs(size_t* count) {
|
||||
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 };
|
||||
struct kinfo_proc *processes = NULL;
|
||||
struct kinfo_proc* processes = NULL;
|
||||
|
||||
/* Note the two calls to sysctl(). One to get length and one to get the
|
||||
* data. This -does- mean that the second call could end up with a missing
|
||||
* process entry or two.
|
||||
*/
|
||||
*count = 0;
|
||||
if (sysctl(mib, 4, NULL, count, NULL, 0) < 0)
|
||||
if (sysctl(mib, 4, NULL, count, NULL, 0) < 0) {
|
||||
CRT_fatalError("Unable to get size of kproc_infos");
|
||||
}
|
||||
|
||||
processes = xMalloc(*count);
|
||||
if (processes == NULL)
|
||||
if (processes == NULL) {
|
||||
CRT_fatalError("Out of memory for kproc_infos");
|
||||
}
|
||||
|
||||
if (sysctl(mib, 4, processes, count, NULL, 0) < 0)
|
||||
if (sysctl(mib, 4, processes, count, NULL, 0) < 0) {
|
||||
CRT_fatalError("Unable to get kinfo_procs");
|
||||
}
|
||||
|
||||
*count = *count / sizeof(struct kinfo_proc);
|
||||
|
||||
@ -145,67 +159,68 @@ void ProcessList_delete(ProcessList* this) {
|
||||
}
|
||||
|
||||
void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) {
|
||||
DarwinProcessList *dpl = (DarwinProcessList *)super;
|
||||
bool preExisting = true;
|
||||
struct kinfo_proc *ps;
|
||||
size_t count;
|
||||
DarwinProcess *proc;
|
||||
DarwinProcessList* dpl = (DarwinProcessList*)super;
|
||||
bool preExisting = true;
|
||||
struct kinfo_proc* ps;
|
||||
size_t count;
|
||||
DarwinProcess* proc;
|
||||
|
||||
/* Update the global data (CPU times and VM stats) */
|
||||
ProcessList_freeCPULoadInfo(&dpl->prev_load);
|
||||
dpl->prev_load = dpl->curr_load;
|
||||
ProcessList_allocateCPULoadInfo(&dpl->curr_load);
|
||||
ProcessList_getVMStats(&dpl->vm_stats);
|
||||
openzfs_sysctl_updateArcStats(&dpl->zfs);
|
||||
/* Update the global data (CPU times and VM stats) */
|
||||
ProcessList_freeCPULoadInfo(&dpl->prev_load);
|
||||
dpl->prev_load = dpl->curr_load;
|
||||
ProcessList_allocateCPULoadInfo(&dpl->curr_load);
|
||||
ProcessList_getVMStats(&dpl->vm_stats);
|
||||
openzfs_sysctl_updateArcStats(&dpl->zfs);
|
||||
|
||||
// in pause mode only gather global data for meters (CPU/memory/...)
|
||||
if (pauseProcessUpdate)
|
||||
return;
|
||||
// in pause mode only gather global data for meters (CPU/memory/...)
|
||||
if (pauseProcessUpdate) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Get the time difference */
|
||||
dpl->global_diff = 0;
|
||||
for(int i = 0; i < dpl->super.cpuCount; ++i) {
|
||||
for(size_t j = 0; j < CPU_STATE_MAX; ++j) {
|
||||
dpl->global_diff += dpl->curr_load[i].cpu_ticks[j] - dpl->prev_load[i].cpu_ticks[j];
|
||||
}
|
||||
}
|
||||
/* Get the time difference */
|
||||
dpl->global_diff = 0;
|
||||
for (int i = 0; i < dpl->super.cpuCount; ++i) {
|
||||
for (size_t j = 0; j < CPU_STATE_MAX; ++j) {
|
||||
dpl->global_diff += dpl->curr_load[i].cpu_ticks[j] - dpl->prev_load[i].cpu_ticks[j];
|
||||
}
|
||||
}
|
||||
|
||||
/* Clear the thread counts */
|
||||
super->kernelThreads = 0;
|
||||
super->userlandThreads = 0;
|
||||
super->totalTasks = 0;
|
||||
super->runningTasks = 0;
|
||||
/* Clear the thread counts */
|
||||
super->kernelThreads = 0;
|
||||
super->userlandThreads = 0;
|
||||
super->totalTasks = 0;
|
||||
super->runningTasks = 0;
|
||||
|
||||
/* We use kinfo_procs for initial data since :
|
||||
*
|
||||
* 1) They always succeed.
|
||||
* 2) The contain the basic information.
|
||||
*
|
||||
* We attempt to fill-in additional information with libproc.
|
||||
*/
|
||||
ps = ProcessList_getKInfoProcs(&count);
|
||||
/* We use kinfo_procs for initial data since :
|
||||
*
|
||||
* 1) They always succeed.
|
||||
* 2) The contain the basic information.
|
||||
*
|
||||
* We attempt to fill-in additional information with libproc.
|
||||
*/
|
||||
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);
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
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);
|
||||
DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], preExisting);
|
||||
DarwinProcess_setFromLibprocPidinfo(proc, dpl);
|
||||
|
||||
// Disabled for High Sierra due to bug in macOS High Sierra
|
||||
bool isScanThreadSupported = ! ( CompareKernelVersion(17, 0, 0) >= 0 && CompareKernelVersion(17, 5, 0) < 0);
|
||||
// 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){
|
||||
DarwinProcess_scanThreads(proc);
|
||||
}
|
||||
if (isScanThreadSupported) {
|
||||
DarwinProcess_scanThreads(proc);
|
||||
}
|
||||
|
||||
super->totalTasks += 1;
|
||||
super->totalTasks += 1;
|
||||
|
||||
if(!preExisting) {
|
||||
proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid);
|
||||
if (!preExisting) {
|
||||
proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid);
|
||||
|
||||
ProcessList_add(super, &proc->super);
|
||||
}
|
||||
}
|
||||
ProcessList_add(super, &proc->super);
|
||||
}
|
||||
}
|
||||
|
||||
free(ps);
|
||||
free(ps);
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ in the source distribution for its full text.
|
||||
|
||||
struct kern;
|
||||
|
||||
void GetKernelVersion(struct kern *k);
|
||||
void GetKernelVersion(struct kern* k);
|
||||
|
||||
/* compare the given os version with the one installed returns:
|
||||
0 if equals the installed version
|
||||
@ -37,15 +37,15 @@ typedef struct DarwinProcessList_ {
|
||||
ZfsArcStats zfs;
|
||||
} DarwinProcessList;
|
||||
|
||||
void ProcessList_getHostInfo(host_basic_info_data_t *p);
|
||||
void ProcessList_getHostInfo(host_basic_info_data_t* p);
|
||||
|
||||
void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p);
|
||||
void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t* p);
|
||||
|
||||
unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p);
|
||||
unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t* p);
|
||||
|
||||
void ProcessList_getVMStats(vm_statistics_t p);
|
||||
|
||||
struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count);
|
||||
struct kinfo_proc* ProcessList_getKInfoProcs(size_t* count);
|
||||
|
||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId);
|
||||
|
||||
|
@ -150,7 +150,7 @@ int Platform_getUptime() {
|
||||
void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
|
||||
double results[3];
|
||||
|
||||
if(3 == getloadavg(results, 3)) {
|
||||
if (3 == getloadavg(results, 3)) {
|
||||
*one = results[0];
|
||||
*five = results[1];
|
||||
*fifteen = results[2];
|
||||
@ -177,7 +177,7 @@ ProcessPidColumn Process_pidColumns[] = {
|
||||
};
|
||||
|
||||
static double Platform_setCPUAverageValues(Meter* mtr) {
|
||||
const ProcessList *dpl = mtr->pl;
|
||||
const ProcessList* dpl = mtr->pl;
|
||||
int cpus = dpl->cpuCount;
|
||||
double sumNice = 0.0;
|
||||
double sumNormal = 0.0;
|
||||
@ -201,22 +201,22 @@ double Platform_setCPUValues(Meter* mtr, int cpu) {
|
||||
return Platform_setCPUAverageValues(mtr);
|
||||
}
|
||||
|
||||
const DarwinProcessList *dpl = (const DarwinProcessList *)mtr->pl;
|
||||
const processor_cpu_load_info_t prev = &dpl->prev_load[cpu-1];
|
||||
const processor_cpu_load_info_t curr = &dpl->curr_load[cpu-1];
|
||||
const DarwinProcessList* dpl = (const DarwinProcessList*)mtr->pl;
|
||||
const processor_cpu_load_info_t prev = &dpl->prev_load[cpu - 1];
|
||||
const 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) {
|
||||
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;
|
||||
= ((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;
|
||||
|
||||
@ -229,7 +229,7 @@ double Platform_setCPUValues(Meter* mtr, int cpu) {
|
||||
}
|
||||
|
||||
void Platform_setMemoryValues(Meter* mtr) {
|
||||
const DarwinProcessList *dpl = (const DarwinProcessList *)mtr->pl;
|
||||
const DarwinProcessList* dpl = (const DarwinProcessList*)mtr->pl;
|
||||
const struct vm_statistics* vm = &dpl->vm_stats;
|
||||
double page_K = (double)vm_page_size / (double)1024;
|
||||
|
||||
@ -240,13 +240,13 @@ void Platform_setMemoryValues(Meter* mtr) {
|
||||
}
|
||||
|
||||
void Platform_setSwapValues(Meter* mtr) {
|
||||
int mib[2] = {CTL_VM, VM_SWAPUSAGE};
|
||||
struct xsw_usage swapused;
|
||||
size_t swlen = sizeof(swapused);
|
||||
sysctl(mib, 2, &swapused, &swlen, NULL, 0);
|
||||
int mib[2] = {CTL_VM, VM_SWAPUSAGE};
|
||||
struct xsw_usage swapused;
|
||||
size_t swlen = sizeof(swapused);
|
||||
sysctl(mib, 2, &swapused, &swlen, NULL, 0);
|
||||
|
||||
mtr->total = swapused.xsu_total / 1024;
|
||||
mtr->values[0] = swapused.xsu_used / 1024;
|
||||
mtr->total = swapused.xsu_total / 1024;
|
||||
mtr->values[0] = swapused.xsu_used / 1024;
|
||||
}
|
||||
|
||||
void Platform_setZfsArcValues(Meter* this) {
|
||||
@ -284,25 +284,25 @@ char* Platform_getProcessEnv(pid_t pid) {
|
||||
p += sizeof(int);
|
||||
|
||||
// skip exe
|
||||
p = strchr(p, 0)+1;
|
||||
p = strchr(p, 0) + 1;
|
||||
|
||||
// skip padding
|
||||
while(!*p && p < endp)
|
||||
while (!*p && p < endp)
|
||||
++p;
|
||||
|
||||
// skip argv
|
||||
for (; argc-- && p < endp; p = strrchr(p, 0)+1)
|
||||
for (; argc-- && p < endp; p = strrchr(p, 0) + 1)
|
||||
;
|
||||
|
||||
// skip padding
|
||||
while(!*p && p < endp)
|
||||
while (!*p && p < endp)
|
||||
++p;
|
||||
|
||||
size_t size = endp - p;
|
||||
env = xMalloc(size+2);
|
||||
env = xMalloc(size + 2);
|
||||
memcpy(env, p, size);
|
||||
env[size] = 0;
|
||||
env[size+1] = 0;
|
||||
env[size + 1] = 0;
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
@ -329,10 +329,10 @@ bool Platform_getDiskIO(DiskIOData* data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Platform_getNetworkIO(unsigned long int *bytesReceived,
|
||||
unsigned long int *packetsReceived,
|
||||
unsigned long int *bytesTransmitted,
|
||||
unsigned long int *packetsTransmitted) {
|
||||
bool Platform_getNetworkIO(unsigned long int* bytesReceived,
|
||||
unsigned long int* packetsReceived,
|
||||
unsigned long int* bytesTransmitted,
|
||||
unsigned long int* packetsTransmitted) {
|
||||
// TODO
|
||||
*bytesReceived = 0;
|
||||
*packetsReceived = 0;
|
||||
|
@ -60,9 +60,9 @@ FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid);
|
||||
|
||||
bool Platform_getDiskIO(DiskIOData* data);
|
||||
|
||||
bool Platform_getNetworkIO(unsigned long int *bytesReceived,
|
||||
unsigned long int *packetsReceived,
|
||||
unsigned long int *bytesTransmitted,
|
||||
unsigned long int *packetsTransmitted);
|
||||
bool Platform_getNetworkIO(unsigned long int* bytesReceived,
|
||||
unsigned long int* packetsReceived,
|
||||
unsigned long int* bytesTransmitted,
|
||||
unsigned long int* packetsTransmitted);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user