1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  * @flow
    
  8.  */
    
  9. 
    
  10. import type {ScrollState} from './view-base/utils/scrollState';
    
  11. 
    
  12. // Source: https://github.com/facebook/flow/issues/4002#issuecomment-323612798
    
  13. // eslint-disable-next-line no-unused-vars
    
  14. type Return_<R, F: (...args: Array<any>) => R> = R;
    
  15. /** Get return type of a function. */
    
  16. export type Return<T> = Return_<mixed, T>;
    
  17. 
    
  18. // Project types
    
  19. 
    
  20. export type ErrorStackFrame = {
    
  21.   fileName: string,
    
  22.   lineNumber: number,
    
  23.   columnNumber: number,
    
  24. };
    
  25. 
    
  26. export type Milliseconds = number;
    
  27. 
    
  28. export type ReactLane = number;
    
  29. 
    
  30. export type NativeEvent = {
    
  31.   +depth: number,
    
  32.   +duration: Milliseconds,
    
  33.   +timestamp: Milliseconds,
    
  34.   +type: string,
    
  35.   warning: string | null,
    
  36. };
    
  37. 
    
  38. type BaseReactEvent = {
    
  39.   +componentName?: string,
    
  40.   +timestamp: Milliseconds,
    
  41.   warning: string | null,
    
  42. };
    
  43. 
    
  44. type BaseReactScheduleEvent = {
    
  45.   ...BaseReactEvent,
    
  46.   +lanes: ReactLane[],
    
  47. };
    
  48. export type ReactScheduleRenderEvent = {
    
  49.   ...BaseReactScheduleEvent,
    
  50.   +type: 'schedule-render',
    
  51. };
    
  52. export type ReactScheduleStateUpdateEvent = {
    
  53.   ...BaseReactScheduleEvent,
    
  54.   +componentStack?: string,
    
  55.   +type: 'schedule-state-update',
    
  56. };
    
  57. export type ReactScheduleForceUpdateEvent = {
    
  58.   ...BaseReactScheduleEvent,
    
  59.   +type: 'schedule-force-update',
    
  60. };
    
  61. 
    
  62. export type Phase = 'mount' | 'update';
    
  63. 
    
  64. export type SuspenseEvent = {
    
  65.   ...BaseReactEvent,
    
  66.   depth: number,
    
  67.   duration: number | null,
    
  68.   +id: string,
    
  69.   +phase: Phase | null,
    
  70.   promiseName: string | null,
    
  71.   resolution: 'rejected' | 'resolved' | 'unresolved',
    
  72.   +type: 'suspense',
    
  73. };
    
  74. 
    
  75. export type ThrownError = {
    
  76.   +componentName?: string,
    
  77.   +message: string,
    
  78.   +phase: Phase,
    
  79.   +timestamp: Milliseconds,
    
  80.   +type: 'thrown-error',
    
  81. };
    
  82. 
    
  83. export type SchedulingEvent =
    
  84.   | ReactScheduleRenderEvent
    
  85.   | ReactScheduleStateUpdateEvent
    
  86.   | ReactScheduleForceUpdateEvent;
    
  87. export type SchedulingEventType = $PropertyType<SchedulingEvent, 'type'>;
    
  88. 
    
  89. export type ReactMeasureType =
    
  90.   | 'commit'
    
  91.   // render-idle: A measure spanning the time when a render starts, through all
    
  92.   // yields and restarts, and ends when commit stops OR render is cancelled.
    
  93.   | 'render-idle'
    
  94.   | 'render'
    
  95.   | 'layout-effects'
    
  96.   | 'passive-effects';
    
  97. 
    
  98. export type BatchUID = number;
    
  99. 
    
  100. export type ReactMeasure = {
    
  101.   +type: ReactMeasureType,
    
  102.   +lanes: ReactLane[],
    
  103.   +timestamp: Milliseconds,
    
  104.   +duration: Milliseconds,
    
  105.   +batchUID: BatchUID,
    
  106.   +depth: number,
    
  107. };
    
  108. 
    
  109. export type NetworkMeasure = {
    
  110.   +depth: number,
    
  111.   finishTimestamp: Milliseconds,
    
  112.   firstReceivedDataTimestamp: Milliseconds,
    
  113.   lastReceivedDataTimestamp: Milliseconds,
    
  114.   priority: string,
    
  115.   receiveResponseTimestamp: Milliseconds,
    
  116.   +requestId: string,
    
  117.   requestMethod: string,
    
  118.   sendRequestTimestamp: Milliseconds,
    
  119.   url: string,
    
  120. };
    
  121. 
    
  122. export type ReactComponentMeasureType =
    
  123.   | 'render'
    
  124.   | 'layout-effect-mount'
    
  125.   | 'layout-effect-unmount'
    
  126.   | 'passive-effect-mount'
    
  127.   | 'passive-effect-unmount';
    
  128. 
    
  129. export type ReactComponentMeasure = {
    
  130.   +componentName: string,
    
  131.   duration: Milliseconds,
    
  132.   +timestamp: Milliseconds,
    
  133.   +type: ReactComponentMeasureType,
    
  134.   warning: string | null,
    
  135. };
    
  136. 
    
  137. /**
    
  138.  * A flamechart stack frame belonging to a stack trace.
    
  139.  */
    
  140. export type FlamechartStackFrame = {
    
  141.   name: string,
    
  142.   timestamp: Milliseconds,
    
  143.   duration: Milliseconds,
    
  144.   scriptUrl?: string,
    
  145.   locationLine?: number,
    
  146.   locationColumn?: number,
    
  147. };
    
  148. 
    
  149. export type UserTimingMark = {
    
  150.   name: string,
    
  151.   timestamp: Milliseconds,
    
  152. };
    
  153. 
    
  154. export type Snapshot = {
    
  155.   height: number,
    
  156.   image: Image | null,
    
  157.   +imageSource: string,
    
  158.   +timestamp: Milliseconds,
    
  159.   width: number,
    
  160. };
    
  161. 
    
  162. /**
    
  163.  * A "layer" of stack frames in the profiler UI, i.e. all stack frames of the
    
  164.  * same depth across all stack traces. Displayed as a flamechart row in the UI.
    
  165.  */
    
  166. export type FlamechartStackLayer = FlamechartStackFrame[];
    
  167. 
    
  168. export type Flamechart = FlamechartStackLayer[];
    
  169. 
    
  170. export type HorizontalScrollStateChangeCallback = (
    
  171.   scrollState: ScrollState,
    
  172. ) => void;
    
  173. export type SearchRegExpStateChangeCallback = (
    
  174.   searchRegExp: RegExp | null,
    
  175. ) => void;
    
  176. 
    
  177. // Imperative view state that corresponds to profiler data.
    
  178. // This state lives outside of React's lifecycle
    
  179. // and should be erased/reset whenever new profiler data is loaded.
    
  180. export type ViewState = {
    
  181.   horizontalScrollState: ScrollState,
    
  182.   onHorizontalScrollStateChange: (
    
  183.     callback: HorizontalScrollStateChangeCallback,
    
  184.   ) => void,
    
  185.   onSearchRegExpStateChange: (
    
  186.     callback: SearchRegExpStateChangeCallback,
    
  187.   ) => void,
    
  188.   searchRegExp: RegExp | null,
    
  189.   updateHorizontalScrollState: (scrollState: ScrollState) => void,
    
  190.   updateSearchRegExpState: (searchRegExp: RegExp | null) => void,
    
  191.   viewToMutableViewStateMap: Map<string, mixed>,
    
  192. };
    
  193. 
    
  194. export type InternalModuleSourceToRanges = Map<
    
  195.   string,
    
  196.   Array<[ErrorStackFrame, ErrorStackFrame]>,
    
  197. >;
    
  198. 
    
  199. export type LaneToLabelMap = Map<ReactLane, string>;
    
  200. 
    
  201. export type TimelineData = {
    
  202.   batchUIDToMeasuresMap: Map<BatchUID, ReactMeasure[]>,
    
  203.   componentMeasures: ReactComponentMeasure[],
    
  204.   duration: number,
    
  205.   flamechart: Flamechart,
    
  206.   internalModuleSourceToRanges: InternalModuleSourceToRanges,
    
  207.   laneToLabelMap: LaneToLabelMap,
    
  208.   laneToReactMeasureMap: Map<ReactLane, ReactMeasure[]>,
    
  209.   nativeEvents: NativeEvent[],
    
  210.   networkMeasures: NetworkMeasure[],
    
  211.   otherUserTimingMarks: UserTimingMark[],
    
  212.   reactVersion: string | null,
    
  213.   schedulingEvents: SchedulingEvent[],
    
  214.   snapshots: Snapshot[],
    
  215.   snapshotHeight: number,
    
  216.   startTime: number,
    
  217.   suspenseEvents: SuspenseEvent[],
    
  218.   thrownErrors: ThrownError[],
    
  219. };
    
  220. 
    
  221. export type TimelineDataExport = {
    
  222.   batchUIDToMeasuresKeyValueArray: Array<[BatchUID, ReactMeasure[]]>,
    
  223.   componentMeasures: ReactComponentMeasure[],
    
  224.   duration: number,
    
  225.   flamechart: Flamechart,
    
  226.   internalModuleSourceToRanges: Array<
    
  227.     [string, Array<[ErrorStackFrame, ErrorStackFrame]>],
    
  228.   >,
    
  229.   laneToLabelKeyValueArray: Array<[ReactLane, string]>,
    
  230.   laneToReactMeasureKeyValueArray: Array<[ReactLane, ReactMeasure[]]>,
    
  231.   nativeEvents: NativeEvent[],
    
  232.   networkMeasures: NetworkMeasure[],
    
  233.   otherUserTimingMarks: UserTimingMark[],
    
  234.   reactVersion: string | null,
    
  235.   schedulingEvents: SchedulingEvent[],
    
  236.   snapshots: Snapshot[],
    
  237.   snapshotHeight: number,
    
  238.   startTime: number,
    
  239.   suspenseEvents: SuspenseEvent[],
    
  240.   thrownErrors: ThrownError[],
    
  241. };
    
  242. 
    
  243. export type ReactEventInfo = {
    
  244.   componentMeasure: ReactComponentMeasure | null,
    
  245.   flamechartStackFrame: FlamechartStackFrame | null,
    
  246.   measure: ReactMeasure | null,
    
  247.   nativeEvent: NativeEvent | null,
    
  248.   networkMeasure: NetworkMeasure | null,
    
  249.   schedulingEvent: SchedulingEvent | null,
    
  250.   suspenseEvent: SuspenseEvent | null,
    
  251.   snapshot: Snapshot | null,
    
  252.   thrownError: ThrownError | null,
    
  253.   userTimingMark: UserTimingMark | null,
    
  254. };