fix §7 TinyProfiler capture — run solve in subprocess#253
Merged
jameslehoux merged 1 commit intomasterfrom Apr 19, 2026
Merged
Conversation
The original implementation tried to close the in-kernel Session, run a new one, redirect sys.stdout to capture TinyProfiler, and restart the Session. Two problems: 1. TinyProfiler prints via C++ streams on AMReX finalize. Python's `sys.stdout = captured` only redirects the Python-level stream, so TinyProfiler output went to the real terminal and was lost. 2. Tearing down + rebuilding AMReX inside a live kernel is fragile — HYPRE/AMReX static state can leave the second init in a bad shape. This manifested in Colab as a silent cell crash. Fix: run one profiled solve in a short-lived subprocess. Python's `capture_output=True` grabs fd 1 + fd 2 at the OS level, which captures everything TinyProfiler emits. The in-kernel Session is never touched, and the result dict is passed back via a `__RESULT__` JSON line. Also: expand the §7 markdown to explain the subprocess rationale and set expectations that TinyProfiler will break down the HYPRE solve (which §3 already showed is 96%+ of wall time).
Code Coverage ReportGenerated by CI — coverage data from gcovr |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The original implementation tried to close the in-kernel Session, run a new one, redirect sys.stdout to capture TinyProfiler, and restart the Session. Two problems:
sys.stdout = capturedonly redirects the Python-level stream, so TinyProfiler output went to the real terminal and was lost.Fix: run one profiled solve in a short-lived subprocess. Python's
capture_output=Truegrabs fd 1 + fd 2 at the OS level, which captures everything TinyProfiler emits. The in-kernel Session is never touched, and the result dict is passed back via a__RESULT__JSON line.Also: expand the §7 markdown to explain the subprocess rationale and set expectations that TinyProfiler will break down the HYPRE solve (which §3 already showed is 96%+ of wall time).