Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/cue: add global cpuprofile and memprofile flags
Mirroring those available via `go help testflag`. These are helpful to get an idea of why a cmd/cue command is slow, for example `cue fmt --check ./...` in the CUE repo taking over 10s. The flags are global to be available for all commands, but hidden, as they should only be necessary for debugging performance issues. We can choose to un-hide them at a later point. Add a small regression test as well, with some basic checks that the pprof files get written and are minimally valid. Signed-off-by: Daniel Martí <mvdan@mvdan.cc> Change-Id: I9491fe67c6f3f8657cfa586a76fcd7bb46b3d429 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1192973 TryBot-Result: CUEcueckoo <cueckoo@cuelang.org> Reviewed-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com> Reviewed-by: Roger Peppe <rogpeppe@gmail.com> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
- Loading branch information
Showing
3 changed files
with
56 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
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,20 @@ | ||
# Grab a CPU profile and check that it's valid. | ||
exec cue eval --cpuprofile cpu.out x.cue | ||
go tool pprof -top cpu.out | ||
stdout 'Type: cpu' | ||
|
||
# Grab an allocation profile and check that it's valid. | ||
exec cue eval --memprofile mem.out x.cue | ||
go tool pprof -top mem.out | ||
stdout 'Type: inuse_space' | ||
|
||
# Both flags can be used at the same time. | ||
rm cpu.out mem.out | ||
exec cue eval --cpuprofile=cpu.out --memprofile=mem.out x.cue | ||
exists cpu.out | ||
exists mem.out | ||
|
||
-- x.cue -- | ||
a: 1 | ||
b: 2 | ||
c: a | b |