|
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 | +} => { |
2 | 10 | let regexMatching = line.match( |
3 | 11 | / (\d+\.\d+): tracing_mark_write: ([A-Z])(.*)/ |
4 | 12 | ); |
@@ -46,27 +54,37 @@ export class FrameTimeParser { |
46 | 54 | const frameTimes: number[] = []; |
47 | 55 |
|
48 | 56 | lines.forEach((line) => { |
49 | | - if (!line.includes("-" + pid + " ")) return; |
| 57 | + try { |
| 58 | + if (!line.includes("-" + pid + " ")) return; |
50 | 59 |
|
51 | | - const { timestamp, ending, methodName } = parseLine(line); |
| 60 | + const { timestamp, ending, methodName } = parseLine(line); |
52 | 61 |
|
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 | + } |
60 | 69 |
|
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 | + } |
67 | 72 | } 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 | + } |
69 | 81 | } |
| 82 | + } catch (error) { |
| 83 | + Logger.error(`Failed to parse Atrace line: |
| 84 | +${line} |
| 85 | +
|
| 86 | +Error: |
| 87 | +${error instanceof Error ? error.message : error}`); |
70 | 88 | } |
71 | 89 | }); |
72 | 90 |
|
|
0 commit comments