@parca/profile 0.16.0 → 0.16.22
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 +40 -0
- package/dist/Callgraph/Edge/index.d.ts +22 -0
- package/dist/Callgraph/Edge/index.js +30 -0
- package/dist/Callgraph/Node/index.d.ts +19 -0
- package/dist/Callgraph/Node/index.js +37 -0
- package/dist/Callgraph/index.d.ts +8 -0
- package/dist/Callgraph/index.js +137 -0
- package/dist/Callgraph/mockData/index.d.ts +148 -0
- package/dist/Callgraph/mockData/index.js +577 -0
- package/dist/Callgraph/utils.d.ts +19 -0
- package/dist/Callgraph/utils.js +82 -0
- package/dist/GraphTooltip/index.d.ts +19 -0
- package/dist/GraphTooltip/index.js +119 -0
- package/dist/IcicleGraph.d.ts +35 -0
- package/dist/IcicleGraph.js +139 -0
- package/dist/MatchersInput/index.d.ts +23 -0
- package/dist/MatchersInput/index.js +479 -0
- package/dist/MetricsCircle/index.d.ts +7 -0
- package/dist/MetricsCircle/index.js +18 -0
- package/dist/MetricsGraph/index.d.ts +35 -0
- package/dist/MetricsGraph/index.js +349 -0
- package/dist/MetricsSeries/index.d.ts +11 -0
- package/dist/MetricsSeries/index.js +21 -0
- package/dist/ProfileExplorer/ProfileExplorerCompare.d.ts +19 -0
- package/dist/ProfileExplorer/ProfileExplorerCompare.js +38 -0
- package/dist/ProfileExplorer/ProfileExplorerSingle.d.ts +15 -0
- package/dist/ProfileExplorer/ProfileExplorerSingle.js +19 -0
- package/dist/ProfileExplorer/index.d.ts +9 -0
- package/dist/ProfileExplorer/index.js +203 -0
- package/dist/ProfileIcicleGraph.d.ts +10 -0
- package/dist/ProfileIcicleGraph.js +28 -0
- package/dist/ProfileMetricsGraph/index.d.ts +22 -0
- package/dist/ProfileMetricsGraph/index.js +127 -0
- package/dist/ProfileSVG.module.css +3 -0
- package/dist/ProfileSelector/CompareButton.d.ts +5 -0
- package/dist/ProfileSelector/CompareButton.js +41 -0
- package/dist/ProfileSelector/MergeButton.d.ts +5 -0
- package/dist/ProfileSelector/MergeButton.js +41 -0
- package/dist/ProfileSelector/index.d.ts +29 -0
- package/dist/ProfileSelector/index.js +133 -0
- package/dist/ProfileSource.d.ts +88 -0
- package/dist/ProfileSource.js +239 -0
- package/dist/ProfileTypeSelector/index.d.ts +20 -0
- package/dist/ProfileTypeSelector/index.js +138 -0
- package/dist/ProfileView.d.ts +39 -0
- package/dist/ProfileView.js +111 -0
- package/dist/ProfileView.styles.css +3 -0
- package/dist/ProfileViewWithData.d.ts +11 -0
- package/dist/ProfileViewWithData.js +116 -0
- package/dist/TopTable.d.ts +9 -0
- package/dist/TopTable.js +140 -0
- package/dist/TopTable.styles.css +7 -0
- package/dist/components/DiffLegend.d.ts +2 -0
- package/dist/components/DiffLegend.js +62 -0
- package/dist/components/ProfileShareButton/ResultBox.d.ts +6 -0
- package/dist/components/ProfileShareButton/ResultBox.js +46 -0
- package/dist/components/ProfileShareButton/index.d.ts +7 -0
- package/dist/components/ProfileShareButton/index.js +119 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +64 -0
- package/dist/styles.css +1 -0
- package/dist/useDelayedLoader.d.ts +5 -0
- package/dist/useDelayedLoader.js +33 -0
- package/dist/useQuery.d.ts +13 -0
- package/dist/useQuery.js +41 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +83 -0
- package/package.json +12 -8
- package/src/Callgraph/Edge/index.tsx +59 -0
- package/src/Callgraph/Node/index.tsx +66 -0
- package/src/Callgraph/index.tsx +169 -0
- package/src/Callgraph/mockData/index.ts +605 -0
- package/src/Callgraph/utils.ts +116 -0
- package/src/GraphTooltip/index.tsx +245 -0
- package/src/IcicleGraph.tsx +3 -3
- package/src/MatchersInput/index.tsx +698 -0
- package/src/MetricsCircle/index.tsx +28 -0
- package/src/MetricsGraph/index.tsx +614 -0
- package/src/MetricsSeries/index.tsx +38 -0
- package/src/ProfileExplorer/ProfileExplorerCompare.tsx +109 -0
- package/src/ProfileExplorer/ProfileExplorerSingle.tsx +72 -0
- package/src/ProfileExplorer/index.tsx +377 -0
- package/src/ProfileMetricsGraph/index.tsx +143 -0
- package/src/ProfileSelector/CompareButton.tsx +72 -0
- package/src/ProfileSelector/MergeButton.tsx +72 -0
- package/src/ProfileSelector/index.tsx +270 -0
- package/src/ProfileTypeSelector/index.tsx +180 -0
- package/src/ProfileView.tsx +2 -7
- package/src/index.tsx +11 -0
- package/src/useQuery.tsx +1 -0
- package/tailwind.config.js +8 -0
- package/tsconfig.json +7 -3
- package/typings.d.ts +14 -0
|
@@ -0,0 +1,169 @@
|
|
|
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 {useState, useEffect, useRef} from 'react';
|
|
15
|
+
import graphviz from 'graphviz-wasm';
|
|
16
|
+
import * as d3 from 'd3';
|
|
17
|
+
import {Stage, Layer} from 'react-konva';
|
|
18
|
+
import Tooltip from '../GraphTooltip';
|
|
19
|
+
import {CallgraphNode, CallgraphEdge, Callgraph as CallgraphType} from '@parca/client';
|
|
20
|
+
import {jsonToDot} from './utils';
|
|
21
|
+
import Node, {INode} from './Node';
|
|
22
|
+
import Edge, {IEdge} from './Edge';
|
|
23
|
+
import type {HoveringNode} from '../GraphTooltip';
|
|
24
|
+
|
|
25
|
+
export interface Props {
|
|
26
|
+
graph: CallgraphType;
|
|
27
|
+
sampleUnit: string;
|
|
28
|
+
width: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface graphvizObject extends CallgraphNode {
|
|
32
|
+
_gvid: number;
|
|
33
|
+
name: string;
|
|
34
|
+
pos: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface graphvizEdge extends CallgraphEdge {
|
|
38
|
+
_gvid: number;
|
|
39
|
+
tail: number;
|
|
40
|
+
head: number;
|
|
41
|
+
pos: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface graphvizType {
|
|
45
|
+
edges: graphvizEdge[];
|
|
46
|
+
objects: graphvizObject[];
|
|
47
|
+
bb: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const Callgraph = ({graph, sampleUnit, width}: Props): JSX.Element => {
|
|
51
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
52
|
+
const [graphData, setGraphData] = useState<string | null>(null);
|
|
53
|
+
const [hoveredNode, setHoveredNode] = useState<INode | null>(null);
|
|
54
|
+
const {nodes: rawNodes, cumulative: total} = graph;
|
|
55
|
+
const nodeRadius = 12;
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
const getDataWithPositions = async (): Promise<void> => {
|
|
59
|
+
// 1. Translate JSON to 'dot' graph string
|
|
60
|
+
const dataAsDot = jsonToDot({graph, width, nodeRadius});
|
|
61
|
+
|
|
62
|
+
// 2. Use Graphviz-WASM to translate the 'dot' graph to a 'JSON' graph
|
|
63
|
+
await graphviz.loadWASM(); // need to load the WASM instance and wait for it
|
|
64
|
+
|
|
65
|
+
const jsonGraph = graphviz.layout(dataAsDot, 'json', 'dot');
|
|
66
|
+
|
|
67
|
+
setGraphData(jsonGraph);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
if (width !== null) {
|
|
71
|
+
void getDataWithPositions();
|
|
72
|
+
}
|
|
73
|
+
}, [graph, width]);
|
|
74
|
+
|
|
75
|
+
// 3. Render the graph with calculated layout in Canvas container
|
|
76
|
+
if (width == null || graphData == null) return <></>;
|
|
77
|
+
|
|
78
|
+
const height = width;
|
|
79
|
+
const {objects, edges: gvizEdges, bb: boundingBox} = JSON.parse(graphData) as graphvizType;
|
|
80
|
+
|
|
81
|
+
const cumulatives: string[] = objects
|
|
82
|
+
.filter(node => node !== undefined)
|
|
83
|
+
.map(node => node.cumulative);
|
|
84
|
+
if (cumulatives.length === 0) {
|
|
85
|
+
cumulatives.push('0');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const valueRange = (d3.extent(cumulatives) as [string, string]).map(value => parseInt(value));
|
|
89
|
+
|
|
90
|
+
const colorScale = d3
|
|
91
|
+
.scaleSequentialLog(d3.interpolateRdGy)
|
|
92
|
+
.domain(valueRange)
|
|
93
|
+
.range(['lightgrey', 'red']);
|
|
94
|
+
const graphBB = boundingBox.split(',');
|
|
95
|
+
const xScale = d3
|
|
96
|
+
.scaleLinear()
|
|
97
|
+
.domain([0, Number(graphBB[2])])
|
|
98
|
+
.range([0, width]);
|
|
99
|
+
const yScale = d3
|
|
100
|
+
.scaleLinear()
|
|
101
|
+
.domain([0, Number(graphBB[3])])
|
|
102
|
+
.range([0, height]);
|
|
103
|
+
|
|
104
|
+
const nodes: INode[] = objects.map(object => {
|
|
105
|
+
const pos = object.pos.split(',');
|
|
106
|
+
return {
|
|
107
|
+
...object,
|
|
108
|
+
id: object._gvid,
|
|
109
|
+
x: xScale(parseInt(pos[0])),
|
|
110
|
+
y: yScale(parseInt(pos[1])),
|
|
111
|
+
color: colorScale(Number(object.cumulative)),
|
|
112
|
+
data: rawNodes.find(n => n.id === object.name) ?? {id: 'n0'},
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const edges: IEdge[] = gvizEdges.map(edge => ({
|
|
117
|
+
...edge,
|
|
118
|
+
source: edge.head,
|
|
119
|
+
target: edge.tail,
|
|
120
|
+
points: edge.pos,
|
|
121
|
+
color: colorScale(+edge.cumulative),
|
|
122
|
+
}));
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<div className="relative">
|
|
126
|
+
<div className={`w-[${width}px] h-[${height}px]`} ref={containerRef}>
|
|
127
|
+
<Stage width={width} height={height}>
|
|
128
|
+
<Layer>
|
|
129
|
+
{edges.map(edge => {
|
|
130
|
+
const sourceNode = nodes.find(n => n.id === edge.source) ?? {x: 0, y: 0};
|
|
131
|
+
const targetNode = nodes.find(n => n.id === edge.target) ?? {x: 0, y: 0};
|
|
132
|
+
return (
|
|
133
|
+
<Edge
|
|
134
|
+
key={`edge-${edge.source}-${edge.target}`}
|
|
135
|
+
edge={edge}
|
|
136
|
+
xScale={xScale}
|
|
137
|
+
yScale={yScale}
|
|
138
|
+
sourceNode={sourceNode}
|
|
139
|
+
targetNode={targetNode}
|
|
140
|
+
nodeRadius={nodeRadius}
|
|
141
|
+
/>
|
|
142
|
+
);
|
|
143
|
+
})}
|
|
144
|
+
{nodes.map(node => (
|
|
145
|
+
<Node
|
|
146
|
+
key={`node-${node.data.id}`}
|
|
147
|
+
node={node}
|
|
148
|
+
hoveredNode={hoveredNode}
|
|
149
|
+
setHoveredNode={setHoveredNode}
|
|
150
|
+
nodeRadius={nodeRadius}
|
|
151
|
+
/>
|
|
152
|
+
))}
|
|
153
|
+
</Layer>
|
|
154
|
+
</Stage>
|
|
155
|
+
<Tooltip
|
|
156
|
+
hoveringNode={rawNodes.find(n => n.id === hoveredNode?.data.id) as HoveringNode}
|
|
157
|
+
unit={sampleUnit}
|
|
158
|
+
total={+total}
|
|
159
|
+
isFixed={false}
|
|
160
|
+
x={hoveredNode?.mouseX ?? 0}
|
|
161
|
+
y={hoveredNode?.mouseY ?? 0}
|
|
162
|
+
contextElement={containerRef.current}
|
|
163
|
+
/>
|
|
164
|
+
</div>
|
|
165
|
+
</div>
|
|
166
|
+
);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export default Callgraph;
|