Commit ac38daf5 authored by Hisham Muhammad's avatar Hisham Muhammad
Browse files

Darwin: reorganize process reading loop

parent 66909bf5
...@@ -60,11 +60,6 @@ void Process_delete(Object* cast) { ...@@ -60,11 +60,6 @@ void Process_delete(Object* cast) {
free(this); free(this);
} }
bool Process_isThread(Process* this) {
(void) this;
return false;
}
void DarwinProcess_setStartTime(Process *proc, struct extern_proc *ep, time_t now) { void DarwinProcess_setStartTime(Process *proc, struct extern_proc *ep, time_t now) {
struct tm date; struct tm date;
...@@ -361,3 +356,12 @@ void DarwinProcess_scanThreads(DarwinProcess *dp) { ...@@ -361,3 +356,12 @@ void DarwinProcess_scanThreads(DarwinProcess *dp) {
} }
proc->state = state; proc->state = state;
} }
bool Process_update(Process* proc, bool isNew, ProcessList* pl, ProcessScanData* psd) {
DarwinProcess_setFromKInfoProc(&proc->super, ps->kinfo, tv.tv_sec, preExisting);
DarwinProcess_setFromLibprocPidinfo(proc, dpl);
DarwinProcess_scanThreads(proc);
if(isNew) {
proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid);
}
}
...@@ -36,6 +36,11 @@ typedef struct DarwinProcessList_ { ...@@ -36,6 +36,11 @@ typedef struct DarwinProcessList_ {
uint64_t global_diff; uint64_t global_diff;
} DarwinProcessList; } DarwinProcessList;
typedef struct DarwinProcessScanData_ {
time_t nowSec;
struct kinfo_proc* kinfo;
} DarwinProcessScanData;
}*/ }*/
void ProcessList_getHostInfo(host_basic_info_data_t *p) { void ProcessList_getHostInfo(host_basic_info_data_t *p) {
...@@ -128,9 +133,8 @@ void ProcessList_delete(ProcessList* this) { ...@@ -128,9 +133,8 @@ void ProcessList_delete(ProcessList* this) {
void ProcessList_goThroughEntries(ProcessList* super) { void ProcessList_goThroughEntries(ProcessList* super) {
DarwinProcessList *dpl = (DarwinProcessList *)super; DarwinProcessList *dpl = (DarwinProcessList *)super;
DarwinProcess *proc;
struct timeval tv;
struct timeval tv;
gettimeofday(&tv, NULL); /* Start processing time */ gettimeofday(&tv, NULL); /* Start processing time */
/* Update the global data (CPU times and VM stats) */ /* Update the global data (CPU times and VM stats) */
...@@ -147,11 +151,8 @@ void ProcessList_goThroughEntries(ProcessList* super) { ...@@ -147,11 +151,8 @@ void ProcessList_goThroughEntries(ProcessList* super) {
} }
} }
/* Clear the thread counts */ DarwinProcessScanData psd;
super->kernelThreads = 0; psd.nowSec = tv.tv_sec;
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 :
* *
...@@ -160,27 +161,11 @@ void ProcessList_goThroughEntries(ProcessList* super) { ...@@ -160,27 +161,11 @@ void ProcessList_goThroughEntries(ProcessList* super) {
* *
* We attempt to fill-in additional information with libproc. * We attempt to fill-in additional information with libproc.
*/ */
size_t count; size_t count;
struct kinfo_proc* ps = ProcessList_getKInfoProcs(&count); struct kinfo_proc* ps = ProcessList_getKInfoProcs(&count);
for(size_t i = 0; i < count; ++i) { for(size_t i = 0; i < count; ++i) {
bool preExisting = true; psd.kinfo = ps[i];
proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, (Process_New)DarwinProcess_new); ProcessList_scanProcess(super, ps[i].kp_proc.p_pid, (ProcessScanData*) psd);
DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], tv.tv_sec, preExisting);
DarwinProcess_setFromLibprocPidinfo(proc, dpl);
DarwinProcess_scanThreads(proc);
super->totalTasks += 1;
if(!preExisting) {
proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid);
ProcessList_add(super, &proc->super);
}
} }
free(ps); free(ps);
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment