(event: string, messagesProcessed: number, batchSize?: number)
| 33 | } |
| 34 | |
| 35 | export function logPerf(event: string, messagesProcessed: number, batchSize?: number): void { |
| 36 | const now = Date.now() |
| 37 | const duration = now - lastLogTime |
| 38 | const messagesDelta = messagesProcessed - lastMessageCount |
| 39 | const speed = duration > 0 ? Math.round((messagesDelta / duration) * 1000) : 0 |
| 40 | |
| 41 | let memory = 0 |
| 42 | try { |
| 43 | const used = process.memoryUsage() |
| 44 | memory = Math.round(used.heapUsed / 1024 / 1024) |
| 45 | } catch { |
| 46 | // Ignore |
| 47 | } |
| 48 | |
| 49 | const logLine = |
| 50 | `[${new Date().toISOString()}] ${event} | ` + |
| 51 | `messages: ${messagesProcessed.toLocaleString()} | ` + |
| 52 | `elapsed: ${duration}ms | ` + |
| 53 | `speed: ${speed.toLocaleString()}/s | ` + |
| 54 | `memory: ${memory}MB` + |
| 55 | (batchSize ? ` | batch: ${batchSize}` : '') + |
| 56 | '\n' |
| 57 | |
| 58 | if (currentLogFile) { |
| 59 | try { |
| 60 | fs.appendFileSync(currentLogFile, logLine, 'utf-8') |
| 61 | } catch { |
| 62 | // Ignore write failure |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | lastLogTime = now |
| 67 | lastMessageCount = messagesProcessed |
| 68 | } |
| 69 | |
| 70 | export function logPerfDetail(detail: string): void { |
| 71 | if (currentLogFile) { |
no test coverage detected