diff --git a/cmd/root.go b/cmd/root.go index 187ed04..36955b3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -28,6 +28,7 @@ Find more information at: https://github.com/qiniu/goc `, PersistentPreRun: func(cmd *cobra.Command, args []string) { + log.DisplayGoc() // init logger log.NewLogger() }, diff --git a/pkg/build/build.go b/pkg/build/build.go index 3e35dba..81b6cc4 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -37,4 +37,6 @@ func (b *Build) Build() { // inject cover vars cover.Inject() + + // build in the temp project } diff --git a/pkg/cover/agent.tpl b/pkg/cover/agent.tpl index 9421624..537c568 100644 --- a/pkg/cover/agent.tpl +++ b/pkg/cover/agent.tpl @@ -21,10 +21,16 @@ import ( var ( waitDelay time.Duration = 10 * time.Second - host string = "127.0.0.1:8080" + host string = "{{.Host}}" ) func init() { + // init host + host_env := os.Getenv("GOC_CUSTOM_HOST") + if host_env != "" { + host = host_env + } + var dialer = websocket.DefaultDialer // 永不退出,出错后统一操作为:延时 + conitnue @@ -116,9 +122,9 @@ func (ga *GocAgent) ResetProfile(req *ProfileReq, res *ProfileRes) error { return fmt.Errorf("wrong command") } - *res = `mode: atomic -qiniu.com/kodo/apiserver/server/main.go:32.49,33.13 1 30 -qiniu.com/kodo/apiserver/server/main.go:42.49,43.13 1 0` + resetValues() + + *res = `ok` return nil } @@ -162,6 +168,22 @@ func loadFileCover(coverCounters map[string][]uint32, coverBlocks map[string][]t coverBlocks[fileName] = block } +// reset counters +func resetValues() { + {{range $i, $pkgCover := .Covers}} + {{range $file, $cover := $pkgCover.Vars}} + clearFileCover(_cover.{{$cover.Var}}.Count[:]) + {{end}} + {{end}} +} + +func clearFileCover(counter []uint32) { + for i := range counter { + counter[i] = 0 + } +} + + // get process meta info for register type processInfo struct { hostname string diff --git a/pkg/log/display.go b/pkg/log/display.go new file mode 100644 index 0000000..39b7813 --- /dev/null +++ b/pkg/log/display.go @@ -0,0 +1,16 @@ +package log + +import "github.com/mgutz/ansi" + +const banner = ` + __ _ ___ ___ + / _ |/ _ \ / __| +| (_| | (_) | (__ + \__, |\___/ \___| + |___/ + +` + +func DisplayGoc() { + stdout.Write([]byte(ansi.Color(banner, "cyan+b"))) +}