FrameworkEventsInspector
Summary: As events get bigger, this change includes the following: - Dedicated event inspector - Stacktrace viewer for events with stacktrace attribution - Stacktrace viewer is displayed within a new BottomPanel. BottomPanel can display any React component and can be reused in the future in different use cases. Reviewed By: LukeDefeo Differential Revision: D44628768 fbshipit-source-id: 71a9ef87e71c9a17f58c2544a1aa356eed14ed27
This commit is contained in:
committed by
Facebook GitHub Bot
parent
7f111a11de
commit
8f5fcf9444
@@ -7,7 +7,7 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, {useState} from 'react';
|
import React, {ReactNode, useEffect, useRef, useState} from 'react';
|
||||||
import {plugin} from '../index';
|
import {plugin} from '../index';
|
||||||
import {
|
import {
|
||||||
DetailSidebar,
|
DetailSidebar,
|
||||||
@@ -23,7 +23,7 @@ import {Visualization2D} from './Visualization2D';
|
|||||||
import {useKeyboardModifiers} from '../hooks/useKeyboardModifiers';
|
import {useKeyboardModifiers} from '../hooks/useKeyboardModifiers';
|
||||||
import {Inspector} from './sidebar/Inspector';
|
import {Inspector} from './sidebar/Inspector';
|
||||||
import {Controls} from './Controls';
|
import {Controls} from './Controls';
|
||||||
import {Spin} from 'antd';
|
import {Button, Spin} from 'antd';
|
||||||
import {QueryClientProvider} from 'react-query';
|
import {QueryClientProvider} from 'react-query';
|
||||||
import {Tree2} from './Tree';
|
import {Tree2} from './Tree';
|
||||||
|
|
||||||
@@ -40,12 +40,24 @@ export function Component() {
|
|||||||
|
|
||||||
const {ctrlPressed} = useKeyboardModifiers();
|
const {ctrlPressed} = useKeyboardModifiers();
|
||||||
|
|
||||||
|
const [bottomPanelComponent, setBottomPanelComponent] = useState<
|
||||||
|
ReactNode | undefined
|
||||||
|
>();
|
||||||
|
const openBottomPanelWithContent = (component: ReactNode) => {
|
||||||
|
setBottomPanelComponent(component);
|
||||||
|
};
|
||||||
|
const dismissBottomPanel = () => {
|
||||||
|
setBottomPanelComponent(undefined);
|
||||||
|
};
|
||||||
|
|
||||||
if (showPerfStats) return <PerfStats events={instance.perfEvents} />;
|
if (showPerfStats) return <PerfStats events={instance.perfEvents} />;
|
||||||
|
|
||||||
if (rootId) {
|
if (rootId) {
|
||||||
return (
|
return (
|
||||||
<QueryClientProvider client={instance.queryClient}>
|
<QueryClientProvider client={instance.queryClient}>
|
||||||
<Layout.Container grow padh="small" padv="medium">
|
<Layout.Container grow padh="small" padv="medium">
|
||||||
|
<Layout.Top>
|
||||||
|
<>
|
||||||
<Controls />
|
<Controls />
|
||||||
<Layout.Horizontal grow pad="small">
|
<Layout.Horizontal grow pad="small">
|
||||||
<Tree2 nodes={nodes} rootId={rootId} />
|
<Tree2 nodes={nodes} rootId={rootId} />
|
||||||
@@ -69,9 +81,18 @@ export function Component() {
|
|||||||
</Layout.ScrollContainer>
|
</Layout.ScrollContainer>
|
||||||
</ResizablePanel>
|
</ResizablePanel>
|
||||||
<DetailSidebar width={350}>
|
<DetailSidebar width={350}>
|
||||||
<Inspector metadata={metadata} nodes={nodes} />
|
<Inspector
|
||||||
|
metadata={metadata}
|
||||||
|
nodes={nodes}
|
||||||
|
showExtra={openBottomPanelWithContent}
|
||||||
|
/>
|
||||||
</DetailSidebar>
|
</DetailSidebar>
|
||||||
</Layout.Horizontal>
|
</Layout.Horizontal>
|
||||||
|
</>
|
||||||
|
<BottomPanel dismiss={dismissBottomPanel}>
|
||||||
|
{bottomPanelComponent}
|
||||||
|
</BottomPanel>
|
||||||
|
</Layout.Top>
|
||||||
</Layout.Container>
|
</Layout.Container>
|
||||||
</QueryClientProvider>
|
</QueryClientProvider>
|
||||||
);
|
);
|
||||||
@@ -93,3 +114,45 @@ export function Centered(props: {children: React.ReactNode}) {
|
|||||||
</Layout.Horizontal>
|
</Layout.Horizontal>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BottomPanelProps = {
|
||||||
|
dismiss: () => void;
|
||||||
|
children: React.ReactNode;
|
||||||
|
};
|
||||||
|
export function BottomPanel({dismiss, children}: BottomPanelProps) {
|
||||||
|
const bottomPanelRef = useRef<any>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleClickOutside = (event: MouseEvent) => {
|
||||||
|
if (
|
||||||
|
bottomPanelRef.current &&
|
||||||
|
!bottomPanelRef.current.contains(event.target)
|
||||||
|
) {
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Add event listener when the component is mounted.
|
||||||
|
document.addEventListener('mousedown', handleClickOutside);
|
||||||
|
|
||||||
|
// Remove event listener when component is unmounted.
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('mousedown', handleClickOutside);
|
||||||
|
};
|
||||||
|
}, [bottomPanelRef, dismiss]);
|
||||||
|
|
||||||
|
if (!children) {
|
||||||
|
return <></>;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div ref={bottomPanelRef}>
|
||||||
|
<ResizablePanel position="bottom" minHeight={200} height={400} gutter>
|
||||||
|
<Layout.ScrollContainer>{children}</Layout.ScrollContainer>
|
||||||
|
<div style={{margin: 10}}>
|
||||||
|
<Button type="ghost" style={{float: 'right'}} onClick={dismiss}>
|
||||||
|
Dismiss
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</ResizablePanel>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,33 +7,25 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React, {ReactNode} from 'react';
|
||||||
// eslint-disable-next-line rulesdir/no-restricted-imports-clone
|
// eslint-disable-next-line rulesdir/no-restricted-imports-clone
|
||||||
import {Glyph} from 'flipper';
|
import {Glyph} from 'flipper';
|
||||||
import {
|
import {Layout, Tab, Tabs, theme, usePlugin, useValue} from 'flipper-plugin';
|
||||||
Layout,
|
|
||||||
Tab,
|
|
||||||
Tabs,
|
|
||||||
theme,
|
|
||||||
usePlugin,
|
|
||||||
useValue,
|
|
||||||
TimelineDataDescription,
|
|
||||||
} from 'flipper-plugin';
|
|
||||||
|
|
||||||
import {Id, Metadata, MetadataId, UINode} from '../../types';
|
import {Id, Metadata, MetadataId, UINode} from '../../types';
|
||||||
|
|
||||||
import {IdentityInspector} from './inspector/IdentityInspector';
|
import {IdentityInspector} from './inspector/IdentityInspector';
|
||||||
import {AttributesInspector} from './inspector/AttributesInspector';
|
import {AttributesInspector} from './inspector/AttributesInspector';
|
||||||
import {Tooltip} from 'antd';
|
import {Tooltip} from 'antd';
|
||||||
import {NoData} from './inspector/NoData';
|
import {NoData} from './inspector/NoData';
|
||||||
import {plugin} from '../../index';
|
import {plugin} from '../../index';
|
||||||
|
import {FrameworkEventsInspector} from './inspector/FrameworkEventsInspector';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
nodes: Map<Id, UINode>;
|
nodes: Map<Id, UINode>;
|
||||||
metadata: Map<MetadataId, Metadata>;
|
metadata: Map<MetadataId, Metadata>;
|
||||||
|
showExtra: (element: ReactNode) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Inspector: React.FC<Props> = ({nodes, metadata}) => {
|
export const Inspector: React.FC<Props> = ({nodes, metadata, showExtra}) => {
|
||||||
const instance = usePlugin(plugin);
|
const instance = usePlugin(plugin);
|
||||||
const selectedNodeId = useValue(instance.uiState.selectedNode);
|
const selectedNodeId = useValue(instance.uiState.selectedNode);
|
||||||
const frameworkEvents = useValue(instance.frameworkEvents);
|
const frameworkEvents = useValue(instance.frameworkEvents);
|
||||||
@@ -43,7 +35,7 @@ export const Inspector: React.FC<Props> = ({nodes, metadata}) => {
|
|||||||
return <NoData message="Please select a node to view its details" />;
|
return <NoData message="Please select a node to view its details" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
const events = selectedNodeId
|
const selectedFrameworkEvents = selectedNodeId
|
||||||
? frameworkEvents?.get(selectedNodeId)
|
? frameworkEvents?.get(selectedNodeId)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
@@ -96,7 +88,7 @@ export const Inspector: React.FC<Props> = ({nodes, metadata}) => {
|
|||||||
metadata={metadata}
|
metadata={metadata}
|
||||||
/>
|
/>
|
||||||
</Tab>
|
</Tab>
|
||||||
{events && (
|
{selectedFrameworkEvents && (
|
||||||
<Tab
|
<Tab
|
||||||
key={'events'}
|
key={'events'}
|
||||||
tab={
|
tab={
|
||||||
@@ -110,19 +102,10 @@ export const Inspector: React.FC<Props> = ({nodes, metadata}) => {
|
|||||||
</Layout.Horizontal>
|
</Layout.Horizontal>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
}>
|
}>
|
||||||
<TimelineDataDescription
|
<FrameworkEventsInspector
|
||||||
timeline={{
|
node={selectedNode}
|
||||||
time: events.map((e) => {
|
events={selectedFrameworkEvents}
|
||||||
return {
|
showExtra={showExtra}
|
||||||
moment: e.timestamp,
|
|
||||||
display: e.type.slice(e.type.lastIndexOf(':') + 1),
|
|
||||||
color: theme.primaryColor,
|
|
||||||
key: e.timestamp.toString(),
|
|
||||||
properties: e.payload as any,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
current: '',
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</Tab>
|
</Tab>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*
|
||||||
|
* @format
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {Button} from 'antd';
|
||||||
|
import {theme, TimelineDataDescription} from 'flipper-plugin';
|
||||||
|
import {FrameworkEvent, UINode} from '../../../types';
|
||||||
|
import React, {ReactNode, useState} from 'react';
|
||||||
|
import {StackTraceInspector} from './StackTraceInspector';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
node: UINode;
|
||||||
|
events: FrameworkEvent[];
|
||||||
|
showExtra?: (element: ReactNode) => void;
|
||||||
|
};
|
||||||
|
export const FrameworkEventsInspector: React.FC<Props> = ({
|
||||||
|
node,
|
||||||
|
events,
|
||||||
|
showExtra,
|
||||||
|
}) => {
|
||||||
|
const [selectedEvent, setSelectedEvent] = useState<FrameworkEvent>(
|
||||||
|
events[events.length - 1],
|
||||||
|
);
|
||||||
|
|
||||||
|
const showStacktrace = () => {
|
||||||
|
const attribution = selectedEvent.attribution;
|
||||||
|
if (attribution?.type === 'stacktrace') {
|
||||||
|
const stacktraceInspector = (
|
||||||
|
<StackTraceInspector
|
||||||
|
stacktrace={attribution.stacktrace}
|
||||||
|
tags={node.tags}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
showExtra?.(stacktraceInspector);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const hasStacktrace = (event: FrameworkEvent) => {
|
||||||
|
return event.attribution?.type === 'stacktrace';
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<TimelineDataDescription
|
||||||
|
key={node.id}
|
||||||
|
canSetCurrent={false}
|
||||||
|
onClick={(current) => {
|
||||||
|
const idx = parseInt(current, 10);
|
||||||
|
setSelectedEvent(events[idx]);
|
||||||
|
}}
|
||||||
|
timeline={{
|
||||||
|
time: events.map((e, idx) => {
|
||||||
|
return {
|
||||||
|
moment: e.timestamp,
|
||||||
|
display: e.type.slice(e.type.lastIndexOf(':') + 1),
|
||||||
|
color: theme.primaryColor,
|
||||||
|
key: idx.toString(),
|
||||||
|
properties: e.payload as any,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
current: (events.length - 1).toString(),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{hasStacktrace(selectedEvent) && (
|
||||||
|
<Button type="ghost" onClick={showStacktrace}>
|
||||||
|
Stacktrace
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*
|
||||||
|
* @format
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
// eslint-disable-next-line rulesdir/no-restricted-imports-clone
|
||||||
|
import {StackTrace} from 'flipper';
|
||||||
|
import {Tag} from '../../../types';
|
||||||
|
|
||||||
|
const FacebookLibraries = ['Facebook'];
|
||||||
|
const CKFilter = ['UIDCKAnalyticsListener'];
|
||||||
|
|
||||||
|
const REGEX =
|
||||||
|
/\d+\s+(?<library>[\s\w\.]+\w)\s+(?<address>0x\w+?)\s+(?<caller>.+) \+ (?<lineNumber>\d+)/;
|
||||||
|
|
||||||
|
function isSystemLibrary(libraryName: string | null | undefined): boolean {
|
||||||
|
return libraryName ? !FacebookLibraries.includes(libraryName) : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
stacktrace: string[];
|
||||||
|
tags: Tag[];
|
||||||
|
};
|
||||||
|
export const StackTraceInspector: React.FC<Props> = ({stacktrace, tags}) => {
|
||||||
|
const filters = tags.includes('CK') ? CKFilter : [];
|
||||||
|
return (
|
||||||
|
<StackTrace>
|
||||||
|
{stacktrace
|
||||||
|
?.filter((line) => filters.every((filter) => !line.includes(filter)))
|
||||||
|
.map((line) => {
|
||||||
|
const trace = REGEX.exec(line)?.groups;
|
||||||
|
return {
|
||||||
|
bold: !isSystemLibrary(trace?.library),
|
||||||
|
library: trace?.library,
|
||||||
|
address: trace?.address,
|
||||||
|
caller: trace?.caller,
|
||||||
|
lineNumber: trace?.lineNumber,
|
||||||
|
};
|
||||||
|
}) ?? [{caller: 'No stacktrace available'}]}
|
||||||
|
</StackTrace>
|
||||||
|
);
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user