@parca/profile 0.16.0 → 0.16.43

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 (98) hide show
  1. package/CHANGELOG.md +52 -25
  2. package/dist/Callgraph/Edge/index.d.ts +23 -0
  3. package/dist/Callgraph/Edge/index.js +30 -0
  4. package/dist/Callgraph/Node/index.d.ts +20 -0
  5. package/dist/Callgraph/Node/index.js +37 -0
  6. package/dist/Callgraph/index.d.ts +9 -0
  7. package/dist/Callgraph/index.js +137 -0
  8. package/dist/Callgraph/mockData/index.d.ts +148 -0
  9. package/dist/Callgraph/mockData/index.js +577 -0
  10. package/dist/Callgraph/utils.d.ts +19 -0
  11. package/dist/Callgraph/utils.js +82 -0
  12. package/dist/GraphTooltip/index.d.ts +20 -0
  13. package/dist/GraphTooltip/index.js +155 -0
  14. package/dist/IcicleGraph.d.ts +36 -0
  15. package/dist/IcicleGraph.js +158 -0
  16. package/dist/MatchersInput/index.d.ts +24 -0
  17. package/dist/MatchersInput/index.js +479 -0
  18. package/dist/MetricsCircle/index.d.ts +8 -0
  19. package/dist/MetricsCircle/index.js +18 -0
  20. package/dist/MetricsGraph/index.d.ts +36 -0
  21. package/dist/MetricsGraph/index.js +327 -0
  22. package/dist/MetricsSeries/index.d.ts +12 -0
  23. package/dist/MetricsSeries/index.js +21 -0
  24. package/dist/ProfileExplorer/ProfileExplorerCompare.d.ts +20 -0
  25. package/dist/ProfileExplorer/ProfileExplorerCompare.js +38 -0
  26. package/dist/ProfileExplorer/ProfileExplorerSingle.d.ts +16 -0
  27. package/dist/ProfileExplorer/ProfileExplorerSingle.js +19 -0
  28. package/dist/ProfileExplorer/index.d.ts +10 -0
  29. package/dist/ProfileExplorer/index.js +203 -0
  30. package/dist/ProfileIcicleGraph.d.ts +11 -0
  31. package/dist/ProfileIcicleGraph.js +28 -0
  32. package/dist/ProfileMetricsGraph/index.d.ts +23 -0
  33. package/dist/ProfileMetricsGraph/index.js +127 -0
  34. package/dist/ProfileSVG.module.css +3 -0
  35. package/dist/ProfileSelector/CompareButton.d.ts +6 -0
  36. package/dist/ProfileSelector/CompareButton.js +41 -0
  37. package/dist/ProfileSelector/MergeButton.d.ts +6 -0
  38. package/dist/ProfileSelector/MergeButton.js +41 -0
  39. package/dist/ProfileSelector/index.d.ts +30 -0
  40. package/dist/ProfileSelector/index.js +133 -0
  41. package/dist/ProfileSource.d.ts +89 -0
  42. package/dist/ProfileSource.js +239 -0
  43. package/dist/ProfileTypeSelector/index.d.ts +21 -0
  44. package/dist/ProfileTypeSelector/index.js +138 -0
  45. package/dist/ProfileView.d.ts +40 -0
  46. package/dist/ProfileView.js +111 -0
  47. package/dist/ProfileView.styles.css +3 -0
  48. package/dist/ProfileViewWithData.d.ts +12 -0
  49. package/dist/ProfileViewWithData.js +116 -0
  50. package/dist/TopTable.d.ts +10 -0
  51. package/dist/TopTable.js +140 -0
  52. package/dist/TopTable.styles.css +7 -0
  53. package/dist/components/DiffLegend.d.ts +3 -0
  54. package/dist/components/DiffLegend.js +62 -0
  55. package/dist/components/ProfileShareButton/ResultBox.d.ts +7 -0
  56. package/dist/components/ProfileShareButton/ResultBox.js +46 -0
  57. package/dist/components/ProfileShareButton/index.d.ts +8 -0
  58. package/dist/components/ProfileShareButton/index.js +119 -0
  59. package/dist/index.d.ts +13 -0
  60. package/dist/index.js +64 -0
  61. package/dist/stories/ProfileTypeSelector.stories.d.ts +5 -0
  62. package/dist/stories/ProfileTypeSelector.stories.js +77 -0
  63. package/dist/stories/ProfileView.stories.d.ts +5 -0
  64. package/dist/stories/ProfileView.stories.js +22 -0
  65. package/dist/stories/mockdata/flamegraphData.json +7960 -0
  66. package/dist/styles.css +1 -0
  67. package/dist/useDelayedLoader.d.ts +5 -0
  68. package/dist/useDelayedLoader.js +33 -0
  69. package/dist/useQuery.d.ts +13 -0
  70. package/dist/useQuery.js +41 -0
  71. package/dist/utils.d.ts +4 -0
  72. package/dist/utils.js +83 -0
  73. package/package.json +13 -8
  74. package/src/Callgraph/Edge/index.tsx +59 -0
  75. package/src/Callgraph/Node/index.tsx +66 -0
  76. package/src/Callgraph/index.tsx +169 -0
  77. package/src/Callgraph/mockData/index.ts +605 -0
  78. package/src/Callgraph/utils.ts +116 -0
  79. package/src/GraphTooltip/index.tsx +340 -0
  80. package/src/IcicleGraph.tsx +28 -8
  81. package/src/MatchersInput/index.tsx +698 -0
  82. package/src/MetricsCircle/index.tsx +28 -0
  83. package/src/MetricsGraph/index.tsx +589 -0
  84. package/src/MetricsSeries/index.tsx +38 -0
  85. package/src/ProfileExplorer/ProfileExplorerCompare.tsx +109 -0
  86. package/src/ProfileExplorer/ProfileExplorerSingle.tsx +72 -0
  87. package/src/ProfileExplorer/index.tsx +377 -0
  88. package/src/ProfileMetricsGraph/index.tsx +143 -0
  89. package/src/ProfileSelector/CompareButton.tsx +72 -0
  90. package/src/ProfileSelector/MergeButton.tsx +72 -0
  91. package/src/ProfileSelector/index.tsx +270 -0
  92. package/src/ProfileTypeSelector/index.tsx +180 -0
  93. package/src/ProfileView.tsx +2 -7
  94. package/src/index.tsx +11 -0
  95. package/src/useQuery.tsx +1 -0
  96. package/tailwind.config.js +8 -0
  97. package/tsconfig.json +7 -3
  98. package/typings.d.ts +14 -0
@@ -0,0 +1,340 @@
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 {CopyToClipboard} from 'react-copy-to-clipboard';
15
+ import {useState, useEffect} from 'react';
16
+ import {usePopper} from 'react-popper';
17
+
18
+ import {CallgraphNode, FlamegraphNode, FlamegraphRootNode} from '@parca/client';
19
+ import {getLastItem, valueFormatter} from '@parca/functions';
20
+ import useIsShiftDown from '@parca/components/src/hooks/useIsShiftDown';
21
+ import {hexifyAddress} from '../';
22
+
23
+ interface GraphTooltipProps {
24
+ x: number;
25
+ y: number;
26
+ unit: string;
27
+ total: number;
28
+ hoveringNode: HoveringNode;
29
+ contextElement: Element | null;
30
+ isFixed?: boolean;
31
+ virtualContextElement?: boolean;
32
+ }
33
+
34
+ const virtualElement = {
35
+ getBoundingClientRect: () =>
36
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
37
+ ({
38
+ width: 0,
39
+ height: 0,
40
+ top: 0,
41
+ left: 0,
42
+ right: 0,
43
+ bottom: 0,
44
+ } as DOMRect),
45
+ };
46
+
47
+ function generateGetBoundingClientRect(contextElement: Element, x = 0, y = 0): () => DOMRect {
48
+ const domRect = contextElement.getBoundingClientRect();
49
+ return () =>
50
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
51
+ ({
52
+ width: 0,
53
+ height: 0,
54
+ top: domRect.y + y,
55
+ left: domRect.x + x,
56
+ right: domRect.x + x,
57
+ bottom: domRect.y + y,
58
+ } as DOMRect);
59
+ }
60
+
61
+ const TooltipMetaInfo = ({
62
+ hoveringNode,
63
+ onCopy,
64
+ }: {
65
+ hoveringNode: FlamegraphNode;
66
+ onCopy: () => void;
67
+ }): JSX.Element => {
68
+ if (hoveringNode.meta === undefined) return <></>;
69
+
70
+ const getTextForFile = (hoveringNode: FlamegraphNode): string => {
71
+ if (hoveringNode.meta === undefined) return '<unknown>';
72
+
73
+ // @ts-expect-error
74
+ return `${hoveringNode.meta.function.filename} ${
75
+ hoveringNode.meta.line?.line !== undefined && hoveringNode.meta.line?.line !== '0'
76
+ ? ` +${hoveringNode.meta.line.line.toString()}`
77
+ : `${
78
+ hoveringNode.meta.function?.startLine !== undefined &&
79
+ hoveringNode.meta.function?.startLine !== '0'
80
+ ? ` +${hoveringNode.meta.function.startLine}`
81
+ : ''
82
+ }`
83
+ }`;
84
+ };
85
+
86
+ return (
87
+ <>
88
+ {hoveringNode.meta.function?.filename !== undefined &&
89
+ hoveringNode.meta.function?.filename !== '' && (
90
+ <tr>
91
+ <td className="w-1/5">File</td>
92
+ <td className="w-4/5 break-all">
93
+ <CopyToClipboard onCopy={onCopy} text={getTextForFile(hoveringNode)}>
94
+ <button className="cursor-pointer text-left">{getTextForFile(hoveringNode)}</button>
95
+ </CopyToClipboard>
96
+ </td>
97
+ </tr>
98
+ )}
99
+ {hoveringNode.meta.location?.address !== undefined &&
100
+ hoveringNode.meta.location?.address !== '0' && (
101
+ <tr>
102
+ <td className="w-1/5">Address</td>
103
+ <td className="w-4/5 break-all">
104
+ <CopyToClipboard
105
+ onCopy={onCopy}
106
+ text={' 0x' + hoveringNode.meta.location.address.toString()}
107
+ >
108
+ <button className="cursor-pointer">
109
+ {' 0x' + hoveringNode.meta.location.address.toString()}
110
+ </button>
111
+ </CopyToClipboard>
112
+ </td>
113
+ </tr>
114
+ )}
115
+ {hoveringNode.meta.mapping !== undefined && hoveringNode.meta.mapping.file !== '' && (
116
+ <tr>
117
+ <td className="w-1/5">Binary</td>
118
+ <td className="w-4/5 break-all">
119
+ <CopyToClipboard onCopy={onCopy} text={hoveringNode.meta.mapping.file}>
120
+ <button className="cursor-pointer">
121
+ {getLastItem(hoveringNode.meta.mapping.file)}
122
+ </button>
123
+ </CopyToClipboard>
124
+ </td>
125
+ </tr>
126
+ )}
127
+ {hoveringNode.meta.mapping !== undefined && hoveringNode.meta.mapping.buildId !== '' && (
128
+ <tr>
129
+ <td className="w-1/5">Build Id</td>
130
+ <td className="w-4/5 break-all">
131
+ <CopyToClipboard onCopy={onCopy} text={hoveringNode.meta.mapping.buildId}>
132
+ <button className="cursor-pointer">
133
+ {getLastItem(hoveringNode.meta.mapping.buildId)}
134
+ </button>
135
+ </CopyToClipboard>
136
+ </td>
137
+ </tr>
138
+ )}
139
+ </>
140
+ );
141
+ };
142
+
143
+ export interface HoveringNode extends CallgraphNode, FlamegraphRootNode {
144
+ diff: string;
145
+ meta?: {[key: string]: any};
146
+ }
147
+
148
+ let timeoutHandle: ReturnType<typeof setTimeout> | null = null;
149
+
150
+ const GraphTooltipContent = ({
151
+ hoveringNode,
152
+ unit,
153
+ total,
154
+ isFixed,
155
+ }: {
156
+ hoveringNode: HoveringNode;
157
+ unit: string;
158
+ total: number;
159
+ isFixed: boolean;
160
+ }): JSX.Element => {
161
+ const [isCopied, setIsCopied] = useState<boolean>(false);
162
+
163
+ const onCopy = (): void => {
164
+ setIsCopied(true);
165
+
166
+ if (timeoutHandle !== null) {
167
+ clearTimeout(timeoutHandle);
168
+ }
169
+ timeoutHandle = setTimeout(() => setIsCopied(false), 3000);
170
+ };
171
+
172
+ const hoveringNodeCumulative = parseFloat(hoveringNode.cumulative);
173
+ const diff = hoveringNode.diff === undefined ? 0 : parseFloat(hoveringNode.diff);
174
+ const prevValue = hoveringNodeCumulative - diff;
175
+ const diffRatio = Math.abs(diff) > 0 ? diff / prevValue : 0;
176
+ const diffSign = diff > 0 ? '+' : '';
177
+ const diffValueText = diffSign + valueFormatter(diff, unit, 1);
178
+ const diffPercentageText = diffSign + (diffRatio * 100).toFixed(2) + '%';
179
+ const diffText = `${diffValueText} (${diffPercentageText})`;
180
+ const metaRows =
181
+ hoveringNode.meta === undefined ? (
182
+ <></>
183
+ ) : (
184
+ <TooltipMetaInfo onCopy={onCopy} hoveringNode={hoveringNode} />
185
+ );
186
+
187
+ const getTextForCumulative = (hoveringNodeCumulative: number): string => {
188
+ return `${valueFormatter(hoveringNodeCumulative, unit, 2)} (
189
+ ${((hoveringNodeCumulative * 100) / total).toFixed(2)}%)`;
190
+ };
191
+
192
+ return (
193
+ <div className={`flex ${isFixed ? 'w-full h-36' : ''}`}>
194
+ <div className={`m-auto w-full ${isFixed ? 'w-full h-36' : ''}`}>
195
+ <div
196
+ className="border-gray-300 dark:border-gray-500 bg-gray-50 dark:bg-gray-900 rounded-lg p-3 shadow-lg opacity-90"
197
+ style={{borderWidth: 1}}
198
+ >
199
+ <div className="flex flex-row">
200
+ <div className="ml-2 mr-6">
201
+ <span className="font-semibold break-all">
202
+ {hoveringNode.meta === undefined ? (
203
+ <p>root</p>
204
+ ) : (
205
+ <>
206
+ {hoveringNode.meta.function !== undefined &&
207
+ hoveringNode.meta.function.name !== '' ? (
208
+ <CopyToClipboard onCopy={onCopy} text={hoveringNode.meta.function.name}>
209
+ <button className="cursor-pointer text-left">
210
+ {hoveringNode.meta.function.name}
211
+ </button>
212
+ </CopyToClipboard>
213
+ ) : (
214
+ <>
215
+ {hoveringNode.meta.location !== undefined &&
216
+ parseInt(hoveringNode.meta.location.address, 10) !== 0 ? (
217
+ <CopyToClipboard
218
+ onCopy={onCopy}
219
+ text={hexifyAddress(hoveringNode.meta.location.address)}
220
+ >
221
+ <button className="cursor-pointer text-left">
222
+ {hexifyAddress(hoveringNode.meta.location.address)}
223
+ </button>
224
+ </CopyToClipboard>
225
+ ) : (
226
+ <p>unknown</p>
227
+ )}
228
+ </>
229
+ )}
230
+ </>
231
+ )}
232
+ </span>
233
+ <span className="text-gray-700 dark:text-gray-300 my-2">
234
+ <table className="table-fixed">
235
+ <tbody>
236
+ <tr>
237
+ <td className="w-1/5">Cumulative</td>
238
+
239
+ <td className="w-4/5">
240
+ <CopyToClipboard
241
+ onCopy={onCopy}
242
+ text={getTextForCumulative(hoveringNodeCumulative)}
243
+ >
244
+ <button className="cursor-pointer">
245
+ {getTextForCumulative(hoveringNodeCumulative)}
246
+ </button>
247
+ </CopyToClipboard>
248
+ </td>
249
+ </tr>
250
+ {hoveringNode.diff !== undefined && diff !== 0 && (
251
+ <tr>
252
+ <td className="w-1/5">Diff</td>
253
+ <td className="w-4/5">
254
+ <CopyToClipboard onCopy={onCopy} text={diffText}>
255
+ <button className="cursor-pointer">{diffText}</button>
256
+ </CopyToClipboard>
257
+ </td>
258
+ </tr>
259
+ )}
260
+ {metaRows}
261
+ </tbody>
262
+ </table>
263
+ </span>
264
+
265
+ <span className="block text-gray-500 text-xs mt-2">
266
+ {isCopied ? 'Copied!' : 'Hold shift and click on a value to copy.'}
267
+ </span>
268
+ </div>
269
+ </div>
270
+ </div>
271
+ </div>
272
+ </div>
273
+ );
274
+ };
275
+
276
+ const GraphTooltip = ({
277
+ x,
278
+ y,
279
+ unit,
280
+ total,
281
+ hoveringNode,
282
+ contextElement,
283
+ isFixed = false,
284
+ virtualContextElement = true,
285
+ }: GraphTooltipProps): JSX.Element => {
286
+ const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null);
287
+
288
+ const {styles, attributes, ...popperProps} = usePopper(
289
+ virtualContextElement ? virtualElement : contextElement,
290
+ popperElement,
291
+ {
292
+ placement: 'auto-start',
293
+ strategy: 'absolute',
294
+ modifiers: [
295
+ {
296
+ name: 'preventOverflow',
297
+ options: {
298
+ tether: false,
299
+ altAxis: true,
300
+ },
301
+ },
302
+ {
303
+ name: 'offset',
304
+ options: {
305
+ offset: [30, 30],
306
+ },
307
+ },
308
+ ],
309
+ }
310
+ );
311
+
312
+ const update = popperProps.update;
313
+ const isShiftDown = useIsShiftDown();
314
+
315
+ useEffect(() => {
316
+ if (contextElement != null) {
317
+ if (isShiftDown) return;
318
+
319
+ virtualElement.getBoundingClientRect = generateGetBoundingClientRect(contextElement, x, y);
320
+ void update?.();
321
+ }
322
+ }, [x, y, contextElement, update, isShiftDown]);
323
+
324
+ if (hoveringNode === undefined || hoveringNode == null) return <></>;
325
+
326
+ return isFixed ? (
327
+ <GraphTooltipContent hoveringNode={hoveringNode} unit={unit} total={total} isFixed={isFixed} />
328
+ ) : (
329
+ <div ref={setPopperElement} style={styles.popper} {...attributes.popper}>
330
+ <GraphTooltipContent
331
+ hoveringNode={hoveringNode}
332
+ unit={unit}
333
+ total={total}
334
+ isFixed={isFixed}
335
+ />
336
+ </div>
337
+ );
338
+ };
339
+
340
+ export default GraphTooltip;
@@ -16,13 +16,14 @@ import React, {MouseEvent, useEffect, useRef, useState} from 'react';
16
16
  import {throttle} from 'lodash';
17
17
  import {pointer} from 'd3-selection';
18
18
  import {scaleLinear} from 'd3-scale';
19
+
19
20
  import {Flamegraph, FlamegraphNode, FlamegraphRootNode} from '@parca/client';
20
- import {GraphTooltip} from '@parca/components';
21
+ import GraphTooltip from './GraphTooltip';
21
22
  import {getLastItem, diffColor, isSearchMatch} from '@parca/functions';
22
23
  import {useAppSelector, selectDarkMode, selectSearchNodeString} from '@parca/store';
23
-
24
+ import useIsShiftDown from '@parca/components/src/hooks/useIsShiftDown';
24
25
  import {hexifyAddress} from './utils';
25
- import {HoveringNode} from '@parca/components/src/GraphTooltip';
26
+ import type {HoveringNode} from './GraphTooltip';
26
27
 
27
28
  interface IcicleGraphProps {
28
29
  graph: Flamegraph;
@@ -161,6 +162,7 @@ export function IcicleGraphNodes({
161
162
  curPath,
162
163
  }: IcicleGraphNodesProps): JSX.Element {
163
164
  const isDarkMode = useAppSelector(selectDarkMode);
165
+ const isShiftDown = useIsShiftDown();
164
166
 
165
167
  const nodes =
166
168
  curPath.length === 0 ? data : data.filter(d => d != null && curPath[0] === nodeLabel(d));
@@ -181,7 +183,7 @@ export function IcicleGraphNodes({
181
183
  : xScale(cumulative);
182
184
 
183
185
  if (width <= 1) {
184
- return <></>;
186
+ return null;
185
187
  }
186
188
 
187
189
  const name = nodeLabel(d);
@@ -200,8 +202,16 @@ export function IcicleGraphNodes({
200
202
  ? scaleLinear().domain([0, cumulative]).range([0, totalWidth])
201
203
  : xScale;
202
204
 
203
- const onMouseEnter = (): void => setHoveringNode(d);
204
- const onMouseLeave = (): void => setHoveringNode(undefined);
205
+ const onMouseEnter = (): void => {
206
+ if (isShiftDown) return;
207
+
208
+ setHoveringNode(d);
209
+ };
210
+ const onMouseLeave = (): void => {
211
+ if (isShiftDown) return;
212
+
213
+ setHoveringNode(undefined);
214
+ };
205
215
 
206
216
  return (
207
217
  <React.Fragment key={`node-${key}`}>
@@ -253,14 +263,24 @@ export function IcicleGraphRootNode({
253
263
  curPath,
254
264
  }: IcicleGraphRootNodeProps): JSX.Element {
255
265
  const isDarkMode = useAppSelector(selectDarkMode);
266
+ const isShiftDown = useIsShiftDown();
256
267
 
257
268
  const cumulative = parseFloat(node.cumulative);
258
269
  const diff = parseFloat(node.diff);
259
270
  const color = diffColor(diff, cumulative, isDarkMode);
260
271
 
261
272
  const onClick = (): void => setCurPath([]);
262
- const onMouseEnter = (): void => setHoveringNode(node);
263
- const onMouseLeave = (): void => setHoveringNode(undefined);
273
+ const onMouseEnter = (): void => {
274
+ if (isShiftDown) return;
275
+
276
+ setHoveringNode(node);
277
+ };
278
+ const onMouseLeave = (): void => {
279
+ if (isShiftDown) return;
280
+
281
+ setHoveringNode(undefined);
282
+ };
283
+
264
284
  const path: string[] = [];
265
285
 
266
286
  return (