diff --git a/main.js b/main.js index 7c7c938..3a22ca7 100644 --- a/main.js +++ b/main.js @@ -1,3 +1,5 @@ +process.env.UV_THREADPOOL_SIZE = process.env.UV_THREADPOOL_SIZE || '64'; +const { monitorEventLoopDelay } = require('perf_hooks'); const { app, BrowserWindow, ipcMain, dialog, clipboard, nativeTheme, Tray, Menu } = require('electron'); nativeTheme.themeSource = 'dark'; const path = require('path'); @@ -25,6 +27,10 @@ const stats = require('./lib/stats'); const { createCollectors } = require('./lib/diagnostics-collectors'); const { createAgent } = require('./lib/diagnostics-agent'); +const _eventLoopDelay = monitorEventLoopDelay({ resolution: 10 }); +_eventLoopDelay.enable(); +let _eldLastLog = 0; + let mainWindow; let _lastImportPath = null; let dropTargetWindow = null; @@ -181,6 +187,21 @@ function logMarker(label, fields) { debugLog(`────── ${label}${extra} ──────`); } +function _maybeLogEventLoopDelay(activeJobs) { + const now = Date.now(); + if (now - _eldLastLog < 5000) return; + _eldLastLog = now; + try { + const ns = 1e6; + const mean = (_eventLoopDelay.mean / ns).toFixed(1); + const max = (_eventLoopDelay.max / ns).toFixed(1); + const p99 = (_eventLoopDelay.percentile(99) / ns).toFixed(1); + const stddev = (_eventLoopDelay.stddev / ns).toFixed(1); + logInfo('perf', `eventloop-delay active=${activeJobs} mean=${mean}ms p99=${p99}ms max=${max}ms stddev=${stddev}ms threadpool=${process.env.UV_THREADPOOL_SIZE}`); + _eventLoopDelay.reset(); + } catch {} +} + // Dedicated account-rotation log so users can trace fallback decisions // without wading through general debug output. Writes to account-rotation.log // in the same directory as fileuploader.log (honors user's configured path). @@ -1705,6 +1726,7 @@ ipcMain.handle('start-upload', (_event, payload) => { if (data.state === 'uploading' && data.activeJobs > 0) { const speedMb = ((Number(data.globalSpeedKbs) || 0) / 1024).toFixed(1); updateTrayTooltip(`Upload: ${data.activeJobs} aktiv - ${speedMb} MB/s`); + _maybeLogEventLoopDelay(data.activeJobs); } else { updateTrayTooltip('Multi-Hoster-Upload'); }