Files
windmill/frontend/src/lib/components/MemoryFootprintViewer.svelte
T
Diego Imbert 5d79f33590 Final Svelte 5 migration (#8211)
* Remove $$props.field usage

* Rename slots to ensure no hyphen

* _props

* _trigger

* OnSelectedIteration type correct capitalization

* rename _content

* Remove afterUpdate

* Migrate everything to svelte 5

* array bind

* Fix popover

* type never

* nit fixes

* Fixed many trivial errors

* onClick

* Fix errors

* use let:

* nit typing

* fix: wrap state_referenced_locally vars with untrack()

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add untrack import

* Fix all syntax errors due to untrack migration

* Fix undefined errors

* Fix more undefined errors

* untrack(() => initialOpen)

* svelte-ignore

* Fix state_descriptors_fixed error in Chart.svelte

Use $state.snapshot() to pass plain copies of data/options to Chart.js
instead of $state proxies. Chart.js's listenArrayEvents tries to define
property descriptors on data arrays, which Svelte 5 proxies reject.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* nit typing

* Merge issue

* Fix "path is not set" error in resource picker / editor

* Fix InputTransformForm error when rerunning some flows

* fix npm run check

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-05 18:11:40 +01:00

112 lines
2.5 KiB
Svelte

<script lang="ts">
import { run } from 'svelte/legacy';
import { type MetricDataPoint, MetricsService } from '$lib/gen'
import { displayTime } from '$lib/utils'
import { workspaceStore } from '$lib/stores'
import {
CategoryScale,
Chart as ChartJS,
Legend,
LinearScale,
LineElement,
PointElement,
Title,
Tooltip
} from 'chart.js'
import { Line } from '$lib/components/chartjs-wrappers/chartJs'
import { Alert } from './common'
ChartJS.register(Title, Tooltip, Legend, LineElement, LinearScale, PointElement, CategoryScale)
interface Props {
jobId: string;
jobUpdateLastFetch: Date | undefined;
}
let { jobId, jobUpdateLastFetch }: Props = $props();
let jobMetricsLastFetch: Date | undefined = undefined
let jobMemoryStats: MetricDataPoint[] | undefined = $state(undefined)
let data: {
x: number
y: number
}[] = $state([])
let labels: string[] = []
async function loadMetricsData() {
try {
let jobStatsPromise = MetricsService.getJobMetrics({
workspace: $workspaceStore!,
id: jobId,
requestBody: {
from_timestamp: jobMetricsLastFetch?.toISOString(),
timeseries_max_datapoints: 0
}
})
jobMetricsLastFetch = new Date()
let jobStats = await jobStatsPromise
let memoryTimeseries =
jobStats.timeseries_metrics?.filter((ts) => ts.metric_id === 'memory_kb') ?? []
if (memoryTimeseries.length > 0) {
jobMemoryStats = (jobMemoryStats ?? []).concat(memoryTimeseries[0].values)
}
} catch {
console.error('Unable to load metrics data for job', jobId)
return
}
for (let dp of jobMemoryStats ?? []) {
let ts = new Date(dp.timestamp).valueOf()
if (data.length === 0 || ts > data[data.length - 1].x) {
data.push({
x: ts,
y: dp.value
})
labels.push(displayTime(dp.timestamp))
}
}
data = [...data]
}
run(() => {
jobUpdateLastFetch && loadMetricsData()
});
</script>
<div class="relative max-h-100">
{#if (jobMemoryStats?.length ?? 0) === 0}
<Alert type="info" title="No metric available"
>No data points available for this job. Metrics are recorded only for jobs running for more
than 500ms.</Alert
>
{/if}
<Line
class="w-full max-h-80"
data={{
labels: labels,
datasets: [
{
label: 'Job memory footprint (kB)',
data: data,
fill: false,
borderColor: 'rgb(59, 130, 246, 0.8)',
backgroundColor: 'rgb(59, 130, 246, 0.8)',
tension: 0.1
}
]
}}
options={{
animation: {
duration: 0
},
maintainAspectRatio: false,
responsive: true
}}
/>
</div>