diff options
author | Mircea Trofin <mtrofin@google.com> | 2025-04-08 06:59:38 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-08 06:59:38 -0700 |
commit | b2dea4fd22b79fa27ef1ebd737401616095a7de6 (patch) | |
tree | f0d23614c227e1c144b676b397b1fd5b8771e400 /clang/lib/Frontend/CreateInvocationFromCommandLine.cpp | |
parent | f19c6f23abefac56fde9f2b393c9ffa7595c86c6 (diff) | |
download | llvm-b2dea4fd22b79fa27ef1ebd737401616095a7de6.zip llvm-b2dea4fd22b79fa27ef1ebd737401616095a7de6.tar.gz llvm-b2dea4fd22b79fa27ef1ebd737401616095a7de6.tar.bz2 |
[ctxprof] root autodetection mechanism (#133147)
This is an optional mechanism that automatically detects roots. It's a best-effort mechanism, and its main goal is to *avoid* pointing at the message pump function as a root. This is the function that polls message queue(s) in an infinite loop, and is thus a bad root (it never exits).
High-level, when collection is requested - which should happen when a server has already been set up and handing requests - we spend a bit of time sampling all the server's threads. Each sample is a stack which we insert in a `PerThreadCallsiteTrie`. After a while, we run for each `PerThreadCallsiteTrie` the root detection logic. We then traverse all the `FunctionData`, find the ones matching the detected roots, and allocate a `ContextRoot` for them. From here, we special case `FunctionData` objects, in `__llvm_ctx_profile_get_context, that have a `CtxRoot` and route them to `__llvm_ctx_profile_start_context`.
For this to work, on the llvm side, we need to have all functions call `__llvm_ctx_profile_release_context` because they _might_ be roots. This comes at a slight (percentages) penalty during collection - which we can afford since the overall technique is ~5x faster than normal instrumentation. We can later explore conditionally enabling autoroot detection and avoiding this penalty, if desired.
Note that functions that `musttail call` can't have their return instrumented this way, and a subsequent patch will harden the mechanism against this case.
The mechanism could be used in combination with explicit root specification, too.
Diffstat (limited to 'clang/lib/Frontend/CreateInvocationFromCommandLine.cpp')
0 files changed, 0 insertions, 0 deletions