summaryrefslogtreecommitdiffstats
path: root/darwin
diff options
context:
space:
mode:
authorDániel Bakai <bakaidl@gmail.com>2020-12-13 15:54:13 +0100
committerBenBE <BenBE@geshi.org>2020-12-13 17:58:16 +0100
commit3655b6ca0b1b89a2d6415211c1ce484dd6afe39f (patch)
tree1db4c8b1ae468aa3f2a6d3fb1c6ddfc4501cdd41 /darwin
parent1506283affdb024106df283fb4dbc0253470f1c9 (diff)
Add column in darwin to indicate whether the the process is running under translation
Diffstat (limited to 'darwin')
-rw-r--r--darwin/DarwinProcess.c64
-rw-r--r--darwin/DarwinProcess.h6
-rw-r--r--darwin/DarwinProcessList.c2
-rw-r--r--darwin/Platform.c2
4 files changed, 61 insertions, 13 deletions
diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c
index b32f3669..0c20bc61 100644
--- a/darwin/DarwinProcess.c
+++ b/darwin/DarwinProcess.c
@@ -17,16 +17,6 @@ in the source distribution for its full text.
#include "Process.h"
-const ProcessClass DarwinProcess_class = {
- .super = {
- .extends = Class(Process),
- .display = Process_display,
- .delete = Process_delete,
- .compare = Process_compare
- },
- .writeField = Process_writeField,
-};
-
ProcessFieldData Process_fields[] = {
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
[PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, },
@@ -53,7 +43,8 @@ ProcessFieldData Process_fields[] = {
[TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, },
[NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, },
[TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, },
- [100] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
+ [TRANSLATED] = { .name = "TRANSLATED", .title = "T ", .description = "Translation info (T translated, N native)", .flags = 0, },
+ [LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
};
Process* DarwinProcess_new(const Settings* settings) {
@@ -64,6 +55,7 @@ Process* DarwinProcess_new(const Settings* settings) {
this->utime = 0;
this->stime = 0;
this->taskAccess = true;
+ this->translated = false;
return &this->super;
}
@@ -75,6 +67,42 @@ void Process_delete(Object* cast) {
free(this);
}
+static void DarwinProcess_writeField(const Process* this, RichString* str, ProcessField field) {
+ const DarwinProcess* dp = (const DarwinProcess*) this;
+ char buffer[256]; buffer[255] = '\0';
+ int attr = CRT_colors[DEFAULT_COLOR];
+ int n = sizeof(buffer) - 1;
+ switch ((int) field) {
+ // add Platform-specific fields here
+ case TRANSLATED: xSnprintf(buffer, n, "%c ", dp->translated ? 'T' : 'N'); break;
+ default:
+ Process_writeField(this, str, field);
+ return;
+ }
+ RichString_appendWide(str, attr, buffer);
+}
+
+static long DarwinProcess_compare(const void* v1, const void* v2) {
+ const DarwinProcess *p1, *p2;
+ const Settings *settings = ((const Process*)v1)->settings;
+
+ if (settings->direction == 1) {
+ p1 = (const DarwinProcess*)v1;
+ p2 = (const DarwinProcess*)v2;
+ } else {
+ p2 = (const DarwinProcess*)v1;
+ p1 = (const DarwinProcess*)v2;
+ }
+
+ switch ((int) settings->sortKey) {
+ // add Platform-specific fields here
+ case TRANSLATED:
+ return SPACESHIP_NUMBER(p1->translated, p2->translated);
+ default:
+ return Process_compare(v1, v2);
+ }
+}
+
bool Process_isThread(const Process* this) {
(void) this;
return false;
@@ -224,6 +252,8 @@ ERROR_A:
}
void DarwinProcess_setFromKInfoProc(Process* proc, const struct kinfo_proc* ps, bool exists) {
+ DarwinProcess* dp = (DarwinProcess*)proc;
+
const struct extern_proc* ep = &ps->kp_proc;
/* UNSET HERE :
@@ -252,6 +282,7 @@ void DarwinProcess_setFromKInfoProc(Process* proc, const struct kinfo_proc* ps,
/* e_tdev = (major << 24) | (minor & 0xffffff) */
/* e_tdev == -1 for "no device" */
proc->tty_nr = ps->kp_eproc.e_tdev & 0xff; /* TODO tty_nr is unsigned */
+ dp->translated = ps->kp_proc.p_flag & P_TRANSLATED;
proc->starttime_ctime = ep->p_starttime.tv_sec;
Process_fillStarttimeBuffer(proc);
@@ -370,3 +401,14 @@ void DarwinProcess_scanThreads(DarwinProcess* dp) {
}
proc->state = state;
}
+
+
+const ProcessClass DarwinProcess_class = {
+ .super = {
+ .extends = Class(Process),
+ .display = Process_display,
+ .delete = Process_delete,
+ .compare = DarwinProcess_compare
+ },
+ .writeField = DarwinProcess_writeField,
+};
diff --git a/darwin/DarwinProcess.h b/darwin/DarwinProcess.h
index ed9562af..33dbcd14 100644
--- a/darwin/DarwinProcess.h
+++ b/darwin/DarwinProcess.h
@@ -12,6 +12,11 @@ in the source distribution for its full text.
#include "DarwinProcessList.h"
#include "Settings.h"
+typedef enum DarwinProcessFields_ {
+ // Add platform-specific fields here, with ids >= 100
+ TRANSLATED = 100,
+ LAST_PROCESSFIELD = 101,
+} DarwinProcessField;
typedef struct DarwinProcess_ {
Process super;
@@ -19,6 +24,7 @@ typedef struct DarwinProcess_ {
uint64_t utime;
uint64_t stime;
bool taskAccess;
+ bool translated;
} DarwinProcess;
extern const ProcessClass DarwinProcess_class;
diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c
index ae1efb15..dec98270 100644
--- a/darwin/DarwinProcessList.c
+++ b/darwin/DarwinProcessList.c
@@ -131,7 +131,7 @@ static struct kinfo_proc* ProcessList_getKInfoProcs(size_t* count) {
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) {
DarwinProcessList* this = xCalloc(1, sizeof(DarwinProcessList));
- ProcessList_init(&this->super, Class(Process), usersTable, pidMatchList, userId);
+ ProcessList_init(&this->super, Class(DarwinProcess), usersTable, pidMatchList, userId);
/* Initialize the CPU information */
this->super.cpuCount = ProcessList_allocateCPULoadInfo(&this->prev_load);
diff --git a/darwin/Platform.c b/darwin/Platform.c
index 5cfaee70..672c1ad0 100644
--- a/darwin/Platform.c
+++ b/darwin/Platform.c
@@ -102,7 +102,7 @@ const MeterClass* const Platform_meterTypes[] = {
NULL
};
-int Platform_numberOfFields = 100;
+int Platform_numberOfFields = LAST_PROCESSFIELD;
void Platform_init(void) {
/* no platform-specific setup needed */

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