mirror of https://github.com/xzeldon/htop.git
Fix the thread counts
This commit is contained in:
parent
6463ea2956
commit
57ab332d5a
|
@ -14,6 +14,8 @@ in the source distribution for its full text.
|
||||||
|
|
||||||
/*{
|
/*{
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
#include "DarwinProcessList.h"
|
||||||
|
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
@ -285,15 +287,22 @@ void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, time_t
|
||||||
proc->updated = true;
|
proc->updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DarwinProcess_setFromLibprocPidinfo(Process *proc, uint64_t total_memory, bool preExisting) {
|
void DarwinProcess_setFromLibprocPidinfo(Process *proc, DarwinProcessList *dpl, bool preExisting) {
|
||||||
struct proc_taskinfo pti;
|
struct proc_taskinfo pti;
|
||||||
|
|
||||||
if(sizeof(pti) == proc_pidinfo(proc->pid, PROC_PIDTASKINFO, 0, &pti, sizeof(pti))) {
|
if(sizeof(pti) == proc_pidinfo(proc->pid, PROC_PIDTASKINFO, 0, &pti, sizeof(pti))) {
|
||||||
|
proc->time = (pti.pti_total_system + pti.pti_total_user) / 10000000;
|
||||||
proc->nlwp = pti.pti_threadnum;
|
proc->nlwp = pti.pti_threadnum;
|
||||||
proc->m_size = pti.pti_virtual_size / 1024;
|
proc->m_size = pti.pti_virtual_size / 1024;
|
||||||
proc->m_resident = pti.pti_resident_size / 1024;
|
proc->m_resident = pti.pti_resident_size / 1024;
|
||||||
proc->majflt = pti.pti_faults;
|
proc->majflt = pti.pti_faults;
|
||||||
proc->percent_mem = (double)pti.pti_resident_size * 100.0 / (double)total_memory;
|
proc->percent_mem = (double)pti.pti_resident_size * 100.0
|
||||||
|
/ (double)dpl->host_info.max_mem;
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,8 @@ in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
#include "DarwinProcessList.h"
|
||||||
|
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +27,7 @@ char *DarwinProcessList_getCmdLine(struct kinfo_proc* k, int show_args );
|
||||||
|
|
||||||
void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, time_t now, bool exists);
|
void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, time_t now, bool exists);
|
||||||
|
|
||||||
void DarwinProcess_setFromLibprocPidinfo(Process *proc, uint64_t total_memory, bool preExisting);
|
void DarwinProcess_setFromLibprocPidinfo(Process *proc, DarwinProcessList *dpl, bool preExisting);
|
||||||
|
|
||||||
void DarwinProcess_parseThreads(Process *proc, time_t now, bool preExisting);
|
void DarwinProcess_parseThreads(Process *proc, time_t now, bool preExisting);
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,10 @@ in the source distribution for its full text.
|
||||||
#include <libproc.h>
|
#include <libproc.h>
|
||||||
#include <mach/vm_page_size.h>
|
#include <mach/vm_page_size.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#include <utmpx.h>
|
||||||
|
|
||||||
/*{
|
/*{
|
||||||
|
#include "ProcessList.h"
|
||||||
#include <mach/mach_host.h>
|
#include <mach/mach_host.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
|
||||||
|
@ -25,8 +27,11 @@ typedef struct DarwinProcessList_ {
|
||||||
ProcessList super;
|
ProcessList super;
|
||||||
|
|
||||||
host_basic_info_data_t host_info;
|
host_basic_info_data_t host_info;
|
||||||
|
vm_statistics64_data_t vm_stats;
|
||||||
processor_cpu_load_info_t prev_load;
|
processor_cpu_load_info_t prev_load;
|
||||||
processor_cpu_load_info_t curr_load;
|
processor_cpu_load_info_t curr_load;
|
||||||
|
uint64_t kernel_threads;
|
||||||
|
uint64_t user_threads;
|
||||||
} DarwinProcessList;
|
} DarwinProcessList;
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
@ -63,6 +68,15 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) {
|
||||||
return cpu_count;
|
return cpu_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProcessList_getVMStats(vm_statistics64_t p) {
|
||||||
|
mach_msg_type_number_t info_size = HOST_VM_INFO64_COUNT;
|
||||||
|
|
||||||
|
if(0 != host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info_t)p, &info_size)) {
|
||||||
|
fprintf(stderr, "Unable to retrieve VM statistics\n");
|
||||||
|
exit(9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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 };
|
||||||
struct kinfo_proc *processes = NULL;
|
struct kinfo_proc *processes = NULL;
|
||||||
|
@ -98,12 +112,20 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
|
||||||
DarwinProcessList* this = calloc(1, sizeof(DarwinProcessList));
|
DarwinProcessList* this = calloc(1, sizeof(DarwinProcessList));
|
||||||
|
|
||||||
ProcessList_init(&this->super, Class(Process), usersTable, pidWhiteList, userId);
|
ProcessList_init(&this->super, Class(Process), usersTable, pidWhiteList, userId);
|
||||||
|
|
||||||
/* Initialize the previous information */
|
/* Initialize the CPU information */
|
||||||
this->super.cpuCount = ProcessList_allocateCPULoadInfo(&this->prev_load);
|
this->super.cpuCount = ProcessList_allocateCPULoadInfo(&this->prev_load);
|
||||||
ProcessList_getHostInfo(&this->host_info);
|
ProcessList_getHostInfo(&this->host_info);
|
||||||
ProcessList_allocateCPULoadInfo(&this->curr_load);
|
ProcessList_allocateCPULoadInfo(&this->curr_load);
|
||||||
|
|
||||||
|
/* Initialize the VM statistics */
|
||||||
|
ProcessList_getVMStats(&this->vm_stats);
|
||||||
|
|
||||||
|
this->super.kernelThreads = 0;
|
||||||
|
this->super.userlandThreads = 0;
|
||||||
|
this->super.totalTasks = 0;
|
||||||
|
this->super.runningTasks = 0;
|
||||||
|
|
||||||
return &this->super;
|
return &this->super;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,10 +144,17 @@ void ProcessList_goThroughEntries(ProcessList* super) {
|
||||||
|
|
||||||
gettimeofday(&tv, NULL); /* Start processing time */
|
gettimeofday(&tv, NULL); /* Start processing time */
|
||||||
|
|
||||||
/* Update the global data (CPU times) */
|
/* Update the global data (CPU times and VM stats) */
|
||||||
ProcessList_freeCPULoadInfo(&dpl->prev_load);
|
ProcessList_freeCPULoadInfo(&dpl->prev_load);
|
||||||
dpl->prev_load = dpl->curr_load;
|
dpl->prev_load = dpl->curr_load;
|
||||||
ProcessList_allocateCPULoadInfo(&dpl->curr_load);
|
ProcessList_allocateCPULoadInfo(&dpl->curr_load);
|
||||||
|
ProcessList_getVMStats(&dpl->vm_stats);
|
||||||
|
|
||||||
|
/* Clear the thread counts */
|
||||||
|
super->kernelThreads = 0;
|
||||||
|
super->userlandThreads = 0;
|
||||||
|
super->totalTasks = 0;
|
||||||
|
super->runningTasks = 0;
|
||||||
|
|
||||||
/* We use kinfo_procs for initial data since :
|
/* We use kinfo_procs for initial data since :
|
||||||
*
|
*
|
||||||
|
@ -140,7 +169,9 @@ void ProcessList_goThroughEntries(ProcessList* super) {
|
||||||
proc = ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, DarwinProcess_new);
|
proc = ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, DarwinProcess_new);
|
||||||
|
|
||||||
DarwinProcess_setFromKInfoProc(proc, ps + i, tv.tv_sec, preExisting);
|
DarwinProcess_setFromKInfoProc(proc, ps + i, tv.tv_sec, preExisting);
|
||||||
DarwinProcess_setFromLibprocPidinfo(proc, dpl->host_info.max_mem, preExisting);
|
DarwinProcess_setFromLibprocPidinfo(proc, dpl, preExisting);
|
||||||
|
|
||||||
|
super->totalTasks += 1;
|
||||||
|
|
||||||
if(!preExisting) {
|
if(!preExisting) {
|
||||||
proc->user = UsersTable_getRef(super->usersTable, proc->st_uid);
|
proc->user = UsersTable_getRef(super->usersTable, proc->st_uid);
|
||||||
|
|
|
@ -9,6 +9,7 @@ Released under the GNU GPL, see the COPYING file
|
||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "ProcessList.h"
|
||||||
#include <mach/mach_host.h>
|
#include <mach/mach_host.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
|
||||||
|
@ -16,8 +17,11 @@ typedef struct DarwinProcessList_ {
|
||||||
ProcessList super;
|
ProcessList super;
|
||||||
|
|
||||||
host_basic_info_data_t host_info;
|
host_basic_info_data_t host_info;
|
||||||
|
vm_statistics64_data_t vm_stats;
|
||||||
processor_cpu_load_info_t prev_load;
|
processor_cpu_load_info_t prev_load;
|
||||||
processor_cpu_load_info_t curr_load;
|
processor_cpu_load_info_t curr_load;
|
||||||
|
uint64_t kernel_threads;
|
||||||
|
uint64_t user_threads;
|
||||||
} DarwinProcessList;
|
} DarwinProcessList;
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,6 +31,8 @@ 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_statistics64_t p);
|
||||||
|
|
||||||
struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count);
|
struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count);
|
||||||
|
|
||||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
|
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
|
||||||
|
|
|
@ -62,7 +62,6 @@ MeterClass* Platform_meterTypes[] = {
|
||||||
&LoadAverageMeter_class,
|
&LoadAverageMeter_class,
|
||||||
&LoadMeter_class,
|
&LoadMeter_class,
|
||||||
&MemoryMeter_class,
|
&MemoryMeter_class,
|
||||||
&SwapMeter_class,
|
|
||||||
&TasksMeter_class,
|
&TasksMeter_class,
|
||||||
&BatteryMeter_class,
|
&BatteryMeter_class,
|
||||||
&HostnameMeter_class,
|
&HostnameMeter_class,
|
||||||
|
@ -86,7 +85,17 @@ char* Process_pidFormat = "%7u ";
|
||||||
char* Process_tpgidFormat = "%7u ";
|
char* Process_tpgidFormat = "%7u ";
|
||||||
|
|
||||||
int Platform_getUptime() {
|
int Platform_getUptime() {
|
||||||
return 0;
|
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);
|
||||||
|
|
||||||
|
return (int) difftime(currTime.tv_sec, bootTime.tv_sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
|
void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
|
||||||
|
@ -163,7 +172,16 @@ double Platform_setCPUValues(Meter* mtr, int cpu) {
|
||||||
return MIN(100.0, MAX(0.0, total));
|
return MIN(100.0, MAX(0.0, total));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform_setMemoryValues(Meter* this) {
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform_setSwapValues(Meter* this) {
|
void Platform_setSwapValues(Meter* this) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ void Process_setupColumnWidths();
|
||||||
|
|
||||||
double Platform_setCPUValues(Meter* mtr, int cpu);
|
double Platform_setCPUValues(Meter* mtr, int cpu);
|
||||||
|
|
||||||
void Platform_setMemoryValues(Meter* this);
|
void Platform_setMemoryValues(Meter* mtr);
|
||||||
|
|
||||||
void Platform_setSwapValues(Meter* this);
|
void Platform_setSwapValues(Meter* this);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue