Skip to content

Commit 1eb2aee

Browse files
committed
darwin: fix process state visualization in DarwinProcessTable
1 parent 658926e commit 1eb2aee

2 files changed

Lines changed: 18 additions & 24 deletions

File tree

darwin/DarwinProcess.c

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -404,22 +404,6 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess* proc, DarwinProcessTable
404404
}
405405
}
406406

407-
static ProcessState stateToChar(int run_state) {
408-
switch (run_state) {
409-
case TH_STATE_RUNNING:
410-
return RUNNING;
411-
case TH_STATE_STOPPED:
412-
return STOPPED;
413-
case TH_STATE_WAITING:
414-
return WAITING;
415-
case TH_STATE_UNINTERRUPTIBLE:
416-
return UNINTERRUPTIBLE_WAIT;
417-
case TH_STATE_HALTED:
418-
return BLOCKED;
419-
}
420-
return UNKNOWN;
421-
}
422-
423407
/*
424408
* Scan threads for process state information.
425409
* Based on: http://stackoverflow.com/questions/6788274/ios-mac-cpu-usage-for-thread
@@ -473,7 +457,6 @@ void DarwinProcess_scanThreads(DarwinProcess* dp, DarwinProcessTable* dpt) {
473457

474458
const bool hideUserlandThreads = dpt->super.super.host->settings->hideUserlandThreads;
475459

476-
integer_t run_state = 999;
477460
for (mach_msg_type_number_t i = 0; i < thread_count; i++) {
478461

479462
thread_identifier_info_data_t identifer_info;
@@ -517,16 +500,12 @@ void DarwinProcess_scanThreads(DarwinProcess* dp, DarwinProcessTable* dpt) {
517500
}
518501

519502
DarwinProcess* tdproc = (DarwinProcess*)tprocess;
520-
tdproc->super.state = stateToChar(extended_info.pth_run_state);
521503
tdproc->super.percent_cpu = extended_info.pth_cpu_usage / 10.0;
522504
tdproc->stime = extended_info.pth_system_time;
523505
tdproc->utime = extended_info.pth_user_time;
524506
tdproc->super.time = (extended_info.pth_system_time + extended_info.pth_user_time) / 10000000;
525507
tdproc->super.priority = extended_info.pth_curpri;
526508

527-
if (extended_info.pth_run_state < run_state)
528-
run_state = extended_info.pth_run_state;
529-
530509
// TODO: depend on setting
531510
const char* name = extended_info.pth_name[0] != '\0' ? extended_info.pth_name : proc->procComm;
532511
Process_updateCmdline(tprocess, name, 0, strlen(name));
@@ -537,9 +516,6 @@ void DarwinProcess_scanThreads(DarwinProcess* dp, DarwinProcessTable* dpt) {
537516

538517
vm_deallocate(mach_task_self(), (vm_address_t) thread_list, sizeof(thread_port_array_t) * thread_count);
539518
mach_port_deallocate(mach_task_self(), task);
540-
541-
if (run_state != 999)
542-
proc->state = stateToChar(run_state);
543519
}
544520

545521

darwin/DarwinProcessTable.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ in the source distribution for its full text.
2828
#include "zfs/ZfsArcStats.h"
2929

3030

31+
static ProcessState ProcessTable_mapDarwinProcessState(int kinfo_proc_state) {
32+
switch(kinfo_proc_state) {
33+
case SRUN:
34+
return RUNNING;
35+
case SSLEEP:
36+
return SLEEPING;
37+
case SSTOP:
38+
return STOPPED;
39+
case SZOMB:
40+
return ZOMBIE;
41+
case SIDL:
42+
return IDLE;
43+
default:
44+
return UNKNOWN;
45+
}
46+
}
47+
3148
static struct kinfo_proc* ProcessTable_getKInfoProcs(size_t* count) {
3249
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 };
3350
struct kinfo_proc* processes = NULL;
@@ -107,6 +124,7 @@ void ProcessTable_goThroughEntries(ProcessTable* super) {
107124
proc->super.st_uid = ps[i].kp_eproc.e_ucred.cr_uid;
108125
proc->super.user = UsersTable_getRef(host->usersTable, proc->super.st_uid);
109126
}
127+
proc->super.state = ProcessTable_mapDarwinProcessState(ps[i].kp_proc.p_stat);
110128

111129
// Disabled for High Sierra due to bug in macOS High Sierra
112130
bool isScanThreadSupported = !Platform_KernelVersionIsBetween((KernelVersion) {17, 0, 0}, (KernelVersion) {17, 5, 0});

0 commit comments

Comments
 (0)