@parca/profile 0.16.349 → 0.16.350
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 +6 -0
- package/dist/SourceView/index.js +44 -12
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +9 -9
- package/src/SourceView/index.tsx +51 -14
- package/src/index.tsx +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 0.16.350 (2024-02-28)
|
|
7
|
+
|
|
8
|
+
# 0.21.0 (2024-02-27)
|
|
9
|
+
|
|
10
|
+
**Note:** Version bump only for package @parca/profile
|
|
11
|
+
|
|
6
12
|
## [0.16.349](https://github.com/parca-dev/parca/compare/@parca/profile@0.16.348...@parca/profile@0.16.349) (2024-02-27)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @parca/profile
|
package/dist/SourceView/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
|
-
import React, { useEffect, useMemo } from 'react';
|
|
14
|
+
import React, { useCallback, useEffect, useMemo } from 'react';
|
|
15
15
|
import { tableFromIPC } from 'apache-arrow';
|
|
16
16
|
import { AnimatePresence, motion } from 'framer-motion';
|
|
17
17
|
import { Item, Menu, useContextMenu } from 'react-contexify';
|
|
@@ -28,25 +28,60 @@ export const SourceView = React.memo(function SourceView({ data, loading, total,
|
|
|
28
28
|
if (data === undefined) {
|
|
29
29
|
return [''];
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
// To use the array index as line number
|
|
32
|
+
return ['', ...data.source.split('\n')];
|
|
32
33
|
}, [data]);
|
|
33
34
|
const { show } = useContextMenu({
|
|
34
35
|
id: MENU_ID,
|
|
35
36
|
});
|
|
36
37
|
const { startLine, endLine } = useLineRange();
|
|
37
|
-
const
|
|
38
|
+
const [cumulative, flat] = useMemo(() => {
|
|
39
|
+
if (data === undefined) {
|
|
40
|
+
return [null, null];
|
|
41
|
+
}
|
|
42
|
+
const table = tableFromIPC(data.record);
|
|
43
|
+
const cumulative = table.getChild('cumulative');
|
|
44
|
+
const flat = table.getChild('flat');
|
|
45
|
+
return [cumulative, flat];
|
|
46
|
+
}, [data]);
|
|
47
|
+
const getProfileDataForLine = useCallback((line, newLine) => {
|
|
48
|
+
if (cumulative == null && flat == null) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
if (cumulative?.get(line - 1) === 0n && flat?.get(line - 1) === 0n) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
line: newLine,
|
|
56
|
+
cumulative: Number(cumulative?.get(line - 1) ?? 0),
|
|
57
|
+
flat: Number(flat?.get(line - 1) ?? 0),
|
|
58
|
+
};
|
|
59
|
+
}, [cumulative, flat]);
|
|
60
|
+
const [selectedCode, profileData] = useMemo(() => {
|
|
38
61
|
if (startLine === -1 && endLine === -1) {
|
|
39
|
-
return '';
|
|
62
|
+
return ['', []];
|
|
40
63
|
}
|
|
41
64
|
if (startLine === endLine) {
|
|
42
|
-
|
|
65
|
+
const profileData = [];
|
|
66
|
+
const profileDataForLine = getProfileDataForLine(startLine, 1);
|
|
67
|
+
if (profileDataForLine != null) {
|
|
68
|
+
profileData.push(profileDataForLine);
|
|
69
|
+
}
|
|
70
|
+
return [sourceCode[startLine - 1], profileData];
|
|
43
71
|
}
|
|
44
72
|
let code = '';
|
|
45
|
-
|
|
73
|
+
let line = 1;
|
|
74
|
+
const profileData = [];
|
|
75
|
+
for (let i = startLine; i <= endLine; i++) {
|
|
46
76
|
code += sourceCode[i] + '\n';
|
|
77
|
+
const profileDataForLine = getProfileDataForLine(i, line);
|
|
78
|
+
if (profileDataForLine != null) {
|
|
79
|
+
profileData.push(profileDataForLine);
|
|
80
|
+
}
|
|
81
|
+
line++;
|
|
47
82
|
}
|
|
48
|
-
return code;
|
|
49
|
-
}, [startLine, endLine, sourceCode]);
|
|
83
|
+
return [code, profileData];
|
|
84
|
+
}, [startLine, endLine, sourceCode, getProfileDataForLine]);
|
|
50
85
|
useEffect(() => {
|
|
51
86
|
setActionButtons?.(_jsx("div", { className: "px-2", children: _jsx(ExpandOnHover, { value: sourceFileName, displayValue: truncateStringReverse(sourceFileName, 50) }) }));
|
|
52
87
|
}, [sourceFileName, setActionButtons]);
|
|
@@ -62,9 +97,6 @@ export const SourceView = React.memo(function SourceView({ data, loading, total,
|
|
|
62
97
|
event,
|
|
63
98
|
});
|
|
64
99
|
};
|
|
65
|
-
|
|
66
|
-
const cumulative = table.getChild('cumulative');
|
|
67
|
-
const flat = table.getChild('flat');
|
|
68
|
-
return (_jsx(AnimatePresence, { children: _jsxs(motion.div, { className: "h-full w-full", initial: { display: 'none', opacity: 0 }, animate: { display: 'block', opacity: 1 }, transition: { duration: 0.5 }, children: [_jsx(Highlighter, { file: sourceFileName, content: data.source, renderer: profileAwareRenderer(cumulative, flat, total, filtered, onContextMenu) }), sourceViewContextMenuItems.length > 0 ? (_jsx(Menu, { id: MENU_ID, children: sourceViewContextMenuItems.map(item => (_jsx(Item, { onClick: () => item.action(selectedCode), children: item.label }, item.id))) })) : null] }, "source-view-loaded") }));
|
|
100
|
+
return (_jsx(AnimatePresence, { children: _jsxs(motion.div, { className: "h-full w-full", initial: { display: 'none', opacity: 0 }, animate: { display: 'block', opacity: 1 }, transition: { duration: 0.5 }, children: [_jsx(Highlighter, { file: sourceFileName, content: data.source, renderer: profileAwareRenderer(cumulative, flat, total, filtered, onContextMenu) }), sourceViewContextMenuItems.length > 0 ? (_jsx(Menu, { id: MENU_ID, children: sourceViewContextMenuItems.map(item => (_jsx(Item, { onClick: () => item.action(selectedCode, profileData), children: item.label }, item.id))) })) : null] }, "source-view-loaded") }));
|
|
69
101
|
});
|
|
70
102
|
export default SourceView;
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './ProfileView';
|
|
|
10
10
|
export * from './ProfileViewWithData';
|
|
11
11
|
export * from './utils';
|
|
12
12
|
export * from './ProfileTypeSelector';
|
|
13
|
+
export * from './SourceView';
|
|
13
14
|
export { default as Callgraph } from './Callgraph';
|
|
14
15
|
export type { CallgraphProps };
|
|
15
16
|
export { ProfileExplorer, ProfileTypeSelector };
|
package/dist/index.js
CHANGED
|
@@ -19,5 +19,6 @@ export * from './ProfileView';
|
|
|
19
19
|
export * from './ProfileViewWithData';
|
|
20
20
|
export * from './utils';
|
|
21
21
|
export * from './ProfileTypeSelector';
|
|
22
|
+
export * from './SourceView';
|
|
22
23
|
export { default as Callgraph } from './Callgraph';
|
|
23
24
|
export { ProfileExplorer, ProfileTypeSelector };
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parca/profile",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.350",
|
|
4
4
|
"description": "Profile viewing libraries",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@parca/client": "^0.16.
|
|
7
|
-
"@parca/components": "^0.16.
|
|
8
|
-
"@parca/dynamicsize": "^0.16.
|
|
9
|
-
"@parca/hooks": "^0.0.
|
|
10
|
-
"@parca/parser": "^0.16.
|
|
11
|
-
"@parca/store": "^0.16.
|
|
12
|
-
"@parca/utilities": "^0.0.
|
|
6
|
+
"@parca/client": "^0.16.106",
|
|
7
|
+
"@parca/components": "^0.16.258",
|
|
8
|
+
"@parca/dynamicsize": "^0.16.61",
|
|
9
|
+
"@parca/hooks": "^0.0.44",
|
|
10
|
+
"@parca/parser": "^0.16.69",
|
|
11
|
+
"@parca/store": "^0.16.132",
|
|
12
|
+
"@parca/utilities": "^0.0.60",
|
|
13
13
|
"@tanstack/react-query": "^4.0.5",
|
|
14
14
|
"@types/react-beautiful-dnd": "^13.1.8",
|
|
15
15
|
"apache-arrow": "^12.0.0",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"access": "public",
|
|
51
51
|
"registry": "https://registry.npmjs.org/"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "4ca1395ad920b41cf74465ab5679796f98a6f930"
|
|
54
54
|
}
|
package/src/SourceView/index.tsx
CHANGED
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
|
|
14
|
-
import React, {useEffect, useMemo} from 'react';
|
|
14
|
+
import React, {useCallback, useEffect, useMemo} from 'react';
|
|
15
15
|
|
|
16
16
|
import {tableFromIPC} from 'apache-arrow';
|
|
17
17
|
import {AnimatePresence, motion} from 'framer-motion';
|
|
18
18
|
import {Item, Menu, useContextMenu} from 'react-contexify';
|
|
19
19
|
|
|
20
20
|
import {Source} from '@parca/client';
|
|
21
|
-
import {SourceSkeleton, useParcaContext, useURLState} from '@parca/components';
|
|
21
|
+
import {SourceSkeleton, useParcaContext, useURLState, type ProfileData} from '@parca/components';
|
|
22
22
|
|
|
23
23
|
import {ExpandOnHover} from '../GraphTooltipArrow/ExpandOnHoverValue';
|
|
24
24
|
import {truncateStringReverse} from '../utils';
|
|
@@ -49,7 +49,8 @@ export const SourceView = React.memo(function SourceView({
|
|
|
49
49
|
if (data === undefined) {
|
|
50
50
|
return [''];
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
// To use the array index as line number
|
|
53
|
+
return ['', ...data.source.split('\n')];
|
|
53
54
|
}, [data]);
|
|
54
55
|
|
|
55
56
|
const {show} = useContextMenu({
|
|
@@ -58,19 +59,59 @@ export const SourceView = React.memo(function SourceView({
|
|
|
58
59
|
|
|
59
60
|
const {startLine, endLine} = useLineRange();
|
|
60
61
|
|
|
61
|
-
const
|
|
62
|
+
const [cumulative, flat] = useMemo(() => {
|
|
63
|
+
if (data === undefined) {
|
|
64
|
+
return [null, null];
|
|
65
|
+
}
|
|
66
|
+
const table = tableFromIPC(data.record);
|
|
67
|
+
const cumulative = table.getChild('cumulative');
|
|
68
|
+
const flat = table.getChild('flat');
|
|
69
|
+
return [cumulative, flat];
|
|
70
|
+
}, [data]);
|
|
71
|
+
|
|
72
|
+
const getProfileDataForLine = useCallback(
|
|
73
|
+
(line: number, newLine: number): ProfileData | undefined => {
|
|
74
|
+
if (cumulative == null && flat == null) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
if (cumulative?.get(line - 1) === 0n && flat?.get(line - 1) === 0n) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
line: newLine,
|
|
82
|
+
cumulative: Number(cumulative?.get(line - 1) ?? 0),
|
|
83
|
+
flat: Number(flat?.get(line - 1) ?? 0),
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
[cumulative, flat]
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const [selectedCode, profileData] = useMemo(() => {
|
|
62
90
|
if (startLine === -1 && endLine === -1) {
|
|
63
|
-
return '';
|
|
91
|
+
return ['', []];
|
|
64
92
|
}
|
|
65
93
|
if (startLine === endLine) {
|
|
66
|
-
|
|
94
|
+
const profileData: ProfileData[] = [];
|
|
95
|
+
const profileDataForLine = getProfileDataForLine(startLine, 1);
|
|
96
|
+
if (profileDataForLine != null) {
|
|
97
|
+
profileData.push(profileDataForLine);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return [sourceCode[startLine - 1], profileData];
|
|
67
101
|
}
|
|
68
102
|
let code = '';
|
|
69
|
-
|
|
103
|
+
let line = 1;
|
|
104
|
+
const profileData: ProfileData[] = [];
|
|
105
|
+
for (let i = startLine; i <= endLine; i++) {
|
|
70
106
|
code += sourceCode[i] + '\n';
|
|
107
|
+
const profileDataForLine = getProfileDataForLine(i, line);
|
|
108
|
+
if (profileDataForLine != null) {
|
|
109
|
+
profileData.push(profileDataForLine);
|
|
110
|
+
}
|
|
111
|
+
line++;
|
|
71
112
|
}
|
|
72
|
-
return code;
|
|
73
|
-
}, [startLine, endLine, sourceCode]);
|
|
113
|
+
return [code, profileData];
|
|
114
|
+
}, [startLine, endLine, sourceCode, getProfileDataForLine]);
|
|
74
115
|
|
|
75
116
|
useEffect(() => {
|
|
76
117
|
setActionButtons?.(
|
|
@@ -102,10 +143,6 @@ export const SourceView = React.memo(function SourceView({
|
|
|
102
143
|
});
|
|
103
144
|
};
|
|
104
145
|
|
|
105
|
-
const table = tableFromIPC(data.record);
|
|
106
|
-
const cumulative = table.getChild('cumulative');
|
|
107
|
-
const flat = table.getChild('flat');
|
|
108
|
-
|
|
109
146
|
return (
|
|
110
147
|
<AnimatePresence>
|
|
111
148
|
<motion.div
|
|
@@ -123,7 +160,7 @@ export const SourceView = React.memo(function SourceView({
|
|
|
123
160
|
{sourceViewContextMenuItems.length > 0 ? (
|
|
124
161
|
<Menu id={MENU_ID}>
|
|
125
162
|
{sourceViewContextMenuItems.map(item => (
|
|
126
|
-
<Item key={item.id} onClick={() => item.action(selectedCode)}>
|
|
163
|
+
<Item key={item.id} onClick={() => item.action(selectedCode, profileData)}>
|
|
127
164
|
{item.label}
|
|
128
165
|
</Item>
|
|
129
166
|
))}
|
package/src/index.tsx
CHANGED
|
@@ -25,6 +25,7 @@ export * from './ProfileView';
|
|
|
25
25
|
export * from './ProfileViewWithData';
|
|
26
26
|
export * from './utils';
|
|
27
27
|
export * from './ProfileTypeSelector';
|
|
28
|
+
export * from './SourceView';
|
|
28
29
|
export {default as Callgraph} from './Callgraph';
|
|
29
30
|
|
|
30
31
|
export type {CallgraphProps};
|