mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-21 22:15:40 +00:00
a63ba3c9cb
* fix(cover-backfill): snapshot-diff worklist and live-tunable parallelism Aggressive cover backfill pegged one tokio worker at ~100% on large, fully-synced libraries while the download queues stayed empty. - Take two snapshots once per pass — the DB catalog (single GROUP BY) and the on-disk cover bucket (one directory walk) — and download the set-difference. No per-row `stat` syscalls and no re-scan loop; the empty cache case (heavy backfill) costs zero per-item disk hits. - Replace the front-loaded enumeration with a producer/consumer pipeline: the producer streams the catalog in chunks and feeds misses into a bounded channel; a fixed consumer pool keeps the download/encode pools saturated. - Make cover backfill parallelism runtime-tunable from the Performance Probe (threads slider + "Run full pass now"); HTTP download and CPU encode semaphores resize live. Not surfaced in app settings. - Add a "nothing changed" idle gate (catalog signature) so a settled pass is not re-run on every library:sync-idle, mirroring the analysis worker. - Cancel promptly on switch to lazy: consumers bail on enabled/focus change and the producer feeds via try_send so a full channel cannot deadlock. - Drop the per-item recursive disk walk from the ensure hot path. * fix(cover-backfill): cheap idle gate, settle on 404s, transient retries Follow-up to the snapshot-diff backfill: stop the periodic CPU spikes and the 89%-plateau wake storm on libraries whose covers can never reach 100%. - Idle gate is now disk-free: compare only the catalog COUNT(DISTINCT) instead of walking ~all cover dirs on every sync-idle. "Did the server change?" never touches the filesystem. Clear-cache commands re-arm the gate (rearm_idle_gate) since a clear leaves the catalog total unchanged, and the settings UI wakes the active server after a clear. - Settle the gate on any completed pass regardless of pending: remaining items are unfetchable-for-now (404), so the wake/sync-idle storm stops once the fetchable set is exhausted. - Stop auto-clearing .fetch-failed markers every pass (it defeated the 30-min backoff and re-attempted 404s forever). The manual "Run full pass now" sends force=true to clear them and retry; wake/sync-idle/configure stay opportunistic. - Rate-limit sync-idle passes (60s cooldown) as defence against chatty syncs. - Retry cover downloads up to 3x with backoff on transient failures (5xx / 429 / network), but never on a real 4xx so missing covers don't hammer the server. * fix(cover-cache): stop re-walking cover dirs from offline & cache menu The settings cover-cache section polled disk usage + progress every 15s for every server, each call doing a full recursive walk of the per-server cover directory. On a fully populated cache this caused periodic CPU spikes whenever that menu was open. - mod.rs: add a 10s TTL memo around the per-server cover dir walk (cached_dir_usage_for_server), shared by cover_cache_stats_server and library_cover_progress; invalidate on clear (per-server and clear-all). - CoverCacheStrategySection: recompute on entry only; rely on the cover:library-progress and cover:cache-cleared events for live updates; drop the per-cover cover:tier-ready refresh storm; turn the 15s loop into a 5-minute safety net. * fix(cover-backfill): keep emitting progress during the whole pass The producer finishes enumerating the worklist long before the consumer pool finishes downloading it, so progress was only emitted while feeding the channel — the "offline & cache" menu and overlay then froze through the entire drain phase. Replace the per-chunk emit with a 3s progress ticker that runs for the lifetime of the pass and is aborted once the consumers drain (final accurate emit still happens at settle). * docs(changelog): record cover-backfill idle-CPU fix (PR #943) Add [1.47.0] Fixed + Changed entries and a settingsCredits line for the cover-backfill idle CPU / offline & cache menu work.
227 lines
8.4 KiB
TypeScript
227 lines
8.4 KiB
TypeScript
import { useMemo, useRef } from 'react';
|
|
import { isPerfLivePollWaitingForCpu, usePerfLiveSnapshot } from '../../../utils/perf/perfLiveStore';
|
|
import { usePerfLiveIncludeThreadGroups } from '../../../utils/perf/perfLivePollSettings';
|
|
import {
|
|
togglePerfLiveOverlayPin,
|
|
togglePipelineOverlayPin,
|
|
usePerfLiveOverlayPins,
|
|
usePipelineOverlayPinned,
|
|
type PerfLiveOverlayPinId,
|
|
} from '../../../utils/perf/perfOverlayPins';
|
|
import PerfProbeMetricCard, { PerfProbeMetricSection } from './PerfProbeMetricCard';
|
|
import PerfOverlayAppearanceControls from './PerfOverlayAppearanceControls';
|
|
import PerfOverlayModeControls from './PerfOverlayModeControls';
|
|
import PerfLivePollControls from './PerfLivePollControls';
|
|
import PerfCoverThreadsControl from './PerfCoverThreadsControl';
|
|
|
|
function memoryBarPct(rssKb: number, maxKb: number): number {
|
|
if (maxKb <= 0) return 0;
|
|
return (rssKb / maxKb) * 100;
|
|
}
|
|
|
|
export default function SidebarPerfProbeMonitorTab() {
|
|
const live = usePerfLiveSnapshot();
|
|
const livePins = usePerfLiveOverlayPins();
|
|
const fpsPinned = usePipelineOverlayPinned('pipeline:fps');
|
|
const analysisPinned = usePipelineOverlayPinned('pipeline:analysis');
|
|
const coverPinned = usePipelineOverlayPinned('pipeline:cover');
|
|
const cpu = live.cpu;
|
|
const cpuSupported = cpu?.supported === true;
|
|
const collecting = isPerfLivePollWaitingForCpu();
|
|
const includeThreadGroups = usePerfLiveIncludeThreadGroups();
|
|
const peakMemoryKbRef = useRef(1);
|
|
const peakThreadCpuRef = useRef(1);
|
|
|
|
const maxMemoryKb = useMemo(() => {
|
|
const current = Math.max(1, ...(cpu?.memory.map(m => m.rss_kb) ?? [1]));
|
|
if (current > peakMemoryKbRef.current) peakMemoryKbRef.current = current;
|
|
return peakMemoryKbRef.current;
|
|
}, [cpu?.memory]);
|
|
|
|
const maxThreadCpu = useMemo(() => {
|
|
const current = Math.max(1, ...(cpu?.threadCpu.map(t => t.pct) ?? [1]));
|
|
if (current > peakThreadCpuRef.current) peakThreadCpuRef.current = current;
|
|
return peakThreadCpuRef.current;
|
|
}, [cpu?.threadCpu]);
|
|
|
|
if (collecting) {
|
|
return (
|
|
<div className="perf-monitor-empty">
|
|
<div className="spinner" style={{ width: 22, height: 22 }} />
|
|
<span>Collecting live samples…</span>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const toggleLive = (id: PerfLiveOverlayPinId) => () => togglePerfLiveOverlayPin(id);
|
|
const livePinned = (id: PerfLiveOverlayPinId) => livePins.has(id);
|
|
|
|
return (
|
|
<div className="perf-monitor">
|
|
<PerfOverlayModeControls />
|
|
<PerfOverlayAppearanceControls />
|
|
<PerfLivePollControls />
|
|
<PerfCoverThreadsControl />
|
|
<PerfProbeMetricSection title="Pipeline overlays" hint="Rust / UI queues">
|
|
<PerfProbeMetricCard
|
|
label="FPS"
|
|
value="—"
|
|
detail="requestAnimationFrame rate"
|
|
pinned={fpsPinned}
|
|
pinKind="pipeline"
|
|
onTogglePin={() => togglePipelineOverlayPin('pipeline:fps')}
|
|
/>
|
|
<PerfProbeMetricCard
|
|
label="Analysis"
|
|
value="—"
|
|
detail="Throughput + last track timings"
|
|
pinned={analysisPinned}
|
|
pinKind="pipeline"
|
|
onTogglePin={() => togglePipelineOverlayPin('pipeline:analysis')}
|
|
/>
|
|
<PerfProbeMetricCard
|
|
label="Cover pipeline"
|
|
value="—"
|
|
detail="Ensure / HTTP / encode queues"
|
|
pinned={coverPinned}
|
|
pinKind="pipeline"
|
|
onTogglePin={() => togglePipelineOverlayPin('pipeline:cover')}
|
|
/>
|
|
</PerfProbeMetricSection>
|
|
|
|
{cpu && !cpuSupported && (
|
|
<div className="perf-monitor-empty perf-monitor-empty--inline">
|
|
Live CPU and RSS sampling is unavailable on this platform. Pipeline, UI rate, and analysis metrics below still work.
|
|
</div>
|
|
)}
|
|
|
|
{cpuSupported && cpu && (
|
|
<>
|
|
<PerfProbeMetricSection title="CPU — processes">
|
|
<PerfProbeMetricCard
|
|
label="psysonic"
|
|
value={cpu.app.toFixed(1)}
|
|
unit="%"
|
|
barPct={cpu.app}
|
|
barTone="cpu"
|
|
pinned={livePinned('cpu:app')}
|
|
onTogglePin={toggleLive('cpu:app')}
|
|
/>
|
|
<PerfProbeMetricCard
|
|
label="WebKit web"
|
|
value={cpu.webkit.toFixed(1)}
|
|
unit="%"
|
|
barPct={cpu.webkit}
|
|
barTone="cpu"
|
|
pinned={livePinned('cpu:webkit')}
|
|
onTogglePin={toggleLive('cpu:webkit')}
|
|
/>
|
|
</PerfProbeMetricSection>
|
|
|
|
{includeThreadGroups && (
|
|
<PerfProbeMetricSection
|
|
title="CPU — psysonic threads"
|
|
defaultOpen
|
|
>
|
|
{cpu.threadCpu.length > 0 ? cpu.threadCpu.map(row => {
|
|
const pinId = `cpu:thread:${row.label}` as PerfLiveOverlayPinId;
|
|
return (
|
|
<PerfProbeMetricCard
|
|
key={row.label}
|
|
label={row.label}
|
|
value={row.pct.toFixed(1)}
|
|
unit="%"
|
|
detail={row.threadCount > 1 ? `${row.threadCount} threads` : undefined}
|
|
barPct={(row.pct / maxThreadCpu) * 100}
|
|
barTone="cpu"
|
|
pinned={livePinned(pinId)}
|
|
onTogglePin={toggleLive(pinId)}
|
|
/>
|
|
);
|
|
}) : (
|
|
<div className="perf-monitor-empty perf-monitor-empty--inline">
|
|
No named psysonic threads yet — wait for the next poll or load audio/analysis work.
|
|
</div>
|
|
)}
|
|
</PerfProbeMetricSection>
|
|
)}
|
|
|
|
{cpu.memory.length > 0 && (
|
|
<PerfProbeMetricSection title="Memory — RSS">
|
|
{cpu.memory.map(row => {
|
|
const pinId = `mem:${row.label}` as PerfLiveOverlayPinId;
|
|
return (
|
|
<PerfProbeMetricCard
|
|
key={row.label}
|
|
label={row.label}
|
|
value={(row.rss_kb / 1024).toFixed(1)}
|
|
unit="MB"
|
|
barPct={memoryBarPct(row.rss_kb, maxMemoryKb)}
|
|
barTone="memory"
|
|
pinned={livePinned(pinId)}
|
|
onTogglePin={toggleLive(pinId)}
|
|
/>
|
|
);
|
|
})}
|
|
</PerfProbeMetricSection>
|
|
)}
|
|
</>
|
|
)}
|
|
|
|
{live.diagRates && (
|
|
<PerfProbeMetricSection title="UI event rates" defaultOpen={false}>
|
|
<PerfProbeMetricCard
|
|
label="audio:progress"
|
|
value={live.diagRates.progress.toFixed(1)}
|
|
unit="/s"
|
|
barPct={Math.min(100, live.diagRates.progress * 2)}
|
|
barTone="rate"
|
|
pinned={livePinned('rate:progress')}
|
|
onTogglePin={toggleLive('rate:progress')}
|
|
/>
|
|
<PerfProbeMetricCard
|
|
label="waveform draws"
|
|
value={live.diagRates.waveform.toFixed(1)}
|
|
unit="/s"
|
|
barPct={Math.min(100, live.diagRates.waveform * 2)}
|
|
barTone="rate"
|
|
pinned={livePinned('rate:waveform')}
|
|
onTogglePin={toggleLive('rate:waveform')}
|
|
/>
|
|
<PerfProbeMetricCard
|
|
label="Home commits"
|
|
value={live.diagRates.home.toFixed(1)}
|
|
unit="/s"
|
|
barPct={Math.min(100, live.diagRates.home * 5)}
|
|
barTone="rate"
|
|
pinned={livePinned('rate:home')}
|
|
onTogglePin={toggleLive('rate:home')}
|
|
/>
|
|
</PerfProbeMetricSection>
|
|
)}
|
|
|
|
{live.analysis && (
|
|
<PerfProbeMetricSection title="Analysis" defaultOpen={false}>
|
|
<PerfProbeMetricCard
|
|
label="Throughput"
|
|
value={live.analysis.tracksPerMinute.toFixed(1)}
|
|
unit="tpm"
|
|
pinned={livePinned('analysis:tpm')}
|
|
onTogglePin={toggleLive('analysis:tpm')}
|
|
/>
|
|
{live.analysis.lastTotalMs != null && (
|
|
<PerfProbeMetricCard
|
|
label="Last track"
|
|
value={(live.analysis.lastTotalMs / 1000).toFixed(1)}
|
|
unit="s"
|
|
detail={`fetch ${((live.analysis.lastFetchMs ?? 0) / 1000).toFixed(1)}s · seed ${((live.analysis.lastSeedMs ?? 0) / 1000).toFixed(1)}s · bpm ${((live.analysis.lastBpmMs ?? 0) / 1000).toFixed(1)}s`}
|
|
pinned={livePinned('analysis:last')}
|
|
onTogglePin={toggleLive('analysis:last')}
|
|
/>
|
|
)}
|
|
</PerfProbeMetricSection>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|