MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / logPerf

Function logPerf

packages/node-runtime/src/import/perf-logger.ts:35–68  ·  view source on GitHub ↗
(event: string, messagesProcessed: number, batchSize?: number)

Source from the content-addressed store, hash-verified

33}
34
35export 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
70export function logPerfDetail(detail: string): void {
71 if (currentLogFile) {

Callers 1

buildElectronLoggerFunction · 0.85

Calls 1

nowMethod · 0.45

Tested by

no test coverage detected