-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(profiler): improve accuracy of CPU measures (#140)
* fix(profiler): ensure process names with space get taken into account The regex also gets rid of the parenthesis automatically * refactor: use thread names constant * fix(profiler): handle multiple processes with same name This is similar to what Android Studio displays Say you have an app loading several images, chances are the app will create a different process to load each images but with the same name For instance, let's say this launches 5 different processes each accounting for 20% CPU usage in the same 500ms window Before this fix, the stats would be additionned, meaning we would see one single thread with that name with 100% CPU usage. It would thus hit the high CPU usage threshold, even though, nothing is actually saturating After this fix you would see process 20% process (2) 20% ... process (5) 20% Worth noting that a more ideal fix would have been to store processes by ids, but that actually makes the list of processes less readable and more difficult to compare Say every 500ms you load 5 requests, your 5 request processes would get recreated with same name but different ids, so every 500ms, 5 new processes would get added to the list. By still grouping by name, but allowing for multiple occurrences in a 500ms window, we keep only a smaller amount of processes, like Android Studio does for instance. It's also easier to compare and track with multiple iterations Side note: I kept the sanitizeName function just for previous reports which included parenthesis, just made sure it didn't remove the parenthesis that we added
- Loading branch information
Showing
16 changed files
with
1,178 additions
and
197 deletions.
There are no files selected for viewing
This file contains 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 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 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
39 changes: 39 additions & 0 deletions
39
...ages/android-performance-profiler/src/commands/cpu/__tests__/getCpuStatsByProcess.test.ts
This file contains 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,39 @@ | ||
import { processOutput } from "../getCpuStatsByProcess"; | ||
|
||
const SAMPLE_STATS = `27986 (OkHttp TaskRunn) S 480 480 0 0 -1 1077952576 6 0 0 0 50 20 40 0 20 0 53 0 233304293 1726836736 45377 18446744073709551615 1 1 0 0 0 0 4612 1 1073775864 0 0 0 -1 5 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
27987 (FrescoDecodeExe) S 480 480 0 0 -1 1077952576 3966 0 0 0 23 3 7 0 30 10 53 0 233304298 1726836736 45377 18446744073709551615 1 1 0 0 0 0 4612 1 1073775864 0 0 0 -1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
27988 (content.com/...) S 480 480 0 0 -1 1077952576 396 0 0 0 28 5 5 0 20 0 53 0 233304298 1726836736 45377 18446744073709551615 1 1 0 0 0 0 4612 1 1073775864 0 0 0 -1 5 0 0 0 0 0 0 0 0 0 0 0 0 0 | ||
1234 (com.example) S 480 480 0 0 -1 1077952576 396 0 0 0 28 5 5 0 20 0 53 0 233304298 1726836736 45377 18446744073709551615 1 1 0 0 0 0 4612 1 1073775864 0 0 0 -1 5 0 0 0 0 0 0 0 0 0 0 0 0 0`; | ||
|
||
describe("getCpuStatsByProcess", () => { | ||
it("extract CPU thread stats from profiler output", () => { | ||
expect(processOutput(SAMPLE_STATS, "1234")).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"cpuNumber": "5", | ||
"processId": "27986", | ||
"processName": "OkHttp TaskRunn", | ||
"totalCpuTime": 70, | ||
}, | ||
{ | ||
"cpuNumber": "2", | ||
"processId": "27987", | ||
"processName": "FrescoDecodeExe", | ||
"totalCpuTime": 26, | ||
}, | ||
{ | ||
"cpuNumber": "5", | ||
"processId": "27988", | ||
"processName": "content.com/...", | ||
"totalCpuTime": 33, | ||
}, | ||
{ | ||
"cpuNumber": "5", | ||
"processId": "1234", | ||
"processName": "UI Thread", | ||
"totalCpuTime": 33, | ||
}, | ||
] | ||
`); | ||
}); | ||
}); |
This file contains 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 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 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
Oops, something went wrong.