@parca/profile 0.16.198 → 0.16.200
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/Callgraph/index.d.ts +0 -1
- package/dist/GraphTooltip/ExpandOnHoverValue.d.ts +0 -1
- package/dist/GraphTooltip/index.d.ts +0 -1
- package/dist/GraphTooltipArrow/ExpandOnHoverValue.d.ts +6 -0
- package/dist/GraphTooltipArrow/ExpandOnHoverValue.js +4 -0
- package/dist/GraphTooltipArrow/index.d.ts +43 -0
- package/dist/GraphTooltipArrow/index.js +244 -0
- package/dist/MatchersInput/SuggestionItem.d.ts +0 -1
- package/dist/MatchersInput/SuggestionsList.d.ts +0 -1
- package/dist/MatchersInput/index.d.ts +0 -1
- package/dist/MetricsCircle/index.d.ts +0 -1
- package/dist/MetricsGraph/MetricsTooltip/index.d.ts +0 -1
- package/dist/MetricsGraph/index.d.ts +5 -3
- package/dist/MetricsGraph/index.js +3 -8
- package/dist/MetricsGraph/useMetricsGraphDimensions.d.ts +9 -0
- package/dist/MetricsGraph/useMetricsGraphDimensions.js +29 -0
- package/dist/MetricsSeries/index.d.ts +0 -1
- package/dist/ProfileExplorer/ProfileExplorerCompare.d.ts +0 -1
- package/dist/ProfileExplorer/ProfileExplorerSingle.d.ts +0 -1
- package/dist/ProfileExplorer/index.d.ts +0 -1
- package/dist/ProfileIcicleGraph/IcicleGraph/ColorStackLegend.d.ts +0 -1
- package/dist/ProfileIcicleGraph/IcicleGraphArrow/ColorStackLegend.d.ts +10 -0
- package/dist/ProfileIcicleGraph/IcicleGraphArrow/ColorStackLegend.js +64 -0
- package/dist/ProfileIcicleGraph/IcicleGraphArrow/IcicleGraphNodes.d.ts +48 -0
- package/dist/ProfileIcicleGraph/IcicleGraphArrow/IcicleGraphNodes.js +150 -0
- package/dist/ProfileIcicleGraph/IcicleGraphArrow/index.d.ts +23 -0
- package/dist/ProfileIcicleGraph/IcicleGraphArrow/index.js +110 -0
- package/dist/ProfileIcicleGraph/IcicleGraphArrow/useNodeColor.d.ts +14 -0
- package/dist/ProfileIcicleGraph/IcicleGraphArrow/useNodeColor.js +26 -0
- package/dist/ProfileIcicleGraph/IcicleGraphArrow/utils.d.ts +4 -0
- package/dist/ProfileIcicleGraph/IcicleGraphArrow/utils.js +42 -0
- package/dist/ProfileIcicleGraph/index.d.ts +4 -3
- package/dist/ProfileIcicleGraph/index.js +7 -5
- package/dist/ProfileMetricsGraph/index.d.ts +4 -1
- package/dist/ProfileMetricsGraph/index.js +24 -14
- package/dist/ProfileSelector/CompareButton.d.ts +0 -1
- package/dist/ProfileSelector/index.d.ts +0 -1
- package/dist/ProfileSelector/index.js +44 -35
- package/dist/ProfileSelector/useAutoQuerySelector.d.ts +9 -0
- package/dist/ProfileSelector/useAutoQuerySelector.js +66 -0
- package/dist/ProfileSource.d.ts +0 -1
- package/dist/ProfileTypeSelector/index.d.ts +1 -1
- package/dist/ProfileTypeSelector/index.js +4 -3
- package/dist/ProfileView/FilterByFunctionButton.d.ts +0 -1
- package/dist/ProfileView/ViewSelector.d.ts +0 -1
- package/dist/ProfileView/index.d.ts +2 -1
- package/dist/ProfileView/index.js +3 -3
- package/dist/ProfileViewWithData.d.ts +0 -1
- package/dist/ProfileViewWithData.js +16 -7
- package/dist/components/DiffLegend.d.ts +0 -1
- package/dist/components/ProfileShareButton/ResultBox.d.ts +0 -1
- package/dist/components/ProfileShareButton/index.d.ts +0 -1
- package/dist/styles.css +1 -1
- package/package.json +6 -5
- package/src/GraphTooltipArrow/ExpandOnHoverValue.tsx +30 -0
- package/src/GraphTooltipArrow/index.tsx +564 -0
- package/src/MetricsGraph/index.tsx +24 -20
- package/src/MetricsGraph/useMetricsGraphDimensions.ts +42 -0
- package/src/ProfileIcicleGraph/IcicleGraphArrow/ColorStackLegend.tsx +109 -0
- package/src/ProfileIcicleGraph/IcicleGraphArrow/IcicleGraphNodes.tsx +327 -0
- package/src/ProfileIcicleGraph/IcicleGraphArrow/index.tsx +212 -0
- package/src/ProfileIcicleGraph/IcicleGraphArrow/useNodeColor.ts +52 -0
- package/src/ProfileIcicleGraph/IcicleGraphArrow/utils.ts +51 -0
- package/src/ProfileIcicleGraph/index.tsx +34 -14
- package/src/ProfileMetricsGraph/index.tsx +38 -20
- package/src/ProfileSelector/index.tsx +66 -54
- package/src/ProfileSelector/useAutoQuerySelector.ts +87 -0
- package/src/ProfileTypeSelector/index.tsx +9 -10
- package/src/ProfileView/index.tsx +5 -2
- package/src/ProfileViewWithData.tsx +22 -7
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Copyright 2022 The Parca Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
|
|
14
|
+
import React, {useMemo} from 'react';
|
|
15
|
+
|
|
16
|
+
import {Icon} from '@iconify/react';
|
|
17
|
+
import cx from 'classnames';
|
|
18
|
+
|
|
19
|
+
import {useURLState} from '@parca/components';
|
|
20
|
+
import {USER_PREFERENCES, useUserPreference} from '@parca/hooks';
|
|
21
|
+
import {EVERYTHING_ELSE} from '@parca/store';
|
|
22
|
+
import type {NavigateFunction} from '@parca/utilities';
|
|
23
|
+
|
|
24
|
+
import {mappingColors} from './IcicleGraphNodes';
|
|
25
|
+
|
|
26
|
+
interface Props {
|
|
27
|
+
mappingColors: mappingColors;
|
|
28
|
+
navigateTo?: NavigateFunction;
|
|
29
|
+
compareMode?: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const ColorStackLegend = ({
|
|
33
|
+
mappingColors,
|
|
34
|
+
navigateTo,
|
|
35
|
+
compareMode = false,
|
|
36
|
+
}: Props): React.JSX.Element => {
|
|
37
|
+
const [colorProfileName] = useUserPreference<string>(
|
|
38
|
+
USER_PREFERENCES.FLAMEGRAPH_COLOR_PROFILE.key
|
|
39
|
+
);
|
|
40
|
+
const [currentSearchString, setSearchString] = useURLState({param: 'search_string', navigateTo});
|
|
41
|
+
|
|
42
|
+
const stackColorArray = useMemo(() => {
|
|
43
|
+
return Object.entries(mappingColors).sort(([featureA], [featureB]) => {
|
|
44
|
+
if (featureA === EVERYTHING_ELSE) {
|
|
45
|
+
return 1;
|
|
46
|
+
}
|
|
47
|
+
if (featureB === EVERYTHING_ELSE) {
|
|
48
|
+
return -1;
|
|
49
|
+
}
|
|
50
|
+
return featureA?.localeCompare(featureB ?? '') ?? 0;
|
|
51
|
+
});
|
|
52
|
+
}, [mappingColors]);
|
|
53
|
+
|
|
54
|
+
if (mappingColors === undefined) {
|
|
55
|
+
return <></>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (Object.entries(mappingColors).length === 0) {
|
|
59
|
+
return <></>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (colorProfileName === 'default' || compareMode) {
|
|
63
|
+
return <></>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<div className="my-6 flex flex-wrap justify-center gap-2">
|
|
68
|
+
{stackColorArray.map(([feature, color]) => {
|
|
69
|
+
const filteringAllowed = feature !== EVERYTHING_ELSE;
|
|
70
|
+
const isHighlighted = currentSearchString === feature;
|
|
71
|
+
return (
|
|
72
|
+
<div
|
|
73
|
+
key={feature}
|
|
74
|
+
className={cx('flex items-center justify-between gap-1 text-ellipsis p-1 pr-2', {
|
|
75
|
+
'cursor-pointer': filteringAllowed,
|
|
76
|
+
'bg-gray-200 dark:bg-gray-800': isHighlighted,
|
|
77
|
+
})}
|
|
78
|
+
onClick={() => {
|
|
79
|
+
if (!filteringAllowed) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (isHighlighted) {
|
|
83
|
+
setSearchString('');
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
setSearchString(feature);
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
<div className="flex items-center">
|
|
90
|
+
<div className="mr-1 inline-block h-4 w-4" style={{backgroundColor: color}} />
|
|
91
|
+
<span className="text-sm">{feature}</span>
|
|
92
|
+
</div>
|
|
93
|
+
{isHighlighted ? (
|
|
94
|
+
<Icon
|
|
95
|
+
icon="radix-icons:cross-circled"
|
|
96
|
+
onClick={e => {
|
|
97
|
+
setSearchString('');
|
|
98
|
+
e.stopPropagation();
|
|
99
|
+
}}
|
|
100
|
+
/>
|
|
101
|
+
) : null}
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
})}
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export default ColorStackLegend;
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
// Copyright 2022 The Parca Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
|
|
14
|
+
import React, {ReactNode, useMemo} from 'react';
|
|
15
|
+
|
|
16
|
+
import {Table} from 'apache-arrow';
|
|
17
|
+
import cx from 'classnames';
|
|
18
|
+
|
|
19
|
+
import {useKeyDown} from '@parca/components';
|
|
20
|
+
import {selectBinaries, setHoveringRow, useAppDispatch, useAppSelector} from '@parca/store';
|
|
21
|
+
import {isSearchMatch, scaleLinear} from '@parca/utilities';
|
|
22
|
+
|
|
23
|
+
import {
|
|
24
|
+
FIELD_CHILDREN,
|
|
25
|
+
FIELD_CUMULATIVE,
|
|
26
|
+
FIELD_DIFF,
|
|
27
|
+
FIELD_FUNCTION_NAME,
|
|
28
|
+
FIELD_MAPPING_FILE,
|
|
29
|
+
} from './index';
|
|
30
|
+
import useNodeColor from './useNodeColor';
|
|
31
|
+
import {nodeLabel} from './utils';
|
|
32
|
+
|
|
33
|
+
export const RowHeight = 26;
|
|
34
|
+
|
|
35
|
+
interface IcicleGraphNodesProps {
|
|
36
|
+
table: Table<any>;
|
|
37
|
+
row: number;
|
|
38
|
+
mappingColors: mappingColors;
|
|
39
|
+
childRows: number[];
|
|
40
|
+
x: number;
|
|
41
|
+
y: number;
|
|
42
|
+
total: bigint;
|
|
43
|
+
totalWidth: number;
|
|
44
|
+
level: number;
|
|
45
|
+
curPath: string[];
|
|
46
|
+
setCurPath: (path: string[]) => void;
|
|
47
|
+
path: string[];
|
|
48
|
+
xScale: (value: bigint) => number;
|
|
49
|
+
searchString?: string;
|
|
50
|
+
sortBy: string;
|
|
51
|
+
darkMode: boolean;
|
|
52
|
+
compareMode: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const IcicleGraphNodes = React.memo(function IcicleGraphNodesNoMemo({
|
|
56
|
+
table,
|
|
57
|
+
childRows,
|
|
58
|
+
mappingColors,
|
|
59
|
+
x,
|
|
60
|
+
y,
|
|
61
|
+
xScale,
|
|
62
|
+
total,
|
|
63
|
+
totalWidth,
|
|
64
|
+
level,
|
|
65
|
+
path,
|
|
66
|
+
setCurPath,
|
|
67
|
+
curPath,
|
|
68
|
+
sortBy,
|
|
69
|
+
searchString,
|
|
70
|
+
darkMode,
|
|
71
|
+
compareMode,
|
|
72
|
+
}: IcicleGraphNodesProps): React.JSX.Element {
|
|
73
|
+
const cumulatives = table.getChild(FIELD_CUMULATIVE);
|
|
74
|
+
|
|
75
|
+
if (childRows === undefined || childRows.length === 0) {
|
|
76
|
+
return <></>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
childRows =
|
|
80
|
+
curPath.length === 0
|
|
81
|
+
? childRows
|
|
82
|
+
: childRows.filter(c => nodeLabel(table, c, false) === curPath[0]);
|
|
83
|
+
|
|
84
|
+
let childrenCumulative = BigInt(0);
|
|
85
|
+
const childrenElements: ReactNode[] = [];
|
|
86
|
+
childRows.forEach((child, i) => {
|
|
87
|
+
const xStart = Math.floor(xScale(childrenCumulative));
|
|
88
|
+
const c: bigint = cumulatives?.get(child);
|
|
89
|
+
childrenCumulative += c;
|
|
90
|
+
|
|
91
|
+
childrenElements.push(
|
|
92
|
+
<IcicleNode
|
|
93
|
+
key={`node-${level}-${i}`}
|
|
94
|
+
table={table}
|
|
95
|
+
row={child}
|
|
96
|
+
mappingColors={mappingColors}
|
|
97
|
+
x={xStart}
|
|
98
|
+
y={0}
|
|
99
|
+
totalWidth={totalWidth}
|
|
100
|
+
height={RowHeight}
|
|
101
|
+
path={path}
|
|
102
|
+
setCurPath={setCurPath}
|
|
103
|
+
level={level}
|
|
104
|
+
curPath={curPath}
|
|
105
|
+
total={total}
|
|
106
|
+
xScale={xScale}
|
|
107
|
+
sortBy={sortBy}
|
|
108
|
+
searchString={searchString}
|
|
109
|
+
darkMode={darkMode}
|
|
110
|
+
compareMode={compareMode}
|
|
111
|
+
/>
|
|
112
|
+
);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
return <g transform={`translate(${x}, ${y})`}>{childrenElements}</g>;
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
export interface mappingColors {
|
|
119
|
+
[key: string]: string;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
interface IcicleNodeProps {
|
|
123
|
+
x: number;
|
|
124
|
+
y: number;
|
|
125
|
+
height: number;
|
|
126
|
+
totalWidth: number;
|
|
127
|
+
curPath: string[];
|
|
128
|
+
level: number;
|
|
129
|
+
table: Table<any>;
|
|
130
|
+
row: number;
|
|
131
|
+
mappingColors: mappingColors;
|
|
132
|
+
path: string[];
|
|
133
|
+
total: bigint;
|
|
134
|
+
setCurPath: (path: string[]) => void;
|
|
135
|
+
xScale: (value: bigint) => number;
|
|
136
|
+
isRoot?: boolean;
|
|
137
|
+
searchString?: string;
|
|
138
|
+
sortBy: string;
|
|
139
|
+
darkMode: boolean;
|
|
140
|
+
compareMode: boolean;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const icicleRectStyles = {
|
|
144
|
+
cursor: 'pointer',
|
|
145
|
+
transition: 'opacity .15s linear',
|
|
146
|
+
};
|
|
147
|
+
const fadedIcicleRectStyles = {
|
|
148
|
+
cursor: 'pointer',
|
|
149
|
+
transition: 'opacity .15s linear',
|
|
150
|
+
opacity: '0.5',
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export const IcicleNode = React.memo(function IcicleNodeNoMemo({
|
|
154
|
+
table,
|
|
155
|
+
row,
|
|
156
|
+
mappingColors,
|
|
157
|
+
x,
|
|
158
|
+
y,
|
|
159
|
+
height,
|
|
160
|
+
setCurPath,
|
|
161
|
+
curPath,
|
|
162
|
+
level,
|
|
163
|
+
path,
|
|
164
|
+
total,
|
|
165
|
+
totalWidth,
|
|
166
|
+
xScale,
|
|
167
|
+
isRoot = false,
|
|
168
|
+
searchString,
|
|
169
|
+
sortBy,
|
|
170
|
+
darkMode,
|
|
171
|
+
compareMode,
|
|
172
|
+
}: IcicleNodeProps): React.JSX.Element {
|
|
173
|
+
const {isShiftDown} = useKeyDown();
|
|
174
|
+
const dispatch = useAppDispatch();
|
|
175
|
+
|
|
176
|
+
// get the columns to read from
|
|
177
|
+
const mappingColumn = table.getChild(FIELD_MAPPING_FILE);
|
|
178
|
+
const functionNameColumn = table.getChild(FIELD_FUNCTION_NAME);
|
|
179
|
+
const cumulativeColumn = table.getChild(FIELD_CUMULATIVE);
|
|
180
|
+
const diffColumn = table.getChild(FIELD_DIFF);
|
|
181
|
+
// get the actual values from the columns
|
|
182
|
+
const mappingFile: string | null = mappingColumn?.get(row);
|
|
183
|
+
const functionName: string | null = functionNameColumn?.get(row);
|
|
184
|
+
const cumulative: bigint = cumulativeColumn?.get(row);
|
|
185
|
+
const diff: bigint | null = diffColumn?.get(row);
|
|
186
|
+
const childRows: number[] = Array.from(table.getChild(FIELD_CHILDREN)?.get(row) ?? []);
|
|
187
|
+
|
|
188
|
+
// TODO: Maybe it's better to pass down the sorter function as prop instead of figuring this out here.
|
|
189
|
+
switch (sortBy) {
|
|
190
|
+
case FIELD_FUNCTION_NAME:
|
|
191
|
+
childRows.sort((a, b) => {
|
|
192
|
+
// TODO: Support fallthrough to comparing addresses or something
|
|
193
|
+
const afn: string = functionNameColumn?.get(a);
|
|
194
|
+
const bfn: string = functionNameColumn?.get(b);
|
|
195
|
+
return afn.localeCompare(bfn);
|
|
196
|
+
});
|
|
197
|
+
break;
|
|
198
|
+
case FIELD_CUMULATIVE:
|
|
199
|
+
childRows.sort((a, b) => {
|
|
200
|
+
const aCumulative: bigint = cumulativeColumn?.get(a);
|
|
201
|
+
const bCumulative: bigint = cumulativeColumn?.get(b);
|
|
202
|
+
return Number(bCumulative - aCumulative);
|
|
203
|
+
});
|
|
204
|
+
break;
|
|
205
|
+
case FIELD_DIFF:
|
|
206
|
+
childRows.sort((a, b) => {
|
|
207
|
+
const aDiff: bigint | null = diffColumn?.get(a);
|
|
208
|
+
const bDiff: bigint | null = diffColumn?.get(b);
|
|
209
|
+
if (aDiff !== null && bDiff !== null) {
|
|
210
|
+
return Number(bDiff - aDiff);
|
|
211
|
+
}
|
|
212
|
+
if (aDiff === null && bDiff !== null) {
|
|
213
|
+
return 1;
|
|
214
|
+
}
|
|
215
|
+
if (aDiff !== null && bDiff === null) {
|
|
216
|
+
return -1;
|
|
217
|
+
}
|
|
218
|
+
// both are null
|
|
219
|
+
return 0;
|
|
220
|
+
});
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const binaries = useAppSelector(selectBinaries);
|
|
225
|
+
const colorResult = useNodeColor({
|
|
226
|
+
isDarkMode: darkMode,
|
|
227
|
+
compareMode,
|
|
228
|
+
cumulative,
|
|
229
|
+
diff,
|
|
230
|
+
mappingColors,
|
|
231
|
+
mappingFile,
|
|
232
|
+
functionName,
|
|
233
|
+
});
|
|
234
|
+
const name = useMemo(() => {
|
|
235
|
+
return isRoot ? 'root' : nodeLabel(table, row, binaries.length > 1);
|
|
236
|
+
}, [table, row, isRoot, binaries]);
|
|
237
|
+
const nextPath = path.concat([name]);
|
|
238
|
+
const isFaded = curPath.length > 0 && name !== curPath[curPath.length - 1];
|
|
239
|
+
const styles = isFaded ? fadedIcicleRectStyles : icicleRectStyles;
|
|
240
|
+
const nextLevel = level + 1;
|
|
241
|
+
const nextCurPath = curPath.length === 0 ? [] : curPath.slice(1);
|
|
242
|
+
const newXScale =
|
|
243
|
+
nextCurPath.length === 0 && curPath.length === 1
|
|
244
|
+
? scaleLinear([0n, cumulative], [0, totalWidth])
|
|
245
|
+
: xScale;
|
|
246
|
+
|
|
247
|
+
const width: number =
|
|
248
|
+
nextCurPath.length > 0 || (nextCurPath.length === 0 && curPath.length === 1)
|
|
249
|
+
? totalWidth
|
|
250
|
+
: xScale(cumulative);
|
|
251
|
+
|
|
252
|
+
const {isHighlightEnabled = false, isHighlighted = false} = useMemo(() => {
|
|
253
|
+
if (searchString === undefined || searchString === '') {
|
|
254
|
+
return {isHighlightEnabled: false};
|
|
255
|
+
}
|
|
256
|
+
return {isHighlightEnabled: true, isHighlighted: isSearchMatch(searchString, name)};
|
|
257
|
+
}, [searchString, name]);
|
|
258
|
+
|
|
259
|
+
if (width <= 1) {
|
|
260
|
+
return <>{null}</>;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const onMouseEnter = (): void => {
|
|
264
|
+
if (isShiftDown) return;
|
|
265
|
+
dispatch(setHoveringRow({row}));
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const onMouseLeave = (): void => {
|
|
269
|
+
if (isShiftDown) return;
|
|
270
|
+
dispatch(setHoveringRow(undefined));
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
return (
|
|
274
|
+
<>
|
|
275
|
+
<g
|
|
276
|
+
transform={`translate(${x + 1}, ${y + 1})`}
|
|
277
|
+
style={styles}
|
|
278
|
+
onMouseEnter={onMouseEnter}
|
|
279
|
+
onMouseLeave={onMouseLeave}
|
|
280
|
+
onClick={() => {
|
|
281
|
+
setCurPath(nextPath);
|
|
282
|
+
}}
|
|
283
|
+
>
|
|
284
|
+
<rect
|
|
285
|
+
x={0}
|
|
286
|
+
y={0}
|
|
287
|
+
width={width}
|
|
288
|
+
height={height}
|
|
289
|
+
style={{
|
|
290
|
+
fill: colorResult,
|
|
291
|
+
}}
|
|
292
|
+
className={cx('stroke-white dark:stroke-gray-700', {
|
|
293
|
+
'opacity-50': isHighlightEnabled && !isHighlighted,
|
|
294
|
+
})}
|
|
295
|
+
/>
|
|
296
|
+
{width > 5 && (
|
|
297
|
+
<svg width={width - 5} height={height}>
|
|
298
|
+
<text x={5} y={15} style={{fontSize: '12px'}}>
|
|
299
|
+
{name}
|
|
300
|
+
</text>
|
|
301
|
+
</svg>
|
|
302
|
+
)}
|
|
303
|
+
</g>
|
|
304
|
+
{childRows.length > 0 && (
|
|
305
|
+
<IcicleGraphNodes
|
|
306
|
+
table={table}
|
|
307
|
+
row={row}
|
|
308
|
+
mappingColors={mappingColors}
|
|
309
|
+
childRows={childRows}
|
|
310
|
+
x={x}
|
|
311
|
+
y={RowHeight}
|
|
312
|
+
xScale={newXScale}
|
|
313
|
+
total={total}
|
|
314
|
+
totalWidth={totalWidth}
|
|
315
|
+
level={nextLevel}
|
|
316
|
+
path={nextPath}
|
|
317
|
+
curPath={nextCurPath}
|
|
318
|
+
setCurPath={setCurPath}
|
|
319
|
+
searchString={searchString}
|
|
320
|
+
sortBy={sortBy}
|
|
321
|
+
darkMode={darkMode}
|
|
322
|
+
compareMode={compareMode}
|
|
323
|
+
/>
|
|
324
|
+
)}
|
|
325
|
+
</>
|
|
326
|
+
);
|
|
327
|
+
});
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// Copyright 2022 The Parca Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
|
|
14
|
+
import React, {memo, useEffect, useMemo, useRef, useState} from 'react';
|
|
15
|
+
|
|
16
|
+
import {Dictionary, Table, Vector} from 'apache-arrow';
|
|
17
|
+
|
|
18
|
+
import {USER_PREFERENCES, useUserPreference} from '@parca/hooks';
|
|
19
|
+
import {
|
|
20
|
+
getColorForFeature,
|
|
21
|
+
selectDarkMode,
|
|
22
|
+
setHoveringNode,
|
|
23
|
+
useAppDispatch,
|
|
24
|
+
useAppSelector,
|
|
25
|
+
} from '@parca/store';
|
|
26
|
+
import {
|
|
27
|
+
getLastItem,
|
|
28
|
+
scaleLinear,
|
|
29
|
+
selectQueryParam,
|
|
30
|
+
type ColorProfileName,
|
|
31
|
+
type NavigateFunction,
|
|
32
|
+
} from '@parca/utilities';
|
|
33
|
+
|
|
34
|
+
import GraphTooltipArrow from '../../GraphTooltipArrow';
|
|
35
|
+
import ColorStackLegend from './ColorStackLegend';
|
|
36
|
+
import {IcicleNode, RowHeight, mappingColors} from './IcicleGraphNodes';
|
|
37
|
+
import {extractFeature} from './utils';
|
|
38
|
+
|
|
39
|
+
export const FIELD_MAPPING_FILE = 'mapping_file';
|
|
40
|
+
export const FIELD_MAPPING_BUILD_ID = 'mapping_build_id';
|
|
41
|
+
export const FIELD_LOCATION_ADDRESS = 'location_address';
|
|
42
|
+
export const FIELD_FUNCTION_NAME = 'function_name';
|
|
43
|
+
export const FIELD_FUNCTION_FILE_NAME = 'function_file_name';
|
|
44
|
+
export const FIELD_CHILDREN = 'children';
|
|
45
|
+
export const FIELD_CUMULATIVE = 'cumulative';
|
|
46
|
+
export const FIELD_DIFF = 'diff';
|
|
47
|
+
|
|
48
|
+
interface IcicleGraphArrowProps {
|
|
49
|
+
table: Table<any>;
|
|
50
|
+
total: bigint;
|
|
51
|
+
filtered: bigint;
|
|
52
|
+
sampleUnit: string;
|
|
53
|
+
width?: number;
|
|
54
|
+
curPath: string[];
|
|
55
|
+
setCurPath: (path: string[]) => void;
|
|
56
|
+
navigateTo?: NavigateFunction;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const IcicleGraphArrow = memo(function IcicleGraphArrow({
|
|
60
|
+
table,
|
|
61
|
+
total,
|
|
62
|
+
filtered,
|
|
63
|
+
width,
|
|
64
|
+
setCurPath,
|
|
65
|
+
curPath,
|
|
66
|
+
sampleUnit,
|
|
67
|
+
navigateTo,
|
|
68
|
+
}: IcicleGraphArrowProps): React.JSX.Element {
|
|
69
|
+
const dispatch = useAppDispatch();
|
|
70
|
+
const [colorProfile] = useUserPreference<ColorProfileName>(
|
|
71
|
+
USER_PREFERENCES.FLAMEGRAPH_COLOR_PROFILE.key
|
|
72
|
+
);
|
|
73
|
+
const isDarkMode = useAppSelector(selectDarkMode);
|
|
74
|
+
|
|
75
|
+
const [height, setHeight] = useState(0);
|
|
76
|
+
const sortBy = FIELD_FUNCTION_NAME; // TODO: make this configurable via UI
|
|
77
|
+
const svg = useRef(null);
|
|
78
|
+
const ref = useRef<SVGGElement>(null);
|
|
79
|
+
|
|
80
|
+
const currentSearchString = (selectQueryParam('search_string') as string) ?? '';
|
|
81
|
+
const compareMode: boolean =
|
|
82
|
+
selectQueryParam('compare_a') === 'true' && selectQueryParam('compare_b') === 'true';
|
|
83
|
+
|
|
84
|
+
const mappings = useMemo(() => {
|
|
85
|
+
// Read the mappings from the dictionary that contains all mapping strings.
|
|
86
|
+
// This is great, as might only have a dozen or so mappings,
|
|
87
|
+
// and don't need to read through all the rows (potentially thousands).
|
|
88
|
+
const mappingsDict: Vector<Dictionary> | null = table.getChild(FIELD_MAPPING_FILE);
|
|
89
|
+
const mappings =
|
|
90
|
+
mappingsDict?.data
|
|
91
|
+
.map(mapping => {
|
|
92
|
+
if (mapping.dictionary == null) {
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
const len = mapping.dictionary.length;
|
|
96
|
+
const entries: string[] = [];
|
|
97
|
+
for (let i = 0; i < len; i++) {
|
|
98
|
+
entries.push(getLastItem(mapping.dictionary.get(i)) ?? '');
|
|
99
|
+
}
|
|
100
|
+
return entries;
|
|
101
|
+
})
|
|
102
|
+
.flat() ?? [];
|
|
103
|
+
|
|
104
|
+
// We add a EVERYTHING ELSE mapping to the list.
|
|
105
|
+
mappings.push('');
|
|
106
|
+
|
|
107
|
+
// We look through the function names to find out if there's a runtime function.
|
|
108
|
+
// Again, we only read through the dictionary, which is much faster than reading through all the rows.
|
|
109
|
+
// We stop as soon as we find a runtime function.
|
|
110
|
+
const functionNamesDict: Vector<Dictionary> | null = table.getChild(FIELD_FUNCTION_NAME);
|
|
111
|
+
functionNamesDict?.data.forEach(fn => {
|
|
112
|
+
if (fn.dictionary == null) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const len = fn.dictionary.length;
|
|
116
|
+
for (let i = 0; i < len; i++) {
|
|
117
|
+
const fn: string | null = functionNamesDict?.get(i);
|
|
118
|
+
if (fn?.startsWith('runtime') === true) {
|
|
119
|
+
mappings.push('runtime');
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// We sort the mappings alphabetically to make sure that the order is always the same.
|
|
126
|
+
mappings.sort((a, b) => a.localeCompare(b));
|
|
127
|
+
return mappings;
|
|
128
|
+
}, [table]);
|
|
129
|
+
|
|
130
|
+
// TODO: Somehow figure out how to add runtime to this, if stacks are present.
|
|
131
|
+
// Potentially read the function name dictionary and check if it contains strings starting with runtime.
|
|
132
|
+
const mappingFeatures = useMemo(() => {
|
|
133
|
+
return mappings.map(mapping => extractFeature(mapping));
|
|
134
|
+
}, [mappings]);
|
|
135
|
+
|
|
136
|
+
// TODO: Unify with mappingFeatures
|
|
137
|
+
const mappingColors = useMemo(() => {
|
|
138
|
+
const colors: mappingColors = {};
|
|
139
|
+
Object.entries(mappingFeatures).forEach(([_, feature]) => {
|
|
140
|
+
colors[feature.name] = getColorForFeature(feature.name, isDarkMode, colorProfile);
|
|
141
|
+
});
|
|
142
|
+
return colors;
|
|
143
|
+
}, [colorProfile, isDarkMode, mappingFeatures]);
|
|
144
|
+
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
if (ref.current != null) {
|
|
147
|
+
setHeight(ref?.current.getBoundingClientRect().height);
|
|
148
|
+
}
|
|
149
|
+
}, [width]);
|
|
150
|
+
|
|
151
|
+
const xScale = useMemo(() => {
|
|
152
|
+
if (width === undefined) {
|
|
153
|
+
return () => 0;
|
|
154
|
+
}
|
|
155
|
+
return scaleLinear([0n, total], [0, width]);
|
|
156
|
+
}, [total, width]);
|
|
157
|
+
|
|
158
|
+
if (table.numRows === 0 || width === undefined) {
|
|
159
|
+
return <></>;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<div onMouseLeave={() => dispatch(setHoveringNode(undefined))}>
|
|
164
|
+
<ColorStackLegend
|
|
165
|
+
mappingColors={mappingColors}
|
|
166
|
+
navigateTo={navigateTo}
|
|
167
|
+
compareMode={compareMode}
|
|
168
|
+
/>
|
|
169
|
+
<GraphTooltipArrow
|
|
170
|
+
table={table}
|
|
171
|
+
unit={sampleUnit}
|
|
172
|
+
total={total}
|
|
173
|
+
totalUnfiltered={total + filtered}
|
|
174
|
+
contextElement={svg.current}
|
|
175
|
+
/>
|
|
176
|
+
<svg
|
|
177
|
+
className="font-robotoMono"
|
|
178
|
+
width={width}
|
|
179
|
+
height={height}
|
|
180
|
+
preserveAspectRatio="xMinYMid"
|
|
181
|
+
ref={svg}
|
|
182
|
+
>
|
|
183
|
+
<g ref={ref}>
|
|
184
|
+
<g transform={'translate(0, 0)'}>
|
|
185
|
+
<IcicleNode
|
|
186
|
+
table={table}
|
|
187
|
+
row={0} // root is always row 0 in the arrow record
|
|
188
|
+
mappingColors={mappingColors}
|
|
189
|
+
x={0}
|
|
190
|
+
y={0}
|
|
191
|
+
totalWidth={width}
|
|
192
|
+
height={RowHeight}
|
|
193
|
+
setCurPath={setCurPath}
|
|
194
|
+
curPath={curPath}
|
|
195
|
+
total={total}
|
|
196
|
+
xScale={xScale}
|
|
197
|
+
path={[]}
|
|
198
|
+
level={0}
|
|
199
|
+
isRoot={true}
|
|
200
|
+
searchString={currentSearchString}
|
|
201
|
+
sortBy={sortBy}
|
|
202
|
+
darkMode={isDarkMode}
|
|
203
|
+
compareMode={compareMode}
|
|
204
|
+
/>
|
|
205
|
+
</g>
|
|
206
|
+
</g>
|
|
207
|
+
</svg>
|
|
208
|
+
</div>
|
|
209
|
+
);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
export default IcicleGraphArrow;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Copyright 2022 The Parca Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
|
|
14
|
+
import {EVERYTHING_ELSE} from '@parca/store';
|
|
15
|
+
import {diffColor, getLastItem} from '@parca/utilities';
|
|
16
|
+
|
|
17
|
+
interface mappingColors {
|
|
18
|
+
[key: string]: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface Props {
|
|
22
|
+
isDarkMode: boolean;
|
|
23
|
+
compareMode: boolean;
|
|
24
|
+
cumulative: bigint;
|
|
25
|
+
diff: bigint | null;
|
|
26
|
+
mappingColors: mappingColors;
|
|
27
|
+
functionName: string | null;
|
|
28
|
+
mappingFile: string | null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const useNodeColor = ({
|
|
32
|
+
isDarkMode,
|
|
33
|
+
compareMode,
|
|
34
|
+
cumulative,
|
|
35
|
+
diff,
|
|
36
|
+
mappingColors,
|
|
37
|
+
functionName,
|
|
38
|
+
mappingFile,
|
|
39
|
+
}: Props): string => {
|
|
40
|
+
if (compareMode) {
|
|
41
|
+
return diffColor(diff ?? 0n, cumulative, isDarkMode);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// To get the color we first check if the function name starts with 'runtime'.
|
|
45
|
+
// If it does, we color it as runtime. Otherwise, we check the mapping file.
|
|
46
|
+
// If there is no mapping file, we color it as 'everything else'.
|
|
47
|
+
return functionName?.startsWith('runtime') === true
|
|
48
|
+
? mappingColors.runtime
|
|
49
|
+
: mappingColors[getLastItem(mappingFile ?? '') ?? EVERYTHING_ELSE];
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default useNodeColor;
|