Skip to content

Commit 2c5edd8

Browse files
authored
fix(profiler): make FPS polling safer (#62)
Should fix #48
1 parent 6e146ad commit 2c5edd8

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

packages/android-performance-profiler/src/commands/atrace/__tests__/pollFpsUsage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ com.example-4808 (-----) [006] .... 176340.064914: tracing_mark_write: B|4808|d
3131
com.example-4808 (-----) [006] .... 176340.064942: tracing_mark_write: B|4808|Record View#draw()
3232
com.example-4808 (-----) [006] .... 176340.065726: tracing_mark_write: E|4808
3333
com.example-4808 (-----) [006] .... 176340.067496: tracing_mark_write: E|4808
34+
com.example-4808 (-----) [005] ..s. 1799.488062: run_rebalance_domains: CPU5 FAILED TO GET (this is one line coming from Samsung A40)
3435
com.example-4808 (-----) [006] .... 176340.067503: tracing_mark_write: E|4808
3536
com.example-4808 (-----) [006] .... 176340.067509: tracing_mark_write: E|4808
3637
com.example-4808 (-----) [006] .... 176340.147257: tracing_mark_write: B|4808|Choreographer#onVsync 4573951

packages/android-performance-profiler/src/commands/atrace/pollFpsUsage.ts

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
export const parseLine = (line: string) => {
1+
import { Logger } from "@perf-profiler/logger";
2+
3+
export const parseLine = (
4+
line: string
5+
): {
6+
timestamp: number;
7+
ending: boolean;
8+
methodName: string | undefined;
9+
} => {
210
let regexMatching = line.match(
311
/ (\d+\.\d+): tracing_mark_write: ([A-Z])(.*)/
412
);
@@ -46,27 +54,37 @@ export class FrameTimeParser {
4654
const frameTimes: number[] = [];
4755

4856
lines.forEach((line) => {
49-
if (!line.includes("-" + pid + " ")) return;
57+
try {
58+
if (!line.includes("-" + pid + " ")) return;
5059

51-
const { timestamp, ending, methodName } = parseLine(line);
60+
const { timestamp, ending, methodName } = parseLine(line);
5261

53-
if (ending) {
54-
this.methodStartedCount--;
55-
if (this.methodStartedCount <= 0) {
56-
if (this.doFrameStartedTimeStamp) {
57-
frameTimes.push(timestamp - this.doFrameStartedTimeStamp);
58-
this.doFrameStartedTimeStamp = null;
59-
}
62+
if (ending) {
63+
this.methodStartedCount--;
64+
if (this.methodStartedCount <= 0) {
65+
if (this.doFrameStartedTimeStamp) {
66+
frameTimes.push(timestamp - this.doFrameStartedTimeStamp);
67+
this.doFrameStartedTimeStamp = null;
68+
}
6069

61-
this.methodStartedCount = 0;
62-
}
63-
} else {
64-
if (methodName.includes("Choreographer#doFrame")) {
65-
this.methodStartedCount = 1;
66-
this.doFrameStartedTimeStamp = timestamp;
70+
this.methodStartedCount = 0;
71+
}
6772
} else {
68-
this.methodStartedCount++;
73+
if (methodName) {
74+
if (methodName.includes("Choreographer#doFrame")) {
75+
this.methodStartedCount = 1;
76+
this.doFrameStartedTimeStamp = timestamp;
77+
} else {
78+
this.methodStartedCount++;
79+
}
80+
}
6981
}
82+
} catch (error) {
83+
Logger.error(`Failed to parse Atrace line:
84+
${line}
85+
86+
Error:
87+
${error instanceof Error ? error.message : error}`);
7088
}
7189
});
7290

0 commit comments

Comments
 (0)