@parca/profile 0.16.496 → 0.16.498
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/MetricsGraph/UtilizationMetrics/AreaChart.d.ts +24 -0
- package/dist/MetricsGraph/UtilizationMetrics/AreaChart.d.ts.map +1 -0
- package/dist/MetricsGraph/UtilizationMetrics/AreaChart.js +278 -0
- package/dist/ProfileSelector/MetricsGraphSection.d.ts.map +1 -1
- package/dist/ProfileSelector/MetricsGraphSection.js +17 -2
- package/dist/ProfileSelector/index.d.ts +1 -0
- package/dist/ProfileSelector/index.d.ts.map +1 -1
- package/dist/SimpleMatchers/Select.d.ts +8 -1
- package/dist/SimpleMatchers/Select.d.ts.map +1 -1
- package/dist/SimpleMatchers/Select.js +33 -13
- package/dist/SimpleMatchers/index.d.ts +1 -1
- package/dist/SimpleMatchers/index.d.ts.map +1 -1
- package/dist/SimpleMatchers/index.js +26 -28
- package/dist/contexts/SimpleMatchersLabelContext.d.ts +5 -1
- package/dist/contexts/SimpleMatchersLabelContext.d.ts.map +1 -1
- package/dist/contexts/SimpleMatchersLabelContext.js +53 -10
- package/dist/contexts/UtilizationLabelsContext.d.ts +1 -0
- package/dist/contexts/UtilizationLabelsContext.d.ts.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +6 -6
- package/src/MetricsGraph/UtilizationMetrics/AreaChart.tsx +605 -0
- package/src/ProfileSelector/MetricsGraphSection.tsx +63 -15
- package/src/ProfileSelector/index.tsx +1 -0
- package/src/SimpleMatchers/Select.tsx +100 -36
- package/src/SimpleMatchers/index.tsx +35 -35
- package/src/contexts/SimpleMatchersLabelContext.tsx +75 -14
- package/src/contexts/UtilizationLabelsContext.tsx +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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.498](https://github.com/parca-dev/parca/compare/@parca/profile@0.16.497...@parca/profile@0.16.498) (2025-04-24)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @parca/profile
|
|
9
|
+
|
|
10
|
+
## [0.16.497](https://github.com/parca-dev/parca/compare/@parca/profile@0.16.496...@parca/profile@0.16.497) (2025-04-24)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @parca/profile
|
|
13
|
+
|
|
6
14
|
## 0.16.496 (2025-04-24)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @parca/profile
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { DateTimeRange } from '@parca/components';
|
|
2
|
+
import { type UtilizationMetrics as MetricSeries } from '../../ProfileSelector';
|
|
3
|
+
interface CommonProps {
|
|
4
|
+
transmitData: MetricSeries[];
|
|
5
|
+
receiveData: MetricSeries[];
|
|
6
|
+
addLabelMatcher: (labels: {
|
|
7
|
+
key: string;
|
|
8
|
+
value: string;
|
|
9
|
+
} | Array<{
|
|
10
|
+
key: string;
|
|
11
|
+
value: string;
|
|
12
|
+
}>) => void;
|
|
13
|
+
setTimeRange: (range: DateTimeRange) => void;
|
|
14
|
+
name: string;
|
|
15
|
+
humanReadableName: string;
|
|
16
|
+
from: number;
|
|
17
|
+
to: number;
|
|
18
|
+
}
|
|
19
|
+
type Props = CommonProps & {
|
|
20
|
+
utilizationMetricsLoading?: boolean;
|
|
21
|
+
};
|
|
22
|
+
declare const AreaChart: ({ transmitData, receiveData, addLabelMatcher, setTimeRange, utilizationMetricsLoading, name, humanReadableName, from, to, }: Props) => JSX.Element;
|
|
23
|
+
export default AreaChart;
|
|
24
|
+
//# sourceMappingURL=AreaChart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AreaChart.d.ts","sourceRoot":"","sources":["../../../src/MetricsGraph/UtilizationMetrics/AreaChart.tsx"],"names":[],"mappings":"AAqBA,OAAO,EAAC,aAAa,EAAqD,MAAM,mBAAmB,CAAC;AAIpG,OAAO,EAAC,KAAK,kBAAkB,IAAI,YAAY,EAAC,MAAM,uBAAuB,CAAC;AAiB9E,UAAU,WAAW;IACnB,YAAY,EAAE,YAAY,EAAE,CAAC;IAC7B,WAAW,EAAE,YAAY,EAAE,CAAC;IAC5B,eAAe,EAAE,CACf,MAAM,EAAE;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,GAAG,KAAK,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,CAAC,KACvE,IAAI,CAAC;IACV,YAAY,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,MAAM,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ;AAQD,KAAK,KAAK,GAAG,WAAW,GAAG;IACzB,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC,CAAC;AAgfF,QAAA,MAAM,SAAS,gIAUZ,KAAK,KAAG,GAAG,CAAC,OAiCd,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// Copyright 2022 The Parca Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
import { Fragment, useCallback, useId, useMemo, useRef, useState } from 'react';
|
|
15
|
+
import * as d3 from 'd3';
|
|
16
|
+
import { pointer } from 'd3-selection';
|
|
17
|
+
import { AnimatePresence, motion } from 'framer-motion';
|
|
18
|
+
import throttle from 'lodash.throttle';
|
|
19
|
+
import { useContextMenu } from 'react-contexify';
|
|
20
|
+
import { DateTimeRange, MetricsGraphSkeleton, useParcaContext, useURLState } from '@parca/components';
|
|
21
|
+
import { formatDate, formatForTimespan, getPrecision, valueFormatter } from '@parca/utilities';
|
|
22
|
+
import MetricsContextMenu from '../MetricsContextMenu';
|
|
23
|
+
import MetricsTooltip from '../MetricsTooltip';
|
|
24
|
+
import { useMetricsGraphDimensions } from '../useMetricsGraphDimensions';
|
|
25
|
+
function transformToSeries(data, isReceive = false) {
|
|
26
|
+
const series = data.reduce(function (agg, s) {
|
|
27
|
+
if (s.labelset !== undefined) {
|
|
28
|
+
const metric = s.labelset.labels.sort((a, b) => a.name.localeCompare(b.name));
|
|
29
|
+
agg.push({
|
|
30
|
+
metric,
|
|
31
|
+
values: s.samples.reduce(function (agg, d) {
|
|
32
|
+
if (d.timestamp !== undefined && d.value !== undefined) {
|
|
33
|
+
// Multiply receive values by -1 to display below zero
|
|
34
|
+
const value = isReceive ? -1 * d.value : d.value;
|
|
35
|
+
agg.push([d.timestamp, value]);
|
|
36
|
+
}
|
|
37
|
+
return agg;
|
|
38
|
+
}, []),
|
|
39
|
+
labelset: metric.map(m => `${m.name}=${m.value}`).join(','),
|
|
40
|
+
isReceive,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return agg;
|
|
44
|
+
}, []);
|
|
45
|
+
// Sort values by timestamp for each series
|
|
46
|
+
return series.map(series => ({
|
|
47
|
+
...series,
|
|
48
|
+
values: series.values.sort((a, b) => a[0] - b[0]),
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
const getYAxisUnit = (name) => {
|
|
52
|
+
switch (name) {
|
|
53
|
+
case 'gpu_utilization_percent':
|
|
54
|
+
return 'percent';
|
|
55
|
+
case 'gpu_memory_utilization_percent':
|
|
56
|
+
return 'percent';
|
|
57
|
+
case 'gpu_power_watt':
|
|
58
|
+
return 'watts';
|
|
59
|
+
case 'gpu_pcie_throughput_transmit_bytes':
|
|
60
|
+
return 'bytes_per_second';
|
|
61
|
+
case 'gpu_pcie_throughput_receive_bytes':
|
|
62
|
+
return 'bytes_per_second';
|
|
63
|
+
default:
|
|
64
|
+
return 'percent';
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const RawAreaChart = ({ transmitData, receiveData, addLabelMatcher, setTimeRange, width, height, margin, name, humanReadableName, from, to, }) => {
|
|
68
|
+
const { timezone } = useParcaContext();
|
|
69
|
+
const graph = useRef(null);
|
|
70
|
+
const [dragging, setDragging] = useState(false);
|
|
71
|
+
const [hovering, setHovering] = useState(false);
|
|
72
|
+
const [relPos, setRelPos] = useState(-1);
|
|
73
|
+
const [pos, setPos] = useState([0, 0]);
|
|
74
|
+
const [isContextMenuOpen, setIsContextMenuOpen] = useState(false);
|
|
75
|
+
const idForContextMenu = useId();
|
|
76
|
+
const [selectedSeries, setSelectedSeries] = useURLState('selectedSeries');
|
|
77
|
+
const [_, setSelectedTimeframe] = useURLState('gpu_selected_timeframe');
|
|
78
|
+
const parsedSelectedSeries = useMemo(() => {
|
|
79
|
+
if (selectedSeries === undefined) {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
return JSON.parse(decodeURIComponent(selectedSeries));
|
|
83
|
+
}, [selectedSeries]);
|
|
84
|
+
const lineStroke = '1px';
|
|
85
|
+
const lineStrokeHover = '2px';
|
|
86
|
+
const lineStrokeSelected = '3px';
|
|
87
|
+
const graphWidth = width - margin * 1.5 - margin / 2;
|
|
88
|
+
const paddedFrom = from;
|
|
89
|
+
const paddedTo = to;
|
|
90
|
+
const series = useMemo(() => {
|
|
91
|
+
const transmitSeries = transformToSeries(transmitData);
|
|
92
|
+
const receiveSeries = transformToSeries(receiveData, true);
|
|
93
|
+
return [...transmitSeries, ...receiveSeries];
|
|
94
|
+
}, [transmitData, receiveData]);
|
|
95
|
+
const extentsY = series.map(function (s) {
|
|
96
|
+
return d3.extent(s.values, function (d) {
|
|
97
|
+
return d[1];
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
const minY = d3.min(extentsY, function (d) {
|
|
101
|
+
return d[0];
|
|
102
|
+
});
|
|
103
|
+
const maxY = d3.max(extentsY, function (d) {
|
|
104
|
+
return d[1];
|
|
105
|
+
});
|
|
106
|
+
// Setup scales with padded time range
|
|
107
|
+
const xScale = d3.scaleUtc().domain([paddedFrom, paddedTo]).range([0, graphWidth]);
|
|
108
|
+
const yScale = d3
|
|
109
|
+
.scaleLinear()
|
|
110
|
+
// Ensure domain is symmetric around 0 for balanced visualization
|
|
111
|
+
.domain([minY ?? 0, maxY ?? 0])
|
|
112
|
+
.range([height - margin, 0])
|
|
113
|
+
.nice();
|
|
114
|
+
const throttledSetPos = throttle(setPos, 20);
|
|
115
|
+
const onMouseMove = (e) => {
|
|
116
|
+
if (isContextMenuOpen) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
// X/Y coordinate array relative to svg
|
|
120
|
+
const rel = pointer(e);
|
|
121
|
+
const xCoordinate = rel[0];
|
|
122
|
+
const xCoordinateWithoutMargin = xCoordinate - margin;
|
|
123
|
+
const yCoordinate = rel[1];
|
|
124
|
+
const yCoordinateWithoutMargin = yCoordinate - margin;
|
|
125
|
+
throttledSetPos([xCoordinateWithoutMargin, yCoordinateWithoutMargin]);
|
|
126
|
+
};
|
|
127
|
+
const trackVisibility = (isVisible) => {
|
|
128
|
+
setIsContextMenuOpen(isVisible);
|
|
129
|
+
};
|
|
130
|
+
const MENU_ID = `areachart-context-menu-${idForContextMenu}`;
|
|
131
|
+
const { show } = useContextMenu({
|
|
132
|
+
id: MENU_ID,
|
|
133
|
+
});
|
|
134
|
+
const displayMenu = useCallback((e) => {
|
|
135
|
+
show({
|
|
136
|
+
event: e,
|
|
137
|
+
});
|
|
138
|
+
}, [show]);
|
|
139
|
+
const getSeriesColor = (series) => {
|
|
140
|
+
return series.isReceive === true ? '#EAB308' : '#22C55E'; // Yellow for receive, Green for transmit
|
|
141
|
+
};
|
|
142
|
+
// Create area generator for transmit (above zero)
|
|
143
|
+
const transmitArea = d3
|
|
144
|
+
.area()
|
|
145
|
+
.x(d => xScale(d[0]))
|
|
146
|
+
.y0(yScale(0)) // Start from zero line
|
|
147
|
+
.y1(d => yScale(d[1])); // Top of the area (data point)
|
|
148
|
+
// Create area generator for receive (below zero)
|
|
149
|
+
const receiveArea = d3
|
|
150
|
+
.area()
|
|
151
|
+
.x(d => xScale(d[0]))
|
|
152
|
+
.y0(yScale(0)) // Start from zero line
|
|
153
|
+
.y1(d => yScale(d[1])); // Bottom of the area (negative data point)
|
|
154
|
+
const highlighted = useMemo(() => {
|
|
155
|
+
if (series.length === 0) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
// Return the closest point as the highlighted point
|
|
159
|
+
const closestPointPerSeries = series.map(function (s) {
|
|
160
|
+
const distances = s.values.map(d => {
|
|
161
|
+
const x = xScale(d[0]) + margin / 2;
|
|
162
|
+
const y = yScale(d[1]) - margin / 3;
|
|
163
|
+
return Math.sqrt(Math.pow(pos[0] - x, 2) + Math.pow(pos[1] - y, 2));
|
|
164
|
+
});
|
|
165
|
+
const pointIndex = d3.minIndex(distances);
|
|
166
|
+
const minDistance = distances[pointIndex];
|
|
167
|
+
return {
|
|
168
|
+
pointIndex,
|
|
169
|
+
distance: minDistance,
|
|
170
|
+
};
|
|
171
|
+
});
|
|
172
|
+
const closestSeriesIndex = d3.minIndex(closestPointPerSeries, s => s.distance);
|
|
173
|
+
const pointIndex = closestPointPerSeries[closestSeriesIndex].pointIndex;
|
|
174
|
+
const point = series[closestSeriesIndex].values[pointIndex];
|
|
175
|
+
return {
|
|
176
|
+
seriesIndex: closestSeriesIndex,
|
|
177
|
+
labels: series[closestSeriesIndex].metric,
|
|
178
|
+
timestamp: point[0],
|
|
179
|
+
valuePerSecond: point[1],
|
|
180
|
+
value: point[2],
|
|
181
|
+
duration: point[3],
|
|
182
|
+
x: xScale(point[0]),
|
|
183
|
+
y: yScale(point[1]),
|
|
184
|
+
};
|
|
185
|
+
}, [pos, series, xScale, yScale, margin]);
|
|
186
|
+
const onMouseDown = (e) => {
|
|
187
|
+
// only left mouse button
|
|
188
|
+
if (e.button !== 0) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
// X/Y coordinate array relative to svg
|
|
192
|
+
const rel = pointer(e);
|
|
193
|
+
const xCoordinate = rel[0];
|
|
194
|
+
const xCoordinateWithoutMargin = xCoordinate - margin;
|
|
195
|
+
if (xCoordinateWithoutMargin >= 0) {
|
|
196
|
+
setRelPos(xCoordinateWithoutMargin);
|
|
197
|
+
setDragging(true);
|
|
198
|
+
}
|
|
199
|
+
e.stopPropagation();
|
|
200
|
+
e.preventDefault();
|
|
201
|
+
};
|
|
202
|
+
const onMouseUp = (e) => {
|
|
203
|
+
setDragging(false);
|
|
204
|
+
if (relPos === -1) {
|
|
205
|
+
// MouseDown happened outside of this element.
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
// This is a normal click. We tolerate tiny movements to still be a
|
|
209
|
+
// click as they can occur when clicking based on user feedback.
|
|
210
|
+
if (Math.abs(relPos - pos[0]) <= 1) {
|
|
211
|
+
setRelPos(-1);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
let startPos = relPos;
|
|
215
|
+
let endPos = pos[0];
|
|
216
|
+
if (startPos > endPos) {
|
|
217
|
+
startPos = pos[0];
|
|
218
|
+
endPos = relPos;
|
|
219
|
+
}
|
|
220
|
+
const startCorrection = 10;
|
|
221
|
+
const endCorrection = 30;
|
|
222
|
+
const firstTime = xScale.invert(startPos - startCorrection).valueOf();
|
|
223
|
+
const secondTime = xScale.invert(endPos - endCorrection).valueOf();
|
|
224
|
+
setTimeRange(DateTimeRange.fromAbsoluteDates(firstTime, secondTime));
|
|
225
|
+
setRelPos(-1);
|
|
226
|
+
e.stopPropagation();
|
|
227
|
+
e.preventDefault();
|
|
228
|
+
};
|
|
229
|
+
return (_jsxs(_Fragment, { children: [_jsx(MetricsContextMenu, { onAddLabelMatcher: addLabelMatcher, menuId: MENU_ID, highlighted: highlighted, trackVisibility: trackVisibility, utilizationMetrics: true }), highlighted != null && hovering && !dragging && pos[0] !== 0 && pos[1] !== 0 && (_jsx("div", { onMouseMove: onMouseMove, onMouseEnter: () => setHovering(true), onMouseLeave: () => setHovering(false), children: !isContextMenuOpen && (_jsx(MetricsTooltip, { x: pos[0] + margin, y: pos[1] + margin, highlighted: {
|
|
230
|
+
...highlighted,
|
|
231
|
+
valuePerSecond: Math.abs(highlighted.valuePerSecond), // Show absolute value in tooltip
|
|
232
|
+
}, contextElement: graph.current, sampleUnit: getYAxisUnit(name), delta: false, utilizationMetrics: true })) })), _jsx("div", { ref: graph, onMouseEnter: () => setHovering(true), onMouseLeave: () => setHovering(false), onContextMenu: displayMenu, children: _jsxs("svg", { width: `${width}px`, height: `${height + margin}px`, onMouseDown: onMouseDown, onMouseUp: onMouseUp, onMouseMove: onMouseMove, children: [_jsx("g", { transform: `translate(${margin}, 0)`, children: dragging && (_jsx("g", { className: "zoom-time-rect", children: _jsx("rect", { className: "bar", x: pos[0] - relPos < 0 ? pos[0] : relPos, y: 0, height: height, width: Math.abs(pos[0] - relPos), fill: 'rgba(0, 0, 0, 0.125)' }) })) }), _jsxs("g", { transform: `translate(${margin * 1.5}, ${margin / 1.5})`, children: [_jsxs("g", { className: "y axis", textAnchor: "end", fontSize: "10", fill: "none", children: [yScale.ticks(6).map((d, i, allTicks) => {
|
|
233
|
+
let decimals = 2;
|
|
234
|
+
const intervalBetweenTicks = allTicks[1] - allTicks[0];
|
|
235
|
+
if (intervalBetweenTicks < 1) {
|
|
236
|
+
const precision = getPrecision(intervalBetweenTicks);
|
|
237
|
+
decimals = precision;
|
|
238
|
+
}
|
|
239
|
+
return (_jsxs(Fragment, { children: [_jsxs("g", { className: "tick", transform: `translate(0, ${yScale(d)})`, children: [_jsx("line", { className: "stroke-gray-300 dark:stroke-gray-500", x2: -6 }), _jsxs("text", { fill: "currentColor", x: -9, dy: '0.32em', children: [d < 0 ? '-' : '', valueFormatter(Math.abs(d), getYAxisUnit(name), decimals)] })] }, `tick-${i}`), _jsx("g", { children: _jsx("line", { className: "stroke-gray-300 dark:stroke-gray-500", x1: xScale(from), x2: xScale(to), y1: yScale(d), y2: yScale(d) }) }, `grid-${i}`)] }, `${i.toString()}-${d.toString()}`));
|
|
240
|
+
}), _jsx("line", { className: "stroke-gray-300 dark:stroke-gray-500", x1: 0, x2: 0, y1: 0, y2: height - margin }), _jsx("line", { className: "stroke-gray-300 dark:stroke-gray-500", x1: xScale(to), x2: xScale(to), y1: 0, y2: height - margin }), _jsx("g", { transform: `translate(${-margin}, ${(height - margin) / 2}) rotate(270)`, children: _jsx("text", { fill: "currentColor", dy: "-0.7em", className: "text-sm capitalize", textAnchor: "middle", children: humanReadableName }) })] }), _jsxs("g", { className: "x axis", fill: "none", fontSize: "10", textAnchor: "middle", transform: `translate(0,${height - margin})`, children: [xScale.ticks(5).map((d, i) => (_jsxs(Fragment, { children: [_jsxs("g", { className: "tick",
|
|
241
|
+
/* eslint-disable-next-line @typescript-eslint/restrict-template-expressions */
|
|
242
|
+
transform: `translate(${xScale(d)}, 0)`, children: [_jsx("line", { y2: 6, className: "stroke-gray-300 dark:stroke-gray-500" }), _jsx("text", { fill: "currentColor", dy: ".71em", y: 9, children: formatDate(d, formatForTimespan(from, to), timezone) })] }, `tick-${i}`), _jsx("g", { children: _jsx("line", { className: "stroke-gray-300 dark:stroke-gray-500", x1: xScale(d), x2: xScale(d), y1: 0, y2: -height + margin }) }, `grid-${i}`)] }, `${i.toString()}-${d.toString()}`))), _jsx("line", { className: "stroke-gray-300 dark:stroke-gray-500", x1: 0, x2: graphWidth, y1: 0, y2: 0 }), _jsx("g", { transform: `translate(${(width - 2.5 * margin) / 2}, ${margin / 2})`, children: _jsx("text", { fill: "currentColor", dy: ".71em", y: 5, className: "text-sm", children: "Time" }) })] }), _jsx("g", { className: "areas", children: series.map((s, i) => {
|
|
243
|
+
let isSelected = false;
|
|
244
|
+
if (parsedSelectedSeries != null && parsedSelectedSeries.length > 0) {
|
|
245
|
+
isSelected = parsedSelectedSeries.every(m => {
|
|
246
|
+
for (let i = 0; i < s.metric.length; i++) {
|
|
247
|
+
if (s.metric[i].name === m.key && s.metric[i].value === m.value) {
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return false;
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
const seriesColor = getSeriesColor(s);
|
|
255
|
+
const fillOpacity = isSelected ? 0.4 : 0.2;
|
|
256
|
+
const strokeOpacity = isSelected ? 1 : 0.8;
|
|
257
|
+
const areaGenerator = s.isReceive === true ? receiveArea : transmitArea;
|
|
258
|
+
return (_jsx("g", { className: "area cursor-pointer", children: _jsx("path", { d: areaGenerator(s.values) ?? '', fill: seriesColor, fillOpacity: fillOpacity, stroke: seriesColor, strokeWidth: isSelected
|
|
259
|
+
? lineStrokeSelected
|
|
260
|
+
: hovering && highlighted != null && i === highlighted.seriesIndex
|
|
261
|
+
? lineStrokeHover
|
|
262
|
+
: lineStroke, strokeOpacity: strokeOpacity, onClick: () => {
|
|
263
|
+
if (highlighted != null) {
|
|
264
|
+
setSelectedSeries(JSON.stringify(highlighted.labels.map(l => ({
|
|
265
|
+
key: l.name,
|
|
266
|
+
value: l.value,
|
|
267
|
+
}))));
|
|
268
|
+
setSelectedTimeframe(undefined);
|
|
269
|
+
}
|
|
270
|
+
} }) }, i));
|
|
271
|
+
}) })] })] }) })] }));
|
|
272
|
+
};
|
|
273
|
+
const AreaChart = ({ transmitData, receiveData, addLabelMatcher, setTimeRange, utilizationMetricsLoading, name, humanReadableName, from, to, }) => {
|
|
274
|
+
const { isDarkMode } = useParcaContext();
|
|
275
|
+
const { width, height, margin, heightStyle } = useMetricsGraphDimensions(false, true);
|
|
276
|
+
return (_jsx(AnimatePresence, { children: _jsx(motion.div, { className: "w-full relative", initial: { display: 'none', opacity: 0 }, animate: { display: 'block', opacity: 1 }, transition: { duration: 0.5 }, children: utilizationMetricsLoading === true ? (_jsx(MetricsGraphSkeleton, { heightStyle: heightStyle, isDarkMode: isDarkMode, isMini: true })) : (_jsx(RawAreaChart, { transmitData: transmitData, receiveData: receiveData, addLabelMatcher: addLabelMatcher, setTimeRange: setTimeRange, width: width, height: height, margin: margin, name: name, humanReadableName: humanReadableName, from: from, to: to })) }, "area-chart-graph-loaded") }));
|
|
277
|
+
};
|
|
278
|
+
export default AreaChart;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetricsGraphSection.d.ts","sourceRoot":"","sources":["../../src/ProfileSelector/MetricsGraphSection.tsx"],"names":[],"mappings":"AAeA,OAAO,EAAQ,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACxD,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAC,KAAK,EAAC,MAAM,eAAe,CAAC;AAEpC,OAAO,EAAyB,gBAAgB,EAAC,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"MetricsGraphSection.d.ts","sourceRoot":"","sources":["../../src/ProfileSelector/MetricsGraphSection.tsx"],"names":[],"mappings":"AAeA,OAAO,EAAQ,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACxD,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAC,KAAK,EAAC,MAAM,eAAe,CAAC;AAEpC,OAAO,EAAyB,gBAAgB,EAAC,MAAM,IAAI,CAAC;AAI5D,OAAO,EAAC,cAAc,EAAE,KAAK,kBAAkB,IAAI,sBAAsB,EAAC,MAAM,SAAS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B,GAAG,GAAG,CAAC,OAAO,CA0LxC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
// Copyright 2022 The Parca Authors
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -15,6 +15,7 @@ import cx from 'classnames';
|
|
|
15
15
|
import { Query } from '@parca/parser';
|
|
16
16
|
import { MergedProfileSelection } from '..';
|
|
17
17
|
import UtilizationMetricsGraph from '../MetricsGraph/UtilizationMetrics';
|
|
18
|
+
import AreaChart from '../MetricsGraph/UtilizationMetrics/AreaChart';
|
|
18
19
|
import ProfileMetricsGraph, { ProfileMetricsEmptyState } from '../ProfileMetricsGraph';
|
|
19
20
|
export function MetricsGraphSection({ showMetricsGraph, setDisplayHideMetricsGraphButton, heightStyle, querySelection, profileSelection, comparing, sumBy, defaultSumByLoading, queryClient, queryExpressionString, setTimeRangeSelection, selectQuery, selectProfile, query, setNewQueryExpression, utilizationMetrics, utilizationMetricsLoading, }) {
|
|
20
21
|
const handleTimeRangeChange = (range) => {
|
|
@@ -75,7 +76,21 @@ export function MetricsGraphSection({ showMetricsGraph, setDisplayHideMetricsGra
|
|
|
75
76
|
const mergeTo = query.profileType().delta ? mergeFrom + durationInMilliseconds : mergeFrom;
|
|
76
77
|
selectProfile(new MergedProfileSelection(mergeFrom, mergeTo, query));
|
|
77
78
|
};
|
|
79
|
+
const UtilizationGraphToShow = ({ utilizationMetrics, }) => {
|
|
80
|
+
const throughputMetrics = utilizationMetrics.filter(metric => metric.name === 'gpu_pcie_throughput_transmit_bytes' ||
|
|
81
|
+
metric.name === 'gpu_pcie_throughput_receive_bytes');
|
|
82
|
+
if (utilizationMetrics === undefined || utilizationMetrics.length === 0) {
|
|
83
|
+
return _jsx(_Fragment, {});
|
|
84
|
+
}
|
|
85
|
+
return (_jsxs("div", { children: [utilizationMetrics.map(({ name, humanReadableName, data }) => {
|
|
86
|
+
if (name !== 'gpu_pcie_throughput_transmit_bytes' &&
|
|
87
|
+
name !== 'gpu_pcie_throughput_receive_bytes') {
|
|
88
|
+
return (_jsx(_Fragment, { children: _jsx(UtilizationMetricsGraph, { data: data, addLabelMatcher: addLabelMatcher, setTimeRange: handleTimeRangeChange, utilizationMetricsLoading: utilizationMetricsLoading, name: name, humanReadableName: humanReadableName, from: querySelection.from, to: querySelection.to }, name) }));
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}), throughputMetrics.length > 0 && (_jsx(AreaChart, { transmitData: throughputMetrics[0].data, receiveData: throughputMetrics[1].data, addLabelMatcher: addLabelMatcher, setTimeRange: handleTimeRangeChange, name: throughputMetrics[0].name, humanReadableName: throughputMetrics[0].humanReadableName, from: querySelection.from, to: querySelection.to, utilizationMetricsLoading: utilizationMetricsLoading }))] }));
|
|
92
|
+
};
|
|
78
93
|
return (_jsxs("div", { className: cx('relative', { 'py-4': !showMetricsGraph }), children: [setDisplayHideMetricsGraphButton != null ? (_jsxs("button", { onClick: () => setDisplayHideMetricsGraphButton(!showMetricsGraph), className: cx('hidden px-3 py-1 text-sm font-medium text-gray-700 dark:text-gray-200 bg-gray-100 rounded-md hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:bg-gray-900 z-10', showMetricsGraph && 'absolute right-0 bottom-3 !flex', !showMetricsGraph && 'relative !flex ml-auto'), children: [showMetricsGraph ? 'Hide' : 'Show', " Metrics Graph"] })) : null, showMetricsGraph && (_jsx(_Fragment, { children: _jsx("div", { style: { height: heightStyle }, children: querySelection.expression !== '' &&
|
|
79
94
|
querySelection.from !== undefined &&
|
|
80
|
-
querySelection.to !== undefined ? (_jsx(_Fragment, { children: utilizationMetrics !== undefined ? (
|
|
95
|
+
querySelection.to !== undefined ? (_jsx(_Fragment, { children: utilizationMetrics !== undefined ? (_jsx(UtilizationGraphToShow, { utilizationMetrics: utilizationMetrics })) : (_jsx(_Fragment, { children: _jsx(ProfileMetricsGraph, { queryClient: queryClient, queryExpression: querySelection.expression, from: querySelection.from, to: querySelection.to, profile: profileSelection, comparing: comparing, sumBy: querySelection.sumBy ?? sumBy ?? [], sumByLoading: defaultSumByLoading, setTimeRange: handleTimeRangeChange, addLabelMatcher: addLabelMatcher, onPointClick: handlePointClick }) })) })) : (profileSelection === null && (_jsx("div", { className: "p-2", children: _jsx(ProfileMetricsEmptyState, { message: "Please select a profile type and click 'Search' to begin." }) }))) }) }))] }));
|
|
81
96
|
}
|
|
@@ -35,6 +35,7 @@ export interface UtilizationLabels {
|
|
|
35
35
|
utilizationLabelNames?: string[];
|
|
36
36
|
utilizationFetchLabelValues?: (key: string) => Promise<string[]>;
|
|
37
37
|
utilizationLabelValues?: string[];
|
|
38
|
+
utilizationLabelNamesLoading?: boolean;
|
|
38
39
|
}
|
|
39
40
|
interface ProfileSelectorProps extends ProfileSelectorFeatures {
|
|
40
41
|
queryClient: QueryServiceClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ProfileSelector/index.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAC,QAAQ,EAAE,cAAc,EAAuC,MAAM,OAAO,CAAC;AAErF,OAAO,EAAC,QAAQ,EAAC,MAAM,0BAA0B,CAAC;AAElD,OAAO,EAAC,oBAAoB,EAAE,kBAAkB,EAAC,MAAM,eAAe,CAAC;AAUvE,OAAO,EAAC,KAAK,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAC,gBAAgB,EAAC,MAAM,IAAI,CAAC;AASpC,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;I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gBAAgB,GAAG,IAAI,CAAC;IAC1C,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,gBAAgB,CAAC;IAC7B,gCAAgC,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IACrE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kBAAkB,CAAC,EAAE,KAAK,CAAC;QACzB,IAAI,EAAE,MAAM,CAAC;QACb,iBAAiB,EAAE,MAAM,CAAC;QAC1B,IAAI,EAAE,kBAAkB,EAAE,CAAC;KAC5B,CAAC,CAAC;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;CACvC;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,oBAAoB,CAAC;IAC5B,KAAK,CAAC,EAAE,QAAQ,CAAC;CAClB;AAED,eAAO,MAAM,eAAe,WAAY,kBAAkB,KAAG,mBAkB5D,CAAC;AAEF,QAAA,MAAM,eAAe,2UAkBlB,oBAAoB,KAAG,GAAG,CAAC,OAkN7B,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -8,8 +8,15 @@ export interface SelectItem {
|
|
|
8
8
|
disabled?: boolean;
|
|
9
9
|
element: SelectElement;
|
|
10
10
|
}
|
|
11
|
+
export interface TypedSelectItem extends SelectItem {
|
|
12
|
+
type: string;
|
|
13
|
+
}
|
|
14
|
+
export interface GroupedSelectItem {
|
|
15
|
+
type: string;
|
|
16
|
+
values: SelectItem[];
|
|
17
|
+
}
|
|
11
18
|
interface CustomSelectProps {
|
|
12
|
-
items: SelectItem[];
|
|
19
|
+
items: GroupedSelectItem[] | SelectItem[];
|
|
13
20
|
selectedKey: string | undefined;
|
|
14
21
|
onSelection: (value: string) => void;
|
|
15
22
|
placeholder?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Select.d.ts","sourceRoot":"","sources":["../../src/SimpleMatchers/Select.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAoC,MAAM,OAAO,CAAC;AAQzD,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC;IACpB,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,aAAa,CAAC;CACxB;AAED,UAAU,iBAAiB;IACzB,KAAK,EAAE,UAAU,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"Select.d.ts","sourceRoot":"","sources":["../../src/SimpleMatchers/Select.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAoC,MAAM,OAAO,CAAC;AAQzD,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC;IACpB,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,aAAa,CAAC;CACxB;AAED,MAAM,WAAW,eAAgB,SAAQ,UAAU;IACjD,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB;AAED,UAAU,iBAAiB;IACzB,KAAK,EAAE,iBAAiB,EAAE,GAAG,UAAU,EAAE,CAAC;IAC1C,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,QAAA,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAqR7C,CAAC;AAkDF,eAAe,YAAY,CAAC"}
|
|
@@ -15,8 +15,8 @@ import { useEffect, useRef, useState } from 'react';
|
|
|
15
15
|
import { Icon } from '@iconify/react';
|
|
16
16
|
import cx from 'classnames';
|
|
17
17
|
import levenshtein from 'fast-levenshtein';
|
|
18
|
-
import { Button, useParcaContext } from '@parca/components';
|
|
19
|
-
const CustomSelect = ({ items, selectedKey, onSelection, placeholder = 'Select an item', width, className = '', loading, primary = false, disabled = false, icon, id, optionsClassname = '', searchable = false, onButtonClick, editable = false, }) => {
|
|
18
|
+
import { Button, DividerWithLabel, useParcaContext } from '@parca/components';
|
|
19
|
+
const CustomSelect = ({ items: itemsProp, selectedKey, onSelection, placeholder = 'Select an item', width, className = '', loading, primary = false, disabled = false, icon, id, optionsClassname = '', searchable = false, onButtonClick, editable = false, }) => {
|
|
20
20
|
const { loader } = useParcaContext();
|
|
21
21
|
const [isOpen, setIsOpen] = useState(false);
|
|
22
22
|
const [focusedIndex, setFocusedIndex] = useState(-1);
|
|
@@ -25,6 +25,13 @@ const CustomSelect = ({ items, selectedKey, onSelection, placeholder = 'Select a
|
|
|
25
25
|
const optionsRef = useRef(null);
|
|
26
26
|
const searchInputRef = useRef(null);
|
|
27
27
|
const optionRefs = useRef([]);
|
|
28
|
+
let items = [];
|
|
29
|
+
if (itemsProp[0] != null && 'type' in itemsProp[0]) {
|
|
30
|
+
items = itemsProp.flatMap(item => item.values.map(v => ({ ...v, type: item.type })));
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
items = itemsProp.map(item => ({ ...item, type: '' }));
|
|
34
|
+
}
|
|
28
35
|
const filteredItems = searchable
|
|
29
36
|
? items
|
|
30
37
|
.filter(item => item.element.active.props.children
|
|
@@ -139,19 +146,32 @@ const CustomSelect = ({ items, selectedKey, onSelection, placeholder = 'Select a
|
|
|
139
146
|
e.target.value = '';
|
|
140
147
|
e.target.value = value;
|
|
141
148
|
};
|
|
149
|
+
const groupedFilteredItems = filteredItems
|
|
150
|
+
.reduce((acc, item) => {
|
|
151
|
+
const group = acc.find(g => g.type === item.type);
|
|
152
|
+
if (group != null) {
|
|
153
|
+
group.values.push(item);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
acc.push({ type: item.type, values: [item] });
|
|
157
|
+
}
|
|
158
|
+
return acc;
|
|
159
|
+
}, [])
|
|
160
|
+
.sort((a, b) => a.values.length - b.values.length);
|
|
142
161
|
return (_jsxs("div", { ref: containerRef, className: "relative", onKeyDown: handleKeyDown, onClick: onButtonClick, children: [_jsxs("div", { id: id, onClick: () => !disabled && setIsOpen(!isOpen), className: cx(styles, width !== undefined ? `w-${width}` : 'w-full', disabled ? 'cursor-not-allowed opacity-50 pointer-events-none' : '', primary ? primaryStyles : defaultStyles, { [className]: className.length > 0 }), tabIndex: 0, role: "button", "aria-haspopup": "listbox", "aria-expanded": isOpen, children: [_jsx("div", { className: cx(icon != null ? '' : 'block overflow-x-hidden text-ellipsis whitespace-nowrap'), children: renderSelection(selection) }), _jsx("div", { className: cx(icon != null ? '' : 'pointer-events-none text-gray-400'), children: icon ?? _jsx(Icon, { icon: "heroicons:chevron-up-down-20-solid", "aria-hidden": "true" }) })] }), isOpen && (_jsxs("div", { ref: optionsRef, className: cx('absolute z-50 mt-1 pt-0 max-h-[50vh] w-max overflow-auto rounded-md bg-gray-50 py-1 text-base shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none dark:border-gray-600 dark:bg-gray-900 dark:ring-white dark:ring-opacity-20 sm:text-sm', { [optionsClassname]: optionsClassname.length > 0 }), role: "listbox", children: [searchable && (_jsx("div", { className: "sticky z-10 top-[-5px] w-auto max-w-full", children: _jsx("div", { className: "flex flex-col", children: editable ? (_jsxs(_Fragment, { children: [_jsx("textarea", { ref: searchInputRef, className: "w-full px-4 py-2 text-sm border-b border-gray-200 rounded-none ring-0 outline-none bg-gray-50 dark:bg-gray-800 dark:text-white min-h-[50px]", placeholder: "Type a RegEx to add", value: searchTerm, onChange: e => setSearchTerm(e.target.value), onFocus: e => moveCaretToEnd(e) }), editable && searchTerm.length > 0 && (_jsx("div", { className: "p-2 border-t border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800", children: _jsx(Button, { variant: "primary", className: "w-full h-[30px]", onClick: () => {
|
|
143
162
|
onSelection(searchTerm);
|
|
144
163
|
setIsOpen(false);
|
|
145
|
-
}, children: "Add" }) }))] })) : (_jsx("input", { ref: searchInputRef, type: "text", className: "w-full px-4 h-[45px] text-sm border-none rounded-none ring-0 outline-none bg-gray-50 dark:bg-gray-800 dark:text-white", placeholder: "Search...", value: searchTerm, onChange: e => setSearchTerm(e.target.value) })) }) })), loading === true ? (_jsx("div", { className: "w-[270px]", children: loader })) : (
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
164
|
+
}, children: "Add" }) }))] })) : (_jsx("input", { ref: searchInputRef, type: "text", className: "w-full px-4 h-[45px] text-sm border-none rounded-none ring-0 outline-none bg-gray-50 dark:bg-gray-800 dark:text-white", placeholder: "Search...", value: searchTerm, onChange: e => setSearchTerm(e.target.value) })) }) })), loading === true ? (_jsx("div", { className: "w-[270px]", children: loader })) : (groupedFilteredItems.map(group => (_jsxs(_Fragment, { children: [groupedFilteredItems.length > 1 ? (_jsx("div", { className: "pl-2", children: _jsx(DividerWithLabel, { label: group.type }) })) : null, group.values.map((item, index) => (_jsx(OptionItem, { item: item, index: index, optionRefs: optionRefs, focusedIndex: focusedIndex, selectedKey: selectedKey, handleSelection: handleSelection }, item.key)))] }))))] }))] }));
|
|
165
|
+
};
|
|
166
|
+
const OptionItem = ({ item, optionRefs, index, focusedIndex, selectedKey, handleSelection, }) => {
|
|
167
|
+
return (_jsxs("div", { ref: el => {
|
|
168
|
+
if (el !== null) {
|
|
169
|
+
optionRefs.current[index] = el;
|
|
170
|
+
}
|
|
171
|
+
}, className: cx('relative cursor-default select-none py-2 pl-3 pr-9', index === focusedIndex && 'bg-indigo-600 text-white', item.key === selectedKey && 'bg-indigo-100 dark:bg-indigo-700', item.disabled !== null && item.disabled === true && 'opacity-50 cursor-not-allowed', 'focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 hover:bg-indigo-600 hover:text-white'), role: "option", "aria-selected": item.key === selectedKey, tabIndex: -1, onClick: () => {
|
|
172
|
+
if (!(item.disabled ?? false)) {
|
|
173
|
+
handleSelection(item.key);
|
|
174
|
+
}
|
|
175
|
+
}, children: [item.element.expanded, item.key === selectedKey && (_jsx("span", { className: "absolute inset-y-0 right-0 flex items-center pr-4 text-indigo-600", children: _jsx(Icon, { icon: "heroicons:check-20-solid", "aria-hidden": "true" }) }))] }));
|
|
156
176
|
};
|
|
157
177
|
export default CustomSelect;
|
|
@@ -9,7 +9,7 @@ interface Props {
|
|
|
9
9
|
profileType: string;
|
|
10
10
|
queryBrowserRef: React.RefObject<HTMLDivElement>;
|
|
11
11
|
}
|
|
12
|
-
export declare const transformLabelsForSelect: (labelNames: string[]
|
|
12
|
+
export declare const transformLabelsForSelect: (labelNames: string[]) => SelectItem[];
|
|
13
13
|
export default function SimpleMathersWithProvider(props: Props): JSX.Element;
|
|
14
14
|
export {};
|
|
15
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/SimpleMatchers/index.tsx"],"names":[],"mappings":"AAmBA,OAAO,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAC;AAEjD,OAAO,EAAC,KAAK,EAAC,MAAM,eAAe,CAAC;AAKpC,OAAe,EAAC,KAAK,UAAU,EAAC,MAAM,UAAU,CAAC;AAEjD,UAAU,KAAK;IACb,WAAW,EAAE,kBAAkB,CAAC;IAChC,iBAAiB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,YAAY,EAAE,KAAK,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;CAClD;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/SimpleMatchers/index.tsx"],"names":[],"mappings":"AAmBA,OAAO,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAC;AAEjD,OAAO,EAAC,KAAK,EAAC,MAAM,eAAe,CAAC;AAKpC,OAAe,EAAC,KAAK,UAAU,EAAC,MAAM,UAAU,CAAC;AAEjD,UAAU,KAAK;IACb,WAAW,EAAE,kBAAkB,CAAC;IAChC,iBAAiB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,YAAY,EAAE,KAAK,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;CAClD;AAoBD,eAAO,MAAM,wBAAwB,eAAgB,MAAM,EAAE,KAAG,UAAU,EAQzE,CAAC;AAwUF,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAAC,KAAK,EAAE,KAAK,GAAG,GAAG,CAAC,OAAO,CAkB3E"}
|
|
@@ -20,12 +20,21 @@ import { sanitizeLabelValue } from '@parca/utilities';
|
|
|
20
20
|
import { LabelProvider, useLabels } from '../contexts/SimpleMatchersLabelContext';
|
|
21
21
|
import { useUtilizationLabels } from '../contexts/UtilizationLabelsContext';
|
|
22
22
|
import Select from './Select';
|
|
23
|
-
|
|
23
|
+
const trimOtelPrefix = (labelName) => {
|
|
24
|
+
if (labelName.startsWith('attributes_resource.')) {
|
|
25
|
+
return labelName.replace('attributes_resource.', '');
|
|
26
|
+
}
|
|
27
|
+
if (labelName.startsWith('attributes.')) {
|
|
28
|
+
return labelName.replace('attributes.', '');
|
|
29
|
+
}
|
|
30
|
+
return labelName;
|
|
31
|
+
};
|
|
32
|
+
export const transformLabelsForSelect = (labelNames) => {
|
|
24
33
|
return labelNames.map(labelName => ({
|
|
25
34
|
key: labelName,
|
|
26
35
|
element: {
|
|
27
|
-
active: _jsx(_Fragment, { children:
|
|
28
|
-
expanded: _jsx(_Fragment, { children:
|
|
36
|
+
active: _jsx(_Fragment, { children: trimOtelPrefix(labelName) }),
|
|
37
|
+
expanded: _jsx(_Fragment, { children: trimOtelPrefix(labelName) }),
|
|
29
38
|
},
|
|
30
39
|
}));
|
|
31
40
|
};
|
|
@@ -100,6 +109,14 @@ const SimpleMatchers = ({ queryClient, setMatchersString, currentQuery, profileT
|
|
|
100
109
|
.join(',');
|
|
101
110
|
setMatchersString(matcherString);
|
|
102
111
|
}, [setMatchersString]);
|
|
112
|
+
const { labelNameOptions, isLoading: labelNamesLoading } = useLabels();
|
|
113
|
+
const fetchLabelValuesUnified = useCallback(async (labelName) => {
|
|
114
|
+
const labelType = labelNameOptions.find(option => option.values.some(e => e.key === labelName))?.type;
|
|
115
|
+
const labelValues = labelType === 'gpu'
|
|
116
|
+
? await fetchLabelValuesUtilization(labelName)
|
|
117
|
+
: await fetchLabelValues(labelName);
|
|
118
|
+
return labelValues;
|
|
119
|
+
}, [fetchLabelValues, fetchLabelValuesUtilization, labelNameOptions]);
|
|
103
120
|
useEffect(() => {
|
|
104
121
|
if (currentMatchers === '') {
|
|
105
122
|
return;
|
|
@@ -113,9 +130,7 @@ const SimpleMatchers = ({ queryClient, setMatchersString, currentQuery, profileT
|
|
|
113
130
|
const trimmedLabelName = labelName.trim();
|
|
114
131
|
if (trimmedLabelName === '')
|
|
115
132
|
return null;
|
|
116
|
-
const labelValues =
|
|
117
|
-
? await fetchLabelValuesUtilization(trimmedLabelName)
|
|
118
|
-
: await fetchLabelValues(trimmedLabelName);
|
|
133
|
+
const labelValues = await fetchLabelValuesUnified(trimmedLabelName);
|
|
119
134
|
const sanitizedLabelValue = labelValue.startsWith('"') && labelValue.endsWith('"')
|
|
120
135
|
? labelValue.slice(1, -1)
|
|
121
136
|
: labelValue;
|
|
@@ -131,14 +146,7 @@ const SimpleMatchers = ({ queryClient, setMatchersString, currentQuery, profileT
|
|
|
131
146
|
updateMatchersString(filteredRows);
|
|
132
147
|
};
|
|
133
148
|
void fetchAndSetQueryRows();
|
|
134
|
-
}, [
|
|
135
|
-
currentMatchers,
|
|
136
|
-
fetchLabelValues,
|
|
137
|
-
updateMatchersString,
|
|
138
|
-
fetchLabelValuesUtilization,
|
|
139
|
-
utilizationLabels,
|
|
140
|
-
]);
|
|
141
|
-
const { labelNameOptions, isLoading: labelNamesLoading } = useLabels();
|
|
149
|
+
}, [currentMatchers, fetchLabelValuesUnified, updateMatchersString]);
|
|
142
150
|
const updateRow = useCallback(async (index, field, value) => {
|
|
143
151
|
const updatedRows = [...queryRows];
|
|
144
152
|
const prevLabelName = updatedRows[index].labelName;
|
|
@@ -148,21 +156,13 @@ const SimpleMatchers = ({ queryClient, setMatchersString, currentQuery, profileT
|
|
|
148
156
|
updatedRows[index].labelValue = '';
|
|
149
157
|
updatedRows[index].isLoading = true;
|
|
150
158
|
setQueryRows([...updatedRows]);
|
|
151
|
-
const labelValues =
|
|
152
|
-
? await fetchLabelValuesUtilization(value)
|
|
153
|
-
: await fetchLabelValues(value);
|
|
159
|
+
const labelValues = await fetchLabelValuesUnified(value);
|
|
154
160
|
updatedRows[index].labelValues = labelValues;
|
|
155
161
|
updatedRows[index].isLoading = false;
|
|
156
162
|
}
|
|
157
163
|
setQueryRows([...updatedRows]);
|
|
158
164
|
updateMatchersString(updatedRows);
|
|
159
|
-
}, [
|
|
160
|
-
queryRows,
|
|
161
|
-
fetchLabelValues,
|
|
162
|
-
updateMatchersString,
|
|
163
|
-
fetchLabelValuesUtilization,
|
|
164
|
-
utilizationLabels,
|
|
165
|
-
]);
|
|
165
|
+
}, [queryRows, fetchLabelValuesUnified, updateMatchersString]);
|
|
166
166
|
const handleUpdateRow = useCallback((index, field, value) => {
|
|
167
167
|
void updateRow(index, field, value);
|
|
168
168
|
}, [updateRow]);
|
|
@@ -200,9 +200,7 @@ const SimpleMatchers = ({ queryClient, setMatchersString, currentQuery, profileT
|
|
|
200
200
|
updatedRows[index].isLoading = true;
|
|
201
201
|
setQueryRows([...updatedRows]);
|
|
202
202
|
try {
|
|
203
|
-
const labelValues =
|
|
204
|
-
? await fetchLabelValuesUtilization(updatedRows[index].labelName)
|
|
205
|
-
: await fetchLabelValues(updatedRows[index].labelName);
|
|
203
|
+
const labelValues = await fetchLabelValuesUnified(updatedRows[index].labelName);
|
|
206
204
|
updatedRows[index].labelValues = labelValues;
|
|
207
205
|
}
|
|
208
206
|
catch (error) {
|
|
@@ -217,7 +215,7 @@ const SimpleMatchers = ({ queryClient, setMatchersString, currentQuery, profileT
|
|
|
217
215
|
console.log(`Label values already present or empty label name`);
|
|
218
216
|
}
|
|
219
217
|
};
|
|
220
|
-
}, [queryRows,
|
|
218
|
+
}, [queryRows, fetchLabelValuesUnified]);
|
|
221
219
|
const isRowRegex = (row) => row.operator === '=~' || row.operator === '!~';
|
|
222
220
|
return (_jsxs("div", { className: `flex items-center gap-3 ${maxWidthInPixels} w-full flex-wrap`, id: "simple-matchers", children: [visibleRows.map((row, index) => (_jsxs("div", { className: "flex items-center", children: [_jsx(Select, { items: labelNameOptions, onSelection: value => handleUpdateRow(index, 'labelName', value), placeholder: "Select label name", selectedKey: row.labelName, className: "rounded-tr-none rounded-br-none ring-0 focus:ring-0 outline-none", loading: labelNamesLoading, searchable: true }), _jsx(Select, { items: operatorOptions, onSelection: value => handleUpdateRow(index, 'operator', value), selectedKey: row.operator, className: "rounded-none ring-0 focus:ring-0 outline-none" }), _jsx(Select, { items: transformLabelsForSelect(row.labelValues), onSelection: value => handleUpdateRow(index, 'labelValue', value), placeholder: "Select label value", selectedKey: row.labelValue, className: "rounded-none ring-0 focus:ring-0 outline-none max-w-48", optionsClassname: cx('max-w-[300px]', {
|
|
223
221
|
'w-[300px]': isRowRegex(row),
|