|
8 | 8 |
|
9 | 9 | #include "vm/os_thread.h" |
10 | 10 |
|
11 | | -#include <errno.h> // NOLINT |
| 11 | +#include <errno.h> |
| 12 | +#include <fcntl.h> |
12 | 13 | #include <stdio.h> |
13 | | -#include <sys/resource.h> // NOLINT |
14 | | -#include <sys/syscall.h> // NOLINT |
15 | | -#include <sys/time.h> // NOLINT |
| 14 | +#include <sys/resource.h> |
| 15 | +#include <sys/syscall.h> |
| 16 | +#include <sys/time.h> |
16 | 17 |
|
17 | 18 | #include "platform/address_sanitizer.h" |
18 | 19 | #include "platform/assert.h" |
@@ -114,6 +115,39 @@ int OSThread::TryStart(const char* name, |
114 | 115 |
|
115 | 116 | pthread_t tid; |
116 | 117 | result = pthread_create(&tid, &attr, ThreadStart, data); |
| 118 | + if (result != 0) { |
| 119 | + fprintf(stderr, "pthread_create failed\n"); |
| 120 | + const char* const kPaths[] = { |
| 121 | + "/proc/self/limits", |
| 122 | + "/proc/sys/kernel/threads-max", |
| 123 | + "/proc/sys/kernel/pid_max", |
| 124 | + "/sys/fs/cgroup/user.slice/memory.current", |
| 125 | + "/sys/fs/cgroup/user.slice/memory.max", |
| 126 | + "/sys/fs/cgroup/user.slice/memory.peak", |
| 127 | + "/sys/fs/cgroup/user.slice/pids.current", |
| 128 | + "/sys/fs/cgroup/user.slice/pids.max", |
| 129 | + "/sys/fs/cgroup/user.slice/pids.peak", |
| 130 | + }; |
| 131 | + for (uintptr_t i = 0; i < ARRAY_SIZE(kPaths); i++) { |
| 132 | + const char* path = kPaths[i]; |
| 133 | + |
| 134 | + int fd = open(path, O_RDONLY | O_CLOEXEC); |
| 135 | + if (fd < 0) { |
| 136 | + fprintf(stderr, "%s: Failed to open\n", path); |
| 137 | + continue; |
| 138 | + } |
| 139 | + const intptr_t kBufferSize = 2048; |
| 140 | + char buffer[kBufferSize]; |
| 141 | + memset(buffer, 0, kBufferSize); |
| 142 | + ssize_t red = read(fd, buffer, kBufferSize - 1); |
| 143 | + close(fd); |
| 144 | + if (red < 0) { |
| 145 | + fprintf(stderr, "%s: Failed to read\n", path); |
| 146 | + continue; |
| 147 | + } |
| 148 | + fprintf(stderr, "%s: %s\n", path, buffer); |
| 149 | + } |
| 150 | + } |
117 | 151 | RETURN_ON_PTHREAD_FAILURE(result); |
118 | 152 |
|
119 | 153 | result = pthread_attr_destroy(&attr); |
|
0 commit comments