@parca/profile 0.17.2 → 0.17.4

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.
Files changed (120) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/GraphTooltipArrow/Content.d.ts +1 -2
  3. package/dist/GraphTooltipArrow/Content.d.ts.map +1 -1
  4. package/dist/GraphTooltipArrow/Content.js +1 -2
  5. package/dist/GraphTooltipArrow/DockedGraphTooltip/index.d.ts +1 -2
  6. package/dist/GraphTooltipArrow/DockedGraphTooltip/index.d.ts.map +1 -1
  7. package/dist/GraphTooltipArrow/DockedGraphTooltip/index.js +1 -2
  8. package/dist/GraphTooltipArrow/useGraphTooltip/index.d.ts +1 -2
  9. package/dist/GraphTooltipArrow/useGraphTooltip/index.d.ts.map +1 -1
  10. package/dist/GraphTooltipArrow/useGraphTooltip/index.js +2 -2
  11. package/dist/ProfileIcicleGraph/IcicleGraphArrow/ContextMenu.d.ts +2 -6
  12. package/dist/ProfileIcicleGraph/IcicleGraphArrow/ContextMenu.d.ts.map +1 -1
  13. package/dist/ProfileIcicleGraph/IcicleGraphArrow/ContextMenu.js +4 -5
  14. package/dist/ProfileIcicleGraph/IcicleGraphArrow/ContextMenuWrapper.d.ts +20 -0
  15. package/dist/ProfileIcicleGraph/IcicleGraphArrow/ContextMenuWrapper.d.ts.map +1 -0
  16. package/{src/Callgraph/constants.ts → dist/ProfileIcicleGraph/IcicleGraphArrow/ContextMenuWrapper.js} +12 -3
  17. package/dist/ProfileIcicleGraph/IcicleGraphArrow/IcicleGraphNodes.d.ts +8 -51
  18. package/dist/ProfileIcicleGraph/IcicleGraphArrow/IcicleGraphNodes.d.ts.map +1 -1
  19. package/dist/ProfileIcicleGraph/IcicleGraphArrow/IcicleGraphNodes.js +59 -136
  20. package/dist/ProfileIcicleGraph/IcicleGraphArrow/MemoizedTooltip.d.ts +8 -0
  21. package/dist/ProfileIcicleGraph/IcicleGraphArrow/MemoizedTooltip.d.ts.map +1 -0
  22. package/dist/ProfileIcicleGraph/IcicleGraphArrow/MemoizedTooltip.js +40 -0
  23. package/dist/ProfileIcicleGraph/IcicleGraphArrow/TooltipContext.d.ts +32 -0
  24. package/dist/ProfileIcicleGraph/IcicleGraphArrow/TooltipContext.d.ts.map +1 -0
  25. package/dist/ProfileIcicleGraph/IcicleGraphArrow/TooltipContext.js +40 -0
  26. package/dist/ProfileIcicleGraph/IcicleGraphArrow/index.d.ts +4 -3
  27. package/dist/ProfileIcicleGraph/IcicleGraphArrow/index.d.ts.map +1 -1
  28. package/dist/ProfileIcicleGraph/IcicleGraphArrow/index.js +62 -76
  29. package/dist/ProfileIcicleGraph/IcicleGraphArrow/utils.d.ts +3 -3
  30. package/dist/ProfileIcicleGraph/IcicleGraphArrow/utils.d.ts.map +1 -1
  31. package/dist/ProfileIcicleGraph/IcicleGraphArrow/utils.js +9 -7
  32. package/dist/ProfileIcicleGraph/index.d.ts +3 -6
  33. package/dist/ProfileIcicleGraph/index.d.ts.map +1 -1
  34. package/dist/ProfileIcicleGraph/index.js +8 -16
  35. package/dist/ProfileView/components/DashboardItems/index.d.ts +3 -5
  36. package/dist/ProfileView/components/DashboardItems/index.d.ts.map +1 -1
  37. package/dist/ProfileView/components/DashboardItems/index.js +4 -9
  38. package/dist/ProfileView/components/Toolbars/index.d.ts.map +1 -1
  39. package/dist/ProfileView/components/Toolbars/index.js +1 -2
  40. package/dist/ProfileView/index.d.ts +1 -1
  41. package/dist/ProfileView/index.d.ts.map +1 -1
  42. package/dist/ProfileView/index.js +1 -13
  43. package/dist/ProfileView/types/visualization.d.ts +1 -1
  44. package/dist/ProfileView/types/visualization.d.ts.map +1 -1
  45. package/dist/index.d.ts +0 -4
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +0 -2
  48. package/dist/styles.css +1 -1
  49. package/package.json +5 -5
  50. package/src/GraphTooltipArrow/Content.tsx +0 -3
  51. package/src/GraphTooltipArrow/DockedGraphTooltip/index.tsx +0 -3
  52. package/src/GraphTooltipArrow/useGraphTooltip/index.ts +1 -3
  53. package/src/ProfileIcicleGraph/IcicleGraphArrow/ContextMenu.tsx +5 -13
  54. package/src/ProfileIcicleGraph/IcicleGraphArrow/ContextMenuWrapper.tsx +53 -0
  55. package/src/ProfileIcicleGraph/IcicleGraphArrow/IcicleGraphNodes.tsx +96 -310
  56. package/src/ProfileIcicleGraph/IcicleGraphArrow/MemoizedTooltip.tsx +78 -0
  57. package/src/ProfileIcicleGraph/IcicleGraphArrow/TooltipContext.tsx +93 -0
  58. package/src/ProfileIcicleGraph/IcicleGraphArrow/index.tsx +110 -213
  59. package/src/ProfileIcicleGraph/IcicleGraphArrow/utils.ts +8 -15
  60. package/src/ProfileIcicleGraph/index.tsx +7 -36
  61. package/src/ProfileView/components/DashboardItems/index.tsx +2 -27
  62. package/src/ProfileView/components/Toolbars/index.tsx +0 -2
  63. package/src/ProfileView/index.tsx +0 -14
  64. package/src/ProfileView/types/visualization.ts +1 -1
  65. package/src/index.tsx +0 -5
  66. package/dist/Callgraph/constants.d.ts +0 -3
  67. package/dist/Callgraph/constants.d.ts.map +0 -1
  68. package/dist/Callgraph/constants.js +0 -14
  69. package/dist/Callgraph/index.d.ts +0 -11
  70. package/dist/Callgraph/index.d.ts.map +0 -1
  71. package/dist/Callgraph/index.js +0 -104
  72. package/dist/Callgraph/mockData/index.d.ts +0 -149
  73. package/dist/Callgraph/mockData/index.d.ts.map +0 -1
  74. package/dist/Callgraph/mockData/index.js +0 -594
  75. package/dist/Callgraph/utils.d.ts +0 -20
  76. package/dist/Callgraph/utils.d.ts.map +0 -1
  77. package/dist/Callgraph/utils.js +0 -97
  78. package/dist/GraphTooltip/ExpandOnHoverValue.d.ts +0 -7
  79. package/dist/GraphTooltip/ExpandOnHoverValue.d.ts.map +0 -1
  80. package/dist/GraphTooltip/ExpandOnHoverValue.js +0 -4
  81. package/dist/GraphTooltip/index.d.ts +0 -41
  82. package/dist/GraphTooltip/index.d.ts.map +0 -1
  83. package/dist/GraphTooltip/index.js +0 -201
  84. package/dist/ProfileIcicleGraph/IcicleGraph/ColorStackLegend.d.ts +0 -6
  85. package/dist/ProfileIcicleGraph/IcicleGraph/ColorStackLegend.d.ts.map +0 -1
  86. package/dist/ProfileIcicleGraph/IcicleGraph/ColorStackLegend.js +0 -59
  87. package/dist/ProfileIcicleGraph/IcicleGraph/IcicleGraphNodes.d.ts +0 -47
  88. package/dist/ProfileIcicleGraph/IcicleGraph/IcicleGraphNodes.d.ts.map +0 -1
  89. package/dist/ProfileIcicleGraph/IcicleGraph/IcicleGraphNodes.js +0 -93
  90. package/dist/ProfileIcicleGraph/IcicleGraph/index.d.ts +0 -14
  91. package/dist/ProfileIcicleGraph/IcicleGraph/index.d.ts.map +0 -1
  92. package/dist/ProfileIcicleGraph/IcicleGraph/index.js +0 -48
  93. package/dist/ProfileIcicleGraph/IcicleGraph/useColoredGraph.d.ts +0 -15
  94. package/dist/ProfileIcicleGraph/IcicleGraph/useColoredGraph.d.ts.map +0 -1
  95. package/dist/ProfileIcicleGraph/IcicleGraph/useColoredGraph.js +0 -57
  96. package/dist/ProfileIcicleGraph/IcicleGraph/useNodeColor.d.ts +0 -8
  97. package/dist/ProfileIcicleGraph/IcicleGraph/useNodeColor.d.ts.map +0 -1
  98. package/dist/ProfileIcicleGraph/IcicleGraph/useNodeColor.js +0 -32
  99. package/dist/ProfileIcicleGraph/IcicleGraph/utils.d.ts +0 -7
  100. package/dist/ProfileIcicleGraph/IcicleGraph/utils.d.ts.map +0 -1
  101. package/dist/ProfileIcicleGraph/IcicleGraph/utils.js +0 -66
  102. package/dist/ProfileIcicleGraph/IcicleGraphArrow/IcicleChartRootNode.d.ts +0 -9
  103. package/dist/ProfileIcicleGraph/IcicleGraphArrow/IcicleChartRootNode.d.ts.map +0 -1
  104. package/dist/ProfileIcicleGraph/IcicleGraphArrow/IcicleChartRootNode.js +0 -45
  105. package/dist/ProfileView/hooks/useGraphviz.d.ts +0 -12
  106. package/dist/ProfileView/hooks/useGraphviz.d.ts.map +0 -1
  107. package/dist/ProfileView/hooks/useGraphviz.js +0 -42
  108. package/src/Callgraph/index.tsx +0 -177
  109. package/src/Callgraph/mockData/index.ts +0 -605
  110. package/src/Callgraph/utils.ts +0 -141
  111. package/src/GraphTooltip/ExpandOnHoverValue.tsx +0 -30
  112. package/src/GraphTooltip/index.tsx +0 -509
  113. package/src/ProfileIcicleGraph/IcicleGraph/ColorStackLegend.tsx +0 -96
  114. package/src/ProfileIcicleGraph/IcicleGraph/IcicleGraphNodes.tsx +0 -266
  115. package/src/ProfileIcicleGraph/IcicleGraph/index.tsx +0 -123
  116. package/src/ProfileIcicleGraph/IcicleGraph/useColoredGraph.ts +0 -117
  117. package/src/ProfileIcicleGraph/IcicleGraph/useNodeColor.ts +0 -54
  118. package/src/ProfileIcicleGraph/IcicleGraph/utils.ts +0 -102
  119. package/src/ProfileIcicleGraph/IcicleGraphArrow/IcicleChartRootNode.tsx +0 -130
  120. package/src/ProfileView/hooks/useGraphviz.ts +0 -69
@@ -1,141 +0,0 @@
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 * as d3 from 'd3';
15
- import {withAlphaHex} from 'with-alpha-hex';
16
-
17
- import {CallgraphEdge, CallgraphNode} from '@parca/client';
18
-
19
- export const pixelsToInches = (pixels: number): number => pixels / 96;
20
-
21
- export const getCurvePoints = ({
22
- pos,
23
- xScale = n => n,
24
- yScale = n => n,
25
- source = [],
26
- target = [],
27
- offset = 0,
28
- isSelfLoop = false,
29
- }: {
30
- pos: string;
31
- xScale?: (pos: number) => number;
32
- yScale?: (pos: number) => number;
33
- source?: number[];
34
- target?: number[];
35
- isSelfLoop?: boolean;
36
- offset?: number;
37
- }): number[] => {
38
- if (isSelfLoop) {
39
- const [sourceX, sourceY] = source;
40
- const [targetX, targetY] = target;
41
-
42
- return [
43
- sourceX,
44
- sourceY + offset,
45
- sourceX,
46
- sourceY + 3 * offset,
47
- targetX + 5 * offset,
48
- targetY,
49
- targetX + offset,
50
- targetY,
51
- ];
52
- }
53
-
54
- // graphviz pos format is in format 'endpoint,startpoint,triple(cp1,cp2,end),...triple...'
55
- const scalePoint = (point: number[]): number[] => [xScale(point[0]), yScale(point[1])];
56
- const strAsNumArray = (string: string): number[] =>
57
- string
58
- .replace('e,', '')
59
- .split(',')
60
- .map(str => Number(str));
61
- const getLastPointWithOffset = (target: number[], last: number[], offset: number): number[] => {
62
- const [targetX, targetY] = target;
63
- const [lastX, lastY] = last;
64
- const diffX = targetX - lastX;
65
- const diffY = targetY - lastY;
66
- const diffZ = Math.hypot(diffX, diffY);
67
-
68
- const offsetX = (diffX * offset) / diffZ;
69
- const offsetY = (diffY * offset) / diffZ;
70
-
71
- return [targetX - offsetX, targetY - offsetY];
72
- };
73
- const points: number[][] = pos.split(' ').map(str => strAsNumArray(str));
74
- const scaledPoints: number[][] = points.map(point => scalePoint(point));
75
-
76
- const lastPointIndex = scaledPoints.length - 1;
77
- const lastPointWithOffset = getLastPointWithOffset(target, scaledPoints[lastPointIndex], offset);
78
-
79
- return [source, ...scaledPoints.slice(2, points.length - 1), lastPointWithOffset].flat();
80
- };
81
-
82
- const objectAsDotAttributes = (obj: {[key: string]: string | number}): string =>
83
- Object.entries(obj)
84
- .map(entry => `${entry[0]}="${entry[1]}"`)
85
- .join(' ');
86
-
87
- export const jsonToDot = ({
88
- graph,
89
- colorRange,
90
- }: {
91
- graph: {nodes: CallgraphNode[]; edges: CallgraphEdge[]};
92
- width: number;
93
- colorRange: [string, string];
94
- }): string => {
95
- const {nodes, edges} = graph;
96
- const cumulatives = edges.map((edge: CallgraphEdge) => Number(edge.cumulative));
97
- const cumulativesRange = d3.extent(cumulatives) as [number, number];
98
- const colorScale = d3
99
- .scaleSequentialLog(d3.interpolateBlues)
100
- .domain(cumulativesRange)
101
- .range(colorRange);
102
- const colorOpacityScale = d3.scaleLinear().domain(cumulativesRange).range([0.5, 1]);
103
-
104
- const nodesAsStrings = nodes.map((node: CallgraphNode) => {
105
- const rgbColor = colorScale(Number(node.cumulative));
106
- const hexColor = d3.color(rgbColor)?.formatHex() ?? 'red';
107
- const dataAttributes = {
108
- label: node.meta?.function?.name.substring(0, 12) ?? '',
109
- root: (node.id === 'root').toString(),
110
- fillcolor: hexColor,
111
- className: 'node',
112
- id: node.id,
113
- };
114
-
115
- return `"${node.id}" [${objectAsDotAttributes(dataAttributes)}]`;
116
- });
117
-
118
- const edgesAsStrings = edges.map((edge: CallgraphEdge) => {
119
- const dataAttributes = {
120
- cumulative: Number(edge.cumulative),
121
- color: withAlphaHex(colorRange[1], colorOpacityScale(Number(edge.cumulative))),
122
- className: 'edge',
123
- // boxHeight: DEFAULT_NODE_HEIGHT,
124
- };
125
-
126
- return `"${edge.source}" -> "${edge.target}" [${objectAsDotAttributes(dataAttributes)}]`;
127
- });
128
-
129
- const graphAsDot = `digraph "callgraph" {
130
- rankdir="TB"
131
- overlap="prism"
132
- ratio="1,3"
133
- margin=15
134
- edge [margin=0]
135
- node [shape=box style="rounded,filled"]
136
- ${nodesAsStrings.join(' ')}
137
- ${edgesAsStrings.join(' ')}
138
- }`;
139
-
140
- return graphAsDot;
141
- };
@@ -1,30 +0,0 @@
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
- interface Props {
15
- value: string | number | undefined;
16
- displayValue?: string | number | undefined;
17
- }
18
-
19
- export const ExpandOnHover = ({value, displayValue}: Props): JSX.Element => {
20
- return (
21
- <div className="group relative w-full">
22
- <div className="w-full overflow-hidden text-ellipsis whitespace-nowrap">
23
- {displayValue ?? value}
24
- </div>
25
- <div className="absolute -inset-2 hidden h-fit max-w-[500px] whitespace-normal break-all rounded bg-gray-50 p-2 shadow-[0_0_10px_2px_rgba(0,0,0,0.3)] group-hover:flex dark:bg-gray-900">
26
- {value}
27
- </div>
28
- </div>
29
- );
30
- };
@@ -1,509 +0,0 @@
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 {useEffect, useMemo, useState} from 'react';
15
-
16
- import {pointer} from 'd3-selection';
17
- import {usePopper} from 'react-popper';
18
-
19
- import {
20
- CallgraphNode,
21
- CallgraphNodeMeta,
22
- FlamegraphNode,
23
- FlamegraphNodeMeta,
24
- FlamegraphRootNode,
25
- } from '@parca/client';
26
- import {
27
- Location,
28
- Mapping,
29
- Function as ParcaFunction,
30
- } from '@parca/client/dist/parca/metastore/v1alpha1/metastore';
31
- import {CopyToClipboard, useKeyDown} from '@parca/components';
32
- import {selectHoveringNode, useAppSelector} from '@parca/store';
33
- import {divide, getLastItem, valueFormatter} from '@parca/utilities';
34
-
35
- import {hexifyAddress, truncateString, truncateStringReverse} from '../';
36
- import {ExpandOnHover} from './ExpandOnHoverValue';
37
-
38
- const NoData = (): JSX.Element => {
39
- return <span className="rounded bg-gray-200 px-2 dark:bg-gray-800">Not available</span>;
40
- };
41
-
42
- interface ExtendedCallgraphNodeMeta extends CallgraphNodeMeta {
43
- lineIndex: number;
44
- locationIndex: number;
45
- }
46
-
47
- interface HoveringNode extends FlamegraphRootNode, FlamegraphNode, CallgraphNode {
48
- diff: bigint;
49
- meta?: FlamegraphNodeMeta | ExtendedCallgraphNodeMeta;
50
- }
51
-
52
- interface GraphTooltipProps {
53
- x?: number;
54
- y?: number;
55
- unit: string;
56
- total: bigint;
57
- totalUnfiltered: bigint;
58
- hoveringNode?: HoveringNode;
59
- contextElement: Element | null;
60
- isFixed?: boolean;
61
- virtualContextElement?: boolean;
62
- strings?: string[];
63
- mappings?: Mapping[];
64
- locations?: Location[];
65
- functions?: ParcaFunction[];
66
- type?: string;
67
- }
68
-
69
- const virtualElement = {
70
- getBoundingClientRect: () =>
71
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
72
- ({
73
- width: 0,
74
- height: 0,
75
- top: 0,
76
- left: 0,
77
- right: 0,
78
- bottom: 0,
79
- } as DOMRect),
80
- };
81
-
82
- function generateGetBoundingClientRect(contextElement: Element, x = 0, y = 0): () => DOMRect {
83
- const domRect = contextElement.getBoundingClientRect();
84
- return () =>
85
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
86
- ({
87
- width: 0,
88
- height: 0,
89
- top: domRect.y + y,
90
- left: domRect.x + x,
91
- right: domRect.x + x,
92
- bottom: domRect.y + y,
93
- } as DOMRect);
94
- }
95
-
96
- const TooltipMetaInfo = ({
97
- hoveringNode,
98
- onCopy,
99
- strings,
100
- mappings,
101
- locations,
102
- functions,
103
- type = 'flamegraph',
104
- }: {
105
- hoveringNode: HoveringNode;
106
- onCopy: () => void;
107
- strings?: string[];
108
- mappings?: Mapping[];
109
- locations?: Location[];
110
- functions?: ParcaFunction[];
111
- type?: string;
112
- }): JSX.Element => {
113
- // populate meta from the flamegraph metadata tables
114
- if (
115
- type === 'flamegraph' &&
116
- locations !== undefined &&
117
- hoveringNode.meta?.locationIndex !== undefined &&
118
- hoveringNode.meta.locationIndex !== 0
119
- ) {
120
- const location = locations[hoveringNode.meta.locationIndex - 1];
121
- hoveringNode.meta.location = location;
122
-
123
- if (location !== undefined) {
124
- if (
125
- mappings !== undefined &&
126
- location.mappingIndex !== undefined &&
127
- location.mappingIndex !== 0
128
- ) {
129
- const mapping = mappings[location.mappingIndex - 1];
130
- if (strings !== undefined && mapping !== undefined) {
131
- mapping.file =
132
- mapping?.fileStringIndex !== undefined ? strings[mapping.fileStringIndex] : '';
133
- mapping.buildId =
134
- mapping?.buildIdStringIndex !== undefined ? strings[mapping.buildIdStringIndex] : '';
135
- }
136
- hoveringNode.meta.mapping = mapping;
137
- }
138
-
139
- if (
140
- functions !== undefined &&
141
- location.lines !== undefined &&
142
- hoveringNode.meta.lineIndex !== undefined &&
143
- hoveringNode.meta.lineIndex < location.lines.length
144
- ) {
145
- const func = functions[location.lines[hoveringNode.meta.lineIndex].functionIndex - 1];
146
- if (strings !== undefined) {
147
- func.name = strings[func.nameStringIndex];
148
- func.systemName = strings[func.systemNameStringIndex];
149
- func.filename = strings[func.filenameStringIndex];
150
- }
151
- hoveringNode.meta.function = func;
152
- }
153
- }
154
- }
155
-
156
- const getTextForFile = (hoveringNode: HoveringNode): string => {
157
- if (hoveringNode.meta?.function == null) return '<unknown>';
158
-
159
- return `${hoveringNode.meta.function.filename} ${
160
- hoveringNode.meta.line?.line !== undefined && hoveringNode.meta.line?.line !== 0n
161
- ? ` +${hoveringNode.meta.line.line.toString()}`
162
- : `${
163
- hoveringNode.meta.function?.startLine !== undefined &&
164
- hoveringNode.meta.function?.startLine !== 0n
165
- ? ` +${hoveringNode.meta.function.startLine}`
166
- : ''
167
- }`
168
- }`;
169
- };
170
- const file = getTextForFile(hoveringNode);
171
-
172
- return (
173
- <>
174
- <tr>
175
- <td className="w-1/4">File</td>
176
- <td className="w-3/4 break-all">
177
- {hoveringNode.meta?.function?.filename == null ||
178
- hoveringNode.meta?.function.filename === '' ? (
179
- <NoData />
180
- ) : (
181
- <CopyToClipboard onCopy={onCopy} text={file}>
182
- <button className="cursor-pointer whitespace-nowrap text-left">
183
- <ExpandOnHover value={file} displayValue={truncateStringReverse(file, 40)} />
184
- </button>
185
- </CopyToClipboard>
186
- )}
187
- </td>
188
- </tr>
189
-
190
- <tr>
191
- <td className="w-1/4">Address</td>
192
- <td className="w-3/4 break-all">
193
- {hoveringNode.meta?.location?.address == null ||
194
- hoveringNode.meta?.location.address === 0n ? (
195
- <NoData />
196
- ) : (
197
- <CopyToClipboard
198
- onCopy={onCopy}
199
- text={hexifyAddress(hoveringNode.meta.location.address)}
200
- >
201
- <button className="cursor-pointer">
202
- {hexifyAddress(hoveringNode.meta.location.address)}
203
- </button>
204
- </CopyToClipboard>
205
- )}
206
- </td>
207
- </tr>
208
- <tr>
209
- <td className="w-1/4">Binary</td>
210
- <td className="w-3/4 break-all">
211
- {hoveringNode.meta?.mapping == null || hoveringNode.meta.mapping.file === '' ? (
212
- <NoData />
213
- ) : (
214
- <CopyToClipboard onCopy={onCopy} text={hoveringNode.meta.mapping.file}>
215
- <button className="cursor-pointer">
216
- {getLastItem(hoveringNode.meta.mapping.file)}
217
- </button>
218
- </CopyToClipboard>
219
- )}
220
- </td>
221
- </tr>
222
-
223
- <tr>
224
- <td className="w-1/4">Build Id</td>
225
- <td className="w-3/4 break-all">
226
- {hoveringNode.meta?.mapping == null || hoveringNode.meta?.mapping.buildId === '' ? (
227
- <NoData />
228
- ) : (
229
- <CopyToClipboard onCopy={onCopy} text={hoveringNode.meta.mapping.buildId}>
230
- <button className="cursor-pointer">
231
- {truncateString(getLastItem(hoveringNode.meta.mapping.buildId) as string, 28)}
232
- </button>
233
- </CopyToClipboard>
234
- )}
235
- </td>
236
- </tr>
237
- </>
238
- );
239
- };
240
-
241
- let timeoutHandle: ReturnType<typeof setTimeout> | null = null;
242
-
243
- export const GraphTooltipContent = ({
244
- hoveringNode,
245
- unit,
246
- total,
247
- totalUnfiltered,
248
- isFixed,
249
- strings,
250
- mappings,
251
- locations,
252
- functions,
253
- type = 'flamegraph',
254
- }: {
255
- hoveringNode: HoveringNode;
256
- unit: string;
257
- total: bigint;
258
- totalUnfiltered: bigint;
259
- isFixed: boolean;
260
- strings?: string[];
261
- mappings?: Mapping[];
262
- locations?: Location[];
263
- functions?: ParcaFunction[];
264
- type?: string;
265
- }): JSX.Element => {
266
- const [isCopied, setIsCopied] = useState<boolean>(false);
267
-
268
- const onCopy = (): void => {
269
- setIsCopied(true);
270
-
271
- if (timeoutHandle !== null) {
272
- clearTimeout(timeoutHandle);
273
- }
274
- timeoutHandle = setTimeout(() => setIsCopied(false), 3000);
275
- };
276
-
277
- const hoveringNodeCumulative = hoveringNode.cumulative;
278
- // '?? 0n' is needed because because diff is undefined in callgraph for some nodes,
279
- // even though the type doesn't allow it.
280
- const diff = hoveringNode.diff ?? 0n;
281
- const prevValue = hoveringNodeCumulative - diff;
282
- const diffRatio = diff !== 0n ? divide(diff, prevValue) : 0;
283
- const diffSign = diff > 0 ? '+' : '';
284
- const diffValueText = diffSign + valueFormatter(diff, unit, 1);
285
- const diffPercentageText = diffSign + (diffRatio * 100).toFixed(2) + '%';
286
- const diffText = `${diffValueText} (${diffPercentageText})`;
287
-
288
- const getTextForCumulative = (hoveringNodeCumulative: bigint): string => {
289
- const filtered =
290
- totalUnfiltered > total
291
- ? ` / ${divide(hoveringNodeCumulative * 100n, total).toFixed(2)}% of filtered`
292
- : '';
293
- return `${valueFormatter(hoveringNodeCumulative, unit, 2)}
294
- (${divide(hoveringNodeCumulative * 100n, totalUnfiltered).toFixed(2)}%${filtered})`;
295
- };
296
-
297
- return (
298
- <div className={`flex text-sm ${isFixed ? 'w-full' : ''}`}>
299
- <div className={`m-auto w-full ${isFixed ? 'w-full' : ''}`}>
300
- <div className="min-h-52 flex w-[500px] flex-col justify-between rounded-lg border border-gray-300 bg-gray-50 p-3 shadow-lg dark:border-gray-500 dark:bg-gray-900">
301
- <div className="flex flex-row">
302
- <div className="mx-2">
303
- <div className="flex h-10 items-center break-all font-semibold">
304
- {hoveringNode.meta === undefined ? (
305
- <p>root</p>
306
- ) : (
307
- <>
308
- {hoveringNode.meta.function !== undefined &&
309
- hoveringNode.meta.function.name !== '' ? (
310
- <CopyToClipboard onCopy={onCopy} text={hoveringNode.meta.function.name}>
311
- <button className="cursor-pointer text-left">
312
- {hoveringNode.meta.function.name}
313
- </button>
314
- </CopyToClipboard>
315
- ) : (
316
- <>
317
- {hoveringNode.meta.location !== undefined &&
318
- hoveringNode.meta.location.address !== 0n ? (
319
- <CopyToClipboard
320
- onCopy={onCopy}
321
- text={hexifyAddress(hoveringNode.meta.location.address)}
322
- >
323
- <button className="cursor-pointer text-left">
324
- {hexifyAddress(hoveringNode.meta.location.address)}
325
- </button>
326
- </CopyToClipboard>
327
- ) : (
328
- <p>unknown</p>
329
- )}
330
- </>
331
- )}
332
- </>
333
- )}
334
- </div>
335
- <table className="my-2 w-full table-fixed pr-0 text-gray-700 dark:text-gray-300">
336
- <tbody>
337
- <tr>
338
- <td className="w-1/4">Cumulative</td>
339
-
340
- <td className="w-3/4">
341
- <CopyToClipboard
342
- onCopy={onCopy}
343
- text={getTextForCumulative(hoveringNodeCumulative)}
344
- >
345
- <button className="cursor-pointer">
346
- {getTextForCumulative(hoveringNodeCumulative)}
347
- </button>
348
- </CopyToClipboard>
349
- </td>
350
- </tr>
351
- {hoveringNode.diff !== undefined && diff !== 0n && (
352
- <tr>
353
- <td className="w-1/4">Diff</td>
354
- <td className="w-3/4">
355
- <CopyToClipboard onCopy={onCopy} text={diffText}>
356
- <button className="cursor-pointer">{diffText}</button>
357
- </CopyToClipboard>
358
- </td>
359
- </tr>
360
- )}
361
- <TooltipMetaInfo
362
- onCopy={onCopy}
363
- hoveringNode={hoveringNode}
364
- strings={strings}
365
- mappings={mappings}
366
- locations={locations}
367
- functions={functions}
368
- type={type}
369
- />
370
- </tbody>
371
- </table>
372
- </div>
373
- </div>
374
- <span className="mx-2 block text-xs text-gray-500">
375
- {isCopied ? 'Copied!' : 'Hold shift and click on a value to copy.'}
376
- </span>
377
- </div>
378
- </div>
379
- </div>
380
- );
381
- };
382
-
383
- const GraphTooltip = ({
384
- x,
385
- y,
386
- unit,
387
- total,
388
- totalUnfiltered,
389
- hoveringNode: hoveringNodeProp,
390
- contextElement,
391
- isFixed = false,
392
- virtualContextElement = true,
393
- strings,
394
- mappings,
395
- locations,
396
- functions,
397
- type = 'flamegraph',
398
- }: GraphTooltipProps): JSX.Element => {
399
- const hoveringNodeState = useAppSelector(selectHoveringNode);
400
- // @ts-expect-error
401
- const hoveringNode = useMemo<HoveringNode>(() => {
402
- const h = hoveringNodeProp ?? hoveringNodeState;
403
- if (h == null) {
404
- return h;
405
- }
406
-
407
- // Cloning the object to avoid the mutating error as this is Redux store object and we are modifying the meta object in GraphTooltipContent component.
408
- return {
409
- ...h,
410
- meta: {
411
- ...h.meta,
412
- },
413
- };
414
- }, [hoveringNodeProp, hoveringNodeState]);
415
-
416
- const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null);
417
-
418
- const {styles, attributes, ...popperProps} = usePopper(
419
- virtualContextElement ? virtualElement : contextElement,
420
- popperElement,
421
- {
422
- placement: 'bottom-start',
423
- strategy: 'absolute',
424
- modifiers: [
425
- {
426
- name: 'preventOverflow',
427
- options: {
428
- tether: false,
429
- altAxis: true,
430
- boundary: contextElement ?? undefined,
431
- },
432
- },
433
- {
434
- name: 'offset',
435
- options: {
436
- offset: [30, 30],
437
- },
438
- },
439
- {
440
- name: 'flip',
441
- options: {
442
- boundary: contextElement ?? undefined,
443
- },
444
- },
445
- ],
446
- }
447
- );
448
-
449
- const {isShiftDown} = useKeyDown();
450
-
451
- useEffect(() => {
452
- if (contextElement === null) return;
453
- const onMouseMove: EventListenerOrEventListenerObject = (e: Event) => {
454
- if (isShiftDown) {
455
- return;
456
- }
457
-
458
- let tooltipX = x;
459
- let tooltipY = y;
460
- if (tooltipX == null || tooltipY == null) {
461
- const rel = pointer(e);
462
- tooltipX = rel[0];
463
- tooltipY = rel[1];
464
- }
465
- virtualElement.getBoundingClientRect = generateGetBoundingClientRect(
466
- contextElement,
467
- tooltipX,
468
- tooltipY
469
- );
470
-
471
- void popperProps.update?.();
472
- };
473
-
474
- contextElement.addEventListener('mousemove', onMouseMove);
475
- return () => {
476
- contextElement.removeEventListener('mousemove', onMouseMove);
477
- };
478
- }, [contextElement, popperProps, isShiftDown, x, y]);
479
-
480
- if (hoveringNode === undefined || hoveringNode == null) return <></>;
481
-
482
- return isFixed ? (
483
- <GraphTooltipContent
484
- hoveringNode={hoveringNode}
485
- unit={unit}
486
- total={total}
487
- totalUnfiltered={totalUnfiltered}
488
- isFixed={isFixed}
489
- type={type}
490
- />
491
- ) : (
492
- <div ref={setPopperElement} style={styles.popper} {...attributes.popper}>
493
- <GraphTooltipContent
494
- hoveringNode={hoveringNode}
495
- unit={unit}
496
- total={total}
497
- totalUnfiltered={totalUnfiltered}
498
- isFixed={isFixed}
499
- strings={strings}
500
- mappings={mappings}
501
- locations={locations}
502
- functions={functions}
503
- type={type}
504
- />
505
- </div>
506
- );
507
- };
508
-
509
- export default GraphTooltip;