Fix high pkd CPU usage issue
Summary: Running `instruments -s devices` causes the `pkd` process in catalina to spike to ~100% for a few seconds. Flipper runs this command every 3 seconds to poll for devices. This switches it to use `idb list-targets` instead which is much more performant. Currently switched off in the open-source version while we make sure it's working well. If you set the GK value 'flipper_use_idb_to_list_devices' to true, then you'll get the new behaviour. Reviewed By: passy Differential Revision: D23102067 fbshipit-source-id: 9e17155d938a4fe326e082511f747444e4b533a2
This commit is contained in:
committed by
Facebook GitHub Bot
parent
939b624dbb
commit
d423afd75d
@@ -342,28 +342,30 @@ export default class CertificateProvider {
|
||||
// It's a simulator, the deviceId is in the filepath.
|
||||
return Promise.resolve(matches[1]);
|
||||
}
|
||||
return iosUtil.targets().then((targets) => {
|
||||
if (targets.length === 0) {
|
||||
throw new Error('No iOS devices found');
|
||||
}
|
||||
const deviceMatchList = targets.map((target) =>
|
||||
this.iOSDeviceHasMatchingCSR(
|
||||
deviceCsrFilePath,
|
||||
target.udid,
|
||||
appName,
|
||||
csr,
|
||||
).then((isMatch) => {
|
||||
return {id: target.udid, isMatch};
|
||||
}),
|
||||
);
|
||||
return Promise.all(deviceMatchList).then((devices) => {
|
||||
const matchingIds = devices.filter((m) => m.isMatch).map((m) => m.id);
|
||||
if (matchingIds.length == 0) {
|
||||
throw new Error(`No matching device found for app: ${appName}`);
|
||||
return iosUtil
|
||||
.targets(this.store.getState().settingsState.idbPath)
|
||||
.then((targets) => {
|
||||
if (targets.length === 0) {
|
||||
throw new Error('No iOS devices found');
|
||||
}
|
||||
return matchingIds[0];
|
||||
const deviceMatchList = targets.map((target) =>
|
||||
this.iOSDeviceHasMatchingCSR(
|
||||
deviceCsrFilePath,
|
||||
target.udid,
|
||||
appName,
|
||||
csr,
|
||||
).then((isMatch) => {
|
||||
return {id: target.udid, isMatch};
|
||||
}),
|
||||
);
|
||||
return Promise.all(deviceMatchList).then((devices) => {
|
||||
const matchingIds = devices.filter((m) => m.isMatch).map((m) => m.id);
|
||||
if (matchingIds.length == 0) {
|
||||
throw new Error(`No matching device found for app: ${appName}`);
|
||||
}
|
||||
return matchingIds[0];
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
androidDeviceHasMatchingCSR(
|
||||
|
||||
@@ -10,11 +10,13 @@
|
||||
import child_process from 'child_process';
|
||||
import {promisify} from 'util';
|
||||
import {Mutex} from 'async-mutex';
|
||||
import {notNull} from './typeUtils';
|
||||
const unsafeExec = promisify(child_process.exec);
|
||||
import {killOrphanedInstrumentsProcesses} from './processCleanup';
|
||||
import {reportPlatformFailures} from './metrics';
|
||||
import {promises, constants} from 'fs';
|
||||
import memoize from 'lodash.memoize';
|
||||
import GK from '../fb-stubs/GK';
|
||||
import {notNull} from './typeUtils';
|
||||
|
||||
// Use debug to get helpful logs when idb fails
|
||||
const idbLogLevel = 'DEBUG';
|
||||
@@ -22,6 +24,15 @@ const operationPrefix = 'iosContainerUtility';
|
||||
|
||||
const mutex = new Mutex();
|
||||
|
||||
type IdbTarget = {
|
||||
name: string;
|
||||
udid: string;
|
||||
state: string;
|
||||
type: string;
|
||||
os_version: string;
|
||||
architecture: string;
|
||||
};
|
||||
|
||||
export type DeviceTarget = {
|
||||
udid: string;
|
||||
type: 'physical' | 'emulator';
|
||||
@@ -44,23 +55,38 @@ function safeExec(command: string): Promise<{stdout: string; stderr: string}> {
|
||||
});
|
||||
}
|
||||
|
||||
async function targets(): Promise<Array<DeviceTarget>> {
|
||||
async function targets(idbPath: string): Promise<Array<DeviceTarget>> {
|
||||
if (process.platform !== 'darwin') {
|
||||
return [];
|
||||
}
|
||||
await killOrphanedInstrumentsProcesses();
|
||||
return safeExec('instruments -s devices').then(({stdout}) =>
|
||||
stdout
|
||||
.toString()
|
||||
.split('\n')
|
||||
.map((line) => line.trim())
|
||||
.map((line) => /(.+) \([^(]+\) \[(.*)\]( \(Simulator\))?/.exec(line))
|
||||
.filter(notNull)
|
||||
.filter(([_match, _name, _udid, isSim]) => !isSim)
|
||||
.map(([_match, name, udid]) => {
|
||||
return {udid: udid, type: 'physical', name: name};
|
||||
}),
|
||||
);
|
||||
if (GK.get('flipper_use_idb_to_list_devices')) {
|
||||
await memoize(checkIdbIsInstalled)(idbPath);
|
||||
return safeExec(`${idbPath} list-targets --json`).then(({stdout}) =>
|
||||
stdout
|
||||
.toString()
|
||||
.split('\n')
|
||||
.map((line) => line.trim())
|
||||
.map((line) => JSON.parse(line))
|
||||
.filter(({type}: IdbTarget) => type !== 'simulator')
|
||||
.map((target: IdbTarget) => {
|
||||
return {udid: target.udid, type: 'physical', name: target.name};
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
await killOrphanedInstrumentsProcesses();
|
||||
return safeExec('instruments -s devices').then(({stdout}) =>
|
||||
stdout
|
||||
.toString()
|
||||
.split('\n')
|
||||
.map((line) => line.trim())
|
||||
.map((line) => /(.+) \([^(]+\) \[(.*)\]( \(Simulator\))?/.exec(line))
|
||||
.filter(notNull)
|
||||
.filter(([_match, _name, _udid, isSim]) => !isSim)
|
||||
.map(([_match, name, udid]) => {
|
||||
return {udid: udid, type: 'physical', name: name};
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function push(
|
||||
@@ -70,7 +96,7 @@ async function push(
|
||||
dst: string,
|
||||
idbPath: string,
|
||||
): Promise<void> {
|
||||
await checkIdbIsInstalled(idbPath);
|
||||
await memoize(checkIdbIsInstalled)(idbPath);
|
||||
return wrapWithErrorMessage(
|
||||
reportPlatformFailures(
|
||||
safeExec(
|
||||
@@ -92,7 +118,7 @@ async function pull(
|
||||
dst: string,
|
||||
idbPath: string,
|
||||
): Promise<void> {
|
||||
await checkIdbIsInstalled(idbPath);
|
||||
await memoize(checkIdbIsInstalled)(idbPath);
|
||||
return wrapWithErrorMessage(
|
||||
reportPlatformFailures(
|
||||
safeExec(
|
||||
|
||||
@@ -19,7 +19,7 @@ export async function listDevices(store: Store): Promise<Array<BaseDevice>> {
|
||||
: [];
|
||||
const iOSDevices: BaseDevice[] = state.application
|
||||
.xcodeCommandLineToolsDetected
|
||||
? await getActiveDevicesAndSimulators()
|
||||
? await getActiveDevicesAndSimulators(store)
|
||||
: [];
|
||||
return [...androidDevices, ...iOSDevices];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user