Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically enable fps debug while running a test #5

Merged
merged 3 commits into from Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -37,8 +37,7 @@ const bundleId = "com.reactnativefeed";
const appActivity = `${bundleId}.MainActivity`;

const stopApp = () => execSync(`adb shell am force-stop ${bundleId}`);
const startApp = () =>
execSync(`adb shell am start ${bundleId}/${appActivity}`);
const startApp = () => execSync(`adb shell am start ${bundleId}/${appActivity}`);

const startTestCase: TestCase = {
duration: 15000,
Expand Down Expand Up @@ -110,6 +109,8 @@ setTimeout(() => {

## Getting FPS Data

FPS debug should be enabled automatically when you run a test. If it doesn't work on your device, follow the steps below:

In developer options, you need to set _Profile HWUI rendering_ to `In adb shell dumpsys gfxinfo`

<img width="453" alt="image" src="https://user-images.githubusercontent.com/4534323/182430625-e051c5aa-8153-46ad-a3f2-b095a2dadf25.png">
Expand Down Expand Up @@ -145,5 +146,4 @@ testCaseResults = [

You should now be able to open [the local server](http://localhost:1234/)


Run `yarn jest Plugin -u` after modifications.
2 changes: 1 addition & 1 deletion jest.config.js
Expand Up @@ -4,7 +4,7 @@ module.exports = {
"^.+\\.tsx?$": "ts-jest",
},
testRegex: "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
testPathIgnorePatterns: ["\\.snap$", "/node_modules/", "/dist/"],
testPathIgnorePatterns: ["\\.snap$", "/node_modules/", "/dist/", "/e2e-example/"],
testEnvironment: "jsdom",
collectCoverageFrom: ["**/*.{ts,tsx}", "!**/node_modules/**", "!**/dist/**"],
};
@@ -1,6 +1,7 @@
import { GfxInfoParser, Measure } from "./parseGfxInfo";
import { compareGfxMeasures } from "./compareGfxMeasures";
import { Logger } from "@perf-profiler/logger";
import { executeCommand } from "../shell";

// gfxinfo is one way
// one of the caveats is Flutter won't be supported
Expand Down Expand Up @@ -32,13 +33,14 @@ import { Logger } from "@perf-profiler/logger";

const TIME_INTERVAL = 500;

const enableFpsDebug = () => executeCommand("adb shell setprop debug.hwui.profile true");
enableFpsDebug();

export const getCommand = (bundleId: string) => `dumpsys gfxinfo ${bundleId}`;
export const processOutput = (result: string) => {
const lines = result.split("\n");

const headerIndex = lines.findIndex(
(line) => line === "\tDraw\tPrepare\tProcess\tExecute"
);
const headerIndex = lines.findIndex((line) => line === "\tDraw\tPrepare\tProcess\tExecute");
if (headerIndex === -1) {
Logger.warn(
`FPS data not found, defaulting to 0, refer to https://github.com/bamlab/android-performance-profiler#getting-fps-data`
Expand All @@ -48,8 +50,7 @@ export const processOutput = (result: string) => {
}

const firstRowIndex = headerIndex + 1;
const lastLineIndex =
lines.slice(firstRowIndex).findIndex((line) => line === "") + firstRowIndex;
const lastLineIndex = lines.slice(firstRowIndex).findIndex((line) => line === "") + firstRowIndex;

const frameTimes = lines.slice(firstRowIndex, lastLineIndex).map((line) =>
line
Expand Down
Expand Up @@ -24,6 +24,8 @@ jest.mock("child_process", () => {
return "123456";
case "adb shell getconf PAGESIZE":
return 4096;
case "adb shell setprop debug.hwui.profile true":
return "";
default:
console.error(`Unknown command: ${command}`);
return "";
Expand Down