-
Notifications
You must be signed in to change notification settings - Fork 484
Expand file tree
/
Copy pathConnectedFlameGraph.tsx
More file actions
242 lines (223 loc) · 8.19 KB
/
Copy pathConnectedFlameGraph.tsx
File metadata and controls
242 lines (223 loc) · 8.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import * as React from 'react';
import { explicitConnectWithForwardRef } from '../../utils/connect';
import { FlameGraph } from './FlameGraph';
import {
getCategories,
getCommittedRange,
getPreviewSelection,
getScrollToSelectionGeneration,
getProfileInterval,
getInnerWindowIDToPageMap,
getProfileUsesMultipleStackTypes,
} from 'firefox-profiler/selectors/profile';
import { selectedThreadSelectors } from 'firefox-profiler/selectors/per-thread';
import { getSelectedThreadsKey } from '../../selectors/url-state';
import {
changeSelectedCallNode,
changeRightClickedCallNode,
handleCallNodeTransformShortcut,
updateBottomBoxContentsAndMaybeOpen,
} from 'firefox-profiler/actions/profile-view';
import type {
Thread,
CategoryList,
Milliseconds,
StartEndRange,
WeightType,
SamplesLikeTable,
PreviewSelection,
CallTreeSummaryStrategy,
IndexIntoCallNodeTable,
ThreadsKey,
InnerWindowID,
Page,
SampleCategoriesAndSubcategories,
} from 'firefox-profiler/types';
import type { FlameGraphTiming } from 'firefox-profiler/profile-logic/flame-graph';
import type { CallNodeInfo } from 'firefox-profiler/profile-logic/call-node-info';
import type {
CallTree,
CallTreeTimings,
} from 'firefox-profiler/profile-logic/call-tree';
import type { ConnectedProps } from 'firefox-profiler/utils/connect';
type StateProps = {
readonly thread: Thread;
readonly weightType: WeightType;
readonly innerWindowIDToPageMap: Map<InnerWindowID, Page> | null;
readonly maxStackDepthPlusOne: number;
readonly timeRange: StartEndRange;
readonly previewSelection: PreviewSelection | null;
readonly flameGraphTiming: FlameGraphTiming;
readonly callTree: CallTree;
readonly callNodeInfo: CallNodeInfo;
readonly threadsKey: ThreadsKey;
readonly selectedCallNodeIndex: IndexIntoCallNodeTable | null;
readonly rightClickedCallNodeIndex: IndexIntoCallNodeTable | null;
readonly scrollToSelectionGeneration: number;
readonly categories: CategoryList;
readonly interval: Milliseconds;
readonly callTreeSummaryStrategy: CallTreeSummaryStrategy;
readonly ctssSamples: SamplesLikeTable;
readonly ctssSampleCategoriesAndSubcategories: SampleCategoriesAndSubcategories;
readonly tracedTiming: CallTreeTimings | null;
readonly displayStackType: boolean;
};
type DispatchProps = {
readonly changeSelectedCallNode: typeof changeSelectedCallNode;
readonly changeRightClickedCallNode: typeof changeRightClickedCallNode;
readonly handleCallNodeTransformShortcut: typeof handleCallNodeTransformShortcut;
readonly updateBottomBoxContentsAndMaybeOpen: typeof updateBottomBoxContentsAndMaybeOpen;
};
type Props = ConnectedProps<{}, StateProps, DispatchProps>;
export interface ConnectedFlameGraphHandle {
focus(): void;
}
class ConnectedFlameGraphImpl
extends React.PureComponent<Props>
implements ConnectedFlameGraphHandle
{
_flameGraph: React.RefObject<FlameGraph | null> = React.createRef();
// eslint-disable-next-line react/no-unused-class-component-methods -- called via ConnectedFlameGraphHandle ref from FlameGraphViewImpl
focus() {
this._flameGraph.current?.focus();
}
_onSelectedCallNodeChange = (
callNodeIndex: IndexIntoCallNodeTable | null
) => {
const { callNodeInfo, threadsKey, changeSelectedCallNode } = this.props;
changeSelectedCallNode(
threadsKey,
callNodeInfo.getCallNodePathFromIndex(callNodeIndex)
);
};
_onRightClickedCallNodeChange = (
callNodeIndex: IndexIntoCallNodeTable | null
) => {
const { callNodeInfo, threadsKey, changeRightClickedCallNode } = this.props;
changeRightClickedCallNode(
threadsKey,
callNodeInfo.getCallNodePathFromIndex(callNodeIndex)
);
};
_onCallNodeEnterOrDoubleClick = (
callNodeIndex: IndexIntoCallNodeTable | null
) => {
if (callNodeIndex === null) {
return;
}
const { callTree, updateBottomBoxContentsAndMaybeOpen } = this.props;
const bottomBoxInfo = callTree.getBottomBoxInfoForCallNode(callNodeIndex);
updateBottomBoxContentsAndMaybeOpen('flame-graph', bottomBoxInfo);
};
_onKeyboardTransformShortcut = (
event: React.KeyboardEvent<HTMLElement>,
nodeIndex: IndexIntoCallNodeTable
) => {
const { threadsKey, callNodeInfo, handleCallNodeTransformShortcut } =
this.props;
handleCallNodeTransformShortcut(event, threadsKey, callNodeInfo, nodeIndex);
};
override render() {
const {
thread,
threadsKey,
maxStackDepthPlusOne,
flameGraphTiming,
callTree,
callNodeInfo,
timeRange,
previewSelection,
rightClickedCallNodeIndex,
selectedCallNodeIndex,
scrollToSelectionGeneration,
callTreeSummaryStrategy,
categories,
interval,
innerWindowIDToPageMap,
weightType,
ctssSamples,
ctssSampleCategoriesAndSubcategories,
tracedTiming,
displayStackType,
} = this.props;
return (
<FlameGraph
ref={this._flameGraph}
thread={thread}
weightType={weightType}
innerWindowIDToPageMap={innerWindowIDToPageMap}
maxStackDepthPlusOne={maxStackDepthPlusOne}
timeRange={timeRange}
previewSelection={previewSelection}
flameGraphTiming={flameGraphTiming}
callTree={callTree}
callNodeInfo={callNodeInfo}
threadsKey={threadsKey}
selectedCallNodeIndex={selectedCallNodeIndex}
rightClickedCallNodeIndex={rightClickedCallNodeIndex}
scrollToSelectionGeneration={scrollToSelectionGeneration}
categories={categories}
interval={interval}
callTreeSummaryStrategy={callTreeSummaryStrategy}
ctssSamples={ctssSamples}
ctssSampleCategoriesAndSubcategories={
ctssSampleCategoriesAndSubcategories
}
tracedTiming={tracedTiming}
displayStackType={displayStackType}
onSelectedCallNodeChange={this._onSelectedCallNodeChange}
onRightClickedCallNodeChange={this._onRightClickedCallNodeChange}
onCallNodeEnterOrDoubleClick={this._onCallNodeEnterOrDoubleClick}
onKeyboardTransformShortcut={this._onKeyboardTransformShortcut}
/>
);
}
}
export const ConnectedFlameGraph = explicitConnectWithForwardRef<
{},
StateProps,
DispatchProps,
ConnectedFlameGraphHandle
>({
mapStateToProps: (state) => ({
thread: selectedThreadSelectors.getFilteredThread(state),
weightType: selectedThreadSelectors.getWeightTypeForCallTree(state),
// Use the filtered call node max depth, rather than the preview filtered one, so
// that the viewport height is stable across preview selections.
maxStackDepthPlusOne:
selectedThreadSelectors.getFilteredCallNodeMaxDepthPlusOne(state),
flameGraphTiming: selectedThreadSelectors.getFlameGraphTiming(state),
callTree: selectedThreadSelectors.getCallTree(state),
timeRange: getCommittedRange(state),
previewSelection: getPreviewSelection(state),
callNodeInfo: selectedThreadSelectors.getCallNodeInfo(state),
categories: getCategories(state),
threadsKey: getSelectedThreadsKey(state),
selectedCallNodeIndex:
selectedThreadSelectors.getSelectedCallNodeIndex(state),
rightClickedCallNodeIndex:
selectedThreadSelectors.getRightClickedCallNodeIndex(state),
scrollToSelectionGeneration: getScrollToSelectionGeneration(state),
interval: getProfileInterval(state),
callTreeSummaryStrategy:
selectedThreadSelectors.getCallTreeSummaryStrategy(state),
innerWindowIDToPageMap: getInnerWindowIDToPageMap(state),
ctssSamples: selectedThreadSelectors.getPreviewFilteredCtssSamples(state),
ctssSampleCategoriesAndSubcategories:
selectedThreadSelectors.getPreviewFilteredCtssSampleCategoriesAndSubcategories(
state
),
tracedTiming: selectedThreadSelectors.getTracedTiming(state),
displayStackType: getProfileUsesMultipleStackTypes(state),
}),
mapDispatchToProps: {
changeSelectedCallNode,
changeRightClickedCallNode,
handleCallNodeTransformShortcut,
updateBottomBoxContentsAndMaybeOpen,
},
component: ConnectedFlameGraphImpl,
});