cli: add -prof flag
This commit is contained in:
parent
09c984ebdb
commit
ca5c3bbfff
4
.gitignore
vendored
4
.gitignore
vendored
@ -2,7 +2,7 @@
|
||||
php-parser
|
||||
*example.php
|
||||
|
||||
cpu.prof
|
||||
mem.prof
|
||||
cpu.pprof
|
||||
mem.pprof
|
||||
php7.test
|
||||
php5.test
|
||||
|
8
Makefile
8
Makefile
@ -36,12 +36,12 @@ compile: ./php5/php5.go ./php7/php7.go ./scanner/scanner.go
|
||||
goyacc -o $@ $<
|
||||
|
||||
cpu_pprof:
|
||||
GOGC=off go test -cpuprofile cpu.prof -bench=. -benchtime=20s ./php7
|
||||
go tool pprof ./php7.test cpu.prof
|
||||
GOGC=off go test -cpuprofile cpu.pprof -bench=. -benchtime=20s ./php7
|
||||
go tool pprof ./php7.test cpu.pprof
|
||||
|
||||
mem_pprof:
|
||||
GOGC=off go test -memprofile mem.prof -bench=. -benchtime=20s -benchmem ./php7
|
||||
go tool pprof -alloc_objects ./php7.test mem.prof
|
||||
GOGC=off go test -memprofile mem.pprof -bench=. -benchtime=20s -benchmem ./php7
|
||||
go tool pprof -alloc_objects ./php7.test mem.pprof
|
||||
|
||||
cpu_pprof_php5:
|
||||
GOGC=off go test -cpuprofile cpu.prof -bench=. -benchtime=20s ./php5
|
||||
|
@ -53,6 +53,7 @@ php-parser [flags] <path> ...
|
||||
| flag | type | description |
|
||||
|-------|------|----------------------------------------------|
|
||||
| -d |string| dump format: [custom, go, json, pretty-json] |
|
||||
| -prof |string| start profiler: [cpu, mem] |
|
||||
| -p | bool | show positions |
|
||||
| -c | bool | show comments |
|
||||
| -r | bool | resolve names |
|
||||
|
10
main.go
10
main.go
@ -8,6 +8,7 @@ import (
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/profile"
|
||||
"github.com/yookoala/realpath"
|
||||
"github.com/z7zmey/php-parser/parser"
|
||||
"github.com/z7zmey/php-parser/php5"
|
||||
@ -18,6 +19,7 @@ import (
|
||||
var wg sync.WaitGroup
|
||||
var usePhp5 *bool
|
||||
var dumpType string
|
||||
var profiler string
|
||||
var showPositions *bool
|
||||
var showComments *bool
|
||||
var showResolvedNs *bool
|
||||
@ -28,9 +30,17 @@ func main() {
|
||||
showComments = flag.Bool("c", false, "show comments")
|
||||
showResolvedNs = flag.Bool("r", false, "resolve names")
|
||||
flag.StringVar(&dumpType, "d", "", "dump format: [custom, go, json, pretty_json]")
|
||||
flag.StringVar(&profiler, "prof", "", "start profiler: [cpu, mem]")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
switch profiler {
|
||||
case "cpu":
|
||||
defer profile.Start(profile.ProfilePath("."), profile.NoShutdownHook).Stop()
|
||||
case "mem":
|
||||
defer profile.Start(profile.MemProfile, profile.ProfilePath("."), profile.NoShutdownHook).Stop()
|
||||
}
|
||||
|
||||
pathCh := make(chan string)
|
||||
resultCh := make(chan parser.Parser)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user