Skip to content

Commit

Permalink
linux: support for monitoring syscall
Browse files Browse the repository at this point in the history
Signed-off-by: John Sanpe <[email protected]>
  • Loading branch information
sanpeqf committed May 30, 2024
1 parent 58efa4e commit 873ad44
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
14 changes: 14 additions & 0 deletions linux/LinuxProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
#endif
[GPU_TIME] = { .name = "GPU_TIME", .title = "GPU_TIME ", .description = "Total GPU time", .flags = PROCESS_FLAG_LINUX_GPU, .defaultSortDesc = true, },
[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, },
[SYSCALL] = { .name = "SYSCALL", .title = "SYSCALL", .description = "Current syscall of the process", .flags = PROCESS_FLAG_LINUX_SYSCALL, .autoWidth = true, },
};

Process* LinuxProcess_new(const Machine* host) {
Expand Down Expand Up @@ -362,6 +363,17 @@ static void LinuxProcess_rowWriteField(const Row* super, RichString* str, Proces
xSnprintf(buffer, n, "N/A ");
}
break;
case SYSCALL: {
const char* syscall;
if (lp->syscall) {
syscall = lp->syscall;
} else {
attr = CRT_colors[PROCESS_SHADOW];
syscall = "N/A";
}
Row_printLeftAlignedField(str, attr, syscall, 8);
return;
}
default:
Process_writeField(this, str, field);
return;
Expand Down Expand Up @@ -466,6 +478,8 @@ static int LinuxProcess_compareByKey(const Process* v1, const Process* v2, Proce
return SPACESHIP_NUMBER(p1->gpu_time, p2->gpu_time);
case ISCONTAINER:
return SPACESHIP_NUMBER(v1->isRunningInContainer, v2->isRunningInContainer);
case SYSCALL:
return SPACESHIP_NULLSTR(p1->syscall, p2->syscall);
default:
return Process_compareByKey_Base(v1, v2, key);
}
Expand Down
3 changes: 3 additions & 0 deletions linux/LinuxProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ in the source distribution for its full text.
#define PROCESS_FLAG_LINUX_AUTOGROUP 0x00080000
#define PROCESS_FLAG_LINUX_GPU 0x00100000
#define PROCESS_FLAG_LINUX_CONTAINER 0x00200000
#define PROCESS_FLAG_LINUX_SYSCALL 0x00400000

typedef struct LinuxProcess_ {
Process super;
Expand Down Expand Up @@ -118,6 +119,8 @@ typedef struct LinuxProcess_ {
/* Autogroup scheduling (CFS) information */
long int autogroup_id;
int autogroup_nice;

char *syscall;
} LinuxProcess;

extern int pageSize;
Expand Down
31 changes: 31 additions & 0 deletions linux/LinuxProcessTable.c
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,33 @@ static void LinuxProcessTable_readCwd(LinuxProcess* process, openat_arg_t procFd
free_and_xStrdup(&process->super.procCwd, pathBuffer);
}

/*
* Read /proc/<pid>/syscall (process-shared data)
*/
static void LinuxProcessTable_readSyscall(LinuxProcess* process, openat_arg_t procFd) {
char buffer[PATH_MAX];
ssize_t r;

r = xReadfileat(procFd, "syscall", buffer, sizeof(buffer));
if (r <= 0) {
free(process->syscall);
process->syscall = NULL;
return;
}

buffer[r - 1] = '\0';

char* arg = strchr(buffer, ' ');
if (arg) {
*arg = '\0';
}

if (process->syscall && String_eq(buffer, process->syscall))
return;

free_and_xStrdup(&process->syscall, buffer);
}

/*
* Read /proc/<pid>/exe (process-shared data)
*/
Expand Down Expand Up @@ -1694,6 +1721,10 @@ static bool LinuxProcessTable_recurseProcTree(LinuxProcessTable* this, openat_ar
LinuxProcessTable_readCwd(lp, procFd, mainTask);
}

if (ss->flags & PROCESS_FLAG_LINUX_SYSCALL) {
LinuxProcessTable_readSyscall(lp, procFd);
}

if ((ss->flags & PROCESS_FLAG_LINUX_AUTOGROUP) && this->haveAutogroup) {
LinuxProcessTable_readAutogroup(lp, procFd, mainTask);
}
Expand Down
1 change: 1 addition & 0 deletions linux/ProcessField.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ in the source distribution for its full text.
GPU_TIME = 132, \
GPU_PERCENT = 133, \
ISCONTAINER = 134, \
SYSCALL = 135, \
// End of list


Expand Down

0 comments on commit 873ad44

Please sign in to comment.