Skip to content

Commit fee30de

Browse files
feat(instruments profiler): add new profiler
1 parent 29149eb commit fee30de

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,40 @@
1+
import { Measure, Profiler, ProfilerPollingOptions, ScreenRecorder } from "@perf-profiler/types";
12
export { killApp } from "./utils/DeviceManager";
3+
4+
export class IOSInstrumentsProfiler implements Profiler {
5+
connectedDevice: IdbDevice | undefined;
6+
recordingProcess: ChildProcess | undefined;
7+
traceFile: string | undefined;
8+
pid: number | undefined;
9+
bundleId: string | undefined;
10+
onMeasure: ((measure: Measure) => void) | undefined;
11+
pollPerformanceMeasures(bundleId: string, options: ProfilerPollingOptions): { stop: () => void } {
12+
if (!this.pid) throw new Error("Profiler is not ready, app is not running");
13+
this.onMeasure = options.onMeasure;
14+
return {
15+
stop: () => {
16+
return;
17+
},
18+
};
19+
}
20+
21+
detectCurrentBundleId(): string {
22+
throw new Error("App Id detection is not implemented on iOS with Instruments");
23+
}
24+
25+
installProfilerOnDevice() {
26+
// Do we need anything here?
27+
}
28+
29+
getScreenRecorder(videoPath: string): ScreenRecorder | undefined {
30+
return undefined;
31+
}
32+
33+
cleanup: () => void = () => {
34+
// Do we need anything here?
35+
};
36+
async stopApp(bundleId: string): Promise<void> {
37+
killApp(bundleId);
38+
return new Promise<void>((resolve) => resolve());
39+
}
40+
}

packages/platforms/profiler/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"dependencies": {
1717
"@perf-profiler/android": "^0.10.7",
1818
"@perf-profiler/ios": "^0.2.0",
19+
"@perf-profiler/ios-instruments": "^0.2.0",
1920
"@perf-profiler/types": "^0.6.0"
2021
}
2122
}
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
import { AndroidProfiler } from "@perf-profiler/android";
22
import { IOSProfiler } from "@perf-profiler/ios";
3+
import { IOSInstrumentsProfiler } from "@perf-profiler/ios-instruments";
34
import { Profiler } from "@perf-profiler/types";
45

5-
export const profiler: Profiler =
6-
process.env.PLATFORM === "ios" ? new IOSProfiler() : new AndroidProfiler();
6+
export const profiler: Profiler = (() => {
7+
switch (process.env.PLATFORM) {
8+
case "android":
9+
return new AndroidProfiler();
10+
case "ios":
11+
return new IOSProfiler();
12+
case "ios-instruments":
13+
return new IOSInstrumentsProfiler();
14+
default:
15+
return new AndroidProfiler();
16+
}
17+
})();
718

819
// TODO move this to a separate package
920
export { waitFor } from "@perf-profiler/android";

0 commit comments

Comments
 (0)