Merge pull request #216 from lyyyuna/v2

some fixs
This commit is contained in:
Li Yiyang 2021-08-10 17:27:50 +08:00 committed by GitHub
commit c406e68e7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 77 additions and 15 deletions

View File

@ -11,7 +11,7 @@ jobs:
- name: Install Go - name: Install Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
with: with:
go-version: 1.14.x go-version: 1.16.x
- name: compile and release - name: compile and release
run: | run: |
./hack/release.sh ./hack/release.sh
@ -28,7 +28,7 @@ jobs:
- name: Install Go - name: Install Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
with: with:
go-version: 1.14.x go-version: 1.16.x
- name: compile and release - name: compile and release
run: | run: |
./hack/release.sh ./hack/release.sh
@ -45,7 +45,7 @@ jobs:
- name: Install Go - name: Install Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
with: with:
go-version: 1.14.x go-version: 1.16.x
- name: compile and release - name: compile and release
run: | run: |
./hack/release.sh ./hack/release.sh

55
cmd/merge.go Normal file
View File

@ -0,0 +1,55 @@
package cmd
import (
"github.com/qiniu/goc/v2/pkg/log"
"github.com/spf13/cobra"
"golang.org/x/tools/cover"
"k8s.io/test-infra/gopherage/pkg/cov"
"k8s.io/test-infra/gopherage/pkg/util"
)
var mergeCmd = &cobra.Command{
Use: "merge [files...]",
Short: "Merge multiple coherent Go coverage files into a single file.",
Long: `merge will merge multiple Go coverage files into a single coverage file.
merge requires that the files are 'coherent', meaning that if they both contain references to the
same paths, then the contents of those source files were identical for the binary that generated
each file.
`,
Run: func(cmd *cobra.Command, args []string) {
runMerge(args, outputMergeProfile)
},
}
var outputMergeProfile string
func init() {
mergeCmd.Flags().StringVarP(&outputMergeProfile, "output", "o", "mergeprofile.cov", "output file")
rootCmd.AddCommand(mergeCmd)
}
func runMerge(args []string, output string) {
if len(args) == 0 {
log.Fatalf("Expected at least one coverage file.")
}
profiles := make([][]*cover.Profile, len(args))
for _, path := range args {
profile, err := util.LoadProfile(path)
if err != nil {
log.Fatalf("failed to open %s: %v", path, err)
}
profiles = append(profiles, profile)
}
merged, err := cov.MergeMultipleProfiles(profiles)
if err != nil {
log.Fatalf("failed to merge files: %v", err)
}
err = util.DumpProfile(output, merged)
if err != nil {
log.Fatalf("fail to dump the merged file: %v", err)
}
}

View File

@ -29,7 +29,7 @@ func (b *Build) readProjectMetaInfo() {
log.Fatalf("Go module is not enabled, please set GO111MODULE=auto or on") log.Fatalf("Go module is not enabled, please set GO111MODULE=auto or on")
} }
// 工程根目录 // 工程根目录
config.GocConfig.CurModProjectDir = pkg.Root config.GocConfig.CurModProjectDir = pkg.Module.Dir
config.GocConfig.ImportPath = pkg.Module.Path config.GocConfig.ImportPath = pkg.Module.Path
break break

View File

@ -80,8 +80,8 @@ func init() {
cov := fmt.Sprintf("%s:%d.%d,%d.%d %d %d", block.name, cov := fmt.Sprintf("%s:%d.%d,%d.%d %d %d", block.name,
block.pos[3*i+0], uint16(block.pos[3*i+2]), block.pos[3*i+0], uint16(block.pos[3*i+2]),
block.pos[3*i+1], uint16(block.pos[3*i+2] >> 16), block.pos[3*i+1], uint16(block.pos[3*i+2] >> 16),
1, block.stmts,
0) 1)
err = ws.WriteMessage(websocket.TextMessage, []byte(cov)) err = ws.WriteMessage(websocket.TextMessage, []byte(cov))
if err != nil { if err != nil {
@ -128,13 +128,14 @@ func getRegisterInfo() (*processInfo, error) {
// //
type blockInfo struct { type blockInfo struct {
name string name string
pos []uint32 pos []uint32
i int i int
stmts int
} }
// UploadCoverChangeEvent_{{.Random}} is non-blocking // UploadCoverChangeEvent_{{.Random}} is non-blocking
func UploadCoverChangeEvent_{{.Random}}(name string, pos []uint32, i int) { func UploadCoverChangeEvent_{{.Random}}(name string, pos []uint32, i int, stmts uint16) {
if watchEnabled == false { if watchEnabled == false {
return return
@ -143,9 +144,10 @@ func UploadCoverChangeEvent_{{.Random}}(name string, pos []uint32, i int) {
// make sure send is non-blocking // make sure send is non-blocking
select { select {
case watchChannel <- &blockInfo{ case watchChannel <- &blockInfo{
name: name, name: name,
pos: pos, pos: pos,
i: i, i: i,
stmts: int(stmts),
}: }:
default: default:
} }

View File

@ -419,7 +419,8 @@ func atomicCounterStmt(f *File, counter string) string {
// watchCounterStmt returns the expression: __count[23]++;UploadCoverChangeEvent(blockname, pos[:], index) // watchCounterStmt returns the expression: __count[23]++;UploadCoverChangeEvent(blockname, pos[:], index)
func watchCounterStmt(f *File, counter string) string { func watchCounterStmt(f *File, counter string) string {
return fmt.Sprintf("%s++; UploadCoverChangeEvent_%v(%s.BlockName, %s.Pos[:], %v)", counter, f.random, f.varVar, f.varVar, len(f.blocks)) index := len(f.blocks)
return fmt.Sprintf("%s++; UploadCoverChangeEvent_%v(%s.BlockName, %s.Pos[:], %v, %s.NumStmt[%v])", counter, f.random, f.varVar, f.varVar, index, f.varVar, index)
} }
// QINIU // QINIU

View File

@ -43,6 +43,10 @@ func BuildCmdArgsParse(cmd *cobra.Command, args []string, cmdType int) []string
allFlagSets := cmd.Flags() allFlagSets := cmd.Flags()
// 因为 args 里面含有 go 的 flag所以需要忽略解析 go flag 的错误 // 因为 args 里面含有 go 的 flag所以需要忽略解析 go flag 的错误
allFlagSets.Init("GOC", pflag.ContinueOnError) allFlagSets.Init("GOC", pflag.ContinueOnError)
// 忽略 go flag 在 goc 中的解析错误
allFlagSets.ParseErrorsWhitelist = pflag.ParseErrorsWhitelist{
UnknownFlags: true,
}
allFlagSets.Parse(args) allFlagSets.Parse(args)
// 重写 help // 重写 help
@ -109,7 +113,7 @@ func findAndDelGocFlag(a []string, x string, v string) []string {
x = "--" + x x = "--" + x
x_v := x + "=" + v x_v := x + "=" + v
for i := 0; i < len(a); i++ { for i := 0; i < len(a); i++ {
if a[i] == "--debug" { if a[i] == "--gocdebug" {
// debug 是 bool就一个元素 // debug 是 bool就一个元素
continue continue
} else if a[i] == x { } else if a[i] == x {