@parca/profile 0.16.209 → 0.16.211
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/GraphTooltipArrow/Content.d.ts +12 -0
- package/dist/GraphTooltipArrow/Content.js +81 -0
- package/dist/GraphTooltipArrow/index.d.ts +2 -34
- package/dist/GraphTooltipArrow/index.js +4 -152
- package/dist/ProfileIcicleGraph/IcicleGraphArrow/IcicleGraphNodes.d.ts +2 -0
- package/dist/ProfileIcicleGraph/IcicleGraphArrow/IcicleGraphNodes.js +7 -8
- package/dist/ProfileIcicleGraph/IcicleGraphArrow/index.d.ts +3 -0
- package/dist/ProfileIcicleGraph/IcicleGraphArrow/index.js +6 -1
- package/dist/ProfileIcicleGraph/index.js +1 -1
- package/dist/styles.css +1 -1
- package/package.json +5 -5
- package/src/GraphTooltipArrow/Content.tsx +272 -0
- package/src/GraphTooltipArrow/index.tsx +5 -431
- package/src/ProfileIcicleGraph/IcicleGraphArrow/IcicleGraphNodes.tsx +9 -4
- package/src/ProfileIcicleGraph/IcicleGraphArrow/index.tsx +16 -7
- package/src/ProfileIcicleGraph/index.tsx +1 -1
|
@@ -0,0 +1,272 @@
|
|
|
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, {useState} from 'react';
|
|
15
|
+
|
|
16
|
+
import {Table} from 'apache-arrow';
|
|
17
|
+
import {CopyToClipboard} from 'react-copy-to-clipboard';
|
|
18
|
+
|
|
19
|
+
import {divide, getLastItem, valueFormatter} from '@parca/utilities';
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
FIELD_CUMULATIVE,
|
|
23
|
+
FIELD_DIFF,
|
|
24
|
+
FIELD_FUNCTION_FILE_NAME,
|
|
25
|
+
FIELD_FUNCTION_NAME,
|
|
26
|
+
FIELD_FUNCTION_START_LINE,
|
|
27
|
+
FIELD_LABELS,
|
|
28
|
+
FIELD_LOCATION_ADDRESS,
|
|
29
|
+
FIELD_LOCATION_LINE,
|
|
30
|
+
FIELD_MAPPING_BUILD_ID,
|
|
31
|
+
FIELD_MAPPING_FILE,
|
|
32
|
+
} from '../ProfileIcicleGraph/IcicleGraphArrow';
|
|
33
|
+
import {hexifyAddress, truncateString, truncateStringReverse} from '../utils';
|
|
34
|
+
import {ExpandOnHover} from './ExpandOnHoverValue';
|
|
35
|
+
|
|
36
|
+
let timeoutHandle: ReturnType<typeof setTimeout> | null = null;
|
|
37
|
+
|
|
38
|
+
interface GraphTooltipArrowContentProps {
|
|
39
|
+
table: Table<any>;
|
|
40
|
+
unit: string;
|
|
41
|
+
total: bigint;
|
|
42
|
+
totalUnfiltered: bigint;
|
|
43
|
+
row: number | null;
|
|
44
|
+
isFixed: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const NoData = (): React.JSX.Element => {
|
|
48
|
+
return <span className="rounded bg-gray-200 px-2 dark:bg-gray-800">Not available</span>;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const GraphTooltipArrowContent = ({
|
|
52
|
+
table,
|
|
53
|
+
unit,
|
|
54
|
+
total,
|
|
55
|
+
totalUnfiltered,
|
|
56
|
+
row,
|
|
57
|
+
isFixed,
|
|
58
|
+
}: GraphTooltipArrowContentProps): React.JSX.Element => {
|
|
59
|
+
const [isCopied, setIsCopied] = useState<boolean>(false);
|
|
60
|
+
|
|
61
|
+
if (row === null) {
|
|
62
|
+
return <></>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const locationAddress: bigint = table.getChild(FIELD_LOCATION_ADDRESS)?.get(row) ?? 0n;
|
|
66
|
+
const functionName: string = table.getChild(FIELD_FUNCTION_NAME)?.get(row) ?? '';
|
|
67
|
+
const cumulative: bigint = table.getChild(FIELD_CUMULATIVE)?.get(row) ?? 0n;
|
|
68
|
+
const diff: bigint = table.getChild(FIELD_DIFF)?.get(row) ?? 0n;
|
|
69
|
+
|
|
70
|
+
const onCopy = (): void => {
|
|
71
|
+
setIsCopied(true);
|
|
72
|
+
|
|
73
|
+
if (timeoutHandle !== null) {
|
|
74
|
+
clearTimeout(timeoutHandle);
|
|
75
|
+
}
|
|
76
|
+
timeoutHandle = setTimeout(() => setIsCopied(false), 3000);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const prevValue = cumulative - diff;
|
|
80
|
+
const diffRatio = diff !== 0n ? divide(diff, prevValue) : 0;
|
|
81
|
+
const diffSign = diff > 0 ? '+' : '';
|
|
82
|
+
const diffValueText = diffSign + valueFormatter(diff, unit, 1);
|
|
83
|
+
const diffPercentageText = diffSign + (diffRatio * 100).toFixed(2) + '%';
|
|
84
|
+
const diffText = `${diffValueText} (${diffPercentageText})`;
|
|
85
|
+
|
|
86
|
+
const getTextForCumulative = (hoveringNodeCumulative: bigint): string => {
|
|
87
|
+
const filtered =
|
|
88
|
+
totalUnfiltered > total
|
|
89
|
+
? ` / ${(100 * divide(hoveringNodeCumulative, total)).toFixed(2)}% of filtered`
|
|
90
|
+
: '';
|
|
91
|
+
return `${valueFormatter(hoveringNodeCumulative, unit, 2)}
|
|
92
|
+
(${(100 * divide(hoveringNodeCumulative, totalUnfiltered)).toFixed(2)}%${filtered})`;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<div className={`flex text-sm ${isFixed ? 'w-full' : ''}`}>
|
|
97
|
+
<div className={`m-auto w-full ${isFixed ? 'w-full' : ''}`}>
|
|
98
|
+
<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">
|
|
99
|
+
<div className="flex flex-row">
|
|
100
|
+
<div className="mx-2">
|
|
101
|
+
<div className="flex h-10 items-center break-all font-semibold">
|
|
102
|
+
{row === 0 ? (
|
|
103
|
+
<p>root</p>
|
|
104
|
+
) : (
|
|
105
|
+
<>
|
|
106
|
+
{functionName !== '' ? (
|
|
107
|
+
<CopyToClipboard onCopy={onCopy} text={functionName}>
|
|
108
|
+
<button className="cursor-pointer text-left">{functionName}</button>
|
|
109
|
+
</CopyToClipboard>
|
|
110
|
+
) : (
|
|
111
|
+
<>
|
|
112
|
+
{locationAddress !== 0n ? (
|
|
113
|
+
<CopyToClipboard onCopy={onCopy} text={hexifyAddress(locationAddress)}>
|
|
114
|
+
<button className="cursor-pointer text-left">
|
|
115
|
+
{hexifyAddress(locationAddress)}
|
|
116
|
+
</button>
|
|
117
|
+
</CopyToClipboard>
|
|
118
|
+
) : (
|
|
119
|
+
<p>unknown</p>
|
|
120
|
+
)}
|
|
121
|
+
</>
|
|
122
|
+
)}
|
|
123
|
+
</>
|
|
124
|
+
)}
|
|
125
|
+
</div>
|
|
126
|
+
<table className="my-2 w-full table-fixed pr-0 text-gray-700 dark:text-gray-300">
|
|
127
|
+
<tbody>
|
|
128
|
+
<tr>
|
|
129
|
+
<td className="w-1/4">Cumulative</td>
|
|
130
|
+
|
|
131
|
+
<td className="w-3/4">
|
|
132
|
+
<CopyToClipboard onCopy={onCopy} text={getTextForCumulative(cumulative)}>
|
|
133
|
+
<button className="cursor-pointer">
|
|
134
|
+
{getTextForCumulative(cumulative)}
|
|
135
|
+
</button>
|
|
136
|
+
</CopyToClipboard>
|
|
137
|
+
</td>
|
|
138
|
+
</tr>
|
|
139
|
+
{diff !== 0n && (
|
|
140
|
+
<tr>
|
|
141
|
+
<td className="w-1/4">Diff</td>
|
|
142
|
+
<td className="w-3/4">
|
|
143
|
+
<CopyToClipboard onCopy={onCopy} text={diffText}>
|
|
144
|
+
<button className="cursor-pointer">{diffText}</button>
|
|
145
|
+
</CopyToClipboard>
|
|
146
|
+
</td>
|
|
147
|
+
</tr>
|
|
148
|
+
)}
|
|
149
|
+
<TooltipMetaInfo table={table} row={row} onCopy={onCopy} />
|
|
150
|
+
</tbody>
|
|
151
|
+
</table>
|
|
152
|
+
</div>
|
|
153
|
+
</div>
|
|
154
|
+
<span className="mx-2 block text-xs text-gray-500">
|
|
155
|
+
{isCopied ? 'Copied!' : 'Hold shift and click on a value to copy.'}
|
|
156
|
+
</span>
|
|
157
|
+
</div>
|
|
158
|
+
</div>
|
|
159
|
+
</div>
|
|
160
|
+
);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const TooltipMetaInfo = ({
|
|
164
|
+
table,
|
|
165
|
+
// total,
|
|
166
|
+
// totalUnfiltered,
|
|
167
|
+
onCopy,
|
|
168
|
+
row,
|
|
169
|
+
}: {
|
|
170
|
+
table: Table<any>;
|
|
171
|
+
row: number;
|
|
172
|
+
onCopy: () => void;
|
|
173
|
+
}): React.JSX.Element => {
|
|
174
|
+
const mappingFile: string = table.getChild(FIELD_MAPPING_FILE)?.get(row) ?? '';
|
|
175
|
+
const mappingBuildID: string = table.getChild(FIELD_MAPPING_BUILD_ID)?.get(row) ?? '';
|
|
176
|
+
const locationAddress: bigint = table.getChild(FIELD_LOCATION_ADDRESS)?.get(row) ?? 0n;
|
|
177
|
+
const locationLine: bigint = table.getChild(FIELD_LOCATION_LINE)?.get(row) ?? 0n;
|
|
178
|
+
const functionFilename: string = table.getChild(FIELD_FUNCTION_FILE_NAME)?.get(row) ?? '';
|
|
179
|
+
const functionStartLine: bigint = table.getChild(FIELD_FUNCTION_START_LINE)?.get(row) ?? 0n;
|
|
180
|
+
const labelsString: string = table.getChild(FIELD_LABELS)?.get(row) ?? '{}';
|
|
181
|
+
|
|
182
|
+
const getTextForFile = (): string => {
|
|
183
|
+
if (functionFilename === '') return '<unknown>';
|
|
184
|
+
|
|
185
|
+
return `${functionFilename} ${
|
|
186
|
+
locationLine !== 0n
|
|
187
|
+
? ` +${locationLine.toString()}`
|
|
188
|
+
: `${functionStartLine !== 0n ? ` +${functionStartLine}` : ''}`
|
|
189
|
+
}`;
|
|
190
|
+
};
|
|
191
|
+
const file = getTextForFile();
|
|
192
|
+
|
|
193
|
+
const labels = Object.entries(JSON.parse(labelsString))
|
|
194
|
+
.sort((a, b) => {
|
|
195
|
+
return a[0].localeCompare(b[0]);
|
|
196
|
+
})
|
|
197
|
+
.map(
|
|
198
|
+
(l): React.JSX.Element => (
|
|
199
|
+
<span
|
|
200
|
+
key={l[0]}
|
|
201
|
+
className="mr-3 inline-block rounded-lg bg-gray-200 px-2 py-1 text-xs font-bold text-gray-700 dark:bg-gray-700 dark:text-gray-400"
|
|
202
|
+
>
|
|
203
|
+
{`${l[0]}="${l[1] as string}"`}
|
|
204
|
+
</span>
|
|
205
|
+
)
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
return (
|
|
209
|
+
<>
|
|
210
|
+
<tr>
|
|
211
|
+
<td className="w-1/4">File</td>
|
|
212
|
+
<td className="w-3/4 break-all">
|
|
213
|
+
{functionFilename === '' ? (
|
|
214
|
+
<NoData />
|
|
215
|
+
) : (
|
|
216
|
+
<CopyToClipboard onCopy={onCopy} text={file}>
|
|
217
|
+
<button className="cursor-pointer whitespace-nowrap text-left">
|
|
218
|
+
<ExpandOnHover value={file} displayValue={truncateStringReverse(file, 40)} />
|
|
219
|
+
</button>
|
|
220
|
+
</CopyToClipboard>
|
|
221
|
+
)}
|
|
222
|
+
</td>
|
|
223
|
+
</tr>
|
|
224
|
+
<tr>
|
|
225
|
+
<td className="w-1/4">Address</td>
|
|
226
|
+
<td className="w-3/4 break-all">
|
|
227
|
+
{locationAddress === 0n ? (
|
|
228
|
+
<NoData />
|
|
229
|
+
) : (
|
|
230
|
+
<CopyToClipboard onCopy={onCopy} text={hexifyAddress(locationAddress)}>
|
|
231
|
+
<button className="cursor-pointer">{hexifyAddress(locationAddress)}</button>
|
|
232
|
+
</CopyToClipboard>
|
|
233
|
+
)}
|
|
234
|
+
</td>
|
|
235
|
+
</tr>
|
|
236
|
+
<tr>
|
|
237
|
+
<td className="w-1/4">Binary</td>
|
|
238
|
+
<td className="w-3/4 break-all">
|
|
239
|
+
{mappingFile === '' ? (
|
|
240
|
+
<NoData />
|
|
241
|
+
) : (
|
|
242
|
+
<CopyToClipboard onCopy={onCopy} text={mappingFile}>
|
|
243
|
+
<button className="cursor-pointer">{getLastItem(mappingFile)}</button>
|
|
244
|
+
</CopyToClipboard>
|
|
245
|
+
)}
|
|
246
|
+
</td>
|
|
247
|
+
</tr>
|
|
248
|
+
<tr>
|
|
249
|
+
<td className="w-1/4">Build Id</td>
|
|
250
|
+
<td className="w-3/4 break-all">
|
|
251
|
+
{mappingBuildID === '' ? (
|
|
252
|
+
<NoData />
|
|
253
|
+
) : (
|
|
254
|
+
<CopyToClipboard onCopy={onCopy} text={mappingBuildID}>
|
|
255
|
+
<button className="cursor-pointer">
|
|
256
|
+
{truncateString(getLastItem(mappingBuildID) as string, 28)}
|
|
257
|
+
</button>
|
|
258
|
+
</CopyToClipboard>
|
|
259
|
+
)}
|
|
260
|
+
</td>
|
|
261
|
+
</tr>
|
|
262
|
+
{labelsString !== '{}' && (
|
|
263
|
+
<tr>
|
|
264
|
+
<td className="w-1/4">Labels</td>
|
|
265
|
+
<td className="w-3/4 break-all">{labels}</td>
|
|
266
|
+
</tr>
|
|
267
|
+
)}
|
|
268
|
+
</>
|
|
269
|
+
);
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
export default GraphTooltipArrowContent;
|