-
-
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
Open
IvanKarpan
wants to merge
3
commits into
exelban:master
Choose a base branch
from
IvanKarpan:fix/2785-performance-cores-should-show-100-percent
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,222 @@ | ||
| // | ||
| // CPU.swift | ||
| // Tests | ||
| // | ||
| // Created to test CPU performance cores utilization calculation fix. | ||
| // Testing issue #2785: Performance cores showing 75% instead of 100% when fully utilized. | ||
| // | ||
| // Copyright © 2025. All rights reserved. | ||
| // | ||
|
|
||
| import XCTest | ||
| import CPU | ||
| import Kit | ||
|
|
||
| class CPU: XCTestCase { | ||
|
|
||
| private func makeCore(id: Int32, type: coreType) -> core_s { | ||
| let json = """ | ||
| {"id": \(id), "type": \(type.rawValue)} | ||
| """ | ||
| guard let data = json.data(using: .utf8), | ||
| let core = try? JSONDecoder().decode(core_s.self, from: data) else { | ||
| fatalError("Failed to create core_s instance") | ||
| } | ||
| return core | ||
| } | ||
|
|
||
| func testPerformanceCoresShouldShow100Percent_Issue2785() throws { | ||
| let usagePerCore: [Double] = [ | ||
| 0.5, 0.5, 0.5, 0.5, | ||
| 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 | ||
| ] | ||
|
|
||
| let cores: [core_s] = [ | ||
| makeCore(id: 0, type: coreType.efficiency), | ||
| makeCore(id: 1, type: coreType.efficiency), | ||
| makeCore(id: 2, type: coreType.efficiency), | ||
| makeCore(id: 3, type: coreType.efficiency), | ||
| makeCore(id: 4, type: coreType.performance), | ||
| makeCore(id: 5, type: coreType.performance), | ||
| makeCore(id: 6, type: coreType.performance), | ||
| makeCore(id: 7, type: coreType.performance), | ||
| makeCore(id: 8, type: coreType.performance), | ||
| makeCore(id: 9, type: coreType.performance), | ||
| makeCore(id: 20, type: coreType.performance), | ||
| makeCore(id: 21, type: coreType.performance) | ||
| ] | ||
|
|
||
| let usagePCores = calculatePerformanceCoresUsage(cores: cores, usagePerCore: usagePerCore) | ||
|
|
||
| XCTAssertNotNil(usagePCores, "Performance cores usage should be calculated") | ||
| XCTAssertEqual(usagePCores!, 1.0, accuracy: 0.01, | ||
| "When all 8 performance cores are at 100%, should show 100%, not 75%") | ||
| XCTAssertEqual(cores.filter({ $0.type == .performance }).count, 8, "Should have 8 performance cores") | ||
| } | ||
|
|
||
| func testCalculatePerformanceCoresUsage_AllCoresAt100Percent() throws { | ||
| let cores: [core_s] = [ | ||
| makeCore(id: 0, type: .efficiency), | ||
| makeCore(id: 1, type: .performance), | ||
| makeCore(id: 2, type: .performance), | ||
| makeCore(id: 3, type: .performance) | ||
| ] | ||
| let usagePerCore: [Double] = [0.5, 1.0, 1.0, 1.0] | ||
|
|
||
| let result = calculatePerformanceCoresUsage(cores: cores, usagePerCore: usagePerCore) | ||
|
|
||
| XCTAssertNotNil(result) | ||
| XCTAssertEqual(result!, 1.0, accuracy: 0.01, "All performance cores at 100% should return 100%") | ||
| } | ||
|
|
||
| func testCalculatePerformanceCoresUsage_MixedUsage() throws { | ||
| let cores: [core_s] = [ | ||
| makeCore(id: 0, type: .efficiency), | ||
| makeCore(id: 1, type: .performance), | ||
| makeCore(id: 2, type: .performance), | ||
| makeCore(id: 3, type: .performance) | ||
| ] | ||
| let usagePerCore: [Double] = [0.5, 0.5, 0.75, 1.0] | ||
|
|
||
| let result = calculatePerformanceCoresUsage(cores: cores, usagePerCore: usagePerCore) | ||
|
|
||
| XCTAssertNotNil(result) | ||
| let expected = (0.5 + 0.75 + 1.0) / 3.0 | ||
| XCTAssertEqual(result!, expected, accuracy: 0.01, "Should calculate average of performance cores") | ||
| } | ||
|
|
||
| func testCalculatePerformanceCoresUsage_NoPerformanceCores() throws { | ||
| let cores: [core_s] = [ | ||
| makeCore(id: 0, type: .efficiency), | ||
| makeCore(id: 1, type: .efficiency), | ||
| makeCore(id: 2, type: .efficiency) | ||
| ] | ||
| let usagePerCore: [Double] = [0.5, 0.6, 0.7] | ||
|
|
||
| let result = calculatePerformanceCoresUsage(cores: cores, usagePerCore: usagePerCore) | ||
|
|
||
| XCTAssertNil(result, "Should return nil when there are no performance cores") | ||
| } | ||
|
|
||
| func testCalculatePerformanceCoresUsage_CountMismatch() throws { | ||
| let cores: [core_s] = [ | ||
| makeCore(id: 0, type: .performance), | ||
| makeCore(id: 1, type: .performance) | ||
| ] | ||
| let usagePerCore: [Double] = [1.0, 1.0, 1.0] | ||
|
|
||
| let result = calculatePerformanceCoresUsage(cores: cores, usagePerCore: usagePerCore) | ||
|
|
||
| XCTAssertNil(result, "Should return nil when counts don't match") | ||
| } | ||
|
|
||
| func testCalculatePerformanceCoresUsage_EmptyArrays() throws { | ||
| let cores: [core_s] = [] | ||
| let usagePerCore: [Double] = [] | ||
|
|
||
| let result = calculatePerformanceCoresUsage(cores: cores, usagePerCore: usagePerCore) | ||
|
|
||
| XCTAssertNil(result, "Should return nil for empty arrays") | ||
| } | ||
|
|
||
| func testCalculatePerformanceCoresUsage_PositionalMatching() throws { | ||
| let cores: [core_s] = [ | ||
| makeCore(id: 0, type: .efficiency), | ||
| makeCore(id: 5, type: .performance), | ||
| makeCore(id: 10, type: .performance), | ||
| makeCore(id: 20, type: .performance) | ||
| ] | ||
| let usagePerCore: [Double] = [0.3, 0.8, 0.9, 1.0] | ||
|
|
||
| let result = calculatePerformanceCoresUsage(cores: cores, usagePerCore: usagePerCore) | ||
|
|
||
| XCTAssertNotNil(result) | ||
| let expected = (0.8 + 0.9 + 1.0) / 3.0 | ||
| XCTAssertEqual(result!, expected, accuracy: 0.01, "Should use positional matching, not ID-based") | ||
| } | ||
|
|
||
| func testCalculateEfficiencyCoresUsage_AllCoresAt50Percent() throws { | ||
| let cores: [core_s] = [ | ||
| makeCore(id: 0, type: .efficiency), | ||
| makeCore(id: 1, type: .efficiency), | ||
| makeCore(id: 2, type: .performance), | ||
| makeCore(id: 3, type: .performance) | ||
| ] | ||
| let usagePerCore: [Double] = [0.5, 0.5, 1.0, 1.0] | ||
|
|
||
| let result = calculateEfficiencyCoresUsage(cores: cores, usagePerCore: usagePerCore) | ||
|
|
||
| XCTAssertNotNil(result) | ||
| XCTAssertEqual(result!, 0.5, accuracy: 0.01, "All efficiency cores at 50% should return 50%") | ||
| } | ||
|
|
||
| func testCalculateEfficiencyCoresUsage_MixedUsage() throws { | ||
| let cores: [core_s] = [ | ||
| makeCore(id: 0, type: .efficiency), | ||
| makeCore(id: 1, type: .efficiency), | ||
| makeCore(id: 2, type: .efficiency), | ||
| makeCore(id: 3, type: .performance) | ||
| ] | ||
| let usagePerCore: [Double] = [0.3, 0.5, 0.7, 1.0] | ||
|
|
||
| let result = calculateEfficiencyCoresUsage(cores: cores, usagePerCore: usagePerCore) | ||
|
|
||
| XCTAssertNotNil(result) | ||
| let expected = (0.3 + 0.5 + 0.7) / 3.0 | ||
| XCTAssertEqual(result!, expected, accuracy: 0.01, "Should calculate average of efficiency cores") | ||
| } | ||
|
|
||
| func testCalculateEfficiencyCoresUsage_NoEfficiencyCores() throws { | ||
| let cores: [core_s] = [ | ||
| makeCore(id: 0, type: .performance), | ||
| makeCore(id: 1, type: .performance), | ||
| makeCore(id: 2, type: .performance) | ||
| ] | ||
| let usagePerCore: [Double] = [1.0, 1.0, 1.0] | ||
|
|
||
| let result = calculateEfficiencyCoresUsage(cores: cores, usagePerCore: usagePerCore) | ||
|
|
||
| XCTAssertNil(result, "Should return nil when there are no efficiency cores") | ||
| } | ||
|
|
||
| func testCalculateEfficiencyCoresUsage_CountMismatch() throws { | ||
| let cores: [core_s] = [ | ||
| makeCore(id: 0, type: .efficiency), | ||
| makeCore(id: 1, type: .efficiency) | ||
| ] | ||
| let usagePerCore: [Double] = [0.5, 0.6, 0.7] | ||
|
|
||
| let result = calculateEfficiencyCoresUsage(cores: cores, usagePerCore: usagePerCore) | ||
|
|
||
| XCTAssertNil(result, "Should return nil when counts don't match") | ||
| } | ||
|
|
||
| func testCalculateEfficiencyCoresUsage_PositionalMatching() throws { | ||
| let cores: [core_s] = [ | ||
| makeCore(id: 100, type: .efficiency), | ||
| makeCore(id: 200, type: .efficiency), | ||
| makeCore(id: 300, type: .performance) | ||
| ] | ||
| let usagePerCore: [Double] = [0.4, 0.6, 1.0] | ||
|
|
||
| let result = calculateEfficiencyCoresUsage(cores: cores, usagePerCore: usagePerCore) | ||
|
|
||
| XCTAssertNotNil(result) | ||
| let expected = (0.4 + 0.6) / 2.0 | ||
| XCTAssertEqual(result!, expected, accuracy: 0.01, "Should use positional matching, not ID-based") | ||
| } | ||
|
|
||
| func testCalculateEfficiencyCoresUsage_ZeroUsage() throws { | ||
| let cores: [core_s] = [ | ||
| makeCore(id: 0, type: .efficiency), | ||
| makeCore(id: 1, type: .efficiency), | ||
| makeCore(id: 2, type: .performance) | ||
| ] | ||
| let usagePerCore: [Double] = [0.0, 0.0, 1.0] | ||
|
|
||
| let result = calculateEfficiencyCoresUsage(cores: cores, usagePerCore: usagePerCore) | ||
|
|
||
| XCTAssertNotNil(result) | ||
| XCTAssertEqual(result!, 0.0, accuracy: 0.01, "Should handle zero usage correctly") | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.