aboutsummaryrefslogtreecommitdiffstats
path: root/darwin/DarwinProcess.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2020-12-07 10:26:01 +0100
committerDaniel Lange <DLange@git.local>2020-12-07 10:26:01 +0100
commit65357c8c46154de4e4eca14075bfe5523bb5fc14 (patch)
tree8f430ee5a0d5de377c4e7c94e47842a27c70d7e8 /darwin/DarwinProcess.c
parentf80394a20254938142011855f2954b3f63fe5909 (diff)
downloaddebian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.tar.gz
debian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.tar.bz2
debian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.zip
New upstream version 3.0.3upstream/3.0.3
Diffstat (limited to 'darwin/DarwinProcess.c')
-rw-r--r--darwin/DarwinProcess.c73
1 files changed, 34 insertions, 39 deletions
diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c
index 430b2b4..f3c3425 100644
--- a/darwin/DarwinProcess.c
+++ b/darwin/DarwinProcess.c
@@ -1,22 +1,23 @@
/*
htop - DarwinProcess.c
(C) 2015 Hisham H. Muhammad
-Released under the GNU GPL, see the COPYING file
+Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text.
*/
-#include "Process.h"
#include "DarwinProcess.h"
-#include <stdlib.h>
#include <libproc.h>
-#include <string.h>
#include <stdio.h>
-
+#include <stdlib.h>
+#include <string.h>
#include <mach/mach.h>
+#include "CRT.h"
+#include "Process.h"
+
-ProcessClass DarwinProcess_class = {
+const ProcessClass DarwinProcess_class = {
.super = {
.extends = Class(Process),
.display = Process_display,
@@ -26,7 +27,7 @@ ProcessClass DarwinProcess_class = {
.writeField = Process_writeField,
};
-DarwinProcess* DarwinProcess_new(Settings* settings) {
+Process* DarwinProcess_new(const Settings* settings) {
DarwinProcess* this = xCalloc(1, sizeof(DarwinProcess));
Object_setClass(this, Class(DarwinProcess));
Process_init(&this->super, settings);
@@ -35,7 +36,7 @@ DarwinProcess* DarwinProcess_new(Settings* settings) {
this->stime = 0;
this->taskAccess = true;
- return this;
+ return &this->super;
}
void Process_delete(Object* cast) {
@@ -45,20 +46,12 @@ void Process_delete(Object* cast) {
free(this);
}
-bool Process_isThread(Process* this) {
+bool Process_isThread(const Process* this) {
(void) this;
return false;
}
-void DarwinProcess_setStartTime(Process *proc, struct extern_proc *ep, time_t now) {
- 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);
-}
-
-char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) {
+static char* DarwinProcess_getCmdLine(const 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;
@@ -74,7 +67,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;
}
@@ -164,12 +157,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;
+ }
+ }
}
/*
@@ -201,8 +194,8 @@ ERROR_A:
return retval;
}
-void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, time_t now, bool exists) {
- struct extern_proc *ep = &ps->kp_proc;
+void DarwinProcess_setFromKInfoProc(Process* proc, const struct kinfo_proc* ps, bool exists) {
+ const struct extern_proc* ep = &ps->kp_proc;
/* UNSET HERE :
*
@@ -211,14 +204,14 @@ void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, time_t
* nlwp
* percent_cpu
* percent_mem
- * m_size
+ * m_virt
* m_resident
* minflt
* majflt
*/
/* 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;
@@ -231,7 +224,9 @@ void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, time_t
/* 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);
+ proc->starttime_ctime = ep->p_starttime.tv_sec;
+ Process_fillStarttimeBuffer(proc);
+
proc->comm = DarwinProcess_getCmdLine(ps, &(proc->basenameOffset));
}
@@ -245,16 +240,16 @@ void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, time_t
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,11 +258,11 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList
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 / PAGE_SIZE_KB;
- proc->super.m_resident = pti.pti_resident_size / 1024 / PAGE_SIZE_KB;
+ proc->super.m_virt = pti.pti_virtual_size / CRT_pageSize;
+ 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;
@@ -284,7 +279,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;

© 2014-2024 Faster IT GmbH | imprint | privacy policy