Skip to content

Commit 873ad44

Browse files
committed
linux: support for monitoring syscall
Signed-off-by: John Sanpe <sanpeqf@gmail.com>
1 parent 58efa4e commit 873ad44

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

linux/LinuxProcess.c

+14
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
112112
#endif
113113
[GPU_TIME] = { .name = "GPU_TIME", .title = "GPU_TIME ", .description = "Total GPU time", .flags = PROCESS_FLAG_LINUX_GPU, .defaultSortDesc = true, },
114114
[GPU_PERCENT] = { .name = "GPU_PERCENT", .title = " GPU% ", .description = "Percentage of the GPU time the process used in the last sampling", .flags = PROCESS_FLAG_LINUX_GPU, .defaultSortDesc = true, },
115+
[SYSCALL] = { .name = "SYSCALL", .title = "SYSCALL", .description = "Current syscall of the process", .flags = PROCESS_FLAG_LINUX_SYSCALL, .autoWidth = true, },
115116
};
116117

117118
Process* LinuxProcess_new(const Machine* host) {
@@ -362,6 +363,17 @@ static void LinuxProcess_rowWriteField(const Row* super, RichString* str, Proces
362363
xSnprintf(buffer, n, "N/A ");
363364
}
364365
break;
366+
case SYSCALL: {
367+
const char* syscall;
368+
if (lp->syscall) {
369+
syscall = lp->syscall;
370+
} else {
371+
attr = CRT_colors[PROCESS_SHADOW];
372+
syscall = "N/A";
373+
}
374+
Row_printLeftAlignedField(str, attr, syscall, 8);
375+
return;
376+
}
365377
default:
366378
Process_writeField(this, str, field);
367379
return;
@@ -466,6 +478,8 @@ static int LinuxProcess_compareByKey(const Process* v1, const Process* v2, Proce
466478
return SPACESHIP_NUMBER(p1->gpu_time, p2->gpu_time);
467479
case ISCONTAINER:
468480
return SPACESHIP_NUMBER(v1->isRunningInContainer, v2->isRunningInContainer);
481+
case SYSCALL:
482+
return SPACESHIP_NULLSTR(p1->syscall, p2->syscall);
469483
default:
470484
return Process_compareByKey_Base(v1, v2, key);
471485
}

linux/LinuxProcess.h

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ in the source distribution for its full text.
3131
#define PROCESS_FLAG_LINUX_AUTOGROUP 0x00080000
3232
#define PROCESS_FLAG_LINUX_GPU 0x00100000
3333
#define PROCESS_FLAG_LINUX_CONTAINER 0x00200000
34+
#define PROCESS_FLAG_LINUX_SYSCALL 0x00400000
3435

3536
typedef struct LinuxProcess_ {
3637
Process super;
@@ -118,6 +119,8 @@ typedef struct LinuxProcess_ {
118119
/* Autogroup scheduling (CFS) information */
119120
long int autogroup_id;
120121
int autogroup_nice;
122+
123+
char *syscall;
121124
} LinuxProcess;
122125

123126
extern int pageSize;

linux/LinuxProcessTable.c

+31
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,33 @@ static void LinuxProcessTable_readCwd(LinuxProcess* process, openat_arg_t procFd
10981098
free_and_xStrdup(&process->super.procCwd, pathBuffer);
10991099
}
11001100

1101+
/*
1102+
* Read /proc/<pid>/syscall (process-shared data)
1103+
*/
1104+
static void LinuxProcessTable_readSyscall(LinuxProcess* process, openat_arg_t procFd) {
1105+
char buffer[PATH_MAX];
1106+
ssize_t r;
1107+
1108+
r = xReadfileat(procFd, "syscall", buffer, sizeof(buffer));
1109+
if (r <= 0) {
1110+
free(process->syscall);
1111+
process->syscall = NULL;
1112+
return;
1113+
}
1114+
1115+
buffer[r - 1] = '\0';
1116+
1117+
char* arg = strchr(buffer, ' ');
1118+
if (arg) {
1119+
*arg = '\0';
1120+
}
1121+
1122+
if (process->syscall && String_eq(buffer, process->syscall))
1123+
return;
1124+
1125+
free_and_xStrdup(&process->syscall, buffer);
1126+
}
1127+
11011128
/*
11021129
* Read /proc/<pid>/exe (process-shared data)
11031130
*/
@@ -1694,6 +1721,10 @@ static bool LinuxProcessTable_recurseProcTree(LinuxProcessTable* this, openat_ar
16941721
LinuxProcessTable_readCwd(lp, procFd, mainTask);
16951722
}
16961723

1724+
if (ss->flags & PROCESS_FLAG_LINUX_SYSCALL) {
1725+
LinuxProcessTable_readSyscall(lp, procFd);
1726+
}
1727+
16971728
if ((ss->flags & PROCESS_FLAG_LINUX_AUTOGROUP) && this->haveAutogroup) {
16981729
LinuxProcessTable_readAutogroup(lp, procFd, mainTask);
16991730
}

linux/ProcessField.h

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ in the source distribution for its full text.
5151
GPU_TIME = 132, \
5252
GPU_PERCENT = 133, \
5353
ISCONTAINER = 134, \
54+
SYSCALL = 135, \
5455
// End of list
5556

5657

0 commit comments

Comments
 (0)