add -memprofile option
parent
ee13f30435
commit
bbff114629
20
goposm.go
20
goposm.go
|
@ -16,7 +16,9 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var skipCoords, skipNodes, skipWays bool
|
var skipCoords, skipNodes, skipWays bool
|
||||||
|
@ -145,6 +147,7 @@ func parse(cache *cache.OSMCache, progress *stats.Statistics, filename string) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cpuprofile = flag.String("cpuprofile", "", "filename of cpu profile output")
|
cpuprofile = flag.String("cpuprofile", "", "filename of cpu profile output")
|
||||||
|
memprofile = flag.String("memprofile", "", "dir name of mem profile output and interval (fname:interval)")
|
||||||
cachedir = flag.String("cachedir", "/tmp/goposm", "cache directory")
|
cachedir = flag.String("cachedir", "/tmp/goposm", "cache directory")
|
||||||
overwritecache = flag.Bool("overwritecache", false, "overwritecache")
|
overwritecache = flag.Bool("overwritecache", false, "overwritecache")
|
||||||
appendcache = flag.Bool("appendcache", false, "append cache")
|
appendcache = flag.Bool("appendcache", false, "append cache")
|
||||||
|
@ -168,6 +171,23 @@ func main() {
|
||||||
defer pprof.StopCPUProfile()
|
defer pprof.StopCPUProfile()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *memprofile != "" {
|
||||||
|
parts := strings.Split(*memprofile, string(os.PathListSeparator))
|
||||||
|
var interval time.Duration
|
||||||
|
|
||||||
|
if len(parts) < 2 {
|
||||||
|
interval, _ = time.ParseDuration("1m")
|
||||||
|
} else {
|
||||||
|
var err error
|
||||||
|
interval, err = time.ParseDuration(parts[1])
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
go stats.MemProfiler(parts[0], interval)
|
||||||
|
}
|
||||||
|
|
||||||
osmCache := cache.NewOSMCache(*cachedir)
|
osmCache := cache.NewOSMCache(*cachedir)
|
||||||
|
|
||||||
if *read != "" && osmCache.Exists() {
|
if *read != "" && osmCache.Exists() {
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package stats
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"runtime/pprof"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func MemProfiler(dir string, interval time.Duration) {
|
||||||
|
if err := os.MkdirAll(dir, 0750); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ticker := time.NewTicker(interval)
|
||||||
|
i := 0
|
||||||
|
for _ = range ticker.C {
|
||||||
|
filename := path.Join(
|
||||||
|
dir,
|
||||||
|
fmt.Sprintf("memprof-%03d.pprof", i),
|
||||||
|
)
|
||||||
|
f, err := os.Create(filename)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
pprof.WriteHeapProfile(f)
|
||||||
|
f.Close()
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue