Skip to content

Commit 0bee3dc

Browse files
committed
kernel: much cleaner STRACE output
1 parent a17538c commit 0bee3dc

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/kernel/kernel.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,22 +1798,25 @@ export class Kernel implements IKernel {
17981798
doSyscall(syscall: Syscall): void {
17991799
if (syscall.name in this.syscalls) {
18001800
if (STRACE) {
1801-
let argfmt = (arg: any): any => {
1802-
if (arg instanceof Uint8Array) {
1801+
let argfmt = (arg: any): string => {
1802+
if (arg.constructor === Uint8Array) {
18031803
let len = arg.length;
18041804
if (len > 0 && arg[len - 1] === 0)
18051805
len--;
1806-
return utf8Slice(arg, 0, len);
1806+
return '(' + len + ') ' + utf8Slice(arg, 0, len > 32 ? 32 : len);
1807+
} else if (typeof arg === 'string' && arg.length > 32) {
1808+
return arg.slice(0, 32);
18071809
} else {
1808-
return arg;
1810+
return '' + arg;
18091811
}
18101812
};
18111813

18121814
if (syscall.args === undefined)
18131815
syscall.args = [undefined];
18141816
let arg = argfmt(syscall.args[0]);
1815-
if (syscall.args[1])
1817+
if (syscall.args[1]) {
18161818
arg += '\t' + argfmt(syscall.args[1]);
1819+
}
18171820
console.log('[' + syscall.ctx.task.pid + '|' + syscall.ctx.id + '] \tsys_' + syscall.name + '\t' + arg);
18181821
}
18191822
this.syscalls[syscall.name].apply(this.syscalls, syscall.callArgs());
@@ -2351,8 +2354,16 @@ export class Task implements ITask {
23512354

23522355
this.state = TaskState.Running;
23532356

2354-
if (STRACE)
2355-
console.log('[' + this.pid + '|' + msg.id + '] \tCOMPLETE'); // ' + JSON.stringify(msg));
2357+
if (STRACE) {
2358+
let add = ' ';
2359+
if (msg.args && msg.args.length > 1) {
2360+
if (msg.args[1].constructor !== Uint8Array)
2361+
add += msg.args[1];
2362+
else
2363+
add += msg.args[1].byteLength;
2364+
}
2365+
console.log('[' + this.pid + '|' + msg.id + '] \tDONE' + add); // ' + JSON.stringify(msg));
2366+
}
23562367
this.worker.postMessage(msg, transferrable || []);
23572368
}
23582369

0 commit comments

Comments
 (0)