mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-25 11:44:44 +00:00
Add cpu and mem profiling options
Following https://golang.org/pkg/runtime/pprof/. When attempting to build images in https://github.com/linuxkit/kubernetes CI the process is mysteriously being SIGKILL'd, which I think might be down to OOMing due to the resource limits placed on the build container. I haven't done so yet but I'm intending to use these options to investigate and they seem potentially useful in any case, even if this turns out to be a red-herring. Signed-off-by: Ian Campbell <ijc@docker.com>
This commit is contained in:
parent
656bd87fd2
commit
9558740c11
@ -5,6 +5,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"runtime/pprof"
|
||||||
|
|
||||||
"github.com/moby/tool/src/moby"
|
"github.com/moby/tool/src/moby"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@ -60,6 +62,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
flagQuiet := flag.Bool("q", false, "Quiet execution")
|
flagQuiet := flag.Bool("q", false, "Quiet execution")
|
||||||
flagVerbose := flag.Bool("v", false, "Verbose execution")
|
flagVerbose := flag.Bool("v", false, "Verbose execution")
|
||||||
|
flagCPUProfile := flag.String("cpuprofile", "", "write cpu profile to `file`")
|
||||||
|
flagMemProfile := flag.String("memprofile", "", "write mem profile to `file`")
|
||||||
|
|
||||||
// config and cache directory
|
// config and cache directory
|
||||||
flagConfigDir := flag.String("config", defaultMobyConfigDir(), "Configuration directory")
|
flagConfigDir := flag.String("config", defaultMobyConfigDir(), "Configuration directory")
|
||||||
@ -101,6 +105,17 @@ func main() {
|
|||||||
}
|
}
|
||||||
moby.MobyDir = mobyDir
|
moby.MobyDir = mobyDir
|
||||||
|
|
||||||
|
if *flagCPUProfile != "" {
|
||||||
|
f, err := os.Create(*flagCPUProfile)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("could not create CPU profile: ", err)
|
||||||
|
}
|
||||||
|
if err := pprof.StartCPUProfile(f); err != nil {
|
||||||
|
log.Fatal("could not start CPU profile: ", err)
|
||||||
|
}
|
||||||
|
defer pprof.StopCPUProfile()
|
||||||
|
}
|
||||||
|
|
||||||
switch args[0] {
|
switch args[0] {
|
||||||
case "build":
|
case "build":
|
||||||
build(args[1:])
|
build(args[1:])
|
||||||
@ -113,4 +128,16 @@ func main() {
|
|||||||
flag.Usage()
|
flag.Usage()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *flagMemProfile != "" {
|
||||||
|
f, err := os.Create(*flagMemProfile)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("could not create memory profile: ", err)
|
||||||
|
}
|
||||||
|
runtime.GC() // get up-to-date statistics
|
||||||
|
if err := pprof.WriteHeapProfile(f); err != nil {
|
||||||
|
log.Fatal("could not write memory profile: ", err)
|
||||||
|
}
|
||||||
|
f.Close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user