Documentation
¶
Overview ¶
memprofile is a memory profiling harness for the orast parser and printer.
It measures how much heap a single SQL file costs, and writes heap profiles (pprof format) so the allocation sites can be inspected with:
go tool pprof -top -sample_index=inuse_space <bin> <profile> go tool pprof -top -sample_index=alloc_space <bin> <profile>
Safety model — a pathological file must never exhaust system memory:
- Every file is profiled in an ISOLATED CHILD PROCESS, so a runaway allocation or an infinite loop cannot take down the whole batch.
- Each child runs under a wall-clock TIMEOUT; on expiry it dumps a heap profile plus a goroutine stack dump, then exits.
- Each child runs under a HARD HEAP CEILING enforced by a watchdog that polls runtime.MemStats. When the heap crosses the ceiling the child dumps a heap profile and exits before the OS runs out of memory.
- The supervisor holds an outer deadline (timeout + -grace) and kills a child that fails to honour its own timeout.
Usage:
# profile every .sql under a directory, validate mode (no AST built)
go run ./test/cmd/memprofile -dir D:\WORK\DOHERP\dbscript\version00000001 \
-mode validate -memlimit 1024 -timeout 30s
# full AST parse of the 50 largest files, profiling anything over 256 MiB
go run ./test/cmd/memprofile -dir <dir> -mode parse -largest 50 \
-profile-above 256 -profile memprof_out
# one file, verbose (runs the child path directly, no supervisor)
go run ./test/cmd/memprofile -single big.sql -mode parse -v
Source Files
¶
- main.go
- rss_other.go