Migrate and rework job view metricplot wrapper

This commit is contained in:
Christoph Kluge 2025-06-26 18:41:27 +02:00
parent e94b250541
commit c3a6126799
3 changed files with 88 additions and 133 deletions

View File

@ -75,26 +75,8 @@
name name
scope scope
metric { metric {
unit {
prefix
base
}
timestep
statisticsSeries {
min
mean
median
max
}
series { series {
hostname hostname
id
data
statistics {
min
avg
max
}
} }
} }
} }
@ -343,8 +325,7 @@
metricName={item.metric} metricName={item.metric}
metricUnit={$initq.data.globalMetrics.find((gm) => gm.name == item.metric)?.unit} metricUnit={$initq.data.globalMetrics.find((gm) => gm.name == item.metric)?.unit}
nativeScope={$initq.data.globalMetrics.find((gm) => gm.name == item.metric)?.scope} nativeScope={$initq.data.globalMetrics.find((gm) => gm.name == item.metric)?.scope}
rawData={item.data.map((x) => x.metric)} presetScopes={item.data.map((x) => x.scope)}
scopes={item.data.map((x) => x.scope)}
isShared={$initq.data.job.exclusive != 1} isShared={$initq.data.job.exclusive != 1}
/> />
{:else if item.disabled == true} {:else if item.disabled == true}

View File

@ -440,7 +440,7 @@
/* IF Zoom Enabled */ /* IF Zoom Enabled */
if (resampleConfig) { if (resampleConfig) {
u.over.addEventListener("dblclick", (e) => { u.over.addEventListener("dblclick", (e) => {
// console.log('Dispatch Reset') // console.log('Dispatch: Zoom Reset')
dispatch('zoom', { dispatch('zoom', {
lastZoomState: { lastZoomState: {
x: { time: false }, x: { time: false },
@ -506,7 +506,7 @@
}); });
// Prevents non-required dispatches // Prevents non-required dispatches
if (timestep !== closest) { if (timestep !== closest) {
// console.log('Dispatch Zoom with Res from / to', timestep, closest) // console.log('Dispatch: Zoom with Res from / to', timestep, closest)
dispatch('zoom', { dispatch('zoom', {
newRes: closest, newRes: closest,
lastZoomState: u?.scales, lastZoomState: u?.scales,
@ -514,6 +514,7 @@
}); });
} }
} else { } else {
// console.log('Dispatch: Zoom Update States')
dispatch('zoom', { dispatch('zoom', {
lastZoomState: u?.scales, lastZoomState: u?.scales,
lastThreshold: thresholds?.normal lastThreshold: thresholds?.normal

View File

@ -31,33 +31,22 @@
} from "../generic/utils.js"; } from "../generic/utils.js";
import Timeseries from "../generic/plots/MetricPlot.svelte"; import Timeseries from "../generic/plots/MetricPlot.svelte";
export let job; /* Svelte 5 Props */
export let metricName; let {
export let metricUnit; job,
export let nativeScope; metricName,
export let scopes; metricUnit,
export let rawData; nativeScope,
export let isShared = false; presetScopes,
isShared = false,
} = $props();
/* Const Init */
const client = getContextClient();
const statsPattern = /(.*)-stat$/;
const resampleConfig = getContext("resampling") || null; const resampleConfig = getContext("resampling") || null;
const resampleDefault = resampleConfig ? Math.max(...resampleConfig.resolutions) : 0; const resampleDefault = resampleConfig ? Math.max(...resampleConfig.resolutions) : 0;
let selectedHost = null;
let error = null;
let selectedScope = minScope(scopes);
let selectedResolution = null;
let pendingResolution = resampleDefault;
let selectedScopeIndex = scopes.findIndex((s) => s == minScope(scopes));
let patternMatches = false;
let nodeOnly = false; // If, after load-all, still only node scope returned
let statsSeries = rawData.map((data) => data?.statisticsSeries ? data.statisticsSeries : null);
let zoomState = null;
let pendingZoomState = null;
let thresholdState = null;
const statsPattern = /(.*)-stat$/;
const unit = (metricUnit?.prefix ? metricUnit.prefix : "") + (metricUnit?.base ? metricUnit.base : ""); const unit = (metricUnit?.prefix ? metricUnit.prefix : "") + (metricUnit?.base ? metricUnit.base : "");
const client = getContextClient();
const subQuery = gql` const subQuery = gql`
query ($dbid: ID!, $selectedMetrics: [String!]!, $selectedScopes: [MetricScope!]!, $selectedResolution: Int) { query ($dbid: ID!, $selectedMetrics: [String!]!, $selectedScopes: [MetricScope!]!, $selectedResolution: Int) {
singleUpdate: jobMetrics(id: $dbid, metrics: $selectedMetrics, scopes: $selectedScopes, resolution: $selectedResolution) { singleUpdate: jobMetrics(id: $dbid, metrics: $selectedMetrics, scopes: $selectedScopes, resolution: $selectedResolution) {
@ -90,84 +79,68 @@
} }
`; `;
function handleZoom(detail) { /* State Init */
if ( // States have to differ, causes deathloop if just set let requestedScopes = $state(presetScopes);
(pendingZoomState?.x?.min !== detail?.lastZoomState?.x?.min) && let selectedResolution = $state(resampleConfig ? resampleDefault : 0);
(pendingZoomState?.y?.max !== detail?.lastZoomState?.y?.max)
) {
pendingZoomState = {...detail.lastZoomState};
}
if (detail?.lastThreshold) { // Handle to correctly reset on summed metric scope change let selectedHost = $state(null);
thresholdState = detail.lastThreshold; let zoomState = $state(null);
} else { let thresholdState = $state(null);
thresholdState = null;
}
if (detail?.newRes) { // Triggers GQL /* Derived */
pendingResolution = detail.newRes; const metricData = $derived(queryStore({
}
};
let metricData;
let selectedScopes = [...scopes];
const dbid = job.id;
const selectedMetrics = [metricName];
$: if (selectedScope || pendingResolution) {
if (resampleConfig && !selectedResolution) {
// Skips reactive data load on init || Only if resampling is enabled
selectedResolution = Number(pendingResolution)
} else {
if (selectedScope == "load-all") {
selectedScopes = [...scopes, "socket", "core", "accelerator"]
}
if (resampleConfig && pendingResolution) {
selectedResolution = Number(pendingResolution)
}
metricData = queryStore({
client: client, client: client,
query: subQuery, query: subQuery,
variables: { dbid, selectedMetrics, selectedScopes, selectedResolution: (resampleConfig ? selectedResolution : 0) }, variables: {
dbid: job.id,
selectedMetrics: [metricName],
selectedScopes: [...requestedScopes],
selectedResolution
},
// Never user network-only: causes reactive load-loop! // Never user network-only: causes reactive load-loop!
})
);
const rawData = $derived($metricData?.data ? $metricData.data.singleUpdate.map((x) => x.metric) : []);
const availableScopes = $derived($metricData?.data ? $metricData.data.singleUpdate.map((x) => x.scope) : presetScopes);
let selectedScope = $derived(minScope(availableScopes));
const patternMatches = $derived(statsPattern.exec(selectedScope));
const selectedScopeIndex = $derived.by(() => {
if (!patternMatches) {
return availableScopes.findIndex((s) => s == selectedScope);
} else {
return availableScopes.findIndex((s) => s == patternMatches[1]);
}
});
const selectedData = $derived(rawData[selectedScopeIndex]);
const selectedSeries = $derived(rawData[selectedScopeIndex]?.series?.filter(
(series) => selectedHost == null || series.hostname == selectedHost
)
);
const statsSeries = $derived(rawData.map((rd) => rd?.statisticsSeries ? rd.statisticsSeries : null));
/* Effect */
$effect(() => {
// Only triggered once
if (selectedScope == "load-all") {
requestedScopes = ["node", "socket", "core", "accelerator"];
}
}); });
if ($metricData && !$metricData.fetching) { /* Functions */
rawData = $metricData.data.singleUpdate.map((x) => x.metric) function handleZoom(detail) {
scopes = $metricData.data.singleUpdate.map((x) => x.scope) // Buffer last zoom state to allow seamless zoom on rerender
statsSeries = rawData.map((data) => data?.statisticsSeries ? data.statisticsSeries : null) // console.log('Update zoomState with:', {...detail.lastZoomState})
zoomState = detail?.lastZoomState ? {...detail.lastZoomState} : null;
// Keep Zoomlevel if ResChange By Zoom // Handle to correctly reset on summed metric scope change
if (pendingZoomState) { // console.log('Update thresholdState with:', detail.lastThreshold)
zoomState = {...pendingZoomState} thresholdState = detail?.lastThreshold ? detail.lastThreshold : null;
// Triggers GQL
if (detail?.newRes) {
// console.log('Update selectedResolution with:', detail.newRes)
selectedResolution = detail.newRes;
} }
};
// On additional scope request
if (selectedScope == "load-all") {
// Set selected scope to min of returned scopes
selectedScope = minScope(scopes)
nodeOnly = (selectedScope == "node") // "node" still only scope after load-all
}
patternMatches = statsPattern.exec(selectedScope)
if (!patternMatches) {
selectedScopeIndex = scopes.findIndex((s) => s == selectedScope);
} else {
selectedScopeIndex = scopes.findIndex((s) => s == patternMatches[1]);
}
}
}
}
$: data = rawData[selectedScopeIndex];
$: series = data?.series?.filter(
(series) => selectedHost == null || series.hostname == selectedHost,
);
</script> </script>
<InputGroup class="mt-2"> <InputGroup class="mt-2">
@ -175,13 +148,13 @@
{metricName} ({unit}) {metricName} ({unit})
</InputGroupText> </InputGroupText>
<select class="form-select" bind:value={selectedScope}> <select class="form-select" bind:value={selectedScope}>
{#each scopes as scope, index} {#each availableScopes as scope, index}
<option value={scope}>{scope}</option> <option value={scope}>{scope}</option>
{#if statsSeries[index]} {#if statsSeries[index]}
<option value={scope + '-stat'}>stats series ({scope})</option> <option value={scope + '-stat'}>stats series ({scope})</option>
{/if} {/if}
{/each} {/each}
{#if scopes.length == 1 && nativeScope != "node" && !nodeOnly} {#if requestedScopes.length == 1 && nativeScope != "node"}
<option value={"load-all"}>Load all...</option> <option value={"load-all"}>Load all...</option>
{/if} {/if}
</select> </select>
@ -194,37 +167,37 @@
</select> </select>
{/if} {/if}
</InputGroup> </InputGroup>
{#key series} {#key selectedSeries}
{#if $metricData?.fetching == true} {#if $metricData.fetching}
<Spinner /> <Spinner />
{:else if error != null} {:else if $metricData.error}
<Card body color="danger">{error.message}</Card> <Card body color="danger">{$metricData.error.message}</Card>
{:else if series != null && !patternMatches} {:else if selectedSeries != null && !patternMatches}
<Timeseries <Timeseries
on:zoom={({detail}) => { handleZoom(detail) }} on:zoom={({detail}) => handleZoom(detail)}
cluster={job.cluster} cluster={job.cluster}
subCluster={job.subCluster} subCluster={job.subCluster}
timestep={data.timestep} timestep={selectedData.timestep}
scope={selectedScope} scope={selectedScope}
metric={metricName} metric={metricName}
numaccs={job.numAcc} numaccs={job.numAcc}
numhwthreads={job.numHWThreads} numhwthreads={job.numHWThreads}
{series} series={selectedSeries}
{isShared} {isShared}
{zoomState} {zoomState}
{thresholdState} {thresholdState}
/> />
{:else if statsSeries[selectedScopeIndex] != null && patternMatches} {:else if statsSeries[selectedScopeIndex] != null && patternMatches}
<Timeseries <Timeseries
on:zoom={({detail}) => { handleZoom(detail) }} on:zoom={({detail}) => handleZoom(detail)}
cluster={job.cluster} cluster={job.cluster}
subCluster={job.subCluster} subCluster={job.subCluster}
timestep={data.timestep} timestep={selectedData.timestep}
scope={selectedScope} scope={selectedScope}
metric={metricName} metric={metricName}
numaccs={job.numAcc} numaccs={job.numAcc}
numhwthreads={job.numHWThreads} numhwthreads={job.numHWThreads}
{series} series={selectedSeries}
{isShared} {isShared}
{zoomState} {zoomState}
{thresholdState} {thresholdState}