only capture selected application in exports

Summary:
Currently flipper export exports all connected the clients. This causes a few problems

1. This might often be unintended by the user, causing accidentally sharing (sensitive) information in the trace
2. This slows down things unnecesary. Especially if there is connected application, which is expensive, but not needed. See the attached video for the impact on exporting flipper: Export size reduzed from 11 to 0.5 mb. Export time from 20 seconds down to 1. (Flipper might not be a representative example, but imagine working on fb4a and having instagram on the emulator as well).

Reviewed By: priteshrnandgaonkar

Differential Revision: D18448194

fbshipit-source-id: f4de4c6dd89bda20251eb5f7423f7996339c8f2d
This commit is contained in:
Michel Weststrate
2019-11-13 08:34:45 -08:00
committed by Facebook Github Bot
parent f2d12f1025
commit 989b32c7b9
2 changed files with 15 additions and 3 deletions

View File

@@ -383,6 +383,7 @@ export const processStore = async (
}; };
export async function fetchMetadata( export async function fetchMetadata(
clients: Client[],
pluginStates: PluginStatesState, pluginStates: PluginStatesState,
pluginsMap: Map<string, typeof FlipperDevicePlugin | typeof FlipperPlugin>, pluginsMap: Map<string, typeof FlipperDevicePlugin | typeof FlipperPlugin>,
store: MiddlewareAPI, store: MiddlewareAPI,
@@ -391,7 +392,6 @@ export async function fetchMetadata(
): Promise<{pluginStates: PluginStatesState; errorArray: Array<Error>}> { ): Promise<{pluginStates: PluginStatesState; errorArray: Array<Error>}> {
const newPluginState = {...pluginStates}; const newPluginState = {...pluginStates};
const errorArray: Array<Error> = []; const errorArray: Array<Error> = [];
const clients = store.getState().connections.clients;
const selectedDevice = store.getState().connections.selectedDevice; const selectedDevice = store.getState().connections.selectedDevice;
for (const client of clients) { for (const client of clients) {
if ( if (
@@ -457,6 +457,9 @@ export async function getStoreExport(
): Promise<{exportData: ExportType | null; errorArray: Array<Error>}> { ): Promise<{exportData: ExportType | null; errorArray: Array<Error>}> {
const state = store.getState(); const state = store.getState();
const {clients} = state.connections; const {clients} = state.connections;
const client = clients.find(
client => client.query.app === state.connections.selectedClient,
);
const {pluginStates} = state; const {pluginStates} = state;
const {plugins} = state; const {plugins} = state;
const {selectedDevice} = store.getState().connections; const {selectedDevice} = store.getState().connections;
@@ -465,6 +468,9 @@ export async function getStoreExport(
} }
// TODO: T39612653 Make Client mockable. Currently rsocket logic is tightly coupled. // TODO: T39612653 Make Client mockable. Currently rsocket logic is tightly coupled.
// Not passing the entire state as currently Client is not mockable. // Not passing the entire state as currently Client is not mockable.
if (!client) {
throw new Error('Please select a client before exporting data.');
}
const pluginsMap: Map< const pluginsMap: Map<
string, string,
@@ -480,6 +486,7 @@ export async function getStoreExport(
const fetchMetaDataMarker = `${EXPORT_FLIPPER_TRACE_EVENT}:fetch-meta-data`; const fetchMetaDataMarker = `${EXPORT_FLIPPER_TRACE_EVENT}:fetch-meta-data`;
performance.mark(fetchMetaDataMarker); performance.mark(fetchMetaDataMarker);
const metadata = await fetchMetadata( const metadata = await fetchMetadata(
[client],
pluginStates, pluginStates,
pluginsMap, pluginsMap,
store, store,
@@ -499,7 +506,7 @@ export async function getStoreExport(
activeNotifications, activeNotifications,
device: selectedDevice, device: selectedDevice,
pluginStates: newPluginState, pluginStates: newPluginState,
clients: clients.map(client => client.toJSON()), clients: [client.toJSON()],
devicePlugins, devicePlugins,
clientPlugins, clientPlugins,
salt: uuid.v4(), salt: uuid.v4(),

View File

@@ -64,7 +64,12 @@ export async function exportMetricsWithoutTrace(
string, string,
typeof FlipperDevicePlugin | typeof FlipperPlugin typeof FlipperDevicePlugin | typeof FlipperPlugin
> = pluginsClassMap(store.getState().plugins); > = pluginsClassMap(store.getState().plugins);
const metadata = await fetchMetadata(pluginStates, pluginsMap, store); const metadata = await fetchMetadata(
store.getState().connections.clients,
pluginStates,
pluginsMap,
store,
);
const newPluginStates = metadata.pluginStates; const newPluginStates = metadata.pluginStates;
const {errorArray} = metadata; const {errorArray} = metadata;
if (errorArray.length > 0) { if (errorArray.length > 0) {