-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(2785): performance cores showing 75% instead of 100% when fully utilized #2814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix(2785): performance cores showing 75% instead of 100% when fully utilized #2814
Conversation
…tilized replace CPU ID-based matching with positional matching in core usage calculations extract calculation logic into testable public functions (calculatePerformanceCoresUsage, calculateEfficiencyCoresUsage) add array count validation before performing calculations add comprehensive test suite (13 tests) covering bug scenario, edge cases, and positional matching update SwiftLint config: rename redundant_optional_initialization to implicit_optional_initialization remove unnecessary SwiftLint disable comment in Charts.swift fix RAM test: update test case PID to avoid conflicts Fixes exelban#2785
|
Hi. Please remove the comments, and please do not make any changes that are related to the problem. |
revert update SwiftLint config: rename redundant_optional_initialization to implicit_optional_initialization revert remove unnecessary SwiftLint disable comment in Charts.swift revert fix RAM test: update test case PID to avoid conflicts
|
Removed all comments I introduced and reverted changes unrelated to #2785. Do you want the other improvements (SwiftLint config deprecated warning fix, unnecessary SwiftLint disable comment, fix for RAM test) in a separate PR? |
|
thx, LGTM |
|
Hi, I’ve taken a closer look at the changes you proposed, and I have a question. Why are there so many modifications for such a small fix? Below is the version I received after reviewing this PR: |
Problem
On systems like M4 Pro 12/16, when performance cores are fully utilized, the Details section incorrectly shows Performance Cores: 75% instead of 100%, even though the bar graph displays correctly.
This occurs when CPU IDs from IORegistry don't align with sequential logical CPU indices from
host_processor_info. The buggy code used CPU IDs directly as array indices (usagePerCore[Int(c.id)]), causing out-of-bounds lookups that returned 0 for cores with non-sequential IDs (e.g., IDs 20, 21 when the array only has indices 0-11).Issue: #2785
Solution
Replaced ID-based matching with positional matching to correctly map cores to usage data:
usagePerCore[Int(c.id)](uses CPU ID as index)usagePerCore[index](uses position in cores array)This ensures that
cores[i]always maps tousagePerCore[i], regardless of what CPU IDs are stored in the core objects.Changes
Core Fix
calculatePerformanceCoresUsage(cores:usagePerCore:)calculateEfficiencyCoresUsage(cores:usagePerCore:)enumerated().compactMapcores.count == usagePerCore.count) before calculationsLoadReaderto use the new functionsTesting
Testing
All 13 tests pass, including:
Impact