diff options
| author | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-26 13:17:55 -0500 |
|---|---|---|
| committer | Jan Trencansky <jan.trencansky@protonmail.com> | 2026-11-26 13:17:55 -0500 |
| commit | bbf861fbb4ea51ca18cd6f372797111984b6f8aa (patch) | |
| tree | 81ac99a1a6d61841cca3562fab529cf38348c73f /runtime/src/thread_stacks.cpp | |
| parent | 4645a3f62a7655ce69b930da70bdc1a858d1d0a1 (diff) | |
| parent | bdbc7e9236465c5d6a1305de6edd3fc09c2d6fd9 (diff) | |
Merge main into fix/depth16-quantise-fallback
runtime/CMakeLists.txt: main added the heavy_pipeline_cache, pipeline_cache_journal and compile_helper tests where this branch adds depth24_fragment; both sides are kept.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/thread_stacks.cpp')
| -rw-r--r-- | runtime/src/thread_stacks.cpp | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/runtime/src/thread_stacks.cpp b/runtime/src/thread_stacks.cpp index 67188d908..38d7cc2a4 100644 --- a/runtime/src/thread_stacks.cpp +++ b/runtime/src/thread_stacks.cpp | |||
| @@ -121,10 +121,10 @@ struct ThreadTrace { | |||
| 121 | size_t count = 0; | 121 | size_t count = 0; |
| 122 | }; | 122 | }; |
| 123 | 123 | ||
| 124 | void print_traces(unsigned at, const std::vector<ThreadTrace>& traces) { | 124 | void print_traces(const std::string& tag, const std::vector<ThreadTrace>& traces) { |
| 125 | std::string out = "[rt] stacks t=" + std::to_string(at) + ": " + std::to_string(traces.size()) + " threads\n"; | 125 | std::string out = "[rt] stacks " + tag + ": " + std::to_string(traces.size()) + " threads\n"; |
| 126 | for (auto it = traces.begin(); it != traces.end(); ++it) { | 126 | for (auto it = traces.begin(); it != traces.end(); ++it) { |
| 127 | out += "[rt] stacks t=" + std::to_string(at) + " thread " + std::to_string(it->tid) + " (" + it->label + "):\n"; | 127 | out += "[rt] stacks " + tag + " thread " + std::to_string(it->tid) + " (" + it->label + "):\n"; |
| 128 | const auto same = std::find_if(traces.begin(), it, [&](const ThreadTrace& earlier) { | 128 | const auto same = std::find_if(traces.begin(), it, [&](const ThreadTrace& earlier) { |
| 129 | return it->count && it->count == earlier.count && | 129 | return it->count && it->count == earlier.count && |
| 130 | std::equal(it->frames.begin(), it->frames.begin() + it->count, earlier.frames.begin()); | 130 | std::equal(it->frames.begin(), it->frames.begin() + it->count, earlier.frames.begin()); |
| @@ -142,10 +142,11 @@ void print_traces(unsigned at, const std::vector<ThreadTrace>& traces) { | |||
| 142 | std::fflush(stderr); | 142 | std::fflush(stderr); |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | void snapshot_threads(unsigned at, StackSampler& sampler, GetDescription describe, QueryThread query) { | 145 | void snapshot_threads(const std::string& tag, StackSampler& sampler, GetDescription describe, QueryThread query, |
| 146 | DWORD only = 0) { | ||
| 146 | const HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); | 147 | const HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); |
| 147 | if (snapshot == INVALID_HANDLE_VALUE) { | 148 | if (snapshot == INVALID_HANDLE_VALUE) { |
| 148 | std::fprintf(stderr, "[rt] stacks t=%u: thread list failed (error %lu)\n", at, GetLastError()); | 149 | std::fprintf(stderr, "[rt] stacks %s: thread list failed (error %lu)\n", tag.c_str(), GetLastError()); |
| 149 | return; | 150 | return; |
| 150 | } | 151 | } |
| 151 | std::vector<ThreadTrace> traces; | 152 | std::vector<ThreadTrace> traces; |
| @@ -157,6 +158,7 @@ void snapshot_threads(unsigned at, StackSampler& sampler, GetDescription describ | |||
| 157 | for (BOOL ok = Thread32First(snapshot, &entry); ok; ok = Thread32Next(snapshot, &entry)) { | 158 | for (BOOL ok = Thread32First(snapshot, &entry); ok; ok = Thread32Next(snapshot, &entry)) { |
| 158 | entry.dwSize = sizeof(entry); | 159 | entry.dwSize = sizeof(entry); |
| 159 | if (entry.th32OwnerProcessID != pid || entry.th32ThreadID == self) continue; | 160 | if (entry.th32OwnerProcessID != pid || entry.th32ThreadID == self) continue; |
| 161 | if (only && entry.th32ThreadID != only) continue; | ||
| 160 | const HANDLE thread = OpenThread(THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION, | 162 | const HANDLE thread = OpenThread(THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION, |
| 161 | FALSE, entry.th32ThreadID); | 163 | FALSE, entry.th32ThreadID); |
| 162 | if (!thread) continue; | 164 | if (!thread) continue; |
| @@ -169,7 +171,7 @@ void snapshot_threads(unsigned at, StackSampler& sampler, GetDescription describ | |||
| 169 | CloseHandle(thread); | 171 | CloseHandle(thread); |
| 170 | } | 172 | } |
| 171 | CloseHandle(snapshot); | 173 | CloseHandle(snapshot); |
| 172 | print_traces(at, traces); | 174 | print_traces(tag, traces); |
| 173 | } | 175 | } |
| 174 | 176 | ||
| 175 | } // namespace | 177 | } // namespace |
| @@ -207,6 +209,20 @@ bool parse_stack_times(std::string_view text, std::vector<unsigned>& seconds) { | |||
| 207 | return true; | 209 | return true; |
| 208 | } | 210 | } |
| 209 | 211 | ||
| 212 | void print_thread_stacks_now(std::uint32_t tid, const char* why) noexcept { | ||
| 213 | static std::mutex mutex; | ||
| 214 | try { | ||
| 215 | std::lock_guard lock(mutex); | ||
| 216 | static StackSampler sampler; | ||
| 217 | const auto describe = reinterpret_cast<GetDescription>(reinterpret_cast<void*>( | ||
| 218 | GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "GetThreadDescription"))); | ||
| 219 | const auto query = reinterpret_cast<QueryThread>(reinterpret_cast<void*>( | ||
| 220 | GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "NtQueryInformationThread"))); | ||
| 221 | snapshot_threads(why ? why : "now", sampler, describe, query, tid); | ||
| 222 | } catch (...) { | ||
| 223 | } | ||
| 224 | } | ||
| 225 | |||
| 210 | std::jthread start_thread_stacks() { | 226 | std::jthread start_thread_stacks() { |
| 211 | const auto start = Clock::now(); | 227 | const auto start = Clock::now(); |
| 212 | char spec[1024]; | 228 | char spec[1024]; |
| @@ -229,7 +245,7 @@ std::jthread start_thread_stacks() { | |||
| 229 | for (const unsigned at : times) { | 245 | for (const unsigned at : times) { |
| 230 | wake.wait_until(lock, stop, start + std::chrono::seconds(at), [] { return false; }); | 246 | wake.wait_until(lock, stop, start + std::chrono::seconds(at), [] { return false; }); |
| 231 | if (stop.stop_requested()) break; | 247 | if (stop.stop_requested()) break; |
| 232 | snapshot_threads(at, sampler, describe, query); | 248 | snapshot_threads("t=" + std::to_string(at), sampler, describe, query); |
| 233 | } | 249 | } |
| 234 | }); | 250 | }); |
| 235 | } | 251 | } |