@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.
Files changed (93) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/Callgraph/Edge/index.d.ts +22 -0
  3. package/dist/Callgraph/Edge/index.js +30 -0
  4. package/dist/Callgraph/Node/index.d.ts +19 -0
  5. package/dist/Callgraph/Node/index.js +37 -0
  6. package/dist/Callgraph/index.d.ts +8 -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 +19 -0
  13. package/dist/GraphTooltip/index.js +119 -0
  14. package/dist/IcicleGraph.d.ts +35 -0
  15. package/dist/IcicleGraph.js +139 -0
  16. package/dist/MatchersInput/index.d.ts +23 -0
  17. package/dist/MatchersInput/index.js +479 -0
  18. package/dist/MetricsCircle/index.d.ts +7 -0
  19. package/dist/MetricsCircle/index.js +18 -0
  20. package/dist/MetricsGraph/index.d.ts +35 -0
  21. package/dist/MetricsGraph/index.js +349 -0
  22. package/dist/MetricsSeries/index.d.ts +11 -0
  23. package/dist/MetricsSeries/index.js +21 -0
  24. package/dist/ProfileExplorer/ProfileExplorerCompare.d.ts +19 -0
  25. package/dist/ProfileExplorer/ProfileExplorerCompare.js +38 -0
  26. package/dist/ProfileExplorer/ProfileExplorerSingle.d.ts +15 -0
  27. package/dist/ProfileExplorer/ProfileExplorerSingle.js +19 -0
  28. package/dist/ProfileExplorer/index.d.ts +9 -0
  29. package/dist/ProfileExplorer/index.js +203 -0
  30. package/dist/ProfileIcicleGraph.d.ts +10 -0
  31. package/dist/ProfileIcicleGraph.js +28 -0
  32. package/dist/ProfileMetricsGraph/index.d.ts +22 -0
  33. package/dist/ProfileMetricsGraph/index.js +127 -0
  34. package/dist/ProfileSVG.module.css +3 -0
  35. package/dist/ProfileSelector/CompareButton.d.ts +5 -0
  36. package/dist/ProfileSelector/CompareButton.js +41 -0
  37. package/dist/ProfileSelector/MergeButton.d.ts +5 -0
  38. package/dist/ProfileSelector/MergeButton.js +41 -0
  39. package/dist/ProfileSelector/index.d.ts +29 -0
  40. package/dist/ProfileSelector/index.js +133 -0
  41. package/dist/ProfileSource.d.ts +88 -0
  42. package/dist/ProfileSource.js +239 -0
  43. package/dist/ProfileTypeSelector/index.d.ts +20 -0
  44. package/dist/ProfileTypeSelector/index.js +138 -0
  45. package/dist/ProfileView.d.ts +39 -0
  46. package/dist/ProfileView.js +111 -0
  47. package/dist/ProfileView.styles.css +3 -0
  48. package/dist/ProfileViewWithData.d.ts +11 -0
  49. package/dist/ProfileViewWithData.js +116 -0
  50. package/dist/TopTable.d.ts +9 -0
  51. package/dist/TopTable.js +140 -0
  52. package/dist/TopTable.styles.css +7 -0
  53. package/dist/components/DiffLegend.d.ts +2 -0
  54. package/dist/components/DiffLegend.js +62 -0
  55. package/dist/components/ProfileShareButton/ResultBox.d.ts +6 -0
  56. package/dist/components/ProfileShareButton/ResultBox.js +46 -0
  57. package/dist/components/ProfileShareButton/index.d.ts +7 -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/styles.css +1 -0
  62. package/dist/useDelayedLoader.d.ts +5 -0
  63. package/dist/useDelayedLoader.js +33 -0
  64. package/dist/useQuery.d.ts +13 -0
  65. package/dist/useQuery.js +41 -0
  66. package/dist/utils.d.ts +4 -0
  67. package/dist/utils.js +83 -0
  68. package/package.json +12 -8
  69. package/src/Callgraph/Edge/index.tsx +59 -0
  70. package/src/Callgraph/Node/index.tsx +66 -0
  71. package/src/Callgraph/index.tsx +169 -0
  72. package/src/Callgraph/mockData/index.ts +605 -0
  73. package/src/Callgraph/utils.ts +116 -0
  74. package/src/GraphTooltip/index.tsx +245 -0
  75. package/src/IcicleGraph.tsx +3 -3
  76. package/src/MatchersInput/index.tsx +698 -0
  77. package/src/MetricsCircle/index.tsx +28 -0
  78. package/src/MetricsGraph/index.tsx +614 -0
  79. package/src/MetricsSeries/index.tsx +38 -0
  80. package/src/ProfileExplorer/ProfileExplorerCompare.tsx +109 -0
  81. package/src/ProfileExplorer/ProfileExplorerSingle.tsx +72 -0
  82. package/src/ProfileExplorer/index.tsx +377 -0
  83. package/src/ProfileMetricsGraph/index.tsx +143 -0
  84. package/src/ProfileSelector/CompareButton.tsx +72 -0
  85. package/src/ProfileSelector/MergeButton.tsx +72 -0
  86. package/src/ProfileSelector/index.tsx +270 -0
  87. package/src/ProfileTypeSelector/index.tsx +180 -0
  88. package/src/ProfileView.tsx +2 -7
  89. package/src/index.tsx +11 -0
  90. package/src/useQuery.tsx +1 -0
  91. package/tailwind.config.js +8 -0
  92. package/tsconfig.json +7 -3
  93. 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;