mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-07-31 12:25:49 +00:00
98ae62c432
* docs: design backend diagnostics memory noise handling * chore(gh): tweak workflow * docs: clarify shared heap snapshot reporting * docs: plan backend diagnostics memory noise handling * chore: ignore local worktrees * feat(diagnostics): add independent delta summary * feat(diagnostics): make heap snapshot deltas noise-aware * docs: correct heap snapshot threshold plan * fix(diagnostics): suppress backend memory noise * ci: refine backend diagnostics sampling * test(diagnostics): address final review * wip * Update heap-snapshot-sampling.ts * wip * wip * docs: design frontend metric noise reporting * docs: plan frontend metric noise reporting * fix(diagnostics): suppress frontend metric noise * docs: remove temporary frontend metric plans * test(diagnostics): cover frontend metric thresholds * docs: design shared diagnostics metric table * docs: plan shared diagnostics metric table * refactor(diagnostics): simplify independent delta statistics * feat(diagnostics): add shared metric table renderer * refactor(diagnostics): use shared heap snapshot table * refactor(diagnostics): use shared backend metric table * refactor(diagnostics): use shared frontend metric table * docs: remove temporary metric table plans * tweak * docs: design metric table no-data output * fix(diagnostics): show marker for empty metric tables * chore: remove temporary diagnostics design
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
export function clampHeapSnapshotRounds(totalRounds: number, requestedRounds: number) {
|
|
return Math.min(totalRounds, requestedRounds);
|
|
}
|
|
|
|
export function shouldCollectHeapSnapshot(round: number, totalRounds: number, requestedRounds: number) {
|
|
const snapshotRounds = clampHeapSnapshotRounds(totalRounds, requestedRounds);
|
|
return round > totalRounds - snapshotRounds;
|
|
}
|
|
|
|
/**
|
|
* 中央値に最も近いラウンドを代表として選ぶ。外れ値のスナップショットを成果物にしないため。
|
|
*/
|
|
export function selectRepresentativeHeapSnapshotRound<T extends { round: number }>(
|
|
samples: T[],
|
|
medianTotal: number | null | undefined,
|
|
getTotal: (sample: T) => number | null | undefined,
|
|
) {
|
|
if (medianTotal == null || !Number.isFinite(medianTotal)) return null;
|
|
|
|
let selected: { round: number; distance: number } | null = null;
|
|
for (const sample of samples) {
|
|
const total = getTotal(sample);
|
|
if (total == null || !Number.isFinite(total)) continue;
|
|
|
|
const distance = Math.abs(total - medianTotal);
|
|
if (selected == null || distance < selected.distance || (distance === selected.distance && sample.round < selected.round)) {
|
|
selected = { round: sample.round, distance };
|
|
}
|
|
}
|
|
|
|
return selected?.round ?? null;
|
|
}
|