Added metrics argument to headless inorder to export metrics
Summary:
This diff makes headless flipper accept `metrics` argument. Once this is passed. The headless flipper will terminate to export the metrics of the plugins, the type of the export looks like the following.
```
export type MetricType = {[metricName: string]: number};
type MetricPluginType = {[pluginID: string]: MetricType};
export type ExportMetricType = {[clientID: string]: MetricPluginType};
```
This diff, uses the store to export the metrics. I will modify the logic to accept the data which gets exported through `exportData`
Reviewed By: passy
Differential Revision: D14933499
fbshipit-source-id: dade5b7bc59ea4beb6d16c5ef471737e8597358a
This commit is contained in:
committed by
Facebook Github Bot
parent
7bbb8c10c4
commit
afd729deb6
52
src/utils/exportMetrics.js
Normal file
52
src/utils/exportMetrics.js
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Copyright 2018-present Facebook.
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* @format
|
||||
*/
|
||||
import type {MiddlewareAPI} from '../reducers';
|
||||
import {serialize} from './serialization.js';
|
||||
import type {FlipperPlugin, FlipperDevicePlugin} from 'flipper';
|
||||
|
||||
type MetricType = Map<string, Map<string, string | number>>;
|
||||
|
||||
export type ExportMetricType = Map<string, MetricType>;
|
||||
|
||||
export default async function exportMetrics(
|
||||
store: MiddlewareAPI,
|
||||
): Promise<string> {
|
||||
const state = store.getState();
|
||||
let metrics: ExportMetricType = new Map();
|
||||
for (let key in state.pluginStates) {
|
||||
const pluginStateData = state.pluginStates[key];
|
||||
const arr = key.split('#');
|
||||
const pluginName = arr.pop();
|
||||
const clientID = arr.join('#');
|
||||
const pluginsMap: Map<
|
||||
string,
|
||||
Class<FlipperDevicePlugin<> | FlipperPlugin<>>,
|
||||
> = new Map([]);
|
||||
state.plugins.clientPlugins.forEach((val, key) => {
|
||||
pluginsMap.set(key, val);
|
||||
});
|
||||
state.plugins.devicePlugins.forEach((val, key) => {
|
||||
pluginsMap.set(key, val);
|
||||
});
|
||||
const exportMetrics1: ?(
|
||||
persistedState: any,
|
||||
) => Promise<Map<string, string | number>> = pluginsMap.get(pluginName)
|
||||
?.exportMetrics;
|
||||
if (pluginsMap.has(pluginName) && exportMetrics1) {
|
||||
const metricMap = await exportMetrics1(pluginStateData);
|
||||
const pluginMap = new Map([[pluginName, metricMap]]);
|
||||
if (!metrics.get(clientID)) {
|
||||
metrics.set(clientID, pluginMap);
|
||||
continue;
|
||||
}
|
||||
const prevMetricMap = metrics.get(clientID);
|
||||
// $FlowFixMe: prevMetricMap cannot be null, because clientID is added only when the pluingMetricMap is available
|
||||
metrics.set(clientID, new Map([...prevMetricMap, ...pluginMap]));
|
||||
}
|
||||
}
|
||||
return Promise.resolve(serialize(metrics));
|
||||
}
|
||||
Reference in New Issue
Block a user