| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | import type {ReactNode} from 'react'; |
| b69ab31 | | | 9 | import type {ExclusiveOr} from 'shared/typeUtils'; |
| b69ab31 | | | 10 | import type {Heartbeat} from '../heartbeat'; |
| b69ab31 | | | 11 | |
| b69ab31 | | | 12 | import * as stylex from '@stylexjs/stylex'; |
| b69ab31 | | | 13 | import {Badge} from 'isl-components/Badge'; |
| b69ab31 | | | 14 | import {Banner, BannerKind} from 'isl-components/Banner'; |
| b69ab31 | | | 15 | import {Button} from 'isl-components/Button'; |
| b69ab31 | | | 16 | import {Checkbox} from 'isl-components/Checkbox'; |
| b69ab31 | | | 17 | import {InlineErrorBadge} from 'isl-components/ErrorNotice'; |
| b69ab31 | | | 18 | import {Icon} from 'isl-components/Icon'; |
| b69ab31 | | | 19 | import {Subtle} from 'isl-components/Subtle'; |
| b69ab31 | | | 20 | import {Tooltip} from 'isl-components/Tooltip'; |
| b69ab31 | | | 21 | import {atom, useAtom, useAtomValue} from 'jotai'; |
| b69ab31 | | | 22 | import {useCallback, useEffect, useState} from 'react'; |
| b69ab31 | | | 23 | import {colors} from '../../../components/theme/tokens.stylex'; |
| b69ab31 | | | 24 | import serverApi, {debugLogMessageTraffic} from '../ClientToServerAPI'; |
| b69ab31 | | | 25 | import {Column, Row} from '../ComponentUtils'; |
| b69ab31 | | | 26 | import {DropdownField, DropdownFields} from '../DropdownFields'; |
| b69ab31 | | | 27 | import {enableReactTools, enableReduxTools} from '../atoms/debugToolAtoms'; |
| b69ab31 | | | 28 | import {holdingCtrlAtom} from '../atoms/keyboardAtoms'; |
| b69ab31 | | | 29 | import {DagCommitInfo} from '../dag/dagCommitInfo'; |
| b69ab31 | | | 30 | import {useHeartbeat} from '../heartbeat'; |
| b69ab31 | | | 31 | import {t, T} from '../i18n'; |
| b69ab31 | | | 32 | import {atomWithOnChange} from '../jotaiUtils'; |
| b69ab31 | | | 33 | import {NopOperation} from '../operations/NopOperation'; |
| b69ab31 | | | 34 | import {useRunOperation} from '../operationsState'; |
| b69ab31 | | | 35 | import platform from '../platform'; |
| b69ab31 | | | 36 | import {dagWithPreviews} from '../previews'; |
| b69ab31 | | | 37 | import {RelativeDate} from '../relativeDate'; |
| b69ab31 | | | 38 | import { |
| b69ab31 | | | 39 | latestCommitsData, |
| b69ab31 | | | 40 | latestUncommittedChangesData, |
| b69ab31 | | | 41 | mainCommandName, |
| b69ab31 | | | 42 | mergeConflicts, |
| b69ab31 | | | 43 | } from '../serverAPIState'; |
| b69ab31 | | | 44 | import {showToast} from '../toast'; |
| b69ab31 | | | 45 | import {isDev} from '../utils'; |
| b69ab31 | | | 46 | import {ComponentExplorerButton} from './ComponentExplorer'; |
| b69ab31 | | | 47 | import {readInterestingAtoms, serializeAtomsState} from './getInterestingAtoms'; |
| b69ab31 | | | 48 | |
| b69ab31 | | | 49 | import './DebugToolsMenu.css'; |
| b69ab31 | | | 50 | |
| b69ab31 | | | 51 | /* eslint-disable no-console */ |
| b69ab31 | | | 52 | |
| b69ab31 | | | 53 | export default function DebugToolsMenu({dismiss}: {dismiss: () => unknown}) { |
| b69ab31 | | | 54 | return ( |
| b69ab31 | | | 55 | <DropdownFields |
| b69ab31 | | | 56 | title={<T>Internal Debugging Tools</T>} |
| b69ab31 | | | 57 | icon="pulse" |
| b69ab31 | | | 58 | data-testid="internal-debug-tools-dropdown" |
| b69ab31 | | | 59 | className="internal-debug-tools-dropdown"> |
| b69ab31 | | | 60 | <Subtle> |
| b69ab31 | | | 61 | <T> |
| b69ab31 | | | 62 | This data is only intended for debugging Interactive Smartlog and may not capture all |
| b69ab31 | | | 63 | issues. |
| b69ab31 | | | 64 | </T> |
| b69ab31 | | | 65 | </Subtle> |
| b69ab31 | | | 66 | <DropdownField title={<T>Performance</T>}> |
| b69ab31 | | | 67 | <DebugPerfInfo /> |
| b69ab31 | | | 68 | </DropdownField> |
| b69ab31 | | | 69 | <DropdownField title={<T>Commit graph</T>}> |
| b69ab31 | | | 70 | <DebugDagInfo /> |
| b69ab31 | | | 71 | </DropdownField> |
| b69ab31 | | | 72 | <DropdownField title={<T>Internal State</T>}> |
| b69ab31 | | | 73 | <InternalState /> |
| b69ab31 | | | 74 | </DropdownField> |
| b69ab31 | | | 75 | <DropdownField title={<T>Server/Client Messages</T>}> |
| b69ab31 | | | 76 | <Column alignStart> |
| b69ab31 | | | 77 | <ServerClientMessageLogging /> |
| b69ab31 | | | 78 | <Row> |
| b69ab31 | | | 79 | <ForceDisconnectButton /> |
| b69ab31 | | | 80 | <NopOperationButtons /> |
| b69ab31 | | | 81 | </Row> |
| b69ab31 | | | 82 | <Row> |
| b69ab31 | | | 83 | <StressTestMessages /> |
| b69ab31 | | | 84 | </Row> |
| b69ab31 | | | 85 | </Column> |
| b69ab31 | | | 86 | </DropdownField> |
| b69ab31 | | | 87 | <DropdownField title={<T>Component Explorer</T>}> |
| b69ab31 | | | 88 | <ComponentExplorerButton dismiss={dismiss} /> |
| b69ab31 | | | 89 | </DropdownField> |
| b69ab31 | | | 90 | </DropdownFields> |
| b69ab31 | | | 91 | ); |
| b69ab31 | | | 92 | } |
| b69ab31 | | | 93 | |
| b69ab31 | | | 94 | function nextTick(): Promise<void> { |
| b69ab31 | | | 95 | return new Promise(res => setTimeout(res, 0)); |
| b69ab31 | | | 96 | } |
| b69ab31 | | | 97 | |
| b69ab31 | | | 98 | const stressTestAtom = atom<{progressPct: number | null; mismatches: Array<number>}>({ |
| b69ab31 | | | 99 | progressPct: null, |
| b69ab31 | | | 100 | mismatches: [], |
| b69ab31 | | | 101 | }); |
| b69ab31 | | | 102 | /** Look for out of order message passing by sending thousands of messages and verifying their ordering */ |
| b69ab31 | | | 103 | function StressTestMessages() { |
| b69ab31 | | | 104 | const [result, setResult] = useAtom(stressTestAtom); |
| b69ab31 | | | 105 | |
| b69ab31 | | | 106 | const N = 100_000; |
| b69ab31 | | | 107 | // how many messages to send before pausing an async tick |
| b69ab31 | | | 108 | const tickEvery = 5_000; |
| b69ab31 | | | 109 | |
| b69ab31 | | | 110 | const ONE_KILOBYTE = 1000; |
| b69ab31 | | | 111 | // how large of a string payload to add to each message |
| b69ab31 | | | 112 | const payloadSize = 1.0 * ONE_KILOBYTE; |
| b69ab31 | | | 113 | |
| b69ab31 | | | 114 | const enableLogging = false; |
| b69ab31 | | | 115 | |
| b69ab31 | | | 116 | return ( |
| b69ab31 | | | 117 | <> |
| b69ab31 | | | 118 | <Button |
| b69ab31 | | | 119 | disabled={result.progressPct != null && result.progressPct !== 100} |
| b69ab31 | | | 120 | onClick={async () => { |
| b69ab31 | | | 121 | const log = enableLogging ? console.log : () => null; |
| b69ab31 | | | 122 | |
| b69ab31 | | | 123 | setResult({ |
| b69ab31 | | | 124 | progressPct: null, |
| b69ab31 | | | 125 | mismatches: [], |
| b69ab31 | | | 126 | }); |
| b69ab31 | | | 127 | await nextTick(); |
| b69ab31 | | | 128 | |
| b69ab31 | | | 129 | log(' ------ Begin Stress ------'); |
| b69ab31 | | | 130 | const payload = 'a'.repeat(payloadSize); |
| b69ab31 | | | 131 | |
| b69ab31 | | | 132 | let lastReceivedId = 0; |
| b69ab31 | | | 133 | const dispose = serverApi.onMessageOfType('stress', ({id, time}) => { |
| b69ab31 | | | 134 | log(' < ', id, time); |
| b69ab31 | | | 135 | if (id !== lastReceivedId + 1) { |
| b69ab31 | | | 136 | setResult(last => ({...last, mismatches: [...last.mismatches, id]})); |
| b69ab31 | | | 137 | } |
| b69ab31 | | | 138 | lastReceivedId = id; |
| b69ab31 | | | 139 | |
| b69ab31 | | | 140 | setResult(last => ({...last, progressPct: (100 * id) / N})); |
| b69ab31 | | | 141 | if (id == N) { |
| b69ab31 | | | 142 | dispose.dispose(); |
| b69ab31 | | | 143 | setResult(last => ({...last, progressPct: 100})); // if last message was out of order, we'd get stuck |
| b69ab31 | | | 144 | log(' ------ End Stress ------'); |
| b69ab31 | | | 145 | } |
| b69ab31 | | | 146 | }); |
| b69ab31 | | | 147 | |
| b69ab31 | | | 148 | for (let id = 1; id <= N; id++) { |
| b69ab31 | | | 149 | if (id % tickEvery === 0) { |
| b69ab31 | | | 150 | // eslint-disable-next-line no-await-in-loop |
| b69ab31 | | | 151 | await nextTick(); |
| b69ab31 | | | 152 | } |
| b69ab31 | | | 153 | serverApi.postMessage({ |
| b69ab31 | | | 154 | type: 'stress', |
| b69ab31 | | | 155 | id, |
| b69ab31 | | | 156 | time: new Date().valueOf(), |
| b69ab31 | | | 157 | message: payload, |
| b69ab31 | | | 158 | }); |
| b69ab31 | | | 159 | log(' > ', id); |
| b69ab31 | | | 160 | } |
| b69ab31 | | | 161 | }}> |
| b69ab31 | | | 162 | <T>Message Stress Test</T> |
| b69ab31 | | | 163 | </Button> |
| b69ab31 | | | 164 | {result.progressPct == null ? null : result.progressPct < 100 ? ( |
| b69ab31 | | | 165 | <Row style={{fontVariant: 'tabular-nums'}}> |
| b69ab31 | | | 166 | <Icon icon="loading" /> {Math.round(result.progressPct)}% |
| b69ab31 | | | 167 | </Row> |
| b69ab31 | | | 168 | ) : ( |
| b69ab31 | | | 169 | <Tooltip title={t(`Sent ${N} messages, with ${result.mismatches.length} out of order`)}> |
| b69ab31 | | | 170 | {result.mismatches.length === 0 ? ( |
| b69ab31 | | | 171 | <Icon icon="pass" color="green" /> |
| b69ab31 | | | 172 | ) : ( |
| b69ab31 | | | 173 | <Icon icon="error" color="red" /> |
| b69ab31 | | | 174 | )} |
| b69ab31 | | | 175 | </Tooltip> |
| b69ab31 | | | 176 | )} |
| b69ab31 | | | 177 | {result.mismatches.length === 0 ? null : ( |
| b69ab31 | | | 178 | <Banner kind={BannerKind.error}>{result.mismatches.join(',')}</Banner> |
| b69ab31 | | | 179 | )} |
| b69ab31 | | | 180 | </> |
| b69ab31 | | | 181 | ); |
| b69ab31 | | | 182 | } |
| b69ab31 | | | 183 | |
| b69ab31 | | | 184 | function InternalState() { |
| b69ab31 | | | 185 | const [reduxTools, setReduxTools] = useAtom(enableReduxTools); |
| b69ab31 | | | 186 | const [reactTools, setReactTools] = useAtom(enableReactTools); |
| b69ab31 | | | 187 | const needSerialize = useAtomValue(holdingCtrlAtom); |
| b69ab31 | | | 188 | |
| b69ab31 | | | 189 | const generate = () => { |
| b69ab31 | | | 190 | // No need for useAtomValue - no need to re-render or recalculate this function. |
| b69ab31 | | | 191 | const atomsState = readInterestingAtoms(); |
| b69ab31 | | | 192 | const value = needSerialize ? serializeAtomsState(atomsState) : atomsState; |
| b69ab31 | | | 193 | console.log(`jotai state (${needSerialize ? 'JSON' : 'objects'}):`, value); |
| b69ab31 | | | 194 | showToast(`logged jotai state to console!${needSerialize ? ' (serialized)' : ''}`); |
| b69ab31 | | | 195 | }; |
| b69ab31 | | | 196 | |
| b69ab31 | | | 197 | return ( |
| b69ab31 | | | 198 | <Column alignStart> |
| b69ab31 | | | 199 | <Row> |
| b69ab31 | | | 200 | <Tooltip |
| b69ab31 | | | 201 | placement="bottom" |
| b69ab31 | | | 202 | title={t( |
| b69ab31 | | | 203 | 'Capture a snapshot of selected Jotai atom states, log it to the dev tools console.\n\n' + |
| b69ab31 | | | 204 | 'Hold Ctrl to use serialized JSON instead of Javascript objects.', |
| b69ab31 | | | 205 | )}> |
| b69ab31 | | | 206 | <Button onClick={generate}> |
| b69ab31 | | | 207 | {needSerialize ? <T>Take Snapshot (JSON)</T> : <T>Take Snapshot (objects)</T>} |
| b69ab31 | | | 208 | </Button> |
| b69ab31 | | | 209 | </Tooltip> |
| b69ab31 | | | 210 | <Tooltip |
| b69ab31 | | | 211 | placement="bottom" |
| b69ab31 | | | 212 | title={t( |
| b69ab31 | | | 213 | 'Log persisted state (localStorage or vscode storage) to the dev tools console.', |
| b69ab31 | | | 214 | )}> |
| b69ab31 | | | 215 | <Button |
| b69ab31 | | | 216 | onClick={() => { |
| b69ab31 | | | 217 | console.log('persisted state:', platform.getAllPersistedState()); |
| b69ab31 | | | 218 | showToast('logged persisted state to console!'); |
| b69ab31 | | | 219 | }}> |
| b69ab31 | | | 220 | <T>Log Persisted State</T> |
| b69ab31 | | | 221 | </Button> |
| b69ab31 | | | 222 | </Tooltip> |
| b69ab31 | | | 223 | <Tooltip |
| b69ab31 | | | 224 | placement="bottom" |
| b69ab31 | | | 225 | title={t( |
| b69ab31 | | | 226 | 'Clear any persisted state (localStorage or vscode storage). Usually only matters after restarting.', |
| b69ab31 | | | 227 | )}> |
| b69ab31 | | | 228 | <Button |
| b69ab31 | | | 229 | onClick={() => { |
| b69ab31 | | | 230 | platform.clearPersistedState(); |
| b69ab31 | | | 231 | console.log('--- cleared isl persisted state ---'); |
| b69ab31 | | | 232 | showToast('cleared persisted state'); |
| b69ab31 | | | 233 | }}> |
| b69ab31 | | | 234 | <T>Clear Persisted State</T> |
| b69ab31 | | | 235 | </Button> |
| b69ab31 | | | 236 | </Tooltip> |
| b69ab31 | | | 237 | </Row> |
| b69ab31 | | | 238 | {isDev && ( |
| b69ab31 | | | 239 | <Row> |
| b69ab31 | | | 240 | <T>Integrate with: </T> |
| b69ab31 | | | 241 | <Checkbox checked={reduxTools} onChange={setReduxTools}> |
| b69ab31 | | | 242 | <T>Redux DevTools</T> |
| b69ab31 | | | 243 | </Checkbox> |
| b69ab31 | | | 244 | <Checkbox checked={reactTools} onChange={setReactTools}> |
| b69ab31 | | | 245 | {t('React <DebugAtoms/>')} |
| b69ab31 | | | 246 | </Checkbox> |
| b69ab31 | | | 247 | </Row> |
| b69ab31 | | | 248 | )} |
| b69ab31 | | | 249 | </Column> |
| b69ab31 | | | 250 | ); |
| b69ab31 | | | 251 | } |
| b69ab31 | | | 252 | |
| b69ab31 | | | 253 | const logMessagesState = atomWithOnChange( |
| b69ab31 | | | 254 | atom(debugLogMessageTraffic.shouldLog), |
| b69ab31 | | | 255 | newValue => { |
| b69ab31 | | | 256 | debugLogMessageTraffic.shouldLog = newValue; |
| b69ab31 | | | 257 | console.log(`----- ${newValue ? 'Enabled' : 'Disabled'} Logging Messages -----`); |
| b69ab31 | | | 258 | }, |
| b69ab31 | | | 259 | /* skipInitialCall */ true, |
| b69ab31 | | | 260 | ); |
| b69ab31 | | | 261 | |
| b69ab31 | | | 262 | function ServerClientMessageLogging() { |
| b69ab31 | | | 263 | const [shouldLog, setShouldLog] = useAtom(logMessagesState); |
| b69ab31 | | | 264 | return ( |
| b69ab31 | | | 265 | <div> |
| b69ab31 | | | 266 | <Checkbox checked={shouldLog} onChange={checked => setShouldLog(checked)}> |
| b69ab31 | | | 267 | <T>Log messages</T> |
| b69ab31 | | | 268 | </Checkbox> |
| b69ab31 | | | 269 | </div> |
| b69ab31 | | | 270 | ); |
| b69ab31 | | | 271 | } |
| b69ab31 | | | 272 | |
| b69ab31 | | | 273 | function DebugPerfInfo() { |
| b69ab31 | | | 274 | const latestStatus = useAtomValue(latestUncommittedChangesData); |
| b69ab31 | | | 275 | const latestLog = useAtomValue(latestCommitsData); |
| b69ab31 | | | 276 | const latestConflicts = useAtomValue(mergeConflicts); |
| b69ab31 | | | 277 | const heartbeat = useHeartbeat(); |
| b69ab31 | | | 278 | const commandName = useAtomValue(mainCommandName); |
| b69ab31 | | | 279 | return ( |
| b69ab31 | | | 280 | <div> |
| b69ab31 | | | 281 | {heartbeat.type === 'timeout' ? ( |
| b69ab31 | | | 282 | <InlineErrorBadge error={new Error(t('Heartbeat timeout'))}> |
| b69ab31 | | | 283 | <T>Heartbeat timed out</T> |
| b69ab31 | | | 284 | </InlineErrorBadge> |
| b69ab31 | | | 285 | ) : ( |
| b69ab31 | | | 286 | <FetchDurationInfo |
| b69ab31 | | | 287 | name={<T>ISL Server Ping</T>} |
| b69ab31 | | | 288 | duration={(heartbeat as Heartbeat & {type: 'success'})?.rtt} |
| b69ab31 | | | 289 | /> |
| b69ab31 | | | 290 | )} |
| b69ab31 | | | 291 | <FetchDurationInfo |
| b69ab31 | | | 292 | name={<T replace={{$cmd: commandName}}>$cmd status</T>} |
| b69ab31 | | | 293 | start={latestStatus.fetchStartTimestamp} |
| b69ab31 | | | 294 | end={latestStatus.fetchCompletedTimestamp} |
| b69ab31 | | | 295 | /> |
| b69ab31 | | | 296 | <FetchDurationInfo |
| b69ab31 | | | 297 | name={<T replace={{$cmd: commandName}}>$cmd log</T>} |
| b69ab31 | | | 298 | start={latestLog.fetchStartTimestamp} |
| b69ab31 | | | 299 | end={latestLog.fetchCompletedTimestamp} |
| b69ab31 | | | 300 | /> |
| b69ab31 | | | 301 | <FetchDurationInfo |
| b69ab31 | | | 302 | name={<T>Merge Conflicts</T>} |
| b69ab31 | | | 303 | start={latestConflicts?.fetchStartTimestamp} |
| b69ab31 | | | 304 | end={latestConflicts?.fetchCompletedTimestamp} |
| b69ab31 | | | 305 | /> |
| b69ab31 | | | 306 | </div> |
| b69ab31 | | | 307 | ); |
| b69ab31 | | | 308 | } |
| b69ab31 | | | 309 | |
| b69ab31 | | | 310 | const styles = stylex.create({ |
| b69ab31 | | | 311 | slow: { |
| b69ab31 | | | 312 | color: colors.signalFg, |
| b69ab31 | | | 313 | backgroundColor: colors.signalBadBg, |
| b69ab31 | | | 314 | }, |
| b69ab31 | | | 315 | ok: { |
| b69ab31 | | | 316 | color: colors.signalFg, |
| b69ab31 | | | 317 | backgroundColor: colors.signalMediumBg, |
| b69ab31 | | | 318 | }, |
| b69ab31 | | | 319 | fast: { |
| b69ab31 | | | 320 | color: colors.signalFg, |
| b69ab31 | | | 321 | backgroundColor: colors.signalGoodBg, |
| b69ab31 | | | 322 | }, |
| b69ab31 | | | 323 | }); |
| b69ab31 | | | 324 | |
| b69ab31 | | | 325 | function FetchDurationInfo( |
| b69ab31 | | | 326 | props: {name: ReactNode} & ExclusiveOr<{start?: number; end?: number}, {duration: number}>, |
| b69ab31 | | | 327 | ) { |
| b69ab31 | | | 328 | const {name} = props; |
| b69ab31 | | | 329 | const {end, start, duration} = props; |
| b69ab31 | | | 330 | const deltaMs = duration != null ? duration : end == null || start == null ? null : end - start; |
| b69ab31 | | | 331 | const xstyle = |
| b69ab31 | | | 332 | deltaMs == null |
| b69ab31 | | | 333 | ? undefined |
| b69ab31 | | | 334 | : deltaMs < 1000 |
| b69ab31 | | | 335 | ? styles.fast |
| b69ab31 | | | 336 | : deltaMs < 3000 |
| b69ab31 | | | 337 | ? styles.ok |
| b69ab31 | | | 338 | : styles.slow; |
| b69ab31 | | | 339 | return ( |
| b69ab31 | | | 340 | <div className={`fetch-duration-info`}> |
| b69ab31 | | | 341 | {name} <Badge xstyle={xstyle}>{deltaMs == null ? 'N/A' : `${deltaMs}ms`}</Badge> |
| b69ab31 | | | 342 | {end == null ? null : ( |
| b69ab31 | | | 343 | <Subtle> |
| b69ab31 | | | 344 | <Tooltip title={new Date(end).toLocaleString()} placement="right"> |
| b69ab31 | | | 345 | <RelativeDate date={end} /> |
| b69ab31 | | | 346 | </Tooltip> |
| b69ab31 | | | 347 | </Subtle> |
| b69ab31 | | | 348 | )} |
| b69ab31 | | | 349 | </div> |
| b69ab31 | | | 350 | ); |
| b69ab31 | | | 351 | } |
| b69ab31 | | | 352 | |
| b69ab31 | | | 353 | function useMeasureDuration(slowOperation: () => void): number | null { |
| b69ab31 | | | 354 | const [measured, setMeasured] = useState<null | number>(null); |
| b69ab31 | | | 355 | useEffect(() => { |
| b69ab31 | | | 356 | requestIdleCallback(() => { |
| b69ab31 | | | 357 | const startTime = performance.now(); |
| b69ab31 | | | 358 | slowOperation(); |
| b69ab31 | | | 359 | const endTime = performance.now(); |
| b69ab31 | | | 360 | setMeasured(endTime - startTime); |
| b69ab31 | | | 361 | }); |
| b69ab31 | | | 362 | return () => setMeasured(null); |
| b69ab31 | | | 363 | }, [slowOperation]); |
| b69ab31 | | | 364 | return measured; |
| b69ab31 | | | 365 | } |
| b69ab31 | | | 366 | |
| b69ab31 | | | 367 | function DebugDagInfo() { |
| b69ab31 | | | 368 | const dag = useAtomValue(dagWithPreviews); |
| b69ab31 | | | 369 | const dagRenderBenchmark = useCallback(() => { |
| b69ab31 | | | 370 | // Slightly change the dag to invalidate its caches. |
| b69ab31 | | | 371 | const noise = performance.now(); |
| b69ab31 | | | 372 | const newDag = dag.add([DagCommitInfo.fromCommitInfo({hash: `dummy-${noise}`, parents: []})]); |
| b69ab31 | | | 373 | newDag.renderToRows(newDag.subsetForRendering()); |
| b69ab31 | | | 374 | }, [dag]); |
| b69ab31 | | | 375 | |
| b69ab31 | | | 376 | const dagSize = dag.all().size; |
| b69ab31 | | | 377 | const dagDisplayedSize = dag.subsetForRendering().size; |
| b69ab31 | | | 378 | const dagSortMs = useMeasureDuration(dagRenderBenchmark); |
| b69ab31 | | | 379 | |
| b69ab31 | | | 380 | return ( |
| b69ab31 | | | 381 | <div> |
| b69ab31 | | | 382 | <T>Size: </T> |
| b69ab31 | | | 383 | {dagSize} |
| b69ab31 | | | 384 | <br /> |
| b69ab31 | | | 385 | <T>Displayed: </T> |
| b69ab31 | | | 386 | {dagDisplayedSize} |
| b69ab31 | | | 387 | <br /> |
| b69ab31 | | | 388 | <> |
| b69ab31 | | | 389 | <T>Render calculation: </T> |
| b69ab31 | | | 390 | {dagSortMs == null ? ( |
| b69ab31 | | | 391 | <T>(Measuring)</T> |
| b69ab31 | | | 392 | ) : ( |
| b69ab31 | | | 393 | <> |
| b69ab31 | | | 394 | {dagSortMs.toFixed(1)} <T>ms</T> |
| b69ab31 | | | 395 | </> |
| b69ab31 | | | 396 | )} |
| b69ab31 | | | 397 | <br /> |
| b69ab31 | | | 398 | </> |
| b69ab31 | | | 399 | </div> |
| b69ab31 | | | 400 | ); |
| b69ab31 | | | 401 | } |
| b69ab31 | | | 402 | |
| b69ab31 | | | 403 | const forceDisconnectDuration = atom<number>(3000); |
| b69ab31 | | | 404 | |
| b69ab31 | | | 405 | function ForceDisconnectButton() { |
| b69ab31 | | | 406 | const [duration, setDuration] = useAtom(forceDisconnectDuration); |
| b69ab31 | | | 407 | const forceDisconnect = platform.messageBus.forceDisconnect?.bind(platform.messageBus); |
| b69ab31 | | | 408 | if (forceDisconnect == null) { |
| b69ab31 | | | 409 | return null; |
| b69ab31 | | | 410 | } |
| b69ab31 | | | 411 | return ( |
| b69ab31 | | | 412 | <Button |
| b69ab31 | | | 413 | onClick={() => forceDisconnect(duration)} |
| b69ab31 | | | 414 | onWheel={e => { |
| b69ab31 | | | 415 | // deltaY is usually -100 +100 per event. |
| b69ab31 | | | 416 | const dy = e.deltaY; |
| b69ab31 | | | 417 | const scale = duration < 20000 ? 10 : 100; |
| b69ab31 | | | 418 | if (dy > 0) { |
| b69ab31 | | | 419 | setDuration(v => Math.max(v - dy * scale, 1000)); |
| b69ab31 | | | 420 | } else if (dy < 0) { |
| b69ab31 | | | 421 | setDuration(v => Math.min(v - dy * scale, 300000)); |
| b69ab31 | | | 422 | } |
| b69ab31 | | | 423 | }}> |
| b69ab31 | | | 424 | <T replace={{$sec: (duration / 1000).toFixed(1)}}>Force disconnect for $sec seconds</T> |
| b69ab31 | | | 425 | </Button> |
| b69ab31 | | | 426 | ); |
| b69ab31 | | | 427 | } |
| b69ab31 | | | 428 | |
| b69ab31 | | | 429 | function NopOperationButtons() { |
| b69ab31 | | | 430 | const runOperation = useRunOperation(); |
| b69ab31 | | | 431 | return ( |
| b69ab31 | | | 432 | <> |
| b69ab31 | | | 433 | {[2, 5, 20].map(durationSeconds => ( |
| b69ab31 | | | 434 | <Button |
| b69ab31 | | | 435 | key={durationSeconds} |
| b69ab31 | | | 436 | onClick={() => runOperation(new NopOperation(durationSeconds))}> |
| b69ab31 | | | 437 | <T replace={{$sec: durationSeconds}}>Nop $sec s</T> |
| b69ab31 | | | 438 | </Button> |
| b69ab31 | | | 439 | ))} |
| b69ab31 | | | 440 | </> |
| b69ab31 | | | 441 | ); |
| b69ab31 | | | 442 | } |