]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cover: handle multiple samples from the same location
authorKeith Randall <khr@golang.org>
Mon, 6 Jun 2016 23:58:27 +0000 (16:58 -0700)
committerKeith Randall <khr@golang.org>
Fri, 18 Nov 2016 20:44:52 +0000 (20:44 +0000)
So we can merge cover profiles from multiple runs.

Change-Id: I1bf921e2b02063a2a62b35d21a6823062d10e5d0
Reviewed-on: https://go-review.googlesource.com/23831
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
src/cmd/cover/profile.go

index a03b5d532a4d7633e88965a22fe54826a16e44eb..5628b91f51990398eca4291c490d8ffb096f4a83 100644 (file)
@@ -93,6 +93,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))