-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add memory debug log when requested via env vars
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {Effect, Layer} from 'effect' | ||
import {type DurationInput} from 'effect/Duration' | ||
|
||
const formatMemoryUsage = (data: number): string => | ||
`${Math.round((data / 1024 / 1024) * 100) / 100} MB` | ||
|
||
export const makeMemoryDebugLayer = ( | ||
logInterval: DurationInput | ||
): Layer.Layer<never> => | ||
Layer.effectDiscard( | ||
Effect.gen(function* (_) { | ||
const memoryData = yield* _(Effect.sync(() => process.memoryUsage())) | ||
|
||
const memoryUsage = { | ||
rss: `${formatMemoryUsage(memoryData.rss)} -> Resident Set Size - total memory allocated for the process execution`, | ||
heapTotal: `${formatMemoryUsage(memoryData.heapTotal)} -> total size of the allocated heap`, | ||
heapUsed: `${formatMemoryUsage(memoryData.heapUsed)} -> actual memory used during the execution`, | ||
external: `${formatMemoryUsage(memoryData.external)} -> V8 external memory`, | ||
} | ||
|
||
yield* _(Effect.logInfo('Memory usage', memoryUsage)) | ||
}).pipe( | ||
Effect.zipLeft(Effect.sleep(logInterval)), | ||
Effect.forever, | ||
Effect.fork | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters