Skip to content

Commit

Permalink
Add main thread filter control
Browse files Browse the repository at this point in the history
Summary: This adds a filter on top of the event types to only highlight when the thread occurs on the main thread

Reviewed By: lblasa

Differential Revision: D47520036

fbshipit-source-id: b4a67b262345d845e5dcbf79bba5a210c1bca4f8
  • Loading branch information
Luke De Feo authored and facebook-github-bot committed Jul 19, 2023
1 parent 5ef3768 commit ff71825
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
30 changes: 30 additions & 0 deletions desktop/plugins/public/ui-debugger/components/Controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
Typography,
TreeSelect,
Space,
Switch,
} from 'antd';
import {
MoreOutlined,
Expand All @@ -39,6 +40,9 @@ export const Controls: React.FC = () => {
const instance = usePlugin(plugin);
const searchTerm = useValue(instance.uiState.searchTerm);
const isPaused = useValue(instance.uiState.isPaused);
const filterMainThreadMonitoring = useValue(
instance.uiState.filterMainThreadMonitoring,
);

const frameworkEventMonitoring: Map<FrameworkEventType, boolean> = useValue(
instance.uiState.frameworkEventMonitoring,
Expand Down Expand Up @@ -81,6 +85,10 @@ export const Controls: React.FC = () => {
}></Button>
{frameworkEventMonitoring.size > 0 && (
<MoreOptionsMenu
filterMainThreadMonitoring={filterMainThreadMonitoring}
onSetFilterMainThreadMonitoring={
instance.uiActions.onSetFilterMainThreadMonitoring
}
onSetEventMonitored={onSetEventMonitored}
frameworkEventTypes={[...frameworkEventMonitoring.entries()]}
/>
Expand All @@ -92,7 +100,11 @@ export const Controls: React.FC = () => {
function MoreOptionsMenu({
onSetEventMonitored,
frameworkEventTypes,
filterMainThreadMonitoring,
onSetFilterMainThreadMonitoring,
}: {
filterMainThreadMonitoring: boolean;
onSetFilterMainThreadMonitoring: (toggled: boolean) => void;
onSetEventMonitored: (
eventType: FrameworkEventType,
monitored: boolean,
Expand Down Expand Up @@ -126,6 +138,8 @@ function MoreOptionsMenu({

{/*invisible until shown*/}
<FrameworkEventsMonitoringModal
filterMainThreadMonitoring={filterMainThreadMonitoring}
onSetFilterMainThreadMonitoring={onSetFilterMainThreadMonitoring}
frameworkEventTypes={frameworkEventTypes}
onSetEventMonitored={onSetEventMonitored}
visible={showFrameworkEventsModal}
Expand All @@ -139,6 +153,8 @@ function FrameworkEventsMonitoringModal({
visible,
onCancel,
onSetEventMonitored,
onSetFilterMainThreadMonitoring,
filterMainThreadMonitoring,
frameworkEventTypes,
}: {
visible: boolean;
Expand All @@ -147,6 +163,8 @@ function FrameworkEventsMonitoringModal({
eventType: FrameworkEventType,
monitored: boolean,
) => void;
filterMainThreadMonitoring: boolean;
onSetFilterMainThreadMonitoring: (toggled: boolean) => void;
frameworkEventTypes: [FrameworkEventType, boolean][];
}) {
const selectedFrameworkEvents = frameworkEventTypes
Expand Down Expand Up @@ -193,6 +211,18 @@ function FrameworkEventsMonitoringModal({
}
}}
/>

<Layout.Horizontal gap="medium">
<Switch
checked={filterMainThreadMonitoring}
onChange={(event) => {
onSetFilterMainThreadMonitoring(event);
}}
/>
<Typography.Text>
Only highlight events that occured on the main thread
</Typography.Text>
</Layout.Horizontal>
</Space>
</Modal>
);
Expand Down
12 changes: 11 additions & 1 deletion desktop/plugins/public/ui-debugger/components/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export function Tree2({nodes, rootId}: {nodes: Map<Id, UINode>; rootId: Id}) {
const hoveredNode = head(useValue(instance.uiState.hoveredNodes));

const frameworkEvents = useValue(instance.frameworkEvents);
const filterMainThreadMonitoring = useValue(
instance.uiState.filterMainThreadMonitoring,
);
const frameworkEventsMonitoring = useValue(
instance.uiState.frameworkEventMonitoring,
);
Expand Down Expand Up @@ -239,6 +242,7 @@ export function Tree2({nodes, rootId}: {nodes: Map<Id, UINode>; rootId: Id}) {
treeNode={treeNodes[virtualRow.index]}
frameworkEvents={frameworkEvents}
frameworkEventsMonitoring={frameworkEventsMonitoring}
filterMainThreadMonitoring={filterMainThreadMonitoring}
highlightedNodes={highlightedNodes}
selectedNode={selectedNode?.id}
hoveredNode={hoveredNode}
Expand Down Expand Up @@ -290,6 +294,7 @@ function TreeItemContainer({
treeNode,
frameworkEvents,
frameworkEventsMonitoring,
filterMainThreadMonitoring,
highlightedNodes,
selectedNode,
hoveredNode,
Expand All @@ -306,6 +311,7 @@ function TreeItemContainer({
frameworkEvents: Map<Id, FrameworkEvent[]>;
highlightedNodes: Set<Id>;
frameworkEventsMonitoring: Map<FrameworkEventType, boolean>;
filterMainThreadMonitoring: boolean;
selectedNode?: Id;
hoveredNode?: Id;
isUsingKBToScroll: RefObject<MillisSinceEpoch>;
Expand All @@ -317,7 +323,11 @@ function TreeItemContainer({
}) {
let events = frameworkEvents.get(treeNode.id);
if (events) {
events = events.filter((e) => frameworkEventsMonitoring.get(e.type));
events = events
.filter((e) => frameworkEventsMonitoring.get(e.type))
.filter(
(e) => filterMainThreadMonitoring === false || e.thread === 'main',
);
}

return (
Expand Down
12 changes: 12 additions & 0 deletions desktop/plugins/public/ui-debugger/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export function plugin(client: PluginClient<Events>) {
frameworkEventMonitoring: createState(
new Map<FrameworkEventType, boolean>(),
),
filterMainThreadMonitoring: createState(false),

isPaused: createState(false),

Expand Down Expand Up @@ -297,11 +298,17 @@ export function plugin(client: PluginClient<Events>) {

const monitoredEvents = uiState.frameworkEventMonitoring.get();

const filterMainThread = uiState.filterMainThreadMonitoring.get();

const nodesToHighlight =
frameScan.frameworkEvents
?.filter(
(frameworkEvent) => monitoredEvents.get(frameworkEvent.type) === true,
)
.filter(
(frameworkEvent) =>
filterMainThread === false || frameworkEvent.thread === 'main',
)
.map((event) => event.nodeId) ?? [];

highlightedNodes.update((draft) => {
Expand Down Expand Up @@ -456,6 +463,10 @@ function uiActions(uiState: UIState, nodes: Atom<Map<Id, UINode>>): UIActions {
uiState.visualiserWidth.set(width);
};

const onSetFilterMainThreadMonitoring = (toggled: boolean) => {
uiState.filterMainThreadMonitoring.set(toggled);
};

return {
onExpandNode,
onCollapseNode,
Expand All @@ -464,6 +475,7 @@ function uiActions(uiState: UIState, nodes: Atom<Map<Id, UINode>>): UIActions {
onContextMenuOpen,
onFocusNode,
setVisualiserWidth,
onSetFilterMainThreadMonitoring,
};
}

Expand Down
3 changes: 3 additions & 0 deletions desktop/plugins/public/ui-debugger/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type UIState = {
expandedNodes: Atom<Set<Id>>;
visualiserWidth: Atom<number>;
frameworkEventMonitoring: Atom<Map<FrameworkEventType, boolean>>;
filterMainThreadMonitoring: Atom<boolean>;
};

export type NodeSelection = {
Expand All @@ -42,6 +43,7 @@ export type UIActions = {
onExpandNode: (node: Id) => void;
onCollapseNode: (node: Id) => void;
setVisualiserWidth: (width: number) => void;
onSetFilterMainThreadMonitoring: (toggled: boolean) => void;
};
export type SelectionSource = 'visualiser' | 'tree' | 'keyboard';

Expand Down Expand Up @@ -113,6 +115,7 @@ export type FrameworkEvent = {
timestamp: number;
payload?: JSON;
attribution?: FrameworkEventAttribution;
thread?: 'main' | string;
};

export type InitEvent = {
Expand Down

0 comments on commit ff71825

Please sign in to comment.