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