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:
John Knox
2020-08-13 03:46:36 -07:00
committed by Facebook GitHub Bot
parent 939b624dbb
commit d423afd75d
6 changed files with 88 additions and 49 deletions

View File

@@ -81,9 +81,11 @@ async function queryDevices(store: Store, logger: Logger): Promise<any> {
getActiveSimulators().then((devices) => {
processDevices(store, logger, devices, 'emulator');
}),
getActiveDevices().then((devices) => {
processDevices(store, logger, devices, 'physical');
}),
getActiveDevices(store.getState().settingsState.idbPath).then(
(devices: IOSDeviceParams[]) => {
processDevices(store, logger, devices, 'physical');
},
),
]);
}
@@ -173,8 +175,8 @@ function getActiveSimulators(): Promise<Array<IOSDeviceParams>> {
.catch((_) => []);
}
function getActiveDevices(): Promise<Array<IOSDeviceParams>> {
return iosUtil.targets().catch((e) => {
function getActiveDevices(idbPath: string): Promise<Array<IOSDeviceParams>> {
return iosUtil.targets(idbPath).catch((e) => {
console.error(e.message);
return [];
});
@@ -233,12 +235,12 @@ async function isXcodeDetected(): Promise<boolean> {
.catch((_) => false);
}
export async function getActiveDevicesAndSimulators(): Promise<
Array<IOSDevice>
> {
export async function getActiveDevicesAndSimulators(
store: Store,
): Promise<Array<IOSDevice>> {
const activeDevices: Array<Array<IOSDeviceParams>> = await Promise.all([
getActiveSimulators(),
getActiveDevices(),
getActiveDevices(store.getState().settingsState.idbPath),
]);
const allDevices = activeDevices[0].concat(activeDevices[1]);
return allDevices.map((device) => {