Skip to content

Commit bb407cb

Browse files
feat(profiler): add stop app function in profiler
1 parent d2aa2fb commit bb407cb

File tree

8 files changed

+20
-13
lines changed

8 files changed

+20
-13
lines changed

packages/commands/test/src/bin.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#!/usr/bin/env node
22

33
import { Option, program } from "commander";
4-
import { execSync } from "child_process";
54
import { TestCase } from ".";
65
import { executeAsync } from "./executeAsync";
76
import { applyLogLevelOption, logLevelOption } from "./commands/logLevelOption";
87
import { PerformanceTester } from "./PerformanceTester";
98
import { Logger } from "@perf-profiler/logger";
10-
import { killApp } from "@perf-profiler/ios-instruments/dist/utils/DeviceManager";
9+
import { profiler } from "@perf-profiler/profiler";
1110

1211
program
1312
.command("test")
@@ -119,14 +118,7 @@ const runTest = async ({
119118
const testCase: TestCase = {
120119
beforeTest: async () => {
121120
if (!skipRestart) {
122-
if (process.env.PLATFORM === "ios" || process.env.PLATFORM === "ios-instruments") {
123-
killApp(bundleId);
124-
} else {
125-
// This is needed in case the e2e test script actually restarts the app
126-
// So far this method of measuring only works if e2e test actually starts the app
127-
execSync(`adb shell am force-stop ${bundleId}`);
128-
await new Promise((resolve) => setTimeout(resolve, 3000));
129-
}
121+
await profiler.stopApp(bundleId);
130122
}
131123

132124
if (beforeEachCommand) await executeAsync(beforeEachCommand);

packages/core/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,5 @@ export interface Profiler {
8484
installProfilerOnDevice: () => void;
8585
cleanup: () => void;
8686
getScreenRecorder: (videoPath: string) => ScreenRecorder | undefined;
87+
stopApp: (bundleId: string) => Promise<void>;
8788
}

packages/platforms/android/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@ import { cleanup } from "./commands/shell";
44
import { ScreenRecorder } from "./commands/ScreenRecorder";
55
import { profiler } from "./commands/platforms/platformProfiler";
66
import { Profiler } from "@perf-profiler/types";
7+
import { execSync } from "child_process";
78

89
export { Measure } from "@perf-profiler/types";
910
export { Measure as GfxInfoMeasure } from "./commands/gfxInfo/parseGfxInfo";
1011
export { waitFor } from "./utils/waitFor";
12+
export { executeAsync, executeCommand } from "./commands/shell";
1113

1214
export class AndroidProfiler implements Profiler {
1315
pollPerformanceMeasures = pollPerformanceMeasures;
1416
detectCurrentBundleId = profiler.detectCurrentBundleId;
1517
installProfilerOnDevice = ensureCppProfilerIsInstalled;
1618
getScreenRecorder = (videoPath: string) => new ScreenRecorder(videoPath);
1719
cleanup = cleanup;
20+
async stopApp(bundleId: string) {
21+
execSync(`adb shell am force-stop ${bundleId}`);
22+
await new Promise((resolve) => setTimeout(resolve, 3000));
23+
}
1824
}

packages/platforms/ios-instruments/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"bin": {
66
"flashlight-ios-poc": "./dist/launchIOS.js"
77
},
8-
"main": "index.js",
8+
"main": "dist/index.js",
99
"scripts": {
1010
"test": "echo \"Error: no test specified\" && exit 1"
1111
},
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { killApp } from "./utils/DeviceManager";

packages/platforms/ios/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"license": "MIT",
1616
"dependencies": {
1717
"@perf-profiler/types": "^0.6.0",
18-
"@perf-profiler/logger": "^0.3.1"
18+
"@perf-profiler/logger": "^0.3.1",
19+
"@perf-profiler/ios-instruments": "^0.2.0"
1920
}
2021
}

packages/platforms/ios/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Measure, Profiler, ProfilerPollingOptions, ScreenRecorder } from "@perf-profiler/types";
22
import { ChildProcess, exec } from "child_process";
3+
import { killApp } from "@perf-profiler/ios-instruments";
34

45
interface AppMonitorData {
56
Pid: number;
@@ -98,4 +99,9 @@ export class IOSProfiler implements Profiler {
9899
cleanup: () => void = () => {
99100
// Do we need anything here?
100101
};
102+
103+
async stopApp(bundleId: string): Promise<void> {
104+
killApp(bundleId);
105+
return new Promise<void>((resolve) => resolve());
106+
}
101107
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
{ "path": "./packages/core/logger" },
1616
{ "path": "./packages/core/types" },
1717
{ "path": "./packages/platforms/android" },
18+
{ "path": "./packages/platforms/ios-instruments" },
1819
{ "path": "./packages/platforms/ios" },
1920
{ "path": "./packages/platforms/profiler" },
20-
{ "path": "./packages/platforms/ios-instruments" },
2121
{ "path": "./packages/plugins/appium-helper" },
2222
{ "path": "./packages/commands/test" },
2323
{ "path": "./packages/commands/tools" },

0 commit comments

Comments
 (0)