[WIP] Fix: retry perf record lookup by task_id with sliding window scan#298
[WIP] Fix: retry perf record lookup by task_id with sliding window scan#298indigo1973 wants to merge 1 commit intohw-native-sys:mainfrom
Conversation
Replace single last-record lookup with a backward scan over a window (kPerfScanWindow=4) of recent PerfBuffer records, retried up to kPerfPatchRetries=4 times with SPIN_WAIT_HINT between attempts. Adds bounds check against PLATFORM_PROF_BUFFER_SIZE and DEV_WARN when no matching task_id is found after all retries. Also unify orchestrator end-timestamp log format to "Thread=%d end=%llu" (matching scheduler threads) and fix --direction help text in perf_to_mermaid.py.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the reliability of performance data collection by introducing a more resilient lookup mechanism for performance records, ensuring that critical metadata is correctly associated even under transient conditions. It also improves logging consistency for profiling and corrects a minor help text error in a related tool. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a robust fix for a potential race condition in performance record lookup by implementing a sliding window scan with a retry mechanism. This is a significant improvement for the reliability of the performance profiling system. The changes also include some nice cleanups, such as unifying a log message format and fixing help text in a script. The core logic change is well-implemented with appropriate safety checks like bounds checking and memory barriers. I have one suggestion to simplify the index calculation for the sliding window to improve readability.
| int32_t start_idx = static_cast<int32_t>(observed_count) - 1; | ||
| int32_t end_idx = start_idx - kPerfScanWindow + 1; | ||
| if (end_idx < 0) { | ||
| end_idx = 0; | ||
| } |
There was a problem hiding this comment.
The calculation of the scan window's end_idx can be simplified. The current logic, which involves an initial calculation followed by a conditional clamp to zero, can be expressed more concisely in a single line using a ternary operator. This would make the code easier to read and understand at a glance.
const int32_t start_idx = static_cast<int32_t>(observed_count) - 1;
const int32_t end_idx = (observed_count > (uint32_t)kPerfScanWindow) ? (static_cast<int32_t>(observed_count) - kPerfScanWindow) : 0;
Replace single last-record lookup with a backward scan over a window (kPerfScanWindow=4) of recent PerfBuffer records, retried up to kPerfPatchRetries=4 times with SPIN_WAIT_HINT between attempts. Adds bounds check against PLATFORM_PROF_BUFFER_SIZE and DEV_WARN when no matching task_id is found after all retries.
Also unify orchestrator end-timestamp log format to "Thread=%d end=%llu" (matching scheduler threads) and fix --direction help text in perf_to_mermaid.py.