Add i/o statistics to wait4() about child process

This commit is contained in:
Justine Tunney 2023-08-21 21:25:33 -07:00
parent b9eb656e41
commit 58ef4e6df8
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
6 changed files with 39 additions and 8 deletions

View file

@ -16,19 +16,17 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/sig.internal.h"
#include "libc/calls/state.internal.h"
#include "libc/calls/struct/rusage.h"
#include "libc/calls/struct/rusage.internal.h"
#include "libc/calls/syscall_support-nt.internal.h"
#include "libc/fmt/conv.h"
#include "libc/nt/accounting.h"
#include "libc/nt/process.h"
#include "libc/nt/runtime.h"
#include "libc/nt/struct/filetime.h"
#include "libc/nt/struct/iocounters.h"
#include "libc/nt/struct/processmemorycounters.h"
#include "libc/nt/thread.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/rusage.h"
#include "libc/sysv/errfuns.h"

View file

@ -35,6 +35,7 @@
#include "libc/nt/process.h"
#include "libc/nt/runtime.h"
#include "libc/nt/struct/filetime.h"
#include "libc/nt/struct/iocounters.h"
#include "libc/nt/struct/processentry32.h"
#include "libc/nt/struct/processmemorycounters.h"
#include "libc/nt/synchronization.h"
@ -68,6 +69,13 @@ static textwindows void AddProcessStats(int64_t h, struct rusage *ru) {
} else {
STRACE("%s failed %u", "GetProcessTimes", GetLastError());
}
struct NtIoCounters iocount;
if (GetProcessIoCounters(h, &iocount)) {
ru->ru_inblock += iocount.ReadOperationCount;
ru->ru_oublock += iocount.WriteOperationCount;
} else {
STRACE("%s failed %u", "GetProcessIoCounters", GetLastError());
}
}
static textwindows int sys_wait4_nt_impl(int *pid, int *opt_out_wstatus,

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/fmt.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**
@ -38,7 +39,11 @@ int fscanf(FILE *stream, const char *fmt, ...) {
int rc;
va_list va;
va_start(va, fmt);
rc = __vcscanf((int (*)(void *))fgetc, (void *)ungetc, stream, fmt, va);
flockfile(stream);
rc = __vcscanf((void *)fgetc_unlocked, //
(void *)ungetc_unlocked, //
stream, fmt, va);
funlockfile(stream);
va_end(va);
return rc;
}

View file

@ -16,7 +16,9 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/struct/fd.internal.h"
#include "libc/fmt/fmt.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**
@ -27,7 +29,11 @@ int scanf(const char *fmt, ...) {
int rc;
va_list va;
va_start(va, fmt);
rc = __vcscanf((int (*)(void *))fgetc, NULL, stdin, fmt, va);
flockfile(stdin);
rc = __vcscanf((void *)fgetc_unlocked, //
(void *)ungetc_unlocked, //
stdin, fmt, va);
funlockfile(stdin);
va_end(va);
return rc;
}

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/fmt.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**
@ -24,5 +25,11 @@
* @see libc/fmt/vcscanf.h
*/
int vfscanf(FILE *stream, const char *fmt, va_list ap) {
return __vcscanf((void *)fgetc, (void *)ungetc, stream, fmt, ap);
int rc;
flockfile(stream);
rc = __vcscanf((void *)fgetc_unlocked, //
(void *)ungetc_unlocked, //
stream, fmt, ap);
funlockfile(stream);
return rc;
}

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/fmt.h"
#include "libc/stdio/lock.internal.h"
#include "libc/stdio/stdio.h"
/**
@ -24,5 +25,11 @@
* @see libc/fmt/vcscanf.h
*/
int vscanf(const char *fmt, va_list ap) {
return __vcscanf((int (*)(void *))fgetc, (void *)ungetc, stdin, fmt, ap);
int rc;
flockfile(stdin);
rc = __vcscanf((void *)fgetc_unlocked, //
(void *)ungetc_unlocked, //
stdin, fmt, ap);
flockfile(stdout);
return rc;
}