Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/function/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
// }
```
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion packages/function/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ export type FunctionProfiling = {
total?: number
}
cpu?: number
memory?: number
memory?: {
total?: number
used?: number
heap?: number
external?: number
}
size?: number
}

Expand Down
7 changes: 7 additions & 0 deletions packages/function/test/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expectType } from 'tsd'
import microlinkFn from '@microlink/function'

/** response shape */
Expand All @@ -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<number | undefined>(data.profiling.memory?.total)
expectType<number | undefined>(data.profiling.memory?.used)
expectType<number | undefined>(data.profiling.memory?.heap)
expectType<number | undefined>(data.profiling.memory?.external)
}

/** discriminated union */
Expand Down
Loading