Skip to content

Commit

Permalink
fix(profiler): make FPS polling safer (#62)
Browse files Browse the repository at this point in the history
Should fix #48
  • Loading branch information
Almouro authored Dec 16, 2022
1 parent 6e146ad commit 2c5edd8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ com.example-4808 (-----) [006] .... 176340.064914: tracing_mark_write: B|4808|d
com.example-4808 (-----) [006] .... 176340.064942: tracing_mark_write: B|4808|Record View#draw()
com.example-4808 (-----) [006] .... 176340.065726: tracing_mark_write: E|4808
com.example-4808 (-----) [006] .... 176340.067496: tracing_mark_write: E|4808
com.example-4808 (-----) [005] ..s. 1799.488062: run_rebalance_domains: CPU5 FAILED TO GET (this is one line coming from Samsung A40)
com.example-4808 (-----) [006] .... 176340.067503: tracing_mark_write: E|4808
com.example-4808 (-----) [006] .... 176340.067509: tracing_mark_write: E|4808
com.example-4808 (-----) [006] .... 176340.147257: tracing_mark_write: B|4808|Choreographer#onVsync 4573951
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
export const parseLine = (line: string) => {
import { Logger } from "@perf-profiler/logger";

export const parseLine = (
line: string
): {
timestamp: number;
ending: boolean;
methodName: string | undefined;
} => {
let regexMatching = line.match(
/ (\d+\.\d+): tracing_mark_write: ([A-Z])(.*)/
);
Expand Down Expand Up @@ -46,27 +54,37 @@ export class FrameTimeParser {
const frameTimes: number[] = [];

lines.forEach((line) => {
if (!line.includes("-" + pid + " ")) return;
try {
if (!line.includes("-" + pid + " ")) return;

const { timestamp, ending, methodName } = parseLine(line);
const { timestamp, ending, methodName } = parseLine(line);

if (ending) {
this.methodStartedCount--;
if (this.methodStartedCount <= 0) {
if (this.doFrameStartedTimeStamp) {
frameTimes.push(timestamp - this.doFrameStartedTimeStamp);
this.doFrameStartedTimeStamp = null;
}
if (ending) {
this.methodStartedCount--;
if (this.methodStartedCount <= 0) {
if (this.doFrameStartedTimeStamp) {
frameTimes.push(timestamp - this.doFrameStartedTimeStamp);
this.doFrameStartedTimeStamp = null;
}

this.methodStartedCount = 0;
}
} else {
if (methodName.includes("Choreographer#doFrame")) {
this.methodStartedCount = 1;
this.doFrameStartedTimeStamp = timestamp;
this.methodStartedCount = 0;
}
} else {
this.methodStartedCount++;
if (methodName) {
if (methodName.includes("Choreographer#doFrame")) {
this.methodStartedCount = 1;
this.doFrameStartedTimeStamp = timestamp;
} else {
this.methodStartedCount++;
}
}
}
} catch (error) {
Logger.error(`Failed to parse Atrace line:
${line}
Error:
${error instanceof Error ? error.message : error}`);
}
});

Expand Down

0 comments on commit 2c5edd8

Please sign in to comment.