/
outbreak
/
kilocode
Обзор
Документация
Войти
/
outbreak
/
kilocode
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
webview-ui/src/utils/sampling.ts
16 строк
615 B
Chris Hasson
perf(webview): sample memory usage telemetry (#2194)
29 авг 2025, 05:32
Не верифицирован
29 авг 2025, 05:32
5d6bcc4
Код
Авторство
О чём код?
/** * Creates a sampled version of a function that only executes based on the provided sample rate. * * @param fn - The function to wrap with sampling * @param sampleRate - The sampling rate as a decimal (e.g., 0.01 for 1%, 0.1 for 10%) * @returns A new function that only executes the original function based on the sample rate */ export function createSampledFunction<T extends (...args: any[]) => any>(fn: T, sampleRate: number): T { const clampedRate = Math.max(0, Math.min(1, sampleRate)) return ((...args: Parameters<T>) => { if (Math.random() < clampedRate) { return fn(...args) } }) as T }