Skip to content

Commit 81efdbc

Browse files
6543ianlancetaylor
authored andcommitted
cover: add function to parse profiles from an io.Reader
Fixes golang/go#19404 Change-Id: I893fbb999bb8d0a6c62ab8752790fce75912be0c GitHub-Last-Rev: 101a2f5 GitHub-Pull-Request: #331 Reviewed-on: https://go-review.googlesource.com/c/tools/+/336329 Reviewed-by: Bryan C. Mills <[email protected]> Trust: Bryan C. Mills <[email protected]> Trust: Michael Knyszek <[email protected]>
1 parent 36e7bf9 commit 81efdbc

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

cover/profile.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"bufio"
1111
"errors"
1212
"fmt"
13+
"io"
1314
"math"
1415
"os"
1516
"sort"
@@ -45,14 +46,18 @@ func ParseProfiles(fileName string) ([]*Profile, error) {
4546
return nil, err
4647
}
4748
defer pf.Close()
49+
return ParseProfilesFromReader(pf)
50+
}
4851

49-
files := make(map[string]*Profile)
50-
buf := bufio.NewReader(pf)
52+
// ParseProfilesFromReader parses profile data from the Reader and
53+
// returns a Profile for each source file described therein.
54+
func ParseProfilesFromReader(rd io.Reader) ([]*Profile, error) {
5155
// First line is "mode: foo", where foo is "set", "count", or "atomic".
5256
// Rest of file is in the format
5357
// encoding/base64/base64.go:34.44,37.40 3 1
5458
// where the fields are: name.go:line.column,line.column numberOfStatements count
55-
s := bufio.NewScanner(buf)
59+
files := make(map[string]*Profile)
60+
s := bufio.NewScanner(rd)
5661
mode := ""
5762
for s.Scan() {
5863
line := s.Text()

0 commit comments

Comments
 (0)