diff --git a/packages/function/README.md b/packages/function/README.md index 6e25c8e..f875174 100644 --- a/packages/function/README.md +++ b/packages/function/README.md @@ -238,7 +238,7 @@ console.log(result.profiling) // { // phases: { install: 0, build: 120, spawn: 45, run: 890, total: 1055 }, // cpu: 234, -// memory: 8, +// memory: { total: 69996544, used: 2359296, heap: 4410880, external: 1742574 }, // size: 156 // } ``` @@ -251,7 +251,10 @@ console.log(result.profiling) | `phases.run` | Time spent executing the function. | | `phases.total` | Wall-clock time from start to finish. | | `cpu` | Peak CPU time in milliseconds. | -| `memory` | Peak memory usage in MB. | +| `memory.total` | Resident memory of the sandbox, Node.js baseline included, in bytes. | +| `memory.used` | Resident memory attributable to your function, in bytes. | +| `memory.heap` | V8 heap in use, in bytes. The only field the memory limit bounds. | +| `memory.external` | Off-heap `Buffer`/`ArrayBuffer` memory, in bytes. | | `size` | Bundled code size in bytes. | ### Plan limits diff --git a/packages/function/src/index.d.ts b/packages/function/src/index.d.ts index aaf4a7e..62de41a 100644 --- a/packages/function/src/index.d.ts +++ b/packages/function/src/index.d.ts @@ -10,7 +10,12 @@ export type FunctionProfiling = { total?: number } cpu?: number - memory?: number + memory?: { + total?: number + used?: number + heap?: number + external?: number + } size?: number } diff --git a/packages/function/test/index.test-d.ts b/packages/function/test/index.test-d.ts index 4f3c8a0..9cc48ba 100644 --- a/packages/function/test/index.test-d.ts +++ b/packages/function/test/index.test-d.ts @@ -1,3 +1,4 @@ +import { expectType } from 'tsd' import microlinkFn from '@microlink/function' /** response shape */ @@ -9,6 +10,12 @@ import microlinkFn from '@microlink/function' console.log(data.isFulfilled) console.log(data.profiling) console.log(data.logging) + + /** memory is a breakdown, not a single number */ + expectType(data.profiling.memory?.total) + expectType(data.profiling.memory?.used) + expectType(data.profiling.memory?.heap) + expectType(data.profiling.memory?.external) } /** discriminated union */