aboutsummaryrefslogtreecommitdiff
path: root/cover
diff options
context:
space:
mode:
authorhaya14busa <haya14busa@gmail.com>2017-12-10 15:23:31 +0000
committerRob Pike <r@golang.org>2017-12-10 23:11:56 +0000
commit5d8e38b9550d35d893ff8276756b4118ec1bf360 (patch)
treed0272f23c78cdebc791a1d1faa87e401fee370fb /cover
parent9b32ad6a0077c7f766ad108c08f5852a8e0690fa (diff)
downloadgolang-x-tools-5d8e38b9550d35d893ff8276756b4118ec1bf360.tar.gz
cover: handle multiple samples from the same location
This change is ported from src/cmd/cover/profile.go[1]. Now that go test supported -coverprofile with multiple packages (#6909), x/tools/cover/profile should also handle multiple samples from the same location. [1]: https://github.com/golang/go/commit/f39050c8ebf894ccedc0b99de96f7412be97af89 Fixes golang/go#23076 Change-Id: I1b1d664bf56f7e22c6cb2726df44fb577408c6f7 Reviewed-on: https://go-review.googlesource.com/83078 Run-TryBot: Rob Pike <r@golang.org> Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'cover')
-rw-r--r--cover/profile.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/cover/profile.go b/cover/profile.go
index 958881a2a..b6c8120a5 100644
--- a/cover/profile.go
+++ b/cover/profile.go
@@ -91,6 +91,29 @@ func ParseProfiles(fileName string) ([]*Profile, error) {
}
for _, p := range files {
sort.Sort(blocksByStart(p.Blocks))
+ // Merge samples from the same location.
+ j := 1
+ for i := 1; i < len(p.Blocks); i++ {
+ b := p.Blocks[i]
+ last := p.Blocks[j-1]
+ if b.StartLine == last.StartLine &&
+ b.StartCol == last.StartCol &&
+ b.EndLine == last.EndLine &&
+ b.EndCol == last.EndCol {
+ if b.NumStmt != last.NumStmt {
+ return nil, fmt.Errorf("inconsistent NumStmt: changed from %d to %d", last.NumStmt, b.NumStmt)
+ }
+ if mode == "set" {
+ p.Blocks[j-1].Count |= b.Count
+ } else {
+ p.Blocks[j-1].Count += b.Count
+ }
+ continue
+ }
+ p.Blocks[j] = b
+ j++
+ }
+ p.Blocks = p.Blocks[:j]
}
// Generate a sorted slice.
profiles := make([]*Profile, 0, len(files))