Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: show pc hit count in /rawcover and /rawcoverfiles #5617

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions pkg/cover/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,26 +181,37 @@ func fileLineContents(file *file, lines [][]byte) lineCoverExport {

func (rg *ReportGenerator) DoRawCoverFiles(w io.Writer, params HandlerParams) error {
progs := fixUpPCs(rg.target.Arch, params.Progs, params.Filter)
if err := rg.symbolizePCs(uniquePCs(progs)); err != nil {
pcs := uniquePCs(progs)
if err := rg.symbolizePCs(pcs); err != nil {
return err
}

resFrames := rg.Frames

sort.Slice(resFrames, func(i, j int) bool {
fl, fr := resFrames[i], resFrames[j]
if fl.PC == fr.PC {
resFrames := make(map[uint64][]backend.Frame)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this change help you achieve?
In the current code, we already print all frames. Moreover, they used to be sorted by PC, but in your change they are now shuffled by the Go's map implementation.

for _, frame := range rg.Frames {
resFrames[frame.PC] = append(resFrames[frame.PC], frame)
}
for pc := range resFrames {
sort.Slice(resFrames[pc], func(i, j int) bool {
fl, fr := resFrames[pc][i], resFrames[pc][j]
return !fl.Inline && fr.Inline // non-inline first
}
return fl.PC < fr.PC
})
})
}

buf := bufio.NewWriter(w)
fmt.Fprintf(buf, "PC,Module,Offset,Filename,Inline,StartLine,EndLine\n")
for _, frame := range resFrames {
offset := frame.PC - frame.Module.Addr
fmt.Fprintf(buf, "0x%x,%v,0x%x,%v,%v,%v,%v\n",
frame.PC, frame.Module.Name, offset, frame.Name, frame.Inline, frame.StartLine, frame.EndLine)
var output []string
for _, pc := range pcs {
for _, frame := range resFrames[pc] {
offset := frame.PC - frame.Module.Addr
if frame.Module.Name == "" {
offset = frame.PC
}
output = append(output, fmt.Sprintf("0x%x,%v,0x%x,%v,%v,%v,%v\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the intention switching to output []string? fmt.Fprintf directly into the buf should be the most efficient way to construct a large output.

frame.PC, frame.Module.Name, offset, frame.Name, frame.Inline, frame.StartLine, frame.EndLine))
}
}
for _, line := range output {
buf.WriteString(line)
}
buf.Flush()
return nil
Expand Down