

Profile Android performance even in production on CLI or Flipper plugin
source link: https://reactnativeexample.com/profile-android-performance-even-in-production-on-cli-or-flipper-plugin/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Android Performance Profiler
Measure the performance of any Android app, even in production, via a Flipper plugin or directly via CLI.
prod-profiler.mp4
Table of Contents
Getting started with the automated profiler
- Install the profiler
yarn add --dev @perf-profiler/e2e
- Write a test
For instance, here we’ll be testing the start up performance of the app for 10 iterations:
import { execSync } from "child_process";
import { TestCase, PerformanceTester } from "@perf-profiler/e2e";
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 startTestCase: TestCase = {
duration: 15000,
beforeTest: () => {
stopApp();
},
run: () => {
startApp();
},
};
const test = async () => {
const performanceTester = new PerformanceTester(bundleId);
await performanceTester.iterate(startTestCase, 10);
performanceTester.writeResults();
};
test();
- Open the JSON file generated in the web profiler:
yarn add --dev @perf-profiler/web-reporter
yarn generate results.json
Flipper Plugin
Install
Search for android-performance-profiler
in the Flipper marketplace
Multiple commands are also available in the standalone package android-performance-profiler
.
⚠️ they will be subject to breaking changes
For instance:
import {
detectCurrentAppBundleId,
getAverageCpuUsage,
getPidId,
Measure,
pollPerformanceMeasures,
} from "@perf-profiler/profiler";
const bundleId = detectCurrentAppBundleId();
const pid = getPidId(bundleId);
const measures: Measure[] = [];
const polling = pollPerformanceMeasures(pid, (measure) => {
measures.push(measure);
console.log(`JS Thread CPU Usage: ${measure.perName["(mqt_js)"]}%`);
});
setTimeout(() => {
polling.stop();
const averageCpuUsage = getAverageCpuUsage(measures);
console.log(`Average CPU Usage: ${averageCpuUsage}%`);
}, 10000);
Contributing
web-reporter
At the root of the repo:
yarn
yarn tsc --build --w
and run in another terminal:
yarn workspace @perf-profiler/web-reporter start
Then in packages/web-reporter/src/App.tsx
, uncomment the lines to add your own measures:
// Uncomment with when locally testing
// eslint-disable-next-line @typescript-eslint/no-var-requires
testCaseResults = [
require("../measures.json"),
];
You should now be able to open the local server
Run yarn jest Plugin -u
after modifications.
GitHub
</div
Recommend
-
55
-
55
-
8
Conan 1.31.0 features a few more significant steps toward our new toolchain strategy, coupled with a lengthy list of quality-of-life features and fixes. Upload Performance Improvements This release includes a long-overdue ch...
-
8
Reselect Debugger Plugin for Flipper flipper-plugin-reselect-debugger allows you debug Reselect selectors inside Flipper Recomputations of selector Selectors Inputs Selectors Output (In case if selector...
-
18
Flipper Flipper Databases plugin for React Native Aug 12, 2021...
-
8
December 18, 2021
-
15
Flipper Plugin to control react-native-mmkv from Flipper Jan 24, 2022 1 min read Flipper plugin for
-
8
Storage React Native Flipper plugin for React Native MMKV Storage Jul 07, 2022 1 min read React Native...
-
9
Stream Chat React Native’s Flipper Plugin ? Stream chat React Native Flipper Plugin is created so that users can debug the Stream Chat React Native using...
-
10
Netflix Moochers Can Now Transfer Their Profile, Even If They're Kicked Out Of Original Owner's Account ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK